node builder: Cleanup and add some docstrings
This commit is contained in:
parent
811fb44dd0
commit
adeb4cefee
229
node/builder.go
229
node/builder.go
@ -171,6 +171,7 @@ type Settings struct {
|
||||
Lite bool // Start node in "lite" mode
|
||||
}
|
||||
|
||||
// Basic lotus-app services
|
||||
func defaults() []Option {
|
||||
return []Option{
|
||||
// global system journal.
|
||||
@ -184,40 +185,44 @@ func defaults() []Option {
|
||||
return metricsi.CtxScope(context.Background(), "lotus")
|
||||
}),
|
||||
|
||||
Override(new(record.Validator), modules.RecordValidator),
|
||||
Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(false)),
|
||||
Override(new(dtypes.ShutdownChan), make(chan struct{})),
|
||||
|
||||
// Filecoin modules
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func libp2p() Option {
|
||||
return Options(
|
||||
var LibP2P = Options(
|
||||
// Host config
|
||||
Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(false)),
|
||||
|
||||
// Host dependencies
|
||||
Override(new(peerstore.Peerstore), pstoremem.NewPeerstore),
|
||||
Override(PstoreAddSelfKeysKey, lp2p.PstoreAddSelfKeys),
|
||||
Override(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),
|
||||
|
||||
// Host settings
|
||||
Override(DefaultTransportsKey, lp2p.DefaultTransports),
|
||||
|
||||
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(AddrsFactoryKey, lp2p.AddrsFactory(nil, nil)),
|
||||
Override(SmuxTransportKey, lp2p.SmuxTransport(true)),
|
||||
Override(RelayKey, lp2p.NoRelay()),
|
||||
Override(SecurityKey, lp2p.Security(true, false)),
|
||||
|
||||
// Host
|
||||
Override(new(lp2p.RawHost), lp2p.Host),
|
||||
Override(new(host.Host), lp2p.RoutedHost),
|
||||
Override(new(lp2p.BaseIpfsRouting), lp2p.DHTRouting(dht.ModeAuto)),
|
||||
|
||||
Override(DiscoveryHandlerKey, lp2p.DiscoveryHandler),
|
||||
|
||||
// Routing
|
||||
Override(new(record.Validator), modules.RecordValidator),
|
||||
Override(BaseRoutingKey, lp2p.BaseRouting),
|
||||
Override(new(routing.Routing), lp2p.Routing),
|
||||
|
||||
// Services
|
||||
Override(NatPortMapKey, lp2p.NatPortMap),
|
||||
Override(BandwidthReporterKey, lp2p.BandwidthCounter),
|
||||
|
||||
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
|
||||
Override(AutoNATSvcKey, lp2p.AutoNATService),
|
||||
|
||||
// Services (pubsub)
|
||||
Override(new(*dtypes.ScoreKeeper), lp2p.ScoreKeeper),
|
||||
Override(new(*pubsub.PubSub), lp2p.GossipSub),
|
||||
Override(new(*config.Pubsub), func(bs dtypes.Bootstrapper) *config.Pubsub {
|
||||
@ -226,97 +231,103 @@ func libp2p() Option {
|
||||
}
|
||||
}),
|
||||
|
||||
Override(PstoreAddSelfKeysKey, lp2p.PstoreAddSelfKeys),
|
||||
Override(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),
|
||||
|
||||
// Services (connection management)
|
||||
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
|
||||
Override(new(*conngater.BasicConnectionGater), lp2p.ConnGater),
|
||||
Override(ConnGaterKey, lp2p.ConnGaterOption),
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
func isType(t repo.RepoType) func(s *Settings) bool {
|
||||
return func(s *Settings) bool { return s.nodeType == t }
|
||||
}
|
||||
|
||||
// Online sets up basic libp2p node
|
||||
func Online() Option {
|
||||
isFullOrLiteNode := func(s *Settings) bool { return s.nodeType == repo.FullNode }
|
||||
isFullNode := func(s *Settings) bool { return s.nodeType == repo.FullNode && !s.Lite }
|
||||
isLiteNode := func(s *Settings) bool { return s.nodeType == repo.FullNode && s.Lite }
|
||||
|
||||
return Options(
|
||||
// make sure that online is applied before Config.
|
||||
// This is important because Config overrides some of Online units
|
||||
func(s *Settings) error { s.Online = true; return nil },
|
||||
ApplyIf(func(s *Settings) bool { return s.Config },
|
||||
Error(errors.New("the Online option must be set before Config option")),
|
||||
),
|
||||
|
||||
libp2p(),
|
||||
|
||||
// common
|
||||
Override(new(*slashfilter.SlashFilter), modules.NewSlashFilter),
|
||||
func isFullOrLiteNode(s *Settings) bool { return s.nodeType == repo.FullNode }
|
||||
func isFullNode(s *Settings) bool { return s.nodeType == repo.FullNode && !s.Lite }
|
||||
func isLiteNode(s *Settings) bool { return s.nodeType == repo.FullNode && s.Lite }
|
||||
|
||||
// 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)
|
||||
var ChainNode = Options(
|
||||
// Full node or lite node
|
||||
ApplyIf(isFullOrLiteNode,
|
||||
// TODO: Fix offline mode
|
||||
|
||||
// Consensus settings
|
||||
Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig),
|
||||
Override(new(stmgr.UpgradeSchedule), stmgr.DefaultUpgradeSchedule()),
|
||||
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),
|
||||
|
||||
// Network bootstrap
|
||||
Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
|
||||
Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap),
|
||||
Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig),
|
||||
|
||||
// Consensus: crypto dependencies
|
||||
Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier),
|
||||
|
||||
// Consensus: VM
|
||||
Override(new(vm.SyscallBuilder), vm.Syscalls),
|
||||
|
||||
// Consensus: Chain storage/access
|
||||
Override(new(*store.ChainStore), modules.ChainStore),
|
||||
Override(new(stmgr.UpgradeSchedule), stmgr.DefaultUpgradeSchedule()),
|
||||
Override(new(*stmgr.StateManager), modules.StateManager),
|
||||
Override(new(*wallet.LocalWallet), wallet.NewWallet),
|
||||
Override(new(wallet.Default), From(new(*wallet.LocalWallet))),
|
||||
Override(new(api.WalletAPI), From(new(wallet.MultiWallet))),
|
||||
Override(new(*messagesigner.MessageSigner), messagesigner.NewMessageSigner),
|
||||
|
||||
Override(new(dtypes.ChainBitswap), modules.ChainBitswap),
|
||||
Override(new(dtypes.ChainBlockService), modules.ChainBlockService),
|
||||
Override(new(dtypes.ChainBlockService), modules.ChainBlockService), // todo: unused
|
||||
|
||||
// Consensus: Chain sync
|
||||
|
||||
// Filecoin services
|
||||
// We don't want the SyncManagerCtor to be used as an fx constructor, but rather as a value.
|
||||
// It will be called implicitly by the Syncer constructor.
|
||||
Override(new(chain.SyncManagerCtor), func() chain.SyncManagerCtor { return chain.NewSyncManager }),
|
||||
Override(new(*chain.Syncer), modules.NewSyncer),
|
||||
Override(new(exchange.Client), exchange.NewClient),
|
||||
Override(new(*messagepool.MessagePool), modules.MessagePool),
|
||||
Override(new(dtypes.DefaultMaxFeeFunc), modules.NewDefaultMaxFeeFunc),
|
||||
|
||||
Override(new(modules.Genesis), modules.ErrorGenesis),
|
||||
Override(new(dtypes.AfterGenesisSet), modules.SetGenesis),
|
||||
Override(SetGenesisKey, modules.DoSetGenesis),
|
||||
|
||||
Override(new(dtypes.NetworkName), modules.NetworkName),
|
||||
// Chain networking
|
||||
Override(new(*hello.Service), hello.NewHelloService),
|
||||
Override(new(exchange.Server), exchange.NewServer),
|
||||
Override(new(*peermgr.PeerMgr), peermgr.NewPeerMgr),
|
||||
|
||||
Override(new(dtypes.Graphsync), modules.Graphsync(config.DefaultFullNode().Client.SimultaneousTransfers)),
|
||||
// Chain mining API dependencies
|
||||
Override(new(*slashfilter.SlashFilter), modules.NewSlashFilter),
|
||||
|
||||
// Service: Message Pool
|
||||
Override(new(dtypes.DefaultMaxFeeFunc), modules.NewDefaultMaxFeeFunc),
|
||||
Override(new(*messagepool.MessagePool), modules.MessagePool),
|
||||
Override(new(*dtypes.MpoolLocker), new(dtypes.MpoolLocker)),
|
||||
Override(new(*discoveryimpl.Local), modules.NewLocalDiscovery),
|
||||
Override(new(discovery.PeerResolver), modules.RetrievalResolver),
|
||||
|
||||
Override(new(retrievalmarket.RetrievalClient), modules.RetrievalClient),
|
||||
Override(new(dtypes.ClientDatastore), modules.NewClientDatastore),
|
||||
Override(new(dtypes.ClientDataTransfer), modules.NewClientGraphsyncDataTransfer),
|
||||
Override(new(storagemarket.StorageClient), modules.StorageClient),
|
||||
Override(new(storagemarket.StorageClientNode), storageadapter.NewClientNodeAdapter),
|
||||
Override(new(beacon.Schedule), modules.RandomSchedule),
|
||||
// Shared graphsync (markets, serving chain)
|
||||
Override(new(dtypes.Graphsync), modules.Graphsync(config.DefaultFullNode().Client.SimultaneousTransfers)),
|
||||
|
||||
// Service: Wallet
|
||||
Override(new(*messagesigner.MessageSigner), messagesigner.NewMessageSigner),
|
||||
Override(new(*wallet.LocalWallet), wallet.NewWallet),
|
||||
Override(new(wallet.Default), From(new(*wallet.LocalWallet))),
|
||||
Override(new(api.WalletAPI), From(new(wallet.MultiWallet))),
|
||||
|
||||
// Service: Payment channels
|
||||
Override(new(*paychmgr.Store), paychmgr.NewStore),
|
||||
Override(new(*paychmgr.Manager), paychmgr.NewManager),
|
||||
Override(new(*market.FundManager), market.NewFundManager),
|
||||
Override(HandleMigrateClientFundsKey, modules.HandleMigrateClientFunds),
|
||||
Override(HandlePaymentChannelManagerKey, paychmgr.HandleManager),
|
||||
Override(SettlePaymentChannelsKey, settler.SettlePaymentChannels),
|
||||
),
|
||||
|
||||
// Lite node
|
||||
// Markets (common)
|
||||
Override(new(*discoveryimpl.Local), modules.NewLocalDiscovery),
|
||||
|
||||
// Markets (retrieval)
|
||||
Override(new(discovery.PeerResolver), modules.RetrievalResolver),
|
||||
Override(new(retrievalmarket.RetrievalClient), modules.RetrievalClient),
|
||||
Override(new(dtypes.ClientDataTransfer), modules.NewClientGraphsyncDataTransfer),
|
||||
|
||||
// Markets (storage)
|
||||
Override(new(*market.FundManager), market.NewFundManager),
|
||||
Override(new(dtypes.ClientDatastore), modules.NewClientDatastore),
|
||||
Override(new(storagemarket.StorageClient), modules.StorageClient),
|
||||
Override(new(storagemarket.StorageClientNode), storageadapter.NewClientNodeAdapter),
|
||||
Override(HandleMigrateClientFundsKey, modules.HandleMigrateClientFunds),
|
||||
|
||||
// Lite node API
|
||||
ApplyIf(isLiteNode,
|
||||
Override(new(messagesigner.MpoolNonceAPI), From(new(modules.MpoolNonceAPI))),
|
||||
Override(new(full.ChainModuleAPI), From(new(api.GatewayAPI))),
|
||||
@ -326,7 +337,7 @@ func Online() Option {
|
||||
Override(new(stmgr.StateManagerAPI), modules.NewRPCStateManager),
|
||||
),
|
||||
|
||||
// Full node
|
||||
// Full node API / service startup
|
||||
ApplyIf(isFullNode,
|
||||
Override(new(messagesigner.MpoolNonceAPI), From(new(*messagepool.MessagePool))),
|
||||
Override(new(full.ChainModuleAPI), From(new(full.ChainModule))),
|
||||
@ -341,51 +352,67 @@ func Online() Option {
|
||||
Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages),
|
||||
Override(HandleIncomingBlocksKey, modules.HandleIncomingBlocks),
|
||||
),
|
||||
)
|
||||
|
||||
// miner
|
||||
ApplyIf(isType(repo.StorageMiner),
|
||||
var MinerNode = Options(
|
||||
// API dependencies
|
||||
Override(new(api.Common), From(new(common.CommonAPI))),
|
||||
Override(new(sectorstorage.StorageAuth), modules.StorageAuth),
|
||||
|
||||
Override(new(*stores.Index), stores.NewIndex),
|
||||
Override(new(stores.SectorIndex), From(new(*stores.Index))),
|
||||
Override(new(dtypes.MinerID), modules.MinerID),
|
||||
// Actor config
|
||||
Override(new(dtypes.MinerAddress), modules.MinerAddress),
|
||||
Override(new(dtypes.MinerID), modules.MinerID),
|
||||
Override(new(abi.RegisteredSealProof), modules.SealProofType),
|
||||
Override(new(stores.LocalStorage), From(new(repo.LockedRepo))),
|
||||
Override(new(sealing.SectorIDCounter), modules.SectorIDCounter),
|
||||
Override(new(*sectorstorage.Manager), modules.SectorStorage),
|
||||
Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier),
|
||||
|
||||
Override(new(sectorstorage.SectorManager), From(new(*sectorstorage.Manager))),
|
||||
Override(new(storage2.Prover), From(new(sectorstorage.SectorManager))),
|
||||
Override(new(storiface.WorkerReturn), From(new(sectorstorage.SectorManager))),
|
||||
|
||||
Override(new(*sectorblocks.SectorBlocks), sectorblocks.NewSectorBlocks),
|
||||
Override(new(*storage.Miner), modules.StorageMiner(config.DefaultStorageMiner().Fees)),
|
||||
Override(new(*storage.AddressSelector), modules.AddressSelector(nil)),
|
||||
Override(new(dtypes.NetworkName), modules.StorageNetworkName),
|
||||
|
||||
// Sector storage
|
||||
Override(new(*stores.Index), stores.NewIndex),
|
||||
Override(new(stores.SectorIndex), From(new(*stores.Index))),
|
||||
Override(new(stores.LocalStorage), From(new(repo.LockedRepo))),
|
||||
Override(new(*sectorstorage.Manager), modules.SectorStorage),
|
||||
Override(new(sectorstorage.SectorManager), From(new(*sectorstorage.Manager))),
|
||||
Override(new(storiface.WorkerReturn), From(new(sectorstorage.SectorManager))),
|
||||
|
||||
// Sector storage: Proofs
|
||||
Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier),
|
||||
Override(new(storage2.Prover), From(new(sectorstorage.SectorManager))),
|
||||
|
||||
// Sealing
|
||||
Override(new(sealing.SectorIDCounter), modules.SectorIDCounter),
|
||||
Override(GetParamsKey, modules.GetParams),
|
||||
|
||||
// Mining / proving
|
||||
Override(new(*slashfilter.SlashFilter), modules.NewSlashFilter),
|
||||
Override(new(*storage.Miner), modules.StorageMiner(config.DefaultStorageMiner().Fees)),
|
||||
Override(new(*miner.Miner), modules.SetupBlockProducer),
|
||||
Override(new(gen.WinningPoStProver), storage.NewWinningPoStProver),
|
||||
|
||||
Override(new(*storage.AddressSelector), modules.AddressSelector(nil)),
|
||||
|
||||
// Markets
|
||||
Override(new(dtypes.StagingMultiDstore), modules.StagingMultiDatastore),
|
||||
Override(new(dtypes.StagingBlockstore), modules.StagingBlockstore),
|
||||
Override(new(dtypes.StagingDAG), modules.StagingDAG),
|
||||
Override(new(dtypes.StagingGraphsync), modules.StagingGraphsync),
|
||||
Override(new(retrievalmarket.RetrievalProvider), modules.RetrievalProvider),
|
||||
Override(new(dtypes.ProviderDataTransfer), modules.NewProviderDAGServiceDataTransfer),
|
||||
Override(new(dtypes.ProviderPieceStore), modules.NewProviderPieceStore),
|
||||
Override(new(*sectorblocks.SectorBlocks), sectorblocks.NewSectorBlocks),
|
||||
|
||||
// Markets (retrieval)
|
||||
Override(new(retrievalmarket.RetrievalProvider), modules.RetrievalProvider),
|
||||
Override(new(dtypes.RetrievalDealFilter), modules.RetrievalDealFilter(nil)),
|
||||
Override(HandleRetrievalKey, modules.HandleRetrieval),
|
||||
|
||||
// Markets (storage)
|
||||
Override(new(dtypes.ProviderDataTransfer), modules.NewProviderDAGServiceDataTransfer),
|
||||
Override(new(*storedask.StoredAsk), modules.NewStorageAsk),
|
||||
Override(new(dtypes.StorageDealFilter), modules.BasicDealFilter(nil)),
|
||||
Override(new(dtypes.RetrievalDealFilter), modules.RetrievalDealFilter(nil)),
|
||||
Override(new(storagemarket.StorageProvider), modules.StorageProvider),
|
||||
Override(new(*storageadapter.DealPublisher), storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{})),
|
||||
Override(new(storagemarket.StorageProviderNode), storageadapter.NewProviderNodeAdapter(nil)),
|
||||
Override(HandleMigrateProviderFundsKey, modules.HandleMigrateProviderFunds),
|
||||
Override(HandleRetrievalKey, modules.HandleRetrieval),
|
||||
Override(GetParamsKey, modules.GetParams),
|
||||
Override(HandleDealsKey, modules.HandleDeals),
|
||||
Override(new(gen.WinningPoStProver), storage.NewWinningPoStProver),
|
||||
Override(new(*miner.Miner), modules.SetupBlockProducer),
|
||||
|
||||
// Config (todo: get a real property system)
|
||||
Override(new(dtypes.ConsiderOnlineStorageDealsConfigFunc), modules.NewConsiderOnlineStorageDealsConfigFunc),
|
||||
Override(new(dtypes.SetConsiderOnlineStorageDealsConfigFunc), modules.NewSetConsideringOnlineStorageDealsFunc),
|
||||
Override(new(dtypes.ConsiderOnlineRetrievalDealsConfigFunc), modules.NewConsiderOnlineRetrievalDealsConfigFunc),
|
||||
@ -404,7 +431,23 @@ func Online() Option {
|
||||
Override(new(dtypes.GetSealingConfigFunc), modules.NewGetSealConfigFunc),
|
||||
Override(new(dtypes.SetExpectedSealDurationFunc), modules.NewSetExpectedSealDurationFunc),
|
||||
Override(new(dtypes.GetExpectedSealDurationFunc), modules.NewGetExpectedSealDurationFunc),
|
||||
)
|
||||
|
||||
// Online sets up basic libp2p node
|
||||
func Online() Option {
|
||||
|
||||
return Options(
|
||||
// make sure that online is applied before Config.
|
||||
// This is important because Config overrides some of Online units
|
||||
func(s *Settings) error { s.Online = true; return nil },
|
||||
ApplyIf(func(s *Settings) bool { return s.Config },
|
||||
Error(errors.New("the Online option must be set before Config option")),
|
||||
),
|
||||
|
||||
LibP2P,
|
||||
|
||||
ApplyIf(isFullOrLiteNode, ChainNode),
|
||||
ApplyIf(isType(repo.StorageMiner), MinerNode),
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user