pass Subsystems to StorageMiner option; add enableLibp2p bool in Settings
This commit is contained in:
parent
caa366bc6a
commit
6b014f57e5
@ -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(),
|
||||
|
@ -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") },
|
||||
|
@ -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),
|
||||
|
@ -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(),
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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...),
|
||||
|
@ -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
|
||||
},
|
||||
|
||||
|
@ -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"))),
|
||||
|
@ -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),
|
||||
|
@ -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"))),
|
||||
|
Loading…
Reference in New Issue
Block a user