From 11dd4c9df7138d07390631b9b8661bacd09beb45 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Wed, 17 Jul 2024 19:19:46 +0200 Subject: [PATCH] chore: config: yet more lp2p removal from miner --- .../en/default-lotus-miner-config.toml | 96 ------------------- node/builder.go | 33 +------ node/builder_chain.go | 35 ++++++- node/builder_miner.go | 6 +- node/config/def.go | 22 +++-- node/config/doc_gen.go | 24 ++--- node/config/types.go | 4 +- 7 files changed, 63 insertions(+), 157 deletions(-) diff --git a/documentation/en/default-lotus-miner-config.toml b/documentation/en/default-lotus-miner-config.toml index bc2c374362d..aaf58fec1cb 100644 --- a/documentation/en/default-lotus-miner-config.toml +++ b/documentation/en/default-lotus-miner-config.toml @@ -32,102 +32,6 @@ #example-subsystem = "INFO" -[Libp2p] - # Binding address for the libp2p host - 0 means random port. - # Format: multiaddress; see https://multiformats.io/multiaddr/ - # - # type: []string - # env var: LOTUS_LIBP2P_LISTENADDRESSES - #ListenAddresses = ["/ip4/0.0.0.0/tcp/0", "/ip6/::/tcp/0", "/ip4/0.0.0.0/udp/0/quic-v1", "/ip6/::/udp/0/quic-v1", "/ip4/0.0.0.0/udp/0/quic-v1/webtransport", "/ip6/::/udp/0/quic-v1/webtransport"] - - # Addresses to explicitally announce to other peers. If not specified, - # all interface addresses are announced - # Format: multiaddress - # - # type: []string - # env var: LOTUS_LIBP2P_ANNOUNCEADDRESSES - #AnnounceAddresses = [] - - # Addresses to not announce - # Format: multiaddress - # - # type: []string - # env var: LOTUS_LIBP2P_NOANNOUNCEADDRESSES - #NoAnnounceAddresses = [] - - # When not disabled (default), lotus asks NAT devices (e.g., routers), to - # open up an external port and forward it to the port lotus is running on. - # When this works (i.e., when your router supports NAT port forwarding), - # it makes the local lotus node accessible from the public internet - # - # type: bool - # env var: LOTUS_LIBP2P_DISABLENATPORTMAP - #DisableNatPortMap = false - - # ConnMgrLow is the number of connections that the basic connection manager - # will trim down to. - # - # type: uint - # env var: LOTUS_LIBP2P_CONNMGRLOW - #ConnMgrLow = 150 - - # ConnMgrHigh is the number of connections that, when exceeded, will trigger - # a connection GC operation. Note: protected/recently formed connections don't - # count towards this limit. - # - # type: uint - # env var: LOTUS_LIBP2P_CONNMGRHIGH - #ConnMgrHigh = 180 - - # ConnMgrGrace is a time duration that new connections are immune from being - # closed by the connection manager. - # - # type: Duration - # env var: LOTUS_LIBP2P_CONNMGRGRACE - #ConnMgrGrace = "20s" - - -[Pubsub] - # Run the node in bootstrap-node mode - # - # type: bool - # env var: LOTUS_PUBSUB_BOOTSTRAPPER - #Bootstrapper = false - - # type: string - # env var: LOTUS_PUBSUB_REMOTETRACER - #RemoteTracer = "" - - # Path to file that will be used to output tracer content in JSON format. - # If present tracer will save data to defined file. - # Format: file path - # - # type: string - # env var: LOTUS_PUBSUB_JSONTRACER - #JsonTracer = "" - - # Connection string for elasticsearch instance. - # If present tracer will save data to elasticsearch. - # Format: https://:@:/ - # - # type: string - # env var: LOTUS_PUBSUB_ELASTICSEARCHTRACER - #ElasticSearchTracer = "" - - # Name of elasticsearch index that will be used to save tracer data. - # This property is used only if ElasticSearchTracer propery is set. - # - # type: string - # env var: LOTUS_PUBSUB_ELASTICSEARCHINDEX - #ElasticSearchIndex = "" - - # Auth token that will be passed with logs to elasticsearch - used for weighted peers score. - # - # type: string - # env var: LOTUS_PUBSUB_TRACERSOURCEAUTH - #TracerSourceAuth = "" - - [Subsystems] # type: bool # env var: LOTUS_SUBSYSTEMS_ENABLEMINING diff --git a/node/builder.go b/node/builder.go index ee501bf54c9..94fe170cc21 100644 --- a/node/builder.go +++ b/node/builder.go @@ -36,7 +36,6 @@ import ( _ "github.com/filecoin-project/lotus/lib/sigs/secp" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/impl/common" - "github.com/filecoin-project/lotus/node/impl/net" "github.com/filecoin-project/lotus/node/modules" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/helpers" @@ -262,7 +261,7 @@ func Base() Option { } // ConfigCommon sets up constructors based on the provided Config -func ConfigCommon(cfg *config.Common, buildVersion build.BuildVersion, enableLibp2pNode bool) Option { +func ConfigCommon(cfg *config.Common, buildVersion build.BuildVersion) Option { // setup logging early lotuslog.SetLevelsFromConfig(cfg.Logging.SubsystemLevels) @@ -283,33 +282,9 @@ func ConfigCommon(cfg *config.Common, buildVersion build.BuildVersion, enableLib return urls, nil }), ApplyIf(func(s *Settings) bool { return s.Base }), // apply only if Base has already been applied - If(!enableLibp2pNode, - Override(new(api.Net), new(api.NetStub)), - Override(new(api.Common), From(new(common.CommonAPI))), - ), - If(enableLibp2pNode, - Override(new(api.Net), From(new(net.NetAPI))), - Override(new(api.Common), From(new(common.CommonAPI))), - Override(StartListeningKey, lp2p.StartListening(cfg.Libp2p.ListenAddresses)), - Override(ConnectionManagerKey, lp2p.ConnectionManager( - cfg.Libp2p.ConnMgrLow, - cfg.Libp2p.ConnMgrHigh, - time.Duration(cfg.Libp2p.ConnMgrGrace), - cfg.Libp2p.ProtectedPeers)), - Override(new(network.ResourceManager), lp2p.ResourceManager(cfg.Libp2p.ConnMgrHigh)), - Override(new(*pubsub.PubSub), lp2p.GossipSub), - Override(new(*config.Pubsub), &cfg.Pubsub), - - ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 }, - Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)), - ), - - Override(AddrsFactoryKey, lp2p.AddrsFactory( - cfg.Libp2p.AnnounceAddresses, - cfg.Libp2p.NoAnnounceAddresses)), - - If(!cfg.Libp2p.DisableNatPortMap, Override(NatPortMapKey, lp2p.NatPortMap)), - ), + Override(new(api.Net), new(api.NetStub)), + Override(new(api.Common), From(new(common.CommonAPI))), + Override(new(dtypes.MetadataDS), modules.Datastore(cfg.Backup.DisableMetadataLog)), ) } diff --git a/node/builder_chain.go b/node/builder_chain.go index deda103042d..23b16a12fd4 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -2,7 +2,10 @@ package node import ( "os" + "time" + pubsub "github.com/libp2p/go-libp2p-pubsub" + "github.com/libp2p/go-libp2p/core/network" "go.uber.org/fx" "golang.org/x/xerrors" @@ -34,9 +37,12 @@ import ( "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/hello" "github.com/filecoin-project/lotus/node/impl" + "github.com/filecoin-project/lotus/node/impl/common" "github.com/filecoin-project/lotus/node/impl/full" + "github.com/filecoin-project/lotus/node/impl/net" "github.com/filecoin-project/lotus/node/modules" "github.com/filecoin-project/lotus/node/modules/dtypes" + "github.com/filecoin-project/lotus/node/modules/lp2p" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/paychmgr" "github.com/filecoin-project/lotus/paychmgr/settler" @@ -165,10 +171,33 @@ func ConfigFullNode(c interface{}) Option { return Error(xerrors.Errorf("invalid config from repo, got: %T", c)) } - enableLibp2pNode := true // always enable libp2p for full nodes - return Options( - ConfigCommon(&cfg.Common, build.NodeUserVersion(), enableLibp2pNode), + ConfigCommon(&cfg.Common, build.NodeUserVersion()), + + // always enable libp2p for full nodes + Override(new(api.Net), new(api.NetStub)), + Override(new(api.Common), From(new(common.CommonAPI))), + Override(new(api.Net), From(new(net.NetAPI))), + Override(new(api.Common), From(new(common.CommonAPI))), + Override(StartListeningKey, lp2p.StartListening(cfg.Libp2p.ListenAddresses)), + Override(ConnectionManagerKey, lp2p.ConnectionManager( + cfg.Libp2p.ConnMgrLow, + cfg.Libp2p.ConnMgrHigh, + time.Duration(cfg.Libp2p.ConnMgrGrace), + cfg.Libp2p.ProtectedPeers)), + Override(new(network.ResourceManager), lp2p.ResourceManager(cfg.Libp2p.ConnMgrHigh)), + Override(new(*pubsub.PubSub), lp2p.GossipSub), + Override(new(*config.Pubsub), &cfg.Pubsub), + + ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 }, + Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)), + ), + + Override(AddrsFactoryKey, lp2p.AddrsFactory( + cfg.Libp2p.AnnounceAddresses, + cfg.Libp2p.NoAnnounceAddresses)), + + If(!cfg.Libp2p.DisableNatPortMap, Override(NatPortMapKey, lp2p.NatPortMap)), Override(new(dtypes.UniversalBlockstore), modules.UniversalBlockstore), diff --git a/node/builder_miner.go b/node/builder_miner.go index 9aaf2fc4bc6..48de2de28ad 100644 --- a/node/builder_miner.go +++ b/node/builder_miner.go @@ -53,11 +53,7 @@ func ConfigStorageMiner(c interface{}) Option { return Options( Override(new(v1api.FullNode), modules.MakeUuidWrapper), - // Needed to instantiate pubsub used by index provider via ConfigCommon - Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig), - Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap), - Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap), - ConfigCommon(&cfg.Common, build.NodeUserVersion(), false), + ConfigCommon(&cfg.Common, build.NodeUserVersion()), Override(CheckFDLimit, modules.CheckFdLimit(build.MinerFDLimit)), // recommend at least 100k FD limit to miners diff --git a/node/config/def.go b/node/config/def.go index d8b8e0babb3..508312731ca 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -32,6 +32,18 @@ func defCommon() Common { Backup: Backup{ DisableMetadataLog: true, }, + } +} + +func DefaultDefaultMaxFee() types.FIL { + return types.MustParseFIL("0.07") +} + +// DefaultFullNode returns the default config +func DefaultFullNode() *FullNode { + return &FullNode{ + Common: defCommon(), + Libp2p: Libp2p{ ListenAddresses: []string{ "/ip4/0.0.0.0/tcp/0", @@ -52,17 +64,7 @@ func defCommon() Common { Bootstrapper: false, DirectPeers: nil, }, - } -} -func DefaultDefaultMaxFee() types.FIL { - return types.MustParseFIL("0.07") -} - -// DefaultFullNode returns the default config -func DefaultFullNode() *FullNode { - return &FullNode{ - Common: defCommon(), Fees: FeeConfig{ DefaultMaxFee: DefaultDefaultMaxFee(), }, diff --git a/node/config/doc_gen.go b/node/config/doc_gen.go index a3360627741..ff7487f5cbd 100644 --- a/node/config/doc_gen.go +++ b/node/config/doc_gen.go @@ -102,18 +102,6 @@ your node if metadata log is disabled`, Name: "Logging", Type: "Logging", - Comment: ``, - }, - { - Name: "Libp2p", - Type: "Libp2p", - - Comment: ``, - }, - { - Name: "Pubsub", - Type: "Pubsub", - Comment: ``, }, }, @@ -246,6 +234,18 @@ Set to 0 to keep all mappings`, }, }, "FullNode": { + { + Name: "Libp2p", + Type: "Libp2p", + + Comment: ``, + }, + { + Name: "Pubsub", + Type: "Pubsub", + + Comment: ``, + }, { Name: "Wallet", Type: "Wallet", diff --git a/node/config/types.go b/node/config/types.go index 580260c702f..ccc8ab25e67 100644 --- a/node/config/types.go +++ b/node/config/types.go @@ -13,13 +13,13 @@ type Common struct { API API Backup Backup Logging Logging - Libp2p Libp2p - Pubsub Pubsub } // FullNode is a full node config type FullNode struct { Common + Libp2p Libp2p + Pubsub Pubsub Wallet Wallet Fees FeeConfig Chainstore Chainstore