github.com/celestiaorg/celestia-node@v0.15.0-beta.1/pruner/full/pruner.go (about)

     1  package full
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  
     7  	"github.com/filecoin-project/dagstore"
     8  	logging "github.com/ipfs/go-log/v2"
     9  
    10  	"github.com/celestiaorg/celestia-node/header"
    11  	"github.com/celestiaorg/celestia-node/share"
    12  	"github.com/celestiaorg/celestia-node/share/eds"
    13  )
    14  
    15  var log = logging.Logger("pruner/full")
    16  
    17  type Pruner struct {
    18  	store *eds.Store
    19  }
    20  
    21  func NewPruner(store *eds.Store) *Pruner {
    22  	return &Pruner{
    23  		store: store,
    24  	}
    25  }
    26  
    27  func (p *Pruner) Prune(ctx context.Context, eh *header.ExtendedHeader) error {
    28  	// short circuit on empty roots
    29  	if eh.DAH.Equals(share.EmptyRoot()) {
    30  		return nil
    31  	}
    32  
    33  	log.Debugf("pruning header %s", eh.DAH.Hash())
    34  
    35  	err := p.store.Remove(ctx, eh.DAH.Hash())
    36  	if err != nil && !errors.Is(err, dagstore.ErrShardUnknown) {
    37  		return err
    38  	}
    39  	return nil
    40  }