From 84df105a92a771f6f51ee89b57558881b527d683 Mon Sep 17 00:00:00 2001 From: pk910 Date: Fri, 24 Jan 2025 21:21:51 +0100 Subject: [PATCH] cleanup old entries from unfinalized_epochs table --- db/unfinalized_epochs.go | 4 ++-- indexer/beacon/finalization.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/unfinalized_epochs.go b/db/unfinalized_epochs.go index 87285fba..cc4230c8 100644 --- a/db/unfinalized_epochs.go +++ b/db/unfinalized_epochs.go @@ -96,8 +96,8 @@ func GetUnfinalizedEpoch(epoch uint64, headRoot []byte) *dbtypes.UnfinalizedEpoc return &unfinalizedEpoch } -func DeleteUnfinalizedEpochsIn(epoch uint64, tx *sqlx.Tx) error { - _, err := tx.Exec(`DELETE FROM unfinalized_epochs WHERE epoch = $1`, epoch) +func DeleteUnfinalizedEpochsBefore(epoch uint64, tx *sqlx.Tx) error { + _, err := tx.Exec(`DELETE FROM unfinalized_epochs WHERE epoch < $1`, epoch) if err != nil { return err } diff --git a/indexer/beacon/finalization.go b/indexer/beacon/finalization.go index 60dd38a0..f297550c 100644 --- a/indexer/beacon/finalization.go +++ b/indexer/beacon/finalization.go @@ -349,8 +349,8 @@ func (indexer *Indexer) finalizeEpoch(epoch phase0.Epoch, justifiedRoot phase0.R } // delete unfinalized epoch aggregations in epoch - if err := db.DeleteUnfinalizedEpochsIn(uint64(epoch), tx); err != nil { - return fmt.Errorf("failed deleting unfinalized epoch aggregations of epoch %v: %v", epoch, err) + if err := db.DeleteUnfinalizedEpochsBefore(uint64(epoch+1), tx); err != nil { + return fmt.Errorf("failed deleting unfinalized epoch aggregations <= epoch %v: %v", epoch, err) } // delete unfinalized forks for canonical roots