Merge pull request #1740 from filecoin-project/feat/bootstrapper-profile
add profile for bootstrappers
This commit is contained in:
commit
d1997b5857
@ -33,6 +33,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/metrics"
|
"github.com/filecoin-project/lotus/metrics"
|
||||||
"github.com/filecoin-project/lotus/node"
|
"github.com/filecoin-project/lotus/node"
|
||||||
"github.com/filecoin-project/lotus/node/modules"
|
"github.com/filecoin-project/lotus/node/modules"
|
||||||
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
"github.com/filecoin-project/lotus/node/modules/testing"
|
"github.com/filecoin-project/lotus/node/modules/testing"
|
||||||
"github.com/filecoin-project/lotus/node/repo"
|
"github.com/filecoin-project/lotus/node/repo"
|
||||||
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
||||||
@ -86,6 +87,10 @@ var DaemonCmd = &cli.Command{
|
|||||||
Name: "pprof",
|
Name: "pprof",
|
||||||
Usage: "specify name of file for writing cpu profile to",
|
Usage: "specify name of file for writing cpu profile to",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "profile",
|
||||||
|
Usage: "specify type of node",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
if prof := cctx.String("pprof"); prof != "" {
|
if prof := cctx.String("pprof"); prof != "" {
|
||||||
@ -100,6 +105,16 @@ var DaemonCmd = &cli.Command{
|
|||||||
defer pprof.StopCPUProfile()
|
defer pprof.StopCPUProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isBootstrapper dtypes.Bootstrapper
|
||||||
|
switch profile := cctx.String("profile"); profile {
|
||||||
|
case "bootstrapper":
|
||||||
|
isBootstrapper = true
|
||||||
|
case "":
|
||||||
|
// do nothing
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unrecognized profile type: %q", profile)
|
||||||
|
}
|
||||||
|
|
||||||
ctx, _ := tag.New(context.Background(), tag.Insert(metrics.Version, build.BuildVersion), tag.Insert(metrics.Commit, build.CurrentCommit))
|
ctx, _ := tag.New(context.Background(), tag.Insert(metrics.Version, build.BuildVersion), tag.Insert(metrics.Commit, build.CurrentCommit))
|
||||||
{
|
{
|
||||||
dir, err := homedir.Expand(cctx.String("repo"))
|
dir, err := homedir.Expand(cctx.String("repo"))
|
||||||
@ -160,6 +175,7 @@ var DaemonCmd = &cli.Command{
|
|||||||
stop, err := node.New(ctx,
|
stop, err := node.New(ctx,
|
||||||
node.FullAPI(&api),
|
node.FullAPI(&api),
|
||||||
|
|
||||||
|
node.Override(new(dtypes.Bootstrapper), isBootstrapper),
|
||||||
node.Online(),
|
node.Online(),
|
||||||
node.Repo(r),
|
node.Repo(r),
|
||||||
|
|
||||||
|
@ -142,12 +142,14 @@ type Settings struct {
|
|||||||
|
|
||||||
Online bool // Online option applied
|
Online bool // Online option applied
|
||||||
Config bool // Config option applied
|
Config bool // Config option applied
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaults() []Option {
|
func defaults() []Option {
|
||||||
return []Option{
|
return []Option{
|
||||||
Override(new(helpers.MetricsCtx), context.Background),
|
Override(new(helpers.MetricsCtx), context.Background),
|
||||||
Override(new(record.Validator), modules.RecordValidator),
|
Override(new(record.Validator), modules.RecordValidator),
|
||||||
|
Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(false)),
|
||||||
|
|
||||||
// Filecoin modules
|
// Filecoin modules
|
||||||
|
|
||||||
@ -178,7 +180,12 @@ func libp2p() Option {
|
|||||||
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
|
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
|
||||||
Override(AutoNATSvcKey, lp2p.AutoNATService),
|
Override(AutoNATSvcKey, lp2p.AutoNATService),
|
||||||
|
|
||||||
Override(new(*pubsub.PubSub), lp2p.GossipSub(&config.Pubsub{})),
|
Override(new(*pubsub.PubSub), lp2p.GossipSub),
|
||||||
|
Override(new(*config.Pubsub), func(bs dtypes.Bootstrapper) *config.Pubsub {
|
||||||
|
return &config.Pubsub{
|
||||||
|
Bootstrapper: bool(bs),
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
Override(PstoreAddSelfKeysKey, lp2p.PstoreAddSelfKeys),
|
Override(PstoreAddSelfKeysKey, lp2p.PstoreAddSelfKeys),
|
||||||
Override(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),
|
Override(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),
|
||||||
@ -354,7 +361,8 @@ func ConfigCommon(cfg *config.Common) Option {
|
|||||||
cfg.Libp2p.ConnMgrHigh,
|
cfg.Libp2p.ConnMgrHigh,
|
||||||
time.Duration(cfg.Libp2p.ConnMgrGrace),
|
time.Duration(cfg.Libp2p.ConnMgrGrace),
|
||||||
cfg.Libp2p.ProtectedPeers)),
|
cfg.Libp2p.ProtectedPeers)),
|
||||||
Override(new(*pubsub.PubSub), lp2p.GossipSub(&cfg.Pubsub)),
|
Override(new(*pubsub.PubSub), lp2p.GossipSub),
|
||||||
|
Override(new(*config.Pubsub), &cfg.Pubsub),
|
||||||
|
|
||||||
ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 },
|
ApplyIf(func(s *Settings) bool { return len(cfg.Libp2p.BootstrapPeers) > 0 },
|
||||||
Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)),
|
Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)),
|
||||||
|
@ -3,3 +3,5 @@ package dtypes
|
|||||||
import "github.com/libp2p/go-libp2p-core/peer"
|
import "github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
|
||||||
type BootstrapPeers []peer.AddrInfo
|
type BootstrapPeers []peer.AddrInfo
|
||||||
|
|
||||||
|
type Bootstrapper bool
|
||||||
|
@ -71,19 +71,23 @@ func MockHost(mn mocknet.Mocknet, id peer.ID, ps peerstore.Peerstore) (RawHost,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DHTRouting(mode dht.ModeOpt) interface{} {
|
func DHTRouting(mode dht.ModeOpt) interface{} {
|
||||||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host RawHost, dstore dtypes.MetadataDS, validator record.Validator, nn dtypes.NetworkName) (BaseIpfsRouting, error) {
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host RawHost, dstore dtypes.MetadataDS, validator record.Validator, nn dtypes.NetworkName, bs dtypes.Bootstrapper) (BaseIpfsRouting, error) {
|
||||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||||
|
|
||||||
d, err := dht.New(
|
if bs {
|
||||||
ctx, host,
|
mode = dht.ModeServer
|
||||||
dht.Mode(mode),
|
}
|
||||||
|
|
||||||
|
opts := []dht.Option{dht.Mode(mode),
|
||||||
dht.Datastore(dstore),
|
dht.Datastore(dstore),
|
||||||
dht.Validator(validator),
|
dht.Validator(validator),
|
||||||
dht.ProtocolPrefix(build.DhtProtocolName(nn)),
|
dht.ProtocolPrefix(build.DhtProtocolName(nn)),
|
||||||
dht.QueryFilter(dht.PublicQueryFilter),
|
dht.QueryFilter(dht.PublicQueryFilter),
|
||||||
dht.RoutingTableFilter(dht.PublicRoutingTableFilter),
|
dht.RoutingTableFilter(dht.PublicRoutingTableFilter),
|
||||||
dht.DisableProviders(),
|
dht.DisableProviders(),
|
||||||
dht.DisableValues(),
|
dht.DisableValues()}
|
||||||
|
d, err := dht.New(
|
||||||
|
ctx, host, opts...,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -28,8 +28,7 @@ func init() {
|
|||||||
pubsub.GossipSubDirectConnectInitialDelay = 30 * time.Second
|
pubsub.GossipSubDirectConnectInitialDelay = 30 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
func GossipSub(cfg *config.Pubsub) interface{} {
|
func GossipSub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtypes.NetworkName, bp dtypes.BootstrapPeers, cfg *config.Pubsub) (service *pubsub.PubSub, err error) {
|
||||||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtypes.NetworkName, bp dtypes.BootstrapPeers) (service *pubsub.PubSub, err error) {
|
|
||||||
bootstrappers := make(map[peer.ID]struct{})
|
bootstrappers := make(map[peer.ID]struct{})
|
||||||
for _, pi := range bp {
|
for _, pi := range bp {
|
||||||
bootstrappers[pi.ID] = struct{}{}
|
bootstrappers[pi.ID] = struct{}{}
|
||||||
@ -205,7 +204,6 @@ func GossipSub(cfg *config.Pubsub) interface{} {
|
|||||||
// options = append(options, pubsub.WithPeerScoreInspect(XXX, time.Second))
|
// options = append(options, pubsub.WithPeerScoreInspect(XXX, time.Second))
|
||||||
|
|
||||||
return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, options...)
|
return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, options...)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HashMsgId(m *pubsub_pb.Message) string {
|
func HashMsgId(m *pubsub_pb.Message) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user