2019-06-29 09:19:06 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-07-04 15:50:48 +00:00
|
|
|
"errors"
|
2020-11-03 22:04:44 +00:00
|
|
|
"os"
|
2019-07-01 10:18:00 +00:00
|
|
|
"time"
|
2019-06-29 09:19:06 +00:00
|
|
|
|
fix metrics wiring.
Some components like go-ds-measure, go-ipfs-blockstore and go-bitswap
expose metrics via ipfs/go-metrics-interface, but Lotus never injects
the Prometheus exporter (ipfs/go-metrics-prometheus). Therefore, those
metrics never surface in instrumentation.
Instead, Lotus uses OpenCensus directly.
This commit injects the Prometheus exporter for go-metrics-interface, and
instructs the OpenCensus Prometheus exporter to use the DefaultRegistry.
This has the effect of exposing blending the metrics of both metrics
libraries.
With this patch, the datastore, cache utilisation, and bitswap metrics
are now exported via the /debug/metrics endpoint.
This commit also fixes an issue where the metrics scope was empty, making
go-metrics-interface default to "<no-scope>". Angle brackets are inadmissible
characters for Prometheus, so it was refusing to export the affected metrics.
(These were the ARC cache metrics.)
2020-11-02 17:56:49 +00:00
|
|
|
metricsi "github.com/ipfs/go-metrics-interface"
|
|
|
|
|
2020-11-05 06:44:46 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-10-08 09:24:31 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain"
|
|
|
|
"github.com/filecoin-project/lotus/chain/exchange"
|
2021-03-12 02:21:18 +00:00
|
|
|
rpcstmgr "github.com/filecoin-project/lotus/chain/stmgr/rpc"
|
2020-10-08 09:24:31 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
|
|
|
"github.com/filecoin-project/lotus/chain/vm"
|
|
|
|
"github.com/filecoin-project/lotus/chain/wallet"
|
|
|
|
"github.com/filecoin-project/lotus/node/hello"
|
2020-12-02 22:26:30 +00:00
|
|
|
"github.com/filecoin-project/lotus/system"
|
2020-10-08 09:24:31 +00:00
|
|
|
|
2021-04-06 13:04:32 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2019-07-01 10:18:00 +00:00
|
|
|
ci "github.com/libp2p/go-libp2p-core/crypto"
|
2019-07-05 10:06:28 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/host"
|
2019-06-29 09:19:06 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
2019-07-05 10:06:28 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/peerstore"
|
|
|
|
"github.com/libp2p/go-libp2p-core/routing"
|
2020-04-21 22:52:46 +00:00
|
|
|
dht "github.com/libp2p/go-libp2p-kad-dht"
|
2019-07-01 10:18:00 +00:00
|
|
|
"github.com/libp2p/go-libp2p-peerstore/pstoremem"
|
2019-07-08 14:07:09 +00:00
|
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
2019-07-05 10:06:28 +00:00
|
|
|
record "github.com/libp2p/go-libp2p-record"
|
2020-11-13 09:44:29 +00:00
|
|
|
"github.com/libp2p/go-libp2p/p2p/net/conngater"
|
2019-11-12 18:31:17 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2019-06-29 09:19:06 +00:00
|
|
|
"go.uber.org/fx"
|
2019-10-30 16:38:39 +00:00
|
|
|
"golang.org/x/xerrors"
|
2019-06-29 09:19:06 +00:00
|
|
|
|
2020-09-29 11:53:30 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/discovery"
|
|
|
|
discoveryimpl "github.com/filecoin-project/go-fil-markets/discovery/impl"
|
2020-01-10 17:13:12 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
2019-12-17 10:46:39 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
2020-05-20 22:46:44 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/storedask"
|
2020-03-11 07:22:21 +00:00
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
storage2 "github.com/filecoin-project/specs-storage/storage"
|
2020-01-13 20:47:27 +00:00
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-03-25 23:16:17 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/beacon"
|
2019-11-25 04:45:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/gen"
|
2020-08-06 01:16:54 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
|
2019-11-08 20:11:56 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/market"
|
2019-12-01 23:11:43 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/messagepool"
|
2020-09-29 10:19:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/messagesigner"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/metrics"
|
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-10-10 22:08:12 +00:00
|
|
|
ledgerwallet "github.com/filecoin-project/lotus/chain/wallet/ledger"
|
2020-09-05 19:36:32 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/wallet/remotewallet"
|
2020-08-17 13:39:33 +00:00
|
|
|
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
|
2020-08-17 13:26:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
2020-09-07 14:12:46 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
2020-08-17 13:39:33 +00:00
|
|
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
2020-07-17 13:22:37 +00:00
|
|
|
"github.com/filecoin-project/lotus/journal"
|
2020-02-22 11:36:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/peermgr"
|
2020-01-31 00:20:04 +00:00
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
|
|
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
2020-08-06 01:16:54 +00:00
|
|
|
"github.com/filecoin-project/lotus/markets/dealfilter"
|
2020-01-10 18:21:46 +00:00
|
|
|
"github.com/filecoin-project/lotus/markets/storageadapter"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/miner"
|
|
|
|
"github.com/filecoin-project/lotus/node/config"
|
|
|
|
"github.com/filecoin-project/lotus/node/impl"
|
2020-03-19 17:11:45 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/impl/common"
|
2020-10-01 15:54:28 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/impl/full"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/testing"
|
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
2020-02-13 00:28:23 +00:00
|
|
|
"github.com/filecoin-project/lotus/paychmgr"
|
2020-07-17 02:26:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/paychmgr/settler"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage"
|
2020-01-16 01:25:49 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
2019-06-29 09:19:06 +00:00
|
|
|
)
|
|
|
|
|
2020-08-20 04:49:10 +00:00
|
|
|
//nolint:deadcode,varcheck
|
2020-01-29 18:10:41 +00:00
|
|
|
var log = logging.Logger("builder")
|
|
|
|
|
2019-07-04 15:50:48 +00:00
|
|
|
// special is a type used to give keys to modules which
|
|
|
|
// can't really be identified by the returned type
|
|
|
|
type special struct{ id int }
|
|
|
|
|
2019-07-05 11:21:54 +00:00
|
|
|
//nolint:golint
|
2019-07-04 15:50:48 +00:00
|
|
|
var (
|
2020-04-28 13:21:56 +00:00
|
|
|
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
|
2020-04-27 17:20:39 +00:00
|
|
|
AutoNATSvcKey = special{10} // Libp2p option
|
2020-09-02 22:25:53 +00:00
|
|
|
BandwidthReporterKey = special{11} // Libp2p option
|
2020-11-13 09:44:29 +00:00
|
|
|
ConnGaterKey = special{12} // libp2p option
|
2019-07-04 15:50:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type invoke int
|
|
|
|
|
2020-09-02 18:15:07 +00:00
|
|
|
// Invokes are called in the order they are defined.
|
2019-07-08 13:36:43 +00:00
|
|
|
//nolint:golint
|
2019-07-04 15:50:48 +00:00
|
|
|
const (
|
2020-09-02 18:15:07 +00:00
|
|
|
// 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)
|
|
|
|
|
2020-12-02 16:40:28 +00:00
|
|
|
// System processes.
|
|
|
|
InitMemoryWatchdog
|
2019-07-04 20:06:02 +00:00
|
|
|
|
2020-12-02 16:40:28 +00:00
|
|
|
// libp2p
|
2020-09-02 18:15:07 +00:00
|
|
|
PstoreAddSelfKeysKey
|
2019-07-04 15:50:48 +00:00
|
|
|
StartListeningKey
|
2019-10-11 00:31:06 +00:00
|
|
|
BootstrapKey
|
2019-07-04 15:50:48 +00:00
|
|
|
|
2019-07-08 13:36:43 +00:00
|
|
|
// filecoin
|
2019-07-09 22:58:51 +00:00
|
|
|
SetGenesisKey
|
2019-07-08 14:07:09 +00:00
|
|
|
|
2019-07-08 13:36:43 +00:00
|
|
|
RunHelloKey
|
2020-09-07 18:45:34 +00:00
|
|
|
RunChainExchangeKey
|
2020-02-17 17:15:30 +00:00
|
|
|
RunChainGraphsync
|
2019-10-17 08:57:56 +00:00
|
|
|
RunPeerMgrKey
|
2019-07-08 14:07:09 +00:00
|
|
|
|
|
|
|
HandleIncomingBlocksKey
|
|
|
|
HandleIncomingMessagesKey
|
2020-11-11 05:06:50 +00:00
|
|
|
HandleMigrateClientFundsKey
|
2020-07-28 23:16:47 +00:00
|
|
|
HandlePaymentChannelManagerKey
|
2019-08-14 20:27:10 +00:00
|
|
|
|
2020-07-11 08:55:13 +00:00
|
|
|
// miner
|
2019-12-04 19:44:15 +00:00
|
|
|
GetParamsKey
|
2020-11-11 05:06:50 +00:00
|
|
|
HandleMigrateProviderFundsKey
|
2019-08-02 16:25:10 +00:00
|
|
|
HandleDealsKey
|
2019-08-26 13:45:36 +00:00
|
|
|
HandleRetrievalKey
|
2019-08-14 20:27:10 +00:00
|
|
|
RunSectorServiceKey
|
2019-08-01 17:12:41 +00:00
|
|
|
|
2019-07-23 15:33:25 +00:00
|
|
|
// daemon
|
2019-07-23 22:34:13 +00:00
|
|
|
ExtractApiKey
|
2019-10-10 11:07:00 +00:00
|
|
|
HeadMetricsKey
|
2020-07-17 02:26:22 +00:00
|
|
|
SettlePaymentChannelsKey
|
2019-12-17 16:28:02 +00:00
|
|
|
RunPeerTaggerKey
|
2021-02-28 22:48:36 +00:00
|
|
|
SetupFallbackBlockstoresKey
|
2019-07-23 22:34:13 +00:00
|
|
|
|
2019-07-10 17:28:49 +00:00
|
|
|
SetApiEndpointKey
|
|
|
|
|
2019-07-04 15:50:48 +00:00
|
|
|
_nInvokes // keep this last
|
|
|
|
)
|
|
|
|
|
2019-07-10 13:06:04 +00:00
|
|
|
type Settings struct {
|
2019-07-04 20:06:02 +00:00
|
|
|
// modules is a map of constructors for DI
|
|
|
|
//
|
|
|
|
// In most cases the index will be a reflect. Type of element returned by
|
|
|
|
// the constructor, but for some 'constructors' it's hard to specify what's
|
|
|
|
// the return type should be (or the constructor returns fx group)
|
2019-07-04 15:50:48 +00:00
|
|
|
modules map[interface{}]fx.Option
|
|
|
|
|
|
|
|
// invokes are separate from modules as they can't be referenced by return
|
|
|
|
// type, and must be applied in correct order
|
|
|
|
invokes []fx.Option
|
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
nodeType repo.RepoType
|
2019-07-19 09:23:24 +00:00
|
|
|
|
2019-07-10 13:06:04 +00:00
|
|
|
Online bool // Online option applied
|
|
|
|
Config bool // Config option applied
|
2020-10-08 09:24:31 +00:00
|
|
|
Lite bool // Start node in "lite" mode
|
2019-07-04 15:50:48 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 15:41:00 +00:00
|
|
|
// Basic lotus-app services
|
2019-07-09 17:03:36 +00:00
|
|
|
func defaults() []Option {
|
|
|
|
return []Option{
|
2020-08-26 15:09:37 +00:00
|
|
|
// global system journal.
|
2020-10-09 19:52:04 +00:00
|
|
|
Override(new(journal.DisabledEvents), journal.EnvDisabledEvents),
|
2020-08-26 15:09:37 +00:00
|
|
|
Override(new(journal.Journal), modules.OpenFilesystemJournal),
|
|
|
|
|
2020-12-02 22:26:30 +00:00
|
|
|
Override(new(system.MemoryConstraints), modules.MemoryConstraints),
|
2020-12-02 16:40:28 +00:00
|
|
|
Override(InitMemoryWatchdog, modules.MemoryWatchdog),
|
|
|
|
|
fix metrics wiring.
Some components like go-ds-measure, go-ipfs-blockstore and go-bitswap
expose metrics via ipfs/go-metrics-interface, but Lotus never injects
the Prometheus exporter (ipfs/go-metrics-prometheus). Therefore, those
metrics never surface in instrumentation.
Instead, Lotus uses OpenCensus directly.
This commit injects the Prometheus exporter for go-metrics-interface, and
instructs the OpenCensus Prometheus exporter to use the DefaultRegistry.
This has the effect of exposing blending the metrics of both metrics
libraries.
With this patch, the datastore, cache utilisation, and bitswap metrics
are now exported via the /debug/metrics endpoint.
This commit also fixes an issue where the metrics scope was empty, making
go-metrics-interface default to "<no-scope>". Angle brackets are inadmissible
characters for Prometheus, so it was refusing to export the affected metrics.
(These were the ARC cache metrics.)
2020-11-02 17:56:49 +00:00
|
|
|
Override(new(helpers.MetricsCtx), func() context.Context {
|
|
|
|
return metricsi.CtxScope(context.Background(), "lotus")
|
|
|
|
}),
|
|
|
|
|
2020-06-02 19:35:11 +00:00
|
|
|
Override(new(dtypes.ShutdownChan), make(chan struct{})),
|
2019-07-09 17:03:36 +00:00
|
|
|
}
|
2019-07-04 15:50:48 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 15:41:00 +00:00
|
|
|
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(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(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 {
|
|
|
|
return &config.Pubsub{
|
|
|
|
Bootstrapper: bool(bs),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
// Services (connection management)
|
|
|
|
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
|
|
|
|
Override(new(*conngater.BasicConnectionGater), lp2p.ConnGater),
|
|
|
|
Override(ConnGaterKey, lp2p.ConnGaterOption),
|
|
|
|
)
|
2019-07-19 09:23:24 +00:00
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
func isType(t repo.RepoType) func(s *Settings) bool {
|
|
|
|
return func(s *Settings) bool { return s.nodeType == t }
|
|
|
|
}
|
|
|
|
|
2021-02-08 15:41:00 +00:00
|
|
|
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
|
|
|
|
// 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),
|
|
|
|
|
|
|
|
// 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.StateManager), modules.StateManager),
|
|
|
|
Override(new(dtypes.ChainBitswap), modules.ChainBitswap),
|
|
|
|
Override(new(dtypes.ChainBlockService), modules.ChainBlockService), // todo: unused
|
|
|
|
|
|
|
|
// Consensus: Chain sync
|
|
|
|
|
|
|
|
// 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),
|
|
|
|
|
|
|
|
// Chain networking
|
|
|
|
Override(new(*hello.Service), hello.NewHelloService),
|
|
|
|
Override(new(exchange.Server), exchange.NewServer),
|
|
|
|
Override(new(*peermgr.PeerMgr), peermgr.NewPeerMgr),
|
|
|
|
|
|
|
|
// 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)),
|
|
|
|
|
|
|
|
// 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))),
|
2021-03-23 12:42:56 +00:00
|
|
|
Override(new(api.Wallet), From(new(wallet.MultiWallet))),
|
2021-02-08 15:41:00 +00:00
|
|
|
|
|
|
|
// Service: Payment channels
|
2021-03-12 10:27:00 +00:00
|
|
|
Override(new(paychmgr.PaychAPI), From(new(modules.PaychAPI))),
|
2021-03-12 01:35:31 +00:00
|
|
|
Override(new(*paychmgr.Store), modules.NewPaychStore),
|
|
|
|
Override(new(*paychmgr.Manager), modules.NewManager),
|
|
|
|
Override(HandlePaymentChannelManagerKey, modules.HandlePaychManager),
|
2021-02-08 15:41:00 +00:00
|
|
|
Override(SettlePaymentChannelsKey, settler.SettlePaymentChannels),
|
|
|
|
|
|
|
|
// 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),
|
|
|
|
|
2021-03-03 15:05:21 +00:00
|
|
|
Override(new(*full.GasPriceCache), full.NewGasPriceCache),
|
|
|
|
|
2021-02-08 15:41:00 +00:00
|
|
|
// Lite node API
|
|
|
|
ApplyIf(isLiteNode,
|
2021-05-07 13:20:37 +00:00
|
|
|
Override(new(messagepool.Provider), messagepool.NewProviderLite),
|
2021-02-08 15:41:00 +00:00
|
|
|
Override(new(messagesigner.MpoolNonceAPI), From(new(modules.MpoolNonceAPI))),
|
2021-03-23 12:42:56 +00:00
|
|
|
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))),
|
2021-03-12 02:21:18 +00:00
|
|
|
Override(new(stmgr.StateManagerAPI), rpcstmgr.NewRPCStateManager),
|
2021-02-08 15:41:00 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
// Full node API / service startup
|
|
|
|
ApplyIf(isFullNode,
|
2021-05-07 13:20:37 +00:00
|
|
|
Override(new(messagepool.Provider), messagepool.NewProvider),
|
2021-02-08 15:41:00 +00:00
|
|
|
Override(new(messagesigner.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),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
var MinerNode = Options(
|
|
|
|
// API dependencies
|
|
|
|
Override(new(api.Common), From(new(common.CommonAPI))),
|
|
|
|
Override(new(sectorstorage.StorageAuth), modules.StorageAuth),
|
|
|
|
|
|
|
|
// Actor config
|
|
|
|
Override(new(dtypes.MinerAddress), modules.MinerAddress),
|
|
|
|
Override(new(dtypes.MinerID), modules.MinerID),
|
|
|
|
Override(new(abi.RegisteredSealProof), modules.SealProofType),
|
|
|
|
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),
|
2021-05-19 13:20:23 +00:00
|
|
|
Override(new(ffiwrapper.Prover), ffiwrapper.ProofProver),
|
2021-02-08 15:41:00 +00:00
|
|
|
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(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(storagemarket.StorageProvider), modules.StorageProvider),
|
|
|
|
Override(new(*storageadapter.DealPublisher), storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{})),
|
2021-03-02 09:24:57 +00:00
|
|
|
Override(new(storagemarket.StorageProviderNode), storageadapter.NewProviderNodeAdapter(nil, nil)),
|
2021-02-08 15:41:00 +00:00
|
|
|
Override(HandleMigrateProviderFundsKey, modules.HandleMigrateProviderFunds),
|
|
|
|
Override(HandleDealsKey, modules.HandleDeals),
|
|
|
|
|
|
|
|
// 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),
|
|
|
|
Override(new(dtypes.SetConsiderOnlineRetrievalDealsConfigFunc), modules.NewSetConsiderOnlineRetrievalDealsConfigFunc),
|
|
|
|
Override(new(dtypes.StorageDealPieceCidBlocklistConfigFunc), modules.NewStorageDealPieceCidBlocklistConfigFunc),
|
|
|
|
Override(new(dtypes.SetStorageDealPieceCidBlocklistConfigFunc), modules.NewSetStorageDealPieceCidBlocklistConfigFunc),
|
|
|
|
Override(new(dtypes.ConsiderOfflineStorageDealsConfigFunc), modules.NewConsiderOfflineStorageDealsConfigFunc),
|
|
|
|
Override(new(dtypes.SetConsiderOfflineStorageDealsConfigFunc), modules.NewSetConsideringOfflineStorageDealsFunc),
|
|
|
|
Override(new(dtypes.ConsiderOfflineRetrievalDealsConfigFunc), modules.NewConsiderOfflineRetrievalDealsConfigFunc),
|
|
|
|
Override(new(dtypes.SetConsiderOfflineRetrievalDealsConfigFunc), modules.NewSetConsiderOfflineRetrievalDealsConfigFunc),
|
|
|
|
Override(new(dtypes.ConsiderVerifiedStorageDealsConfigFunc), modules.NewConsiderVerifiedStorageDealsConfigFunc),
|
|
|
|
Override(new(dtypes.SetConsiderVerifiedStorageDealsConfigFunc), modules.NewSetConsideringVerifiedStorageDealsFunc),
|
|
|
|
Override(new(dtypes.ConsiderUnverifiedStorageDealsConfigFunc), modules.NewConsiderUnverifiedStorageDealsConfigFunc),
|
|
|
|
Override(new(dtypes.SetConsiderUnverifiedStorageDealsConfigFunc), modules.NewSetConsideringUnverifiedStorageDealsFunc),
|
|
|
|
Override(new(dtypes.SetSealingConfigFunc), modules.NewSetSealConfigFunc),
|
|
|
|
Override(new(dtypes.GetSealingConfigFunc), modules.NewGetSealConfigFunc),
|
|
|
|
Override(new(dtypes.SetExpectedSealDurationFunc), modules.NewSetExpectedSealDurationFunc),
|
|
|
|
Override(new(dtypes.GetExpectedSealDurationFunc), modules.NewGetExpectedSealDurationFunc),
|
|
|
|
)
|
|
|
|
|
2019-07-19 09:23:24 +00:00
|
|
|
// Online sets up basic libp2p node
|
|
|
|
func Online() Option {
|
2020-10-08 09:24:31 +00:00
|
|
|
|
2019-07-19 09:23:24 +00:00
|
|
|
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")),
|
|
|
|
),
|
2019-07-08 13:36:43 +00:00
|
|
|
|
2021-02-08 15:41:00 +00:00
|
|
|
LibP2P,
|
2020-10-08 09:24:31 +00:00
|
|
|
|
2021-02-08 15:41:00 +00:00
|
|
|
ApplyIf(isFullOrLiteNode, ChainNode),
|
|
|
|
ApplyIf(isType(repo.StorageMiner), MinerNode),
|
2019-07-19 09:23:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-24 00:58:31 +00:00
|
|
|
func StorageMiner(out *api.StorageMiner) Option {
|
2019-07-19 09:23:24 +00:00
|
|
|
return Options(
|
|
|
|
ApplyIf(func(s *Settings) bool { return s.Config },
|
|
|
|
Error(errors.New("the StorageMiner option must be set before Config option")),
|
|
|
|
),
|
|
|
|
ApplyIf(func(s *Settings) bool { return s.Online },
|
|
|
|
Error(errors.New("the StorageMiner option must be set before Online option")),
|
|
|
|
),
|
|
|
|
|
|
|
|
func(s *Settings) error {
|
2019-11-12 17:59:38 +00:00
|
|
|
s.nodeType = repo.StorageMiner
|
2019-07-19 09:23:24 +00:00
|
|
|
return nil
|
|
|
|
},
|
2019-07-24 00:58:31 +00:00
|
|
|
|
|
|
|
func(s *Settings) error {
|
2019-07-24 01:13:56 +00:00
|
|
|
resAPI := &impl.StorageMinerAPI{}
|
2020-09-16 01:14:56 +00:00
|
|
|
s.invokes[ExtractApiKey] = fx.Populate(resAPI)
|
2019-07-24 00:58:31 +00:00
|
|
|
*out = resAPI
|
|
|
|
return nil
|
|
|
|
},
|
2019-07-04 15:50:48 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-10 13:06:04 +00:00
|
|
|
// Config sets up constructors based on the provided Config
|
2019-10-30 16:38:39 +00:00
|
|
|
func ConfigCommon(cfg *config.Common) Option {
|
2019-07-04 15:50:48 +00:00
|
|
|
return Options(
|
2019-07-10 13:06:04 +00:00
|
|
|
func(s *Settings) error { s.Config = true; return nil },
|
2020-03-16 17:50:07 +00:00
|
|
|
Override(new(dtypes.APIEndpoint), func() (dtypes.APIEndpoint, error) {
|
|
|
|
return multiaddr.NewMultiaddr(cfg.API.ListenAddress)
|
|
|
|
}),
|
|
|
|
Override(SetApiEndpointKey, func(lr repo.LockedRepo, e dtypes.APIEndpoint) error {
|
|
|
|
return lr.SetAPIEndpoint(e)
|
|
|
|
}),
|
2020-08-17 13:26:18 +00:00
|
|
|
Override(new(sectorstorage.URLs), func(e dtypes.APIEndpoint) (sectorstorage.URLs, error) {
|
2020-04-03 04:54:07 +00:00
|
|
|
ip := cfg.API.RemoteListenAddress
|
2019-11-12 18:31:17 +00:00
|
|
|
|
2020-08-17 13:26:18 +00:00
|
|
|
var urls sectorstorage.URLs
|
2020-04-03 05:01:39 +00:00
|
|
|
urls = append(urls, "http://"+ip+"/remote") // TODO: This makes no assumptions, and probably could...
|
2020-03-16 17:50:07 +00:00
|
|
|
return urls, nil
|
|
|
|
}),
|
2019-07-10 13:06:04 +00:00
|
|
|
ApplyIf(func(s *Settings) bool { return s.Online },
|
2019-07-04 15:50:48 +00:00
|
|
|
Override(StartListeningKey, lp2p.StartListening(cfg.Libp2p.ListenAddresses)),
|
2019-12-17 16:09:43 +00:00
|
|
|
Override(ConnectionManagerKey, lp2p.ConnectionManager(
|
|
|
|
cfg.Libp2p.ConnMgrLow,
|
|
|
|
cfg.Libp2p.ConnMgrHigh,
|
|
|
|
time.Duration(cfg.Libp2p.ConnMgrGrace),
|
|
|
|
cfg.Libp2p.ProtectedPeers)),
|
2020-05-14 01:10:49 +00:00
|
|
|
Override(new(*pubsub.PubSub), lp2p.GossipSub),
|
|
|
|
Override(new(*config.Pubsub), &cfg.Pubsub),
|
2019-10-11 02:45:45 +00:00
|
|
|
|
2019-10-11 03:16:12 +00:00
|
|
|
ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 },
|
|
|
|
Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)),
|
|
|
|
),
|
2019-07-04 15:50:48 +00:00
|
|
|
),
|
2020-06-09 00:03:11 +00:00
|
|
|
Override(AddrsFactoryKey, lp2p.AddrsFactory(
|
|
|
|
cfg.Libp2p.AnnounceAddresses,
|
|
|
|
cfg.Libp2p.NoAnnounceAddresses)),
|
2021-03-09 21:33:01 +00:00
|
|
|
Override(new(dtypes.MetadataDS), modules.Datastore(cfg.Backup.DisableMetadataLog)),
|
2019-07-04 15:50:48 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-12 17:59:38 +00:00
|
|
|
func ConfigFullNode(c interface{}) Option {
|
2019-10-30 16:38:39 +00:00
|
|
|
cfg, ok := c.(*config.FullNode)
|
|
|
|
if !ok {
|
|
|
|
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
|
2019-07-10 15:38:35 +00:00
|
|
|
}
|
2019-10-30 16:38:39 +00:00
|
|
|
|
2020-05-26 12:50:35 +00:00
|
|
|
ipfsMaddr := cfg.Client.IpfsMAddr
|
2019-11-12 17:59:38 +00:00
|
|
|
return Options(
|
|
|
|
ConfigCommon(&cfg.Common),
|
2020-11-25 18:57:38 +00:00
|
|
|
|
2020-04-29 23:51:55 +00:00
|
|
|
If(cfg.Client.UseIpfs,
|
2020-10-29 18:16:45 +00:00
|
|
|
Override(new(dtypes.ClientBlockstore), modules.IpfsClientBlockstore(ipfsMaddr, cfg.Client.IpfsOnlineMode)),
|
2020-07-31 20:24:50 +00:00
|
|
|
If(cfg.Client.IpfsUseForRetrieval,
|
|
|
|
Override(new(dtypes.ClientRetrievalStoreManager), modules.ClientBlockstoreRetrievalStoreManager),
|
|
|
|
),
|
2020-04-29 23:51:55 +00:00
|
|
|
),
|
2020-11-25 18:57:38 +00:00
|
|
|
Override(new(dtypes.Graphsync), modules.Graphsync(cfg.Client.SimultaneousTransfers)),
|
|
|
|
|
2019-12-11 15:08:50 +00:00
|
|
|
If(cfg.Metrics.HeadNotifs,
|
|
|
|
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
|
|
|
|
),
|
2020-10-10 22:08:12 +00:00
|
|
|
|
2020-09-05 19:36:32 +00:00
|
|
|
If(cfg.Wallet.RemoteBackend != "",
|
2020-10-10 22:08:12 +00:00
|
|
|
Override(new(*remotewallet.RemoteWallet), remotewallet.SetupRemoteWallet(cfg.Wallet.RemoteBackend)),
|
|
|
|
),
|
|
|
|
If(cfg.Wallet.EnableLedger,
|
|
|
|
Override(new(*ledgerwallet.LedgerWallet), ledgerwallet.NewWallet),
|
|
|
|
),
|
|
|
|
If(cfg.Wallet.DisableLocal,
|
|
|
|
Unset(new(*wallet.LocalWallet)),
|
|
|
|
Override(new(wallet.Default), wallet.NilDefault),
|
2020-09-05 19:36:32 +00:00
|
|
|
),
|
2019-11-12 17:59:38 +00:00
|
|
|
)
|
2019-10-30 16:38:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 22:19:22 +00:00
|
|
|
func ConfigStorageMiner(c interface{}) Option {
|
2019-10-30 16:38:39 +00:00
|
|
|
cfg, ok := c.(*config.StorageMiner)
|
|
|
|
if !ok {
|
|
|
|
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
|
2019-07-10 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 19:38:00 +00:00
|
|
|
return Options(
|
|
|
|
ConfigCommon(&cfg.Common),
|
|
|
|
|
2020-07-30 17:36:31 +00:00
|
|
|
If(cfg.Dealmaking.Filter != "",
|
2020-10-15 16:24:48 +00:00
|
|
|
Override(new(dtypes.StorageDealFilter), modules.BasicDealFilter(dealfilter.CliStorageDealFilter(cfg.Dealmaking.Filter))),
|
2020-10-16 15:30:55 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
If(cfg.Dealmaking.RetrievalFilter != "",
|
|
|
|
Override(new(dtypes.RetrievalDealFilter), modules.RetrievalDealFilter(dealfilter.CliRetrievalDealFilter(cfg.Dealmaking.RetrievalFilter))),
|
2020-07-30 17:36:31 +00:00
|
|
|
),
|
|
|
|
|
2021-02-01 09:23:05 +00:00
|
|
|
Override(new(*storageadapter.DealPublisher), storageadapter.NewDealPublisher(&cfg.Fees, storageadapter.PublishMsgConfig{
|
|
|
|
Period: time.Duration(cfg.Dealmaking.PublishMsgPeriod),
|
|
|
|
MaxDealsPerMsg: cfg.Dealmaking.MaxDealsPerPublishMsg,
|
|
|
|
})),
|
2021-03-02 09:24:57 +00:00
|
|
|
Override(new(storagemarket.StorageProviderNode), storageadapter.NewProviderNodeAdapter(&cfg.Fees, &cfg.Dealmaking)),
|
2020-10-02 16:34:50 +00:00
|
|
|
|
2020-08-17 13:26:18 +00:00
|
|
|
Override(new(sectorstorage.SealerConfig), cfg.Storage),
|
2020-12-02 18:58:00 +00:00
|
|
|
Override(new(*storage.AddressSelector), modules.AddressSelector(&cfg.Addresses)),
|
2020-08-12 17:47:00 +00:00
|
|
|
Override(new(*storage.Miner), modules.StorageMiner(cfg.Fees)),
|
2020-03-24 19:38:00 +00:00
|
|
|
)
|
2019-10-30 16:38:39 +00:00
|
|
|
}
|
2019-07-10 15:38:35 +00:00
|
|
|
|
2019-10-30 16:38:39 +00:00
|
|
|
func Repo(r repo.Repo) Option {
|
2019-10-30 22:33:31 +00:00
|
|
|
return func(settings *Settings) error {
|
|
|
|
lr, err := r.Lock(settings.nodeType)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c, err := lr.Config()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-07-10 17:36:17 +00:00
|
|
|
|
2021-03-02 13:45:36 +00:00
|
|
|
var cfg *config.Chainstore
|
2021-02-26 13:45:30 +00:00
|
|
|
switch settings.nodeType {
|
|
|
|
case repo.FullNode:
|
|
|
|
cfgp, ok := c.(*config.FullNode)
|
|
|
|
if !ok {
|
|
|
|
return xerrors.Errorf("invalid config from repo, got: %T", c)
|
|
|
|
}
|
2021-03-02 13:45:36 +00:00
|
|
|
cfg = &cfgp.Chainstore
|
2021-02-26 13:45:30 +00:00
|
|
|
default:
|
2021-03-02 13:45:36 +00:00
|
|
|
cfg = &config.Chainstore{}
|
2021-02-26 13:45:30 +00:00
|
|
|
}
|
|
|
|
|
2019-10-30 22:33:31 +00:00
|
|
|
return Options(
|
|
|
|
Override(new(repo.LockedRepo), modules.LockedRepo(lr)), // module handles closing
|
2019-07-16 16:02:51 +00:00
|
|
|
|
2021-02-28 22:48:36 +00:00
|
|
|
Override(new(dtypes.UniversalBlockstore), modules.UniversalBlockstore),
|
2021-02-26 13:45:30 +00:00
|
|
|
|
2021-02-27 13:20:14 +00:00
|
|
|
If(cfg.EnableSplitstore,
|
2021-03-02 13:45:36 +00:00
|
|
|
If(cfg.Splitstore.HotStoreType == "badger",
|
2021-02-26 13:45:30 +00:00
|
|
|
Override(new(dtypes.HotBlockstore), modules.BadgerHotBlockstore)),
|
2021-02-27 10:10:10 +00:00
|
|
|
Override(new(dtypes.SplitBlockstore), modules.SplitBlockstore(cfg)),
|
2021-04-09 13:29:16 +00:00
|
|
|
Override(new(dtypes.BasicChainBlockstore), modules.ChainSplitBlockstore),
|
|
|
|
Override(new(dtypes.BasicStateBlockstore), modules.StateSplitBlockstore),
|
2021-02-26 13:45:30 +00:00
|
|
|
Override(new(dtypes.BaseBlockstore), From(new(dtypes.SplitBlockstore))),
|
|
|
|
Override(new(dtypes.ExposedBlockstore), From(new(dtypes.SplitBlockstore))),
|
|
|
|
),
|
2021-02-27 13:20:14 +00:00
|
|
|
If(!cfg.EnableSplitstore,
|
2021-04-09 13:29:16 +00:00
|
|
|
Override(new(dtypes.BasicChainBlockstore), modules.ChainFlatBlockstore),
|
|
|
|
Override(new(dtypes.BasicStateBlockstore), modules.StateFlatBlockstore),
|
2021-02-26 13:45:30 +00:00
|
|
|
Override(new(dtypes.BaseBlockstore), From(new(dtypes.UniversalBlockstore))),
|
|
|
|
Override(new(dtypes.ExposedBlockstore), From(new(dtypes.UniversalBlockstore))),
|
|
|
|
),
|
2020-11-03 22:04:44 +00:00
|
|
|
|
2021-04-09 13:29:16 +00:00
|
|
|
Override(new(dtypes.ChainBlockstore), From(new(dtypes.BasicChainBlockstore))),
|
|
|
|
Override(new(dtypes.StateBlockstore), From(new(dtypes.BasicStateBlockstore))),
|
|
|
|
|
2020-11-03 22:04:44 +00:00
|
|
|
If(os.Getenv("LOTUS_ENABLE_CHAINSTORE_FALLBACK") == "1",
|
|
|
|
Override(new(dtypes.ChainBlockstore), modules.FallbackChainBlockstore),
|
2021-02-28 22:48:36 +00:00
|
|
|
Override(new(dtypes.StateBlockstore), modules.FallbackStateBlockstore),
|
|
|
|
Override(SetupFallbackBlockstoresKey, modules.InitFallbackBlockstores),
|
2020-11-03 22:04:44 +00:00
|
|
|
),
|
2019-07-23 20:23:44 +00:00
|
|
|
|
2020-07-07 08:52:19 +00:00
|
|
|
Override(new(dtypes.ClientImportMgr), modules.ClientImportMgr),
|
2020-07-06 23:39:30 +00:00
|
|
|
Override(new(dtypes.ClientMultiDstore), modules.ClientMultiDatastore),
|
2020-07-07 08:52:19 +00:00
|
|
|
|
2019-10-30 22:33:31 +00:00
|
|
|
Override(new(dtypes.ClientBlockstore), modules.ClientBlockstore),
|
2020-07-31 20:24:50 +00:00
|
|
|
Override(new(dtypes.ClientRetrievalStoreManager), modules.ClientRetrievalStoreManager),
|
2019-10-30 22:33:31 +00:00
|
|
|
Override(new(ci.PrivKey), lp2p.PrivKey),
|
|
|
|
Override(new(ci.PubKey), ci.PrivKey.GetPublic),
|
|
|
|
Override(new(peer.ID), peer.IDFromPublicKey),
|
2019-07-23 20:23:44 +00:00
|
|
|
|
2019-10-30 22:33:31 +00:00
|
|
|
Override(new(types.KeyStore), modules.KeyStore),
|
|
|
|
|
|
|
|
Override(new(*dtypes.APIAlg), modules.APISecret),
|
2020-04-29 23:51:55 +00:00
|
|
|
|
|
|
|
ApplyIf(isType(repo.FullNode), ConfigFullNode(c)),
|
|
|
|
ApplyIf(isType(repo.StorageMiner), ConfigStorageMiner(c)),
|
2019-10-30 22:33:31 +00:00
|
|
|
)(settings)
|
|
|
|
}
|
2019-07-10 15:38:35 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 16:43:22 +00:00
|
|
|
type FullOption = Option
|
|
|
|
|
|
|
|
func Lite(enable bool) FullOption {
|
|
|
|
return func(s *Settings) error {
|
|
|
|
s.Lite = enable
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func FullAPI(out *api.FullNode, fopts ...FullOption) Option {
|
2020-09-14 03:00:08 +00:00
|
|
|
return Options(
|
|
|
|
func(s *Settings) error {
|
|
|
|
s.nodeType = repo.FullNode
|
|
|
|
return nil
|
|
|
|
},
|
2020-10-09 16:43:22 +00:00
|
|
|
Options(fopts...),
|
2020-09-14 03:00:08 +00:00
|
|
|
func(s *Settings) error {
|
|
|
|
resAPI := &impl.FullNodeAPI{}
|
2020-09-16 01:14:56 +00:00
|
|
|
s.invokes[ExtractApiKey] = fx.Populate(resAPI)
|
2020-09-14 03:00:08 +00:00
|
|
|
*out = resAPI
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
)
|
2019-07-23 22:34:13 +00:00
|
|
|
}
|
|
|
|
|
2019-09-17 14:23:08 +00:00
|
|
|
type StopFunc func(context.Context) error
|
|
|
|
|
2019-07-02 13:05:43 +00:00
|
|
|
// New builds and starts new Filecoin node
|
2019-09-17 14:23:08 +00:00
|
|
|
func New(ctx context.Context, opts ...Option) (StopFunc, error) {
|
2019-07-10 13:06:04 +00:00
|
|
|
settings := Settings{
|
2020-09-14 03:00:08 +00:00
|
|
|
modules: map[interface{}]fx.Option{},
|
|
|
|
invokes: make([]fx.Option, _nInvokes),
|
2019-07-04 15:50:48 +00:00
|
|
|
}
|
2019-06-29 09:19:06 +00:00
|
|
|
|
2019-07-04 20:06:02 +00:00
|
|
|
// apply module options in the right order
|
2019-07-09 17:03:36 +00:00
|
|
|
if err := Options(Options(defaults()...), Options(opts...))(&settings); err != nil {
|
2020-02-27 23:14:15 +00:00
|
|
|
return nil, xerrors.Errorf("applying node options failed: %w", err)
|
2019-07-04 15:50:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-04 20:06:02 +00:00
|
|
|
// gather constructors for fx.Options
|
2019-07-04 15:50:48 +00:00
|
|
|
ctors := make([]fx.Option, 0, len(settings.modules))
|
|
|
|
for _, opt := range settings.modules {
|
|
|
|
ctors = append(ctors, opt)
|
|
|
|
}
|
|
|
|
|
2019-07-04 20:06:02 +00:00
|
|
|
// fill holes in invokes for use in fx.Options
|
2019-07-04 15:50:48 +00:00
|
|
|
for i, opt := range settings.invokes {
|
|
|
|
if opt == nil {
|
|
|
|
settings.invokes[i] = fx.Options()
|
|
|
|
}
|
|
|
|
}
|
2019-07-01 10:18:00 +00:00
|
|
|
|
2019-06-29 09:19:06 +00:00
|
|
|
app := fx.New(
|
2019-07-04 15:50:48 +00:00
|
|
|
fx.Options(ctors...),
|
|
|
|
fx.Options(settings.invokes...),
|
2019-06-29 09:19:06 +00:00
|
|
|
|
2019-07-09 17:03:36 +00:00
|
|
|
fx.NopLogger,
|
2019-06-29 09:19:06 +00:00
|
|
|
)
|
|
|
|
|
2019-07-04 20:06:02 +00:00
|
|
|
// TODO: we probably should have a 'firewall' for Closing signal
|
|
|
|
// on this context, and implement closing logic through lifecycles
|
|
|
|
// correctly
|
2019-06-29 09:19:06 +00:00
|
|
|
if err := app.Start(ctx); err != nil {
|
2019-07-30 11:45:48 +00:00
|
|
|
// comment fx.NopLogger few lines above for easier debugging
|
2020-02-27 23:14:15 +00:00
|
|
|
return nil, xerrors.Errorf("starting node: %w", err)
|
2019-06-29 09:19:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-17 14:23:08 +00:00
|
|
|
return app.Stop, nil
|
2019-06-29 09:19:06 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 10:18:00 +00:00
|
|
|
// In-memory / testing
|
|
|
|
|
2019-10-23 11:02:00 +00:00
|
|
|
func Test() Option {
|
2019-07-04 15:50:48 +00:00
|
|
|
return Options(
|
2019-10-23 11:02:00 +00:00
|
|
|
Unset(RunPeerMgrKey),
|
|
|
|
Unset(new(*peermgr.PeerMgr)),
|
2020-09-09 18:37:12 +00:00
|
|
|
Override(new(beacon.Schedule), testing.RandomBeacon),
|
2021-02-01 09:23:05 +00:00
|
|
|
Override(new(*storageadapter.DealPublisher), storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{})),
|
2019-07-01 10:18:00 +00:00
|
|
|
)
|
|
|
|
}
|
2021-03-03 21:15:13 +00:00
|
|
|
|
|
|
|
// For 3rd party dep injection.
|
|
|
|
|
|
|
|
func WithRepoType(repoType repo.RepoType) func(s *Settings) error {
|
|
|
|
return func(s *Settings) error {
|
|
|
|
s.nodeType = repoType
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithInvokesKey(i invoke, resApi interface{}) func(s *Settings) error {
|
|
|
|
return func(s *Settings) error {
|
|
|
|
s.invokes[i] = fx.Populate(resApi)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|