Skip to content

Commit

Permalink
bugfix: modified logic around looking up etxs in state processor in c…
Browse files Browse the repository at this point in the history
…ase of needing to rebuild state
  • Loading branch information
kiltsonfire authored and gameofpointers committed Aug 23, 2023
1 parent efd66b4 commit 9de8edc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ func (p *StateProcessor) ContractCodeWithPrefix(hash common.Hash) ([]byte, error
func (p *StateProcessor) StateAtBlock(block *types.Block, reexec uint64, base *state.StateDB, checkLive bool) (statedb *state.StateDB, err error) {
var (
current *types.Block
etxSet types.EtxSet
database state.Database
report = true
origin = block.NumberU64()
Expand All @@ -630,7 +629,7 @@ func (p *StateProcessor) StateAtBlock(block *types.Block, reexec uint64, base *s
return statedb, nil
}
}
etxSet = rawdb.ReadEtxSet(p.hc.bc.db, block.Hash(), block.NumberU64())

if base != nil {
// The optional base statedb is given, mark the start point as parent block
statedb, database, report = base, base.Database(), false
Expand Down Expand Up @@ -689,11 +688,17 @@ func (p *StateProcessor) StateAtBlock(block *types.Block, reexec uint64, base *s
log.Info("Regenerating historical state", "block", current.NumberU64()+1, "target", origin, "remaining", origin-current.NumberU64()-1, "elapsed", time.Since(start))
logged = time.Now()
}

// Retrieve the next block to regenerate and process it
next := current.NumberU64() + 1
if current = p.hc.GetBlockByNumber(next); current == nil {
return nil, fmt.Errorf("block #%d not found", next)
}

etxSet := rawdb.ReadEtxSet(p.hc.bc.db, current.ParentHash(), current.NumberU64()-1)
inboundEtxs := rawdb.ReadInboundEtxs(p.hc.bc.db, current.Hash())
etxSet.Update(inboundEtxs, current.NumberU64())

_, _, _, _, err := p.Process(current, etxSet)
if err != nil {
return nil, fmt.Errorf("processing block %d failed: %v", current.NumberU64(), err)
Expand Down

0 comments on commit 9de8edc

Please sign in to comment.