node

package
v0.0.0-...-2701d8d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 118 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InitJournal at position 0 initializes the journal global var as soon as
	// the system starts, so that it's available for all other components.
	InitJournalKey = invoke(iota)

	// System processes.
	InitMemoryWatchdog

	// health checks
	CheckFDLimit
	CheckFvmConcurrency
	CheckUDPBufferSize
	LegacyMarketsEOL

	// libp2p
	PstoreAddSelfKeysKey
	StartListeningKey
	BootstrapKey

	// filecoin
	SetGenesisKey

	RunHelloKey
	RunChainExchangeKey
	RunChainGraphsync
	RunPeerMgrKey

	HandleIncomingBlocksKey
	HandleIncomingMessagesKey
	HandleMigrateClientFundsKey
	HandlePaymentChannelManagerKey

	RelayIndexerMessagesKey

	// miner
	PreflightChecksKey
	GetParamsKey
	HandleMigrateProviderFundsKey
	HandleDealsKey
	HandleRetrievalKey
	RunSectorServiceKey
	RunPqcMinerKey

	// daemon
	ExtractApiKey
	HeadMetricsKey
	SettlePaymentChannelsKey
	RunPeerTaggerKey
	SetupFallbackBlockstoresKey
	GoRPCServer

	ConsensusReporterKey

	SetApiEndpointKey

	StoreEventsKey
)

Invokes are called in the order they are defined.

Variables

View Source
var (
	DefaultTransportsKey = special{0}  // Libp2p option
	DiscoveryHandlerKey  = special{2}  // Private type
	AddrsFactoryKey      = special{3}  // Libp2p option
	SmuxTransportKey     = special{4}  // Libp2p option
	RelayKey             = special{5}  // Libp2p option
	SecurityKey          = special{6}  // Libp2p option
	BaseRoutingKey       = special{7}  // fx groups + multiret
	NatPortMapKey        = special{8}  // Libp2p option
	ConnectionManagerKey = special{9}  // Libp2p option
	AutoNATSvcKey        = special{10} // Libp2p option
	BandwidthReporterKey = special{11} // Libp2p option
	ConnGaterKey         = special{12} // Libp2p option
	DAGStoreKey          = special{13} // constructor returns multiple values
	ResourceManagerKey   = special{14} // Libp2p option
	UserAgentKey         = special{15} // Libp2p option
)
View Source
var ChainNode = Options(

	Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig),
	Override(new(stmgr.UpgradeSchedule), modules.UpgradeSchedule),
	Override(new(dtypes.NetworkName), modules.NetworkName),
	Override(new(modules.Genesis), modules.ErrorGenesis),
	Override(new(dtypes.AfterGenesisSet), modules.SetGenesis),
	Override(SetGenesisKey, modules.DoSetGenesis),
	Override(new(beacon.Schedule), modules.RandomSchedule),

	Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
	Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap),

	Override(new(storiface.Verifier), ffiwrapper.ProofVerifier),
	Override(new(storiface.Prover), ffiwrapper.ProofProver),

	Override(new(vm.SyscallBuilder), vm.Syscalls),

	Override(new(chain.Genesis), chain.LoadGenesis),
	Override(new(store.WeightFunc), filcns.Weight),
	Override(new(stmgr.Executor), consensus.NewTipSetExecutor(filcns.PqcRewardFunc)),
	Override(new(consensus.Consensus), filcns.NewFilecoinExpectedConsensus),
	Override(new(*store.ChainStore), modules.ChainStore),
	Override(new(*stmgr.StateManager), modules.StateManager),
	Override(new(dtypes.ChainBitswap), modules.ChainBitswap),
	Override(new(dtypes.ChainBlockService), modules.ChainBlockService),

	Override(new(chain.SyncManagerCtor), func() chain.SyncManagerCtor { return chain.NewSyncManager }),
	Override(new(*chain.Syncer), modules.NewSyncer),
	Override(new(exchange.Client), exchange.NewClient),

	Override(new(*hello.Service), hello.NewHelloService),
	Override(new(exchange.Server), exchange.NewServer),
	Override(new(*peermgr.PeerMgr), peermgr.NewPeerMgr),

	Override(new(*slashfilter.SlashFilter), modules.NewSlashFilter),

	Override(new(dtypes.DefaultMaxFeeFunc), modules.NewDefaultMaxFeeFunc),
	Override(new(*messagepool.MessagePool), modules.MessagePool),
	Override(new(*dtypes.MpoolLocker), new(dtypes.MpoolLocker)),

	Override(new(dtypes.Graphsync), modules.Graphsync(config.DefaultFullNode().Client.SimultaneousTransfersForStorage, config.DefaultFullNode().Client.SimultaneousTransfersForRetrieval)),

	Override(new(*messagesigner.MessageSigner), messagesigner.NewMessageSigner),
	Override(new(messagesigner.MsgSigner), func(ms *messagesigner.MessageSigner) *messagesigner.MessageSigner { return ms }),
	Override(new(*wallet.LocalWallet), wallet.NewWallet),
	Override(new(wallet.Default), From(new(*pqcwallet.PqcWallet))),
	Override(new(api.Wallet), From(new(wallet.MultiWallet))),

	Override(new(*pqcwallet.PqcWallet), pqcwallet.NewWallet),

	Override(new(paychmgr.PaychAPI), From(new(modules.PaychAPI))),
	Override(new(*paychmgr.Store), modules.NewPaychStore),
	Override(new(*paychmgr.Manager), modules.NewManager),
	Override(HandlePaymentChannelManagerKey, modules.HandlePaychManager),
	Override(SettlePaymentChannelsKey, settler.SettlePaymentChannels),

	Override(new(*discoveryimpl.Local), modules.NewLocalDiscovery),

	Override(new(discovery.PeerResolver), modules.RetrievalResolver),
	Override(new(retrievalmarket.BlockstoreAccessor), modules.RetrievalBlockstoreAccessor),
	Override(new(retrievalmarket.RetrievalClient), modules.RetrievalClient(false)),
	Override(new(dtypes.ClientDataTransfer), modules.NewClientGraphsyncDataTransfer),

	Override(new(*market.FundManager), market.NewFundManager),
	Override(new(dtypes.ClientDatastore), modules.NewClientDatastore),
	Override(new(storagemarket.BlockstoreAccessor), modules.StorageBlockstoreAccessor),
	Override(new(*retrievaladapter.APIBlockstoreAccessor), retrievaladapter.NewAPIBlockstoreAdapter),
	Override(new(storagemarket.StorageClient), modules.StorageClient),
	Override(new(storagemarket.StorageClientNode), storageadapter.NewClientNodeAdapter),
	Override(HandleMigrateClientFundsKey, modules.HandleMigrateClientFunds),

	Override(new(*full.GasPriceCache), full.NewGasPriceCache),

	Override(RelayIndexerMessagesKey, modules.RelayIndexerMessages),

	ApplyIf(isLiteNode,
		Override(new(messagepool.Provider), messagepool.NewProviderLite),
		Override(new(messagepool.MpoolNonceAPI), From(new(modules.MpoolNonceAPI))),
		Override(new(full.ChainModuleAPI), From(new(api.Gateway))),
		Override(new(full.GasModuleAPI), From(new(api.Gateway))),
		Override(new(full.MpoolModuleAPI), From(new(api.Gateway))),
		Override(new(full.StateModuleAPI), From(new(api.Gateway))),
		Override(new(stmgr.StateManagerAPI), rpcstmgr.NewRPCStateManager),
		Override(new(full.EthModuleAPI), From(new(api.Gateway))),
		Override(new(full.EthEventAPI), From(new(api.Gateway))),
		Override(new(full.ActorEventAPI), From(new(api.Gateway))),
	),

	ApplyIf(isFullNode,
		Override(new(messagepool.Provider), messagepool.NewProvider),
		Override(new(messagepool.MpoolNonceAPI), From(new(*messagepool.MessagePool))),
		Override(new(full.ChainModuleAPI), From(new(full.ChainModule))),
		Override(new(full.GasModuleAPI), From(new(full.GasModule))),
		Override(new(full.MpoolModuleAPI), From(new(full.MpoolModule))),
		Override(new(full.StateModuleAPI), From(new(full.StateModule))),
		Override(new(stmgr.StateManagerAPI), From(new(*stmgr.StateManager))),

		Override(RunHelloKey, modules.RunHello),
		Override(RunChainExchangeKey, modules.RunChainExchange),
		Override(RunPeerMgrKey, modules.RunPeerMgr),
		Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages),
		Override(HandleIncomingBlocksKey, modules.HandleIncomingBlocks),
	),
)

Chain node provides access to the Filecoin blockchain, by setting up a full validator node, or by delegating some actions to other nodes (lite mode)

View Source
var LibP2P = Options(

	Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(false)),

	Override(new(peerstore.Peerstore), lp2p.Peerstore),
	Override(PstoreAddSelfKeysKey, lp2p.PstoreAddSelfKeys),
	Override(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),

	Override(DefaultTransportsKey, lp2p.DefaultTransports),
	Override(AddrsFactoryKey, lp2p.AddrsFactory(nil, nil)),
	Override(SmuxTransportKey, lp2p.SmuxTransport()),
	Override(RelayKey, lp2p.NoRelay()),
	Override(SecurityKey, lp2p.Security(true, false)),

	Override(new(lp2p.RawHost), lp2p.Host),
	Override(new(host.Host), lp2p.RoutedHost),
	Override(new(lp2p.BaseIpfsRouting), lp2p.DHTRouting(dht.ModeAuto)),

	Override(DiscoveryHandlerKey, lp2p.DiscoveryHandler),

	Override(new(record.Validator), modules.RecordValidator),
	Override(BaseRoutingKey, lp2p.BaseRouting),
	Override(new(routing.Routing), lp2p.Routing),

	Override(BandwidthReporterKey, lp2p.BandwidthCounter),
	Override(AutoNATSvcKey, lp2p.AutoNATService),

	Override(new(*dtypes.ScoreKeeper), lp2p.ScoreKeeper),
	Override(new(*pubsub.PubSub), lp2p.GossipSub),
	Override(new(*config.Pubsub), func(bs dtypes.Bootstrapper) *config.Pubsub {
		return &config.Pubsub{
			Bootstrapper: bool(bs),
		}
	}),

	Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
	Override(new(*conngater.BasicConnectionGater), lp2p.ConnGater),
	Override(ConnGaterKey, lp2p.ConnGaterOption),

	Override(new(network.ResourceManager), lp2p.ResourceManager(200)),
	Override(ResourceManagerKey, lp2p.ResourceManagerOption),
)

Functions

func From

func From(typ interface{}) interface{}

From(*T) -> func(t T) T {return t}

func FromVal

func FromVal[T any](v T) func() T

func FullNodeHandler

func FullNodeHandler(a v1api.FullNode, permissioned bool, opts ...jsonrpc.ServerOption) (http.Handler, error)

FullNodeHandler returns a full node handler, to be mounted as-is on the server.

func IsType

func IsType(t repo.RepoType) func(s *Settings) bool

func MinerHandler

func MinerHandler(a api.StorageMiner, permissioned bool) (http.Handler, error)

MinerHandler returns a miner handler, to be mounted as-is on the server.

func MonitorShutdown

func MonitorShutdown(triggerCh <-chan struct{}, handlers ...ShutdownHandler) <-chan struct{}

MonitorShutdown manages shutdown requests, by watching signals and invoking the supplied handlers in order.

It watches SIGTERM and SIGINT OS signals, as well as the trigger channel. When any of them fire, it calls the supplied handlers in order. If any of them errors, it merely logs the error.

Once the shutdown has completed, it closes the returned channel. The caller can watch this channel

func WithEnableLibp2pNode

func WithEnableLibp2pNode(enable bool) func(s *Settings) error

func WithInvokesKey

func WithInvokesKey(i invoke, resApi interface{}) func(s *Settings) error

func WithRepoType

func WithRepoType(repoType repo.RepoType) func(s *Settings) error

Types

type FullOption

type FullOption = Option

func Lite

func Lite(enable bool) FullOption

type HealthHandler

type HealthHandler struct {
	// contains filtered or unexported fields
}

func NewLiveHandler

func NewLiveHandler(api lapi.FullNode) *HealthHandler

Check that the node is still working. That is, that it's still processing the chain. If there have been no recent changes, consider the node to be dead.

func NewReadyHandler

func NewReadyHandler(api lapi.FullNode) *HealthHandler

Check if we are ready to handle traffic. 1. sync workers are reasonably up to date. 2. libp2p is servicable

func (*HealthHandler) ServeHTTP

func (h *HealthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HealthHandler) SetHealthy

func (h *HealthHandler) SetHealthy(healthy bool)

type Option

type Option func(*Settings) error

Option is a functional option which can be used with the New function to change how the node is constructed

Options are applied in sequence

func ApplyIf

func ApplyIf(check func(s *Settings) bool, opts ...Option) Option

func Base

func Base() Option

func ConfigCommon

func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option

Config sets up constructors based on the provided Config

func ConfigFullNode

func ConfigFullNode(c interface{}) Option

func ConfigStorageMiner

func ConfigStorageMiner(c interface{}) Option

func Error

func Error(err error) Option

Error is a special option which returns an error when applied

func FullAPI

func FullAPI(out *api.FullNode, fopts ...FullOption) Option

func If

func If(b bool, opts ...Option) Option

func Options

func Options(opts ...Option) Option

Options groups multiple options into one

func Override

func Override(typ, constructor interface{}) Option

Override option changes constructor for a given type

func Repo

func Repo(r repo.Repo) Option

func StorageMiner

func StorageMiner(out *api.StorageMiner, subsystemsCfg config.MinerSubsystemConfig) Option

func Test

func Test() Option

func Unset

func Unset(typ interface{}) Option

type Settings

type Settings struct {
	Base   bool // Base option applied
	Config bool // Config option applied
	Lite   bool // Start node in "lite" mode
	// contains filtered or unexported fields
}

type ShutdownHandler

type ShutdownHandler struct {
	Component string
	StopFunc  StopFunc
}

type StopFunc

type StopFunc func(context.Context) error

func New

func New(ctx context.Context, opts ...Option) (StopFunc, error)

New builds and starts new Filecoin node

func ServeRPC

func ServeRPC(h http.Handler, id string, addr multiaddr.Multiaddr) (StopFunc, error)

ServeRPC serves an HTTP handler over the supplied listen multiaddr.

This function spawns a goroutine to run the server, and returns immediately. It returns the stop function to be called to terminate the endpoint.

The supplied ID is used in tracing, by inserting a tag in the context.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL