@@ -452,17 +452,16 @@ func (a *APIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.
452
452
return nil , errors .New ("invalid arguments; neither block nor hash specified" )
453
453
}
454
454
455
- func ( a * APIBackend ) stateAndHeaderFromHeader ( ctx context.Context , header * types.Header , err error ) (* state.StateDB , * types.Header , error ) {
455
+ func StateAndHeaderFromHeader ( ctx context.Context , chainDb ethdb. Database , bc * core. BlockChain , maxRecreateStateDepth int64 , header * types.Header , err error ) (* state.StateDB , * types.Header , error ) {
456
456
if err != nil {
457
457
return nil , header , err
458
458
}
459
459
if header == nil {
460
460
return nil , nil , errors .New ("header not found" )
461
461
}
462
- if ! a . BlockChain () .Config ().IsArbitrumNitro (header .Number ) {
462
+ if ! bc .Config ().IsArbitrumNitro (header .Number ) {
463
463
return nil , header , types .ErrUseFallback
464
464
}
465
- bc := a .BlockChain ()
466
465
stateFor := func (db state.Database , snapshots * snapshot.Tree ) func (header * types.Header ) (* state.StateDB , StateReleaseFunc , error ) {
467
466
return func (header * types.Header ) (* state.StateDB , StateReleaseFunc , error ) {
468
467
if header .Root != (common.Hash {}) {
@@ -495,8 +494,8 @@ func (a *APIBackend) stateAndHeaderFromHeader(ctx context.Context, header *types
495
494
// note: triedb cleans cache is disabled in trie.HashDefaults
496
495
// note: only states committed to diskdb can be found as we're creating new triedb
497
496
// note: snapshots are not used here
498
- ephemeral := state .NewDatabaseWithConfig (a . ChainDb () , trie .HashDefaults )
499
- lastState , lastHeader , lastStateRelease , err := FindLastAvailableState (ctx , bc , stateFor (ephemeral , nil ), header , nil , a . b . config . MaxRecreateStateDepth )
497
+ ephemeral := state .NewDatabaseWithConfig (chainDb , trie .HashDefaults )
498
+ lastState , lastHeader , lastStateRelease , err := FindLastAvailableState (ctx , bc , stateFor (ephemeral , nil ), header , nil , maxRecreateStateDepth )
500
499
if err != nil {
501
500
return nil , nil , err
502
501
}
@@ -521,7 +520,7 @@ func (a *APIBackend) stateAndHeaderFromHeader(ctx context.Context, header *types
521
520
reexec := uint64 (0 )
522
521
checkLive := false
523
522
preferDisk := false // preferDisk is ignored in this case
524
- statedb , release , err := eth .NewArbEthereum (a . b . arb . BlockChain (), a . ChainDb () ).StateAtBlock (ctx , targetBlock , reexec , lastState , lastBlock , checkLive , preferDisk )
523
+ statedb , release , err := eth .NewArbEthereum (bc , chainDb ).StateAtBlock (ctx , targetBlock , reexec , lastState , lastBlock , checkLive , preferDisk )
525
524
if err != nil {
526
525
return nil , nil , fmt .Errorf ("failed to recreate state: %w" , err )
527
526
}
@@ -536,7 +535,7 @@ func (a *APIBackend) stateAndHeaderFromHeader(ctx context.Context, header *types
536
535
537
536
func (a * APIBackend ) StateAndHeaderByNumber (ctx context.Context , number rpc.BlockNumber ) (* state.StateDB , * types.Header , error ) {
538
537
header , err := a .HeaderByNumber (ctx , number )
539
- return a . stateAndHeaderFromHeader ( ctx , header , err )
538
+ return StateAndHeaderFromHeader ( ctx , a . ChainDb (), a . b . arb . BlockChain (), a . b . config . MaxRecreateStateDepth , header , err )
540
539
}
541
540
542
541
func (a * APIBackend ) StateAndHeaderByNumberOrHash (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash ) (* state.StateDB , * types.Header , error ) {
@@ -547,7 +546,7 @@ func (a *APIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOr
547
546
if ishash && header != nil && header .Number .Cmp (bc .CurrentBlock ().Number ) > 0 && bc .GetCanonicalHash (header .Number .Uint64 ()) != hash {
548
547
return nil , nil , errors .New ("requested block ahead of current block and the hash is not currently canonical" )
549
548
}
550
- return a . stateAndHeaderFromHeader ( ctx , header , err )
549
+ return StateAndHeaderFromHeader ( ctx , a . ChainDb (), a . b . arb . BlockChain (), a . b . config . MaxRecreateStateDepth , header , err )
551
550
}
552
551
553
552
func (a * APIBackend ) StateAtBlock (ctx context.Context , block * types.Block , reexec uint64 , base * state.StateDB , checkLive bool , preferDisk bool ) (statedb * state.StateDB , release tracers.StateReleaseFunc , err error ) {
0 commit comments