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

     1  package pruner
     2  
     3  import (
     4  	"context"
     5  
     6  	"go.uber.org/fx"
     7  
     8  	"github.com/celestiaorg/celestia-node/nodebuilder/node"
     9  	"github.com/celestiaorg/celestia-node/pruner"
    10  	"github.com/celestiaorg/celestia-node/pruner/archival"
    11  	"github.com/celestiaorg/celestia-node/pruner/full"
    12  	"github.com/celestiaorg/celestia-node/pruner/light"
    13  	"github.com/celestiaorg/celestia-node/share/eds"
    14  )
    15  
    16  func ConstructModule(tp node.Type, cfg *Config) fx.Option {
    17  	if !cfg.EnableService {
    18  		switch tp {
    19  		case node.Light:
    20  			// light nodes are still subject to sampling within window
    21  			// even if pruning is not enabled.
    22  			return fx.Supply(light.Window)
    23  		case node.Full, node.Bridge:
    24  			return fx.Supply(archival.Window)
    25  		default:
    26  			panic("unknown node type")
    27  		}
    28  	}
    29  
    30  	baseComponents := fx.Options(
    31  		fx.Provide(fx.Annotate(
    32  			newPrunerService,
    33  			fx.OnStart(func(ctx context.Context, p *pruner.Service) error {
    34  				return p.Start(ctx)
    35  			}),
    36  			fx.OnStop(func(ctx context.Context, p *pruner.Service) error {
    37  				return p.Stop(ctx)
    38  			}),
    39  		)),
    40  		// This is necessary to invoke the pruner service as independent thanks to a
    41  		// quirk in FX.
    42  		fx.Invoke(func(p *pruner.Service) {}),
    43  	)
    44  
    45  	switch tp {
    46  	case node.Full:
    47  		return fx.Module("prune",
    48  			baseComponents,
    49  			fx.Provide(func(store *eds.Store) pruner.Pruner {
    50  				return full.NewPruner(store)
    51  			}),
    52  			fx.Supply(full.Window),
    53  		)
    54  	case node.Bridge:
    55  		return fx.Module("prune",
    56  			baseComponents,
    57  			fx.Provide(func(store *eds.Store) pruner.Pruner {
    58  				return full.NewPruner(store)
    59  			}),
    60  			fx.Supply(full.Window),
    61  		)
    62  	// TODO: Eventually, light nodes will be capable of pruning samples
    63  	//  in which case, this can be enabled.
    64  	case node.Light:
    65  		return fx.Module("prune",
    66  			baseComponents,
    67  			fx.Provide(func() pruner.Pruner {
    68  				return light.NewPruner()
    69  			}),
    70  			fx.Supply(light.Window),
    71  		)
    72  	default:
    73  		panic("unknown node type")
    74  	}
    75  }