Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fork detection for forks starting before the finalized checkpoint #232

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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