@@ -28,17 +28,34 @@ func (indexer *Indexer) GetAllClients() []*Client {
2828}
2929
3030// GetReadyClientsByCheckpoint returns a slice of clients that are ready for processing based on the finalized root and preference for archive clients.
31- func (indexer * Indexer ) GetReadyClientsByCheckpoint (finalizedRoot phase0.Root , preferArchive bool ) []* Client {
31+ func (indexer * Indexer ) GetReadyClientsByCheckpoint (finalizedEpoch phase0. Epoch , finalizedRoot phase0.Root , preferArchive bool ) []* Client {
3232 clients := make ([]* Client , 0 )
3333
34+ finalizedSlot := indexer .consensusPool .GetChainState ().EpochToSlot (finalizedEpoch )
35+
3436 for _ , client := range indexer .clients {
3537 if client .client .GetStatus () != consensus .ClientStatusOnline {
3638 continue
3739 }
3840
3941 _ , root , _ , _ := client .client .GetFinalityCheckpoint ()
40- if ! bytes .Equal (root [:], finalizedRoot [:]) && ! bytes .Equal (root [:], consensus .NullRoot [:]) {
41- continue
42+ if ! bytes .Equal (root [:], finalizedRoot [:]) {
43+ block := indexer .blockCache .getBlockByRoot (root )
44+ if block == nil {
45+ // block is not in the cache, probably a very old block before the finalizatio checkpoint
46+ continue
47+ }
48+
49+ if block .Slot < finalizedSlot {
50+ // block is before the finalized slot, so client is lagging behind
51+ continue
52+ }
53+
54+ isInChain , _ := indexer .blockCache .getCanonicalDistance (finalizedRoot , root , 0 )
55+ if ! isInChain {
56+ // block is not in the canonical chain, so client is on a different fork
57+ continue
58+ }
4259 }
4360
4461 clients = append (clients , client )
@@ -101,10 +118,10 @@ func (indexer *Indexer) GetReadyClientByBlockRoot(blockRoot phase0.Root, preferA
101118
102119// GetReadyClients returns a slice of clients that are on the finalized chain and preference for archive clients.
103120func (indexer * Indexer ) GetReadyClients (preferArchive bool ) []* Client {
104- _ , finalizedRoot := indexer .consensusPool .GetChainState ().GetFinalizedCheckpoint ()
105- clients := indexer .GetReadyClientsByCheckpoint (finalizedRoot , preferArchive )
121+ finalizedEpoch , finalizedRoot := indexer .consensusPool .GetChainState ().GetFinalizedCheckpoint ()
122+ clients := indexer .GetReadyClientsByCheckpoint (finalizedEpoch , finalizedRoot , preferArchive )
106123 if len (clients ) == 0 {
107- clients = indexer .GetReadyClientsByCheckpoint (consensus .NullRoot , preferArchive )
124+ clients = indexer .GetReadyClientsByCheckpoint (finalizedEpoch , consensus .NullRoot , preferArchive )
108125 }
109126 return clients
110127}
0 commit comments