Skip to content

Commit

Permalink
Merge pull request #232 from ethpandaops/pk910/purge-parent-fork-ids-…
Browse files Browse the repository at this point in the history
…cache

fix fork detection for forks starting before the finalized checkpoint
  • Loading branch information
pk910 authored Feb 7, 2025
2 parents 815cea4 + d275fbc commit eb936f5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions indexer/beacon/forkdetection.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ func (cache *forkCache) processBlock(block *Block) error {
otherChildren = append(otherChildren, child)
}

if parentIsFinalized {
// parent is finalized, so blocks building on top of it might be finalized as well.
// check if we have other finalized blocks building on top of the parent in the database
for _, child := range db.GetSlotsByParentRoot((*parentRoot)[:]) {
if bytes.Equal(child.Root, block.Root[:]) {
continue
}

otherChildren = append(otherChildren, newBlock(cache.indexer.dynSsz, phase0.Root(child.Root), phase0.Slot(child.Slot)))
}
}

if len(otherChildren) > 0 {
logbuf := strings.Builder{}

Expand Down Expand Up @@ -227,6 +239,9 @@ func (cache *forkCache) processBlock(block *Block) error {

// persist new forks and updated blocks to the database
if len(newForks) > 0 || len(updatedBlocks) > 0 {
// purge parent ids cache as the fork id tree has changed
cache.parentIdsCache.Purge()

err := db.RunDBTransaction(func(tx *sqlx.Tx) error {
// helper function to update unfinalized block fork ids in batches
updateUnfinalizedBlockForkIds := func(updateRoots [][]byte, forkId ForkKey) error {
Expand Down

0 comments on commit eb936f5

Please sign in to comment.