From a5d329cf2078bcbb5631134b9fab707be4b6ed32 Mon Sep 17 00:00:00 2001 From: Wondertan Date: Mon, 13 May 2024 17:42:35 +0200 Subject: [PATCH] remove retry info and noop in case of empty block --- pruner/light/pruner.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pruner/light/pruner.go b/pruner/light/pruner.go index 296e100fc1..8986f81d10 100644 --- a/pruner/light/pruner.go +++ b/pruner/light/pruner.go @@ -4,20 +4,28 @@ import ( "context" "github.com/ipfs/boxo/blockservice" + "github.com/ipfs/go-datastore" "github.com/celestiaorg/celestia-node/header" + "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/ipld" ) type Pruner struct { bserv blockservice.BlockService + ds datastore.Datastore } -func NewPruner(bserv blockservice.BlockService) *Pruner { - return &Pruner{bserv: bserv} +func NewPruner(bserv blockservice.BlockService, ds datastore.Datastore) *Pruner { + return &Pruner{bserv: bserv, ds: ds} } func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { + dah := h.DAH + if share.DataHash(dah.Hash()).IsEmptyRoot() { + return nil + } + var roots [][]byte roots = append(roots, h.DAH.RowRoots...) roots = append(roots, h.DAH.ColumnRoots...) @@ -28,5 +36,15 @@ func (p *Pruner) Prune(ctx context.Context, h *header.ExtendedHeader) error { } } + key := rootKey(dah) + err := p.ds.Delete(ctx, key) + if err != nil { + return err + } + return nil } + +func rootKey(root *share.Root) datastore.Key { + return datastore.NewKey(root.String()) +}