diff --git a/chain/sync_test.go b/chain/sync_test.go index f68d596ba..5312dff0b 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -279,7 +279,7 @@ func (tu *syncTestUtil) addSourceNode(gen int) { stop, err := node.New(tu.ctx, node.FullAPI(&out), - node.Base(sourceRepo), + node.Base(), node.Repo(sourceRepo), node.MockHost(tu.mn), node.Test(), @@ -313,7 +313,7 @@ func (tu *syncTestUtil) addClientNode() int { r := repo.NewMemory(nil) stop, err := node.New(tu.ctx, node.FullAPI(&out), - node.Base(r), + node.Base(), node.Repo(r), node.MockHost(tu.mn), node.Test(), diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 241d1b2c2..cb21ae0e9 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -143,9 +143,9 @@ var runCmd = &cli.Command{ var minerapi api.StorageMiner stop, err := node.New(ctx, - node.StorageMiner(&minerapi), + node.StorageMiner(&minerapi, cfg.Subsystems), node.Override(new(dtypes.ShutdownChan), shutdownChan), - node.Base(r), + node.Base(), node.Repo(r), node.ApplyIf(func(s *node.Settings) bool { return cctx.IsSet("miner-api") }, diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 74dd6cd39..0d5961aae 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -314,7 +314,7 @@ var DaemonCmd = &cli.Command{ stop, err := node.New(ctx, node.FullAPI(&api, node.Lite(isLite)), - node.Base(r), + node.Base(), node.Repo(r), node.Override(new(dtypes.Bootstrapper), isBootstrapper), diff --git a/itests/kit/ensemble.go b/itests/kit/ensemble.go index d6d8fc850..1651193f7 100644 --- a/itests/kit/ensemble.go +++ b/itests/kit/ensemble.go @@ -276,7 +276,7 @@ func (n *Ensemble) Start() *Ensemble { r := repo.NewMemory(nil) opts := []node.Option{ node.FullAPI(&full.FullNode, node.Lite(full.options.lite)), - node.Base(r), + node.Base(), node.Repo(r), node.MockHost(n.mn), node.Test(), @@ -493,8 +493,8 @@ func (n *Ensemble) Start() *Ensemble { var mineBlock = make(chan lotusminer.MineReq) opts := []node.Option{ - node.StorageMiner(&m.StorageMiner), - node.Base(r), + node.StorageMiner(&m.StorageMiner, cfg.Subsystems), + node.Base(), node.Repo(r), node.Test(), diff --git a/node/builder.go b/node/builder.go index 56fcd8b43..457f7d01e 100644 --- a/node/builder.go +++ b/node/builder.go @@ -3,7 +3,6 @@ package node import ( "context" "errors" - "fmt" "os" "time" @@ -135,6 +134,8 @@ type Settings struct { Base bool // Base option applied Config bool // Config option applied Lite bool // Start node in "lite" mode + + enableLibp2pNode bool } // Basic lotus-app services @@ -211,13 +212,13 @@ 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 } -func Base(r repo.Repo) Option { +func Base() Option { return Options( func(s *Settings) error { s.Base = true; return nil }, // mark Base as applied ApplyIf(func(s *Settings) bool { return s.Config }, Error(errors.New("the Base() option must be set before Config option")), ), - ApplyIf(func(s *Settings) bool { result, _ := enableLibp2pNode(s, r); return result }, + ApplyIf(func(s *Settings) bool { return s.enableLibp2pNode }, LibP2P, ), ApplyIf(isFullOrLiteNode, ChainNode), @@ -225,34 +226,6 @@ func Base(r repo.Repo) Option { ) } -func enableLibp2pNode(s *Settings, r repo.Repo) (bool, error) { - lr, err := r.Lock(s.nodeType) - if err != nil { - return false, err - } - c, err := lr.Config() - if err != nil { - return false, err - } - defer lr.Close() //nolint:errcheck - - switch s.nodeType { - case repo.FullNode: - return true, nil - case repo.StorageMiner: - cfg, ok := c.(*config.StorageMiner) - if !ok { - return false, fmt.Errorf("invalid config for repo, got: %T", c) - } - - enableLibP2P := cfg.Subsystems.EnableStorageMarket - return enableLibP2P, nil - default: - // TODO: log error - return false, errors.New("unknown repo type") - } -} - // Config sets up constructors based on the provided Config func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option { return Options( diff --git a/node/builder_chain.go b/node/builder_chain.go index 31cb95984..1447a4df7 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -204,6 +204,7 @@ func FullAPI(out *api.FullNode, fopts ...FullOption) Option { return Options( func(s *Settings) error { s.nodeType = repo.FullNode + s.enableLibp2pNode = true return nil }, Options(fopts...), diff --git a/node/builder_miner.go b/node/builder_miner.go index 25c9c0cc1..db5c9b60b 100644 --- a/node/builder_miner.go +++ b/node/builder_miner.go @@ -201,7 +201,7 @@ func ConfigStorageMiner(c interface{}) Option { ) } -func StorageMiner(out *api.StorageMiner) Option { +func StorageMiner(out *api.StorageMiner, subsystemsCfg config.MinerSubsystemConfig) Option { return Options( ApplyIf(func(s *Settings) bool { return s.Config }, Error(errors.New("the StorageMiner option must be set before Config option")), @@ -209,6 +209,7 @@ func StorageMiner(out *api.StorageMiner) Option { func(s *Settings) error { s.nodeType = repo.StorageMiner + s.enableLibp2pNode = subsystemsCfg.EnableStorageMarket return nil }, diff --git a/testplans/lotus-soup/testkit/role_bootstrapper.go b/testplans/lotus-soup/testkit/role_bootstrapper.go index d6738a7c8..4a6ac56c9 100644 --- a/testplans/lotus-soup/testkit/role_bootstrapper.go +++ b/testplans/lotus-soup/testkit/role_bootstrapper.go @@ -123,7 +123,7 @@ func PrepareBootstrapper(t *TestEnvironment) (*Bootstrapper, error) { r := repo.NewMemory(nil) stop, err := node.New(context.Background(), node.FullAPI(&n.FullApi), - node.Base(r), + node.Base(), node.Repo(r), node.Override(new(modules.Genesis), modtest.MakeGenesisMem(&genesisBuffer, genesisTemplate)), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), diff --git a/testplans/lotus-soup/testkit/role_client.go b/testplans/lotus-soup/testkit/role_client.go index 31a5d7a30..d18a835d2 100644 --- a/testplans/lotus-soup/testkit/role_client.go +++ b/testplans/lotus-soup/testkit/role_client.go @@ -66,7 +66,7 @@ func PrepareClient(t *TestEnvironment) (*LotusClient, error) { n := &LotusNode{} stop, err := node.New(context.Background(), node.FullAPI(&n.FullApi), - node.Base(nodeRepo), + node.Base(), node.Repo(nodeRepo), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), withGenesis(genesisMsg.Genesis), diff --git a/testplans/lotus-soup/testkit/role_miner.go b/testplans/lotus-soup/testkit/role_miner.go index a98cb5466..b2a4d9d87 100644 --- a/testplans/lotus-soup/testkit/role_miner.go +++ b/testplans/lotus-soup/testkit/role_miner.go @@ -239,7 +239,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) { stop1, err := node.New(context.Background(), node.FullAPI(&n.FullApi), - node.Base(nodeRepo), + node.Base(), node.Repo(nodeRepo), withGenesis(genesisMsg.Genesis), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), @@ -261,7 +261,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) { minerOpts := []node.Option{ node.StorageMiner(&n.MinerApi), - node.Base(minerRepo), + node.Base(), node.Repo(minerRepo), node.Override(new(api.FullNode), n.FullApi), node.Override(new(*storageadapter.DealPublisher), storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{ @@ -443,7 +443,7 @@ func RestoreMiner(t *TestEnvironment, m *LotusMiner) (*LotusMiner, error) { stop1, err := node.New(context.Background(), node.FullAPI(&n.FullApi), - node.Base(nodeRepo), + node.Base(), node.Repo(nodeRepo), //withGenesis(genesisMsg.Genesis), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), @@ -458,7 +458,7 @@ func RestoreMiner(t *TestEnvironment, m *LotusMiner) (*LotusMiner, error) { minerOpts := []node.Option{ node.StorageMiner(&n.MinerApi), - node.Base(minerRepo), + node.Base(), node.Repo(minerRepo), node.Override(new(api.FullNode), n.FullApi), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("miner_rpc", "0"))),