From e668c586ef8ef7809ac2955b57865cc2cb080fa7 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 21 Oct 2023 09:19:26 +0200 Subject: [PATCH] dont prune too earlyy --- proposals/handler.go | 6 +++++- prune/prune.go | 7 ++++++- prune/prune_test.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/proposals/handler.go b/proposals/handler.go index 93352312cb..e8cde20e8a 100644 --- a/proposals/handler.go +++ b/proposals/handler.go @@ -463,7 +463,11 @@ func (h *Handler) checkBallotDataIntegrity(ctx context.Context, b *types.Ballot) if b.EpochData.Beacon == types.EmptyBeacon { return nil, errMissingBeacon } - if b.Layer.GetEpoch() == h.clock.CurrentLayer().GetEpoch() { + epoch := h.clock.CurrentLayer().GetEpoch() + if epoch > 0 { + epoch-- // download activesets in the previous epoch too + } + if b.Layer.GetEpoch() >= epoch { if err := h.fetcher.GetActiveSet(ctx, b.EpochData.ActiveSetHash); err != nil { return nil, err } diff --git a/prune/prune.go b/prune/prune.go index 1ac6582dd7..15fc3a1625 100644 --- a/prune/prune.go +++ b/prune/prune.go @@ -85,7 +85,12 @@ func (p *Pruner) Prune(current types.LayerID) error { propTxLatency.Observe(time.Since(start).Seconds()) if current.GetEpoch() > p.activesetEpoch { start = time.Now() - if err := activesets.DeleteBeforeEpoch(p.db, current.GetEpoch()); err != nil { + epoch := current.GetEpoch() + if epoch > 0 { + epoch-- + } + // current - 1 as activesets will be fetched in hare eligibility oracle + if err := activesets.DeleteBeforeEpoch(p.db, epoch); err != nil { return err } activeSetLatency.Observe(time.Since(start).Seconds()) diff --git a/prune/prune_test.go b/prune/prune_test.go index 4caa4700aa..c2e2cf0f66 100644 --- a/prune/prune_test.go +++ b/prune/prune_test.go @@ -83,7 +83,7 @@ func TestPrune(t *testing.T) { for epoch, epochSets := range sets { for _, id := range epochSets { _, err := activesets.Get(db, id) - if epoch >= current.GetEpoch() { + if epoch >= current.GetEpoch()-1 { require.NoError(t, err) } else { require.ErrorIs(t, err, sql.ErrNotFound)