From e218714ee941d8aaba7eb36330086a3d48dd4e00 Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 4 Feb 2025 00:28:46 +0100 Subject: [PATCH 1/2] purge parent fork ids cache on new forks --- indexer/beacon/forkdetection.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/indexer/beacon/forkdetection.go b/indexer/beacon/forkdetection.go index 0e781880..20574d01 100644 --- a/indexer/beacon/forkdetection.go +++ b/indexer/beacon/forkdetection.go @@ -227,6 +227,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 { From d275fbc986256f1f3abee169db21d04e2c4295f8 Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 4 Feb 2025 00:50:26 +0100 Subject: [PATCH 2/2] fix fork detection when fork starts from a finalized block --- indexer/beacon/forkdetection.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/indexer/beacon/forkdetection.go b/indexer/beacon/forkdetection.go index 20574d01..ba0912de 100644 --- a/indexer/beacon/forkdetection.go +++ b/indexer/beacon/forkdetection.go @@ -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{}