Skip to content

Commit 51ff426

Browse files
Merge pull request #364 from OffchainLabs/remove-advancestateuptoblock-func
Remove AdvanceStateUpToBlock function
2 parents 2ab7e39 + 5a10a61 commit 51ff426

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

arbitrum/recordingdb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (r *RecordingDatabase) GetOrRecreateState(ctx context.Context, header *type
322322
returnedBlockNumber := header.Number.Uint64()
323323
for ctx.Err() == nil {
324324
var block *types.Block
325-
state, block, err = AdvanceStateByBlock(ctx, r.bc, state, header, blockToRecreate, prevHash, logFunc)
325+
state, block, err = AdvanceStateByBlock(ctx, r.bc, state, blockToRecreate, prevHash, logFunc)
326326
if err != nil {
327327
return nil, err
328328
}

arbitrum/recreatestate.go

+4-25
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type StateReleaseFunc tracers.StateReleaseFunc
2121

2222
var NoopStateRelease StateReleaseFunc = func() {}
2323

24-
type StateBuildingLogFunction func(targetHeader, header *types.Header, hasState bool)
24+
type StateBuildingLogFunction func(header *types.Header, hasState bool)
2525
type StateForHeaderFunction func(header *types.Header) (*state.StateDB, StateReleaseFunc, error)
2626

2727
// finds last available state and header checking it first for targetHeader then looking backwards
@@ -56,7 +56,7 @@ func FindLastAvailableState(ctx context.Context, bc *core.BlockChain, stateFor S
5656
return nil, lastHeader, nil, err
5757
}
5858
if logFunc != nil {
59-
logFunc(targetHeader, currentHeader, false)
59+
logFunc(currentHeader, false)
6060
}
6161
if currentHeader.Number.Uint64() <= genesis {
6262
return nil, lastHeader, nil, errors.Wrap(err, fmt.Sprintf("moved beyond genesis looking for state %d, genesis %d", targetHeader.Number.Uint64(), genesis))
@@ -69,7 +69,7 @@ func FindLastAvailableState(ctx context.Context, bc *core.BlockChain, stateFor S
6969
return state, currentHeader, release, ctx.Err()
7070
}
7171

72-
func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state.StateDB, targetHeader *types.Header, blockToRecreate uint64, prevBlockHash common.Hash, logFunc StateBuildingLogFunction) (*state.StateDB, *types.Block, error) {
72+
func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state.StateDB, blockToRecreate uint64, prevBlockHash common.Hash, logFunc StateBuildingLogFunction) (*state.StateDB, *types.Block, error) {
7373
block := bc.GetBlockByNumber(blockToRecreate)
7474
if block == nil {
7575
return nil, nil, fmt.Errorf("block not found while recreating: %d", blockToRecreate)
@@ -78,32 +78,11 @@ func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state.
7878
return nil, nil, fmt.Errorf("reorg detected: number %d expectedPrev: %v foundPrev: %v", blockToRecreate, prevBlockHash, block.ParentHash())
7979
}
8080
if logFunc != nil {
81-
logFunc(targetHeader, block.Header(), true)
81+
logFunc(block.Header(), true)
8282
}
8383
_, _, _, err := bc.Processor().Process(block, state, vm.Config{})
8484
if err != nil {
8585
return nil, nil, fmt.Errorf("failed recreating state for block %d : %w", blockToRecreate, err)
8686
}
8787
return state, block, nil
8888
}
89-
90-
func AdvanceStateUpToBlock(ctx context.Context, bc *core.BlockChain, state *state.StateDB, targetHeader *types.Header, lastAvailableHeader *types.Header, logFunc StateBuildingLogFunction) (*state.StateDB, error) {
91-
returnedBlockNumber := targetHeader.Number.Uint64()
92-
blockToRecreate := lastAvailableHeader.Number.Uint64() + 1
93-
prevHash := lastAvailableHeader.Hash()
94-
for ctx.Err() == nil {
95-
state, block, err := AdvanceStateByBlock(ctx, bc, state, targetHeader, blockToRecreate, prevHash, logFunc)
96-
if err != nil {
97-
return nil, err
98-
}
99-
prevHash = block.Hash()
100-
if blockToRecreate >= returnedBlockNumber {
101-
if block.Hash() != targetHeader.Hash() {
102-
return nil, fmt.Errorf("blockHash doesn't match when recreating number: %d expected: %v got: %v", blockToRecreate, targetHeader.Hash(), block.Hash())
103-
}
104-
return state, nil
105-
}
106-
blockToRecreate++
107-
}
108-
return nil, ctx.Err()
109-
}

0 commit comments

Comments
 (0)