add profile for bootstrappers
This commit is contained in:
parent
42269e17cc
commit
d3eb808ff4
@ -33,6 +33,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/metrics"
|
||||
"github.com/filecoin-project/lotus/node"
|
||||
"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/repo"
|
||||
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
||||
@ -86,6 +87,10 @@ var DaemonCmd = &cli.Command{
|
||||
Name: "pprof",
|
||||
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 {
|
||||
if prof := cctx.String("pprof"); prof != "" {
|
||||
@ -100,6 +105,16 @@ var DaemonCmd = &cli.Command{
|
||||
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))
|
||||
{
|
||||
dir, err := homedir.Expand(cctx.String("repo"))
|
||||
@ -160,6 +175,7 @@ var DaemonCmd = &cli.Command{
|
||||
stop, err := node.New(ctx,
|
||||
node.FullAPI(&api),
|
||||
|
||||
node.Override(new(dtypes.Bootstrapper), isBootstrapper),
|
||||
node.Online(),
|
||||
node.Repo(r),
|
||||
|
||||
|
@ -142,12 +142,14 @@ type Settings struct {
|
||||
|
||||
Online bool // Online option applied
|
||||
Config bool // Config option applied
|
||||
|
||||
}
|
||||
|
||||
func defaults() []Option {
|
||||
return []Option{
|
||||
Override(new(helpers.MetricsCtx), context.Background),
|
||||
Override(new(record.Validator), modules.RecordValidator),
|
||||
Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(false)),
|
||||
|
||||
// Filecoin modules
|
||||
|
||||
@ -178,7 +180,12 @@ func libp2p() Option {
|
||||
Override(ConnectionManagerKey, lp2p.ConnectionManager(50, 200, 20*time.Second, nil)),
|
||||
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(StartListeningKey, lp2p.StartListening(config.DefaultFullNode().Libp2p.ListenAddresses)),
|
||||
@ -354,7 +361,8 @@ func ConfigCommon(cfg *config.Common) Option {
|
||||
cfg.Libp2p.ConnMgrHigh,
|
||||
time.Duration(cfg.Libp2p.ConnMgrGrace),
|
||||
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 },
|
||||
Override(new(dtypes.BootstrapPeers), modules.ConfigBootstrap(cfg.Libp2p.BootstrapPeers)),
|
||||
|
@ -3,3 +3,5 @@ package dtypes
|
||||
import "github.com/libp2p/go-libp2p-core/peer"
|
||||
|
||||
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{} {
|
||||
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)
|
||||
|
||||
d, err := dht.New(
|
||||
ctx, host,
|
||||
dht.Mode(mode),
|
||||
if bs {
|
||||
mode = dht.ModeServer
|
||||
}
|
||||
|
||||
opts := []dht.Option{dht.Mode(mode),
|
||||
dht.Datastore(dstore),
|
||||
dht.Validator(validator),
|
||||
dht.ProtocolPrefix(build.DhtProtocolName(nn)),
|
||||
dht.QueryFilter(dht.PublicQueryFilter),
|
||||
dht.RoutingTableFilter(dht.PublicRoutingTableFilter),
|
||||
dht.DisableProviders(),
|
||||
dht.DisableValues(),
|
||||
dht.DisableValues()}
|
||||
d, err := dht.New(
|
||||
ctx, host, opts...,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -28,8 +28,7 @@ func init() {
|
||||
pubsub.GossipSubDirectConnectInitialDelay = 30 * time.Second
|
||||
}
|
||||
|
||||
func GossipSub(cfg *config.Pubsub) interface{} {
|
||||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, nn dtypes.NetworkName, bp dtypes.BootstrapPeers) (service *pubsub.PubSub, err error) {
|
||||
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) {
|
||||
bootstrappers := make(map[peer.ID]struct{})
|
||||
for _, pi := range bp {
|
||||
bootstrappers[pi.ID] = struct{}{}
|
||||
@ -206,7 +205,6 @@ func GossipSub(cfg *config.Pubsub) interface{} {
|
||||
|
||||
return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, options...)
|
||||
}
|
||||
}
|
||||
|
||||
func HashMsgId(m *pubsub_pb.Message) string {
|
||||
hash := blake2b.Sum256(m.Data)
|
||||
|
Loading…
Reference in New Issue
Block a user