Skip to content

Commit

Permalink
fix(pruner): findPruneable also prunes genesis block, return windows …
Browse files Browse the repository at this point in the history
…to proper values, sane MaxPruneable values, return gc cycle to every 5 min
  • Loading branch information
renaynay committed Feb 22, 2024
1 parent 3e39c77 commit 1f67976
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 23 deletions.
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 4 additions & 1 deletion pruner/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pruner/full/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions pruner/light/window.go
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions pruner/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type Params struct {

func DefaultParams() Params {
return Params{
gcCycle: time.Minute * 1,
maxPruneablePerGC: 50000,
gcCycle: time.Minute * 5,
maxPruneablePerGC: 1024,
}
}

Expand Down
3 changes: 0 additions & 3 deletions pruner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pruner/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 1f67976

Please sign in to comment.