pass Subsystems to StorageMiner option; add enableLibp2p bool in Settings

This commit is contained in:
Anton Evangelatov 2021-07-07 13:56:37 +02:00
parent caa366bc6a
commit 6b014f57e5
10 changed files with 21 additions and 46 deletions

View File

@ -279,7 +279,7 @@ func (tu *syncTestUtil) addSourceNode(gen int) {
stop, err := node.New(tu.ctx, stop, err := node.New(tu.ctx,
node.FullAPI(&out), node.FullAPI(&out),
node.Base(sourceRepo), node.Base(),
node.Repo(sourceRepo), node.Repo(sourceRepo),
node.MockHost(tu.mn), node.MockHost(tu.mn),
node.Test(), node.Test(),
@ -313,7 +313,7 @@ func (tu *syncTestUtil) addClientNode() int {
r := repo.NewMemory(nil) r := repo.NewMemory(nil)
stop, err := node.New(tu.ctx, stop, err := node.New(tu.ctx,
node.FullAPI(&out), node.FullAPI(&out),
node.Base(r), node.Base(),
node.Repo(r), node.Repo(r),
node.MockHost(tu.mn), node.MockHost(tu.mn),
node.Test(), node.Test(),

View File

@ -143,9 +143,9 @@ var runCmd = &cli.Command{
var minerapi api.StorageMiner var minerapi api.StorageMiner
stop, err := node.New(ctx, stop, err := node.New(ctx,
node.StorageMiner(&minerapi), node.StorageMiner(&minerapi, cfg.Subsystems),
node.Override(new(dtypes.ShutdownChan), shutdownChan), node.Override(new(dtypes.ShutdownChan), shutdownChan),
node.Base(r), node.Base(),
node.Repo(r), node.Repo(r),
node.ApplyIf(func(s *node.Settings) bool { return cctx.IsSet("miner-api") }, node.ApplyIf(func(s *node.Settings) bool { return cctx.IsSet("miner-api") },

View File

@ -314,7 +314,7 @@ var DaemonCmd = &cli.Command{
stop, err := node.New(ctx, stop, err := node.New(ctx,
node.FullAPI(&api, node.Lite(isLite)), node.FullAPI(&api, node.Lite(isLite)),
node.Base(r), node.Base(),
node.Repo(r), node.Repo(r),
node.Override(new(dtypes.Bootstrapper), isBootstrapper), node.Override(new(dtypes.Bootstrapper), isBootstrapper),

View File

@ -276,7 +276,7 @@ func (n *Ensemble) Start() *Ensemble {
r := repo.NewMemory(nil) r := repo.NewMemory(nil)
opts := []node.Option{ opts := []node.Option{
node.FullAPI(&full.FullNode, node.Lite(full.options.lite)), node.FullAPI(&full.FullNode, node.Lite(full.options.lite)),
node.Base(r), node.Base(),
node.Repo(r), node.Repo(r),
node.MockHost(n.mn), node.MockHost(n.mn),
node.Test(), node.Test(),
@ -493,8 +493,8 @@ func (n *Ensemble) Start() *Ensemble {
var mineBlock = make(chan lotusminer.MineReq) var mineBlock = make(chan lotusminer.MineReq)
opts := []node.Option{ opts := []node.Option{
node.StorageMiner(&m.StorageMiner), node.StorageMiner(&m.StorageMiner, cfg.Subsystems),
node.Base(r), node.Base(),
node.Repo(r), node.Repo(r),
node.Test(), node.Test(),

View File

@ -3,7 +3,6 @@ package node
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"os" "os"
"time" "time"
@ -135,6 +134,8 @@ type Settings struct {
Base bool // Base option applied Base bool // Base option applied
Config bool // Config option applied Config bool // Config option applied
Lite bool // Start node in "lite" mode Lite bool // Start node in "lite" mode
enableLibp2pNode bool
} }
// Basic lotus-app services // 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 isFullNode(s *Settings) bool { return s.nodeType == repo.FullNode && !s.Lite }
func isLiteNode(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( return Options(
func(s *Settings) error { s.Base = true; return nil }, // mark Base as applied func(s *Settings) error { s.Base = true; return nil }, // mark Base as applied
ApplyIf(func(s *Settings) bool { return s.Config }, ApplyIf(func(s *Settings) bool { return s.Config },
Error(errors.New("the Base() option must be set before Config option")), 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, LibP2P,
), ),
ApplyIf(isFullOrLiteNode, ChainNode), 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 // Config sets up constructors based on the provided Config
func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option { func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option {
return Options( return Options(

View File

@ -204,6 +204,7 @@ func FullAPI(out *api.FullNode, fopts ...FullOption) Option {
return Options( return Options(
func(s *Settings) error { func(s *Settings) error {
s.nodeType = repo.FullNode s.nodeType = repo.FullNode
s.enableLibp2pNode = true
return nil return nil
}, },
Options(fopts...), Options(fopts...),

View File

@ -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( return Options(
ApplyIf(func(s *Settings) bool { return s.Config }, ApplyIf(func(s *Settings) bool { return s.Config },
Error(errors.New("the StorageMiner option must be set before Config option")), 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 { func(s *Settings) error {
s.nodeType = repo.StorageMiner s.nodeType = repo.StorageMiner
s.enableLibp2pNode = subsystemsCfg.EnableStorageMarket
return nil return nil
}, },

View File

@ -123,7 +123,7 @@ func PrepareBootstrapper(t *TestEnvironment) (*Bootstrapper, error) {
r := repo.NewMemory(nil) r := repo.NewMemory(nil)
stop, err := node.New(context.Background(), stop, err := node.New(context.Background(),
node.FullAPI(&n.FullApi), node.FullAPI(&n.FullApi),
node.Base(r), node.Base(),
node.Repo(r), node.Repo(r),
node.Override(new(modules.Genesis), modtest.MakeGenesisMem(&genesisBuffer, genesisTemplate)), node.Override(new(modules.Genesis), modtest.MakeGenesisMem(&genesisBuffer, genesisTemplate)),
withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))),

View File

@ -66,7 +66,7 @@ func PrepareClient(t *TestEnvironment) (*LotusClient, error) {
n := &LotusNode{} n := &LotusNode{}
stop, err := node.New(context.Background(), stop, err := node.New(context.Background(),
node.FullAPI(&n.FullApi), node.FullAPI(&n.FullApi),
node.Base(nodeRepo), node.Base(),
node.Repo(nodeRepo), node.Repo(nodeRepo),
withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))),
withGenesis(genesisMsg.Genesis), withGenesis(genesisMsg.Genesis),

View File

@ -239,7 +239,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) {
stop1, err := node.New(context.Background(), stop1, err := node.New(context.Background(),
node.FullAPI(&n.FullApi), node.FullAPI(&n.FullApi),
node.Base(nodeRepo), node.Base(),
node.Repo(nodeRepo), node.Repo(nodeRepo),
withGenesis(genesisMsg.Genesis), withGenesis(genesisMsg.Genesis),
withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), 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{ minerOpts := []node.Option{
node.StorageMiner(&n.MinerApi), node.StorageMiner(&n.MinerApi),
node.Base(minerRepo), node.Base(),
node.Repo(minerRepo), node.Repo(minerRepo),
node.Override(new(api.FullNode), n.FullApi), node.Override(new(api.FullNode), n.FullApi),
node.Override(new(*storageadapter.DealPublisher), storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{ 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(), stop1, err := node.New(context.Background(),
node.FullAPI(&n.FullApi), node.FullAPI(&n.FullApi),
node.Base(nodeRepo), node.Base(),
node.Repo(nodeRepo), node.Repo(nodeRepo),
//withGenesis(genesisMsg.Genesis), //withGenesis(genesisMsg.Genesis),
withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("node_rpc", "0"))), 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{ minerOpts := []node.Option{
node.StorageMiner(&n.MinerApi), node.StorageMiner(&n.MinerApi),
node.Base(minerRepo), node.Base(),
node.Repo(minerRepo), node.Repo(minerRepo),
node.Override(new(api.FullNode), n.FullApi), node.Override(new(api.FullNode), n.FullApi),
withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("miner_rpc", "0"))), withApiEndpoint(fmt.Sprintf("/ip4/0.0.0.0/tcp/%s", t.PortNumber("miner_rpc", "0"))),