Skip to content

Commit

Permalink
chore: config: yet more lp2p removal from miner
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi authored and aarshkshah1992 committed Jul 19, 2024
1 parent c053d71 commit 11dd4c9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 157 deletions.
96 changes: 0 additions & 96 deletions documentation/en/default-lotus-miner-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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://<username>:<password>@<elasticsearch_url>:<port>/
#
# 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
Expand Down
33 changes: 4 additions & 29 deletions node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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)),
)
}
Expand Down
35 changes: 32 additions & 3 deletions node/builder_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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),

Expand Down
6 changes: 1 addition & 5 deletions node/builder_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 12 additions & 10 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(),
},
Expand Down
24 changes: 12 additions & 12 deletions node/config/doc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11dd4c9

Please sign in to comment.