Skip to content

Commit

Permalink
Recreate statedb after Commit() in RecordingDb
Browse files Browse the repository at this point in the history
statedb must now be recreated after Commit is called on it, see
ethereum/go-ethereum#27428
  • Loading branch information
Tristan-Wilson committed Oct 27, 2023
1 parent 2a53ab6 commit 627e5f3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions arbitrum/recordingdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ func (r *RecordingDatabase) dereferenceRoot(root common.Hash) {
r.db.TrieDB().Dereference(root)
}

func (r *RecordingDatabase) addStateVerify(statedb *state.StateDB, expected common.Hash, blockNumber uint64) error {
func (r *RecordingDatabase) addStateVerify(statedb *state.StateDB, expected common.Hash, blockNumber uint64) (*state.StateDB, error) {
r.mutex.Lock()
defer r.mutex.Unlock()
result, err := statedb.Commit(blockNumber, true)
if err != nil {
return err
return nil, err
}
if result != expected {
return fmt.Errorf("bad root hash expected: %v got: %v", expected, result)
return nil, fmt.Errorf("bad root hash expected: %v got: %v", expected, result)
}
r.referenceRootLockHeld(result)

Expand All @@ -250,7 +250,7 @@ func (r *RecordingDatabase) addStateVerify(statedb *state.StateDB, expected comm
size, _ = r.db.TrieDB().Size()
recordingDbSize.Update(int64(size))
}
return nil
return state.New(result, statedb.Database(), nil)
}

func (r *RecordingDatabase) PrepareRecording(ctx context.Context, lastBlockHeader *types.Header, logFunc StateBuildingLogFunction) (*state.StateDB, core.ChainContext, *RecordingKV, error) {
Expand Down Expand Up @@ -319,12 +319,13 @@ func (r *RecordingDatabase) GetOrRecreateState(ctx context.Context, header *type
prevHash := currentHeader.Hash()
returnedBlockNumber := header.Number.Uint64()
for ctx.Err() == nil {
state, block, err := AdvanceStateByBlock(ctx, r.bc, state, header, blockToRecreate, prevHash, logFunc)
var block *types.Block
state, block, err = AdvanceStateByBlock(ctx, r.bc, state, header, blockToRecreate, prevHash, logFunc)
if err != nil {
return nil, err
}
prevHash = block.Hash()
err = r.addStateVerify(state, block.Root(), block.NumberU64())
state, err = r.addStateVerify(state, block.Root(), block.NumberU64())
if err != nil {
return nil, fmt.Errorf("failed committing state for block %d : %w", blockToRecreate, err)
}
Expand Down

0 comments on commit 627e5f3

Please sign in to comment.