From 1f679760dc906d1df372da0575faabcd34ebf112 Mon Sep 17 00:00:00 2001 From: rene <41963722+renaynay@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:38:11 +0100 Subject: [PATCH] fix(pruner): findPruneable also prunes genesis block, return windows to proper values, sane MaxPruneable values, return gc cycle to every 5 min --- go.sum | 10 ---------- pruner/finder.go | 5 ++++- pruner/full/window.go | 4 ++-- pruner/light/window.go | 4 +--- pruner/params.go | 4 ++-- pruner/service.go | 3 --- pruner/service_test.go | 4 ++-- 7 files changed, 11 insertions(+), 23 deletions(-) diff --git a/go.sum b/go.sum index 809a8a4a36..6fe259ff0c 100644 --- a/go.sum +++ b/go.sum @@ -370,16 +370,6 @@ github.com/celestiaorg/go-fraud v0.2.0 h1:aaq2JiW0gTnhEdac3l51UCqSyJ4+VjFGTTpN83 github.com/celestiaorg/go-fraud v0.2.0/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc= github.com/celestiaorg/go-header v0.5.3 h1:8CcflT6aIlcQXKNWcMekoBNs3EU50mEmDp17gbn1pP4= github.com/celestiaorg/go-header v0.5.3/go.mod h1:7BVR6myjRfACbqW1de6s8OjuK66XzHm8MpFNYr0G+nU= -github.com/celestiaorg/go-header v0.5.2 h1:CFsTAXcs1o38JVd8YN1Naq/Yzs6m9orMPEPNpLEgFJA= -github.com/celestiaorg/go-header v0.5.2/go.mod h1:7BVR6myjRfACbqW1de6s8OjuK66XzHm8MpFNYr0G+nU= -github.com/celestiaorg/go-header v0.5.0-rc1 h1:DAcVW8V76VI5VU4fOAdXePpq15UFblwZIMZeHCAVr0w= -github.com/celestiaorg/go-header v0.5.0-rc1/go.mod h1:H8xhnDLDLbkpwmWPhCaZyTnIV3dlVxBHPnxNXS2Qu6c= -github.com/celestiaorg/go-ds-badger4 v0.0.0-20231125235544-5604cb7c10bb h1:gC5krQEhNTjhnNJcgiBfnqk+VxOwq5i4llqSVgMZx8k= -github.com/celestiaorg/go-ds-badger4 v0.0.0-20231125235544-5604cb7c10bb/go.mod h1:r6xB3nvGotmlTACpAr3SunxtoXeesbqb57elgMJqflY= -github.com/celestiaorg/go-fraud v0.2.0 h1:aaq2JiW0gTnhEdac3l51UCqSyJ4+VjFGTTpN83V4q7I= -github.com/celestiaorg/go-fraud v0.2.0/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc= -github.com/celestiaorg/go-header v0.5.3-0.20240125165231-c34c25d653de h1:VYyGgW5RjYkkX4ql9LD8/3UBSIKexLj5xI78Vzd/Me4= -github.com/celestiaorg/go-header v0.5.3-0.20240125165231-c34c25d653de/go.mod h1:7BVR6myjRfACbqW1de6s8OjuK66XzHm8MpFNYr0G+nU= github.com/celestiaorg/go-libp2p-messenger v0.2.0 h1:/0MuPDcFamQMbw9xTZ73yImqgTO3jHV7wKHvWD/Irao= github.com/celestiaorg/go-libp2p-messenger v0.2.0/go.mod h1:s9PIhMi7ApOauIsfBcQwbr7m+HBzmVfDIS+QLdgzDSo= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= diff --git a/pruner/finder.go b/pruner/finder.go index 0e3a7a151c..3253ce45d7 100644 --- a/pruner/finder.go +++ b/pruner/finder.go @@ -9,7 +9,6 @@ import ( // findPruneableHeaders returns all headers that are eligible for pruning // (outside the sampling window). -// TODO @renaynay @distractedm1nd: This will not prune the genesis block func (s *Service) findPruneableHeaders(ctx context.Context) ([]*header.ExtendedHeader, error) { lastPruned := s.lastPruned() @@ -31,6 +30,10 @@ func (s *Service) findPruneableHeaders(ctx context.Context) ([]*header.ExtendedH if err != nil { return nil, err } + // ensures genesis block gets pruned + if lastPruned.Height() == 1 { + headers = append([]*header.ExtendedHeader{lastPruned}, headers...) + } // if our estimated range didn't cover enough headers, we need to fetch more // TODO: This is really inefficient in the case that lastPruned is the default value, or if the diff --git a/pruner/full/window.go b/pruner/full/window.go index 96e9268b30..1939f61214 100644 --- a/pruner/full/window.go +++ b/pruner/full/window.go @@ -3,9 +3,9 @@ package full import ( "time" - "github.com/celestiaorg/celestia-node/pruner" + "github.com/celestiaorg/celestia-node/pruner/light" ) // Window is the availability window for light nodes in the Celestia // network (30 days). -const Window = pruner.AvailabilityWindow(time.Hour * 2) +const Window = time.Duration(light.Window) + time.Hour diff --git a/pruner/light/window.go b/pruner/light/window.go index d54c79329d..2241ecb063 100644 --- a/pruner/light/window.go +++ b/pruner/light/window.go @@ -1,11 +1,9 @@ package light import ( - "time" - "github.com/celestiaorg/celestia-node/pruner" ) // Window is the availability window for light nodes in the Celestia // network (30 days). -const Window = pruner.AvailabilityWindow(time.Hour * 2) +const Window = pruner.AvailabilityWindow(30 * 24 * 60 * 60) diff --git a/pruner/params.go b/pruner/params.go index ec3c824caf..fec734219e 100644 --- a/pruner/params.go +++ b/pruner/params.go @@ -17,8 +17,8 @@ type Params struct { func DefaultParams() Params { return Params{ - gcCycle: time.Minute * 1, - maxPruneablePerGC: 50000, + gcCycle: time.Minute * 5, + maxPruneablePerGC: 1024, } } diff --git a/pruner/service.go b/pruner/service.go index 208fe88935..273927b50e 100644 --- a/pruner/service.go +++ b/pruner/service.go @@ -26,9 +26,6 @@ type Service struct { ds datastore.Datastore checkpoint *checkpoint - // TODO @renaynay: how would this impact a node that enables pruning after being an archival node? - // e.g. Node has already 600k+ blocks stored, how long will it take to clean up all blocks outside - // of pruning window? maxPruneablePerGC uint64 numBlocksInWindow uint64 diff --git a/pruner/service_test.go b/pruner/service_test.go index 7a34a8476f..aad3d0f236 100644 --- a/pruner/service_test.go +++ b/pruner/service_test.go @@ -171,7 +171,7 @@ func TestFindPruneableHeaders(t *testing.T) { headerAmount: 2 * (24 * 7), startTime: time.Now().Add(-2 * time.Hour * 24 * 7), // One week of headers are pruneable - expectedLength: 24 * 7, + expectedLength: (24 * 7) + 1, }, { name: "Estimated range not sufficient but finds the correct tail", @@ -182,7 +182,7 @@ func TestFindPruneableHeaders(t *testing.T) { headerAmount: 3 * (24 * 7), startTime: time.Now().Add(-3 * time.Hour * 24 * 7), // Two weeks of headers are pruneable - expectedLength: 2 * 24 * 7, + expectedLength: (2 * 24 * 7) + 1, }, { name: "No pruneable headers",