diff --git a/arbitrum/recordingdb.go b/arbitrum/recordingdb.go index ef1aa730a6..f7fd017520 100644 --- a/arbitrum/recordingdb.go +++ b/arbitrum/recordingdb.go @@ -322,7 +322,7 @@ func (r *RecordingDatabase) GetOrRecreateState(ctx context.Context, header *type returnedBlockNumber := header.Number.Uint64() for ctx.Err() == nil { var block *types.Block - state, block, err = AdvanceStateByBlock(ctx, r.bc, state, header, blockToRecreate, prevHash, logFunc) + state, block, err = AdvanceStateByBlock(ctx, r.bc, state, blockToRecreate, prevHash, logFunc) if err != nil { return nil, err } diff --git a/arbitrum/recreatestate.go b/arbitrum/recreatestate.go index bd16c9d3a9..2b433b2974 100644 --- a/arbitrum/recreatestate.go +++ b/arbitrum/recreatestate.go @@ -21,7 +21,7 @@ type StateReleaseFunc tracers.StateReleaseFunc var NoopStateRelease StateReleaseFunc = func() {} -type StateBuildingLogFunction func(targetHeader, header *types.Header, hasState bool) +type StateBuildingLogFunction func(header *types.Header, hasState bool) type StateForHeaderFunction func(header *types.Header) (*state.StateDB, StateReleaseFunc, error) // 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 return nil, lastHeader, nil, err } if logFunc != nil { - logFunc(targetHeader, currentHeader, false) + logFunc(currentHeader, false) } if currentHeader.Number.Uint64() <= genesis { 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 return state, currentHeader, release, ctx.Err() } -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) { +func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state.StateDB, blockToRecreate uint64, prevBlockHash common.Hash, logFunc StateBuildingLogFunction) (*state.StateDB, *types.Block, error) { block := bc.GetBlockByNumber(blockToRecreate) if block == nil { return nil, nil, fmt.Errorf("block not found while recreating: %d", blockToRecreate) @@ -78,7 +78,7 @@ func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state. return nil, nil, fmt.Errorf("reorg detected: number %d expectedPrev: %v foundPrev: %v", blockToRecreate, prevBlockHash, block.ParentHash()) } if logFunc != nil { - logFunc(targetHeader, block.Header(), true) + logFunc(block.Header(), true) } _, _, _, err := bc.Processor().Process(block, state, vm.Config{}) if err != nil { @@ -86,24 +86,3 @@ func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state. } return state, block, nil } - -func AdvanceStateUpToBlock(ctx context.Context, bc *core.BlockChain, state *state.StateDB, targetHeader *types.Header, lastAvailableHeader *types.Header, logFunc StateBuildingLogFunction) (*state.StateDB, error) { - returnedBlockNumber := targetHeader.Number.Uint64() - blockToRecreate := lastAvailableHeader.Number.Uint64() + 1 - prevHash := lastAvailableHeader.Hash() - for ctx.Err() == nil { - state, block, err := AdvanceStateByBlock(ctx, bc, state, targetHeader, blockToRecreate, prevHash, logFunc) - if err != nil { - return nil, err - } - prevHash = block.Hash() - if blockToRecreate >= returnedBlockNumber { - if block.Hash() != targetHeader.Hash() { - return nil, fmt.Errorf("blockHash doesn't match when recreating number: %d expected: %v got: %v", blockToRecreate, targetHeader.Hash(), block.Hash()) - } - return state, nil - } - blockToRecreate++ - } - return nil, ctx.Err() -}