@@ -36,7 +36,7 @@ import {
36
36
import { CheckpointWithHex , ExecutionStatus , IForkChoice , ProtoBlock , UpdateHeadOpt } from "@lodestar/fork-choice" ;
37
37
import { ProcessShutdownCallback } from "@lodestar/validator" ;
38
38
import { Logger , gweiToWei , isErrorAborted , pruneSetToMax , sleep , toHex } from "@lodestar/utils" ;
39
- import { ForkSeq , SLOTS_PER_EPOCH } from "@lodestar/params" ;
39
+ import { ForkSeq , GENESIS_SLOT , SLOTS_PER_EPOCH } from "@lodestar/params" ;
40
40
41
41
import { GENESIS_EPOCH , ZERO_HASH } from "../constants/index.js" ;
42
42
import { IBeaconDb } from "../db/index.js" ;
@@ -430,7 +430,11 @@ export class BeaconChain implements IBeaconChain {
430
430
{ dontTransferCache : true } ,
431
431
RegenCaller . restApi
432
432
) ;
433
- return { state, executionOptimistic : isOptimisticBlock ( block ) , finalized : slot === finalizedBlock . slot } ;
433
+ return {
434
+ state,
435
+ executionOptimistic : isOptimisticBlock ( block ) ,
436
+ finalized : slot === finalizedBlock . slot && finalizedBlock . slot !== GENESIS_SLOT ,
437
+ } ;
434
438
} else {
435
439
// Just check if state is already in the cache. If it's not dialed to the correct slot,
436
440
// do not bother in advancing the state. restApiCanTriggerRegen == false means do no work
@@ -440,7 +444,13 @@ export class BeaconChain implements IBeaconChain {
440
444
}
441
445
442
446
const state = this . regen . getStateSync ( block . stateRoot ) ;
443
- return state && { state, executionOptimistic : isOptimisticBlock ( block ) , finalized : slot === finalizedBlock . slot } ;
447
+ return (
448
+ state && {
449
+ state,
450
+ executionOptimistic : isOptimisticBlock ( block ) ,
451
+ finalized : slot === finalizedBlock . slot && finalizedBlock . slot !== GENESIS_SLOT ,
452
+ }
453
+ ) ;
444
454
}
445
455
} else {
446
456
// request for finalized state
@@ -458,10 +468,11 @@ export class BeaconChain implements IBeaconChain {
458
468
if ( opts ?. allowRegen ) {
459
469
const state = await this . regen . getState ( stateRoot , RegenCaller . restApi ) ;
460
470
const block = this . forkChoice . getBlock ( state . latestBlockHeader . hashTreeRoot ( ) ) ;
471
+ const finalizedEpoch = this . forkChoice . getFinalizedCheckpoint ( ) . epoch ;
461
472
return {
462
473
state,
463
474
executionOptimistic : block != null && isOptimisticBlock ( block ) ,
464
- finalized : state . epochCtx . epoch <= this . forkChoice . getFinalizedCheckpoint ( ) . epoch ,
475
+ finalized : state . epochCtx . epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH ,
465
476
} ;
466
477
}
467
478
@@ -473,10 +484,11 @@ export class BeaconChain implements IBeaconChain {
473
484
const cachedStateCtx = this . regen . getStateSync ( stateRoot ) ;
474
485
if ( cachedStateCtx ) {
475
486
const block = this . forkChoice . getBlock ( cachedStateCtx . latestBlockHeader . hashTreeRoot ( ) ) ;
487
+ const finalizedEpoch = this . forkChoice . getFinalizedCheckpoint ( ) . epoch ;
476
488
return {
477
489
state : cachedStateCtx ,
478
490
executionOptimistic : block != null && isOptimisticBlock ( block ) ,
479
- finalized : cachedStateCtx . epochCtx . epoch <= this . forkChoice . getFinalizedCheckpoint ( ) . epoch ,
491
+ finalized : cachedStateCtx . epochCtx . epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH ,
480
492
} ;
481
493
}
482
494
@@ -491,10 +503,11 @@ export class BeaconChain implements IBeaconChain {
491
503
const cachedStateCtx = this . regen . getCheckpointStateSync ( checkpoint ) ;
492
504
if ( cachedStateCtx ) {
493
505
const block = this . forkChoice . getBlock ( cachedStateCtx . latestBlockHeader . hashTreeRoot ( ) ) ;
506
+ const finalizedEpoch = this . forkChoice . getFinalizedCheckpoint ( ) . epoch ;
494
507
return {
495
508
state : cachedStateCtx ,
496
509
executionOptimistic : block != null && isOptimisticBlock ( block ) ,
497
- finalized : cachedStateCtx . epochCtx . epoch <= this . forkChoice . getFinalizedCheckpoint ( ) . epoch ,
510
+ finalized : cachedStateCtx . epochCtx . epoch <= finalizedEpoch && finalizedEpoch !== GENESIS_EPOCH ,
498
511
} ;
499
512
}
500
513
0 commit comments