basic ensemble provider
This commit is contained in:
parent
0490359ac6
commit
becfc470a2
@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
|
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||||
@ -45,6 +46,9 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet/key"
|
"github.com/filecoin-project/lotus/chain/wallet/key"
|
||||||
|
"github.com/filecoin-project/lotus/cmd/lotus-provider/deps"
|
||||||
|
"github.com/filecoin-project/lotus/cmd/lotus-provider/rpc"
|
||||||
|
"github.com/filecoin-project/lotus/cmd/lotus-provider/tasks"
|
||||||
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
|
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
|
||||||
"github.com/filecoin-project/lotus/cmd/lotus-worker/sealworker"
|
"github.com/filecoin-project/lotus/cmd/lotus-worker/sealworker"
|
||||||
"github.com/filecoin-project/lotus/gateway"
|
"github.com/filecoin-project/lotus/gateway"
|
||||||
@ -121,11 +125,13 @@ type Ensemble struct {
|
|||||||
|
|
||||||
inactive struct {
|
inactive struct {
|
||||||
fullnodes []*TestFullNode
|
fullnodes []*TestFullNode
|
||||||
|
providernodes []*TestProviderNode
|
||||||
miners []*TestMiner
|
miners []*TestMiner
|
||||||
workers []*TestWorker
|
workers []*TestWorker
|
||||||
}
|
}
|
||||||
active struct {
|
active struct {
|
||||||
fullnodes []*TestFullNode
|
fullnodes []*TestFullNode
|
||||||
|
providernodes []*TestProviderNode
|
||||||
miners []*TestMiner
|
miners []*TestMiner
|
||||||
workers []*TestWorker
|
workers []*TestWorker
|
||||||
bms map[*TestMiner]*BlockMiner
|
bms map[*TestMiner]*BlockMiner
|
||||||
@ -221,6 +227,20 @@ func (n *Ensemble) FullNode(full *TestFullNode, opts ...NodeOpt) *Ensemble {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FullNode enrolls a new Provider node.
|
||||||
|
func (n *Ensemble) Provider(lp *TestProviderNode, opts ...NodeOpt) *Ensemble {
|
||||||
|
options := DefaultNodeOpts
|
||||||
|
for _, o := range opts {
|
||||||
|
err := o(&options)
|
||||||
|
require.NoError(n.t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*lp = TestProviderNode{t: n.t, options: options, Deps: &deps.Deps{}}
|
||||||
|
|
||||||
|
n.inactive.providernodes = append(n.inactive.providernodes, lp)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
// Miner enrolls a new miner, using the provided full node for chain
|
// Miner enrolls a new miner, using the provided full node for chain
|
||||||
// interactions.
|
// interactions.
|
||||||
func (n *Ensemble) MinerEnroll(minerNode *TestMiner, full *TestFullNode, opts ...NodeOpt) *Ensemble {
|
func (n *Ensemble) MinerEnroll(minerNode *TestMiner, full *TestFullNode, opts ...NodeOpt) *Ensemble {
|
||||||
@ -886,6 +906,28 @@ func (n *Ensemble) Start() *Ensemble {
|
|||||||
// to active, so clear the slice.
|
// to active, so clear the slice.
|
||||||
n.inactive.workers = n.inactive.workers[:0]
|
n.inactive.workers = n.inactive.workers[:0]
|
||||||
|
|
||||||
|
for _, p := range n.inactive.providernodes {
|
||||||
|
|
||||||
|
// TODO setup config with options
|
||||||
|
err := p.Deps.PopulateRemainingDeps(context.Background(), &cli.Context{}, false)
|
||||||
|
require.NoError(n.t, err)
|
||||||
|
|
||||||
|
shutdownChan := make(chan struct{})
|
||||||
|
taskEngine, err := tasks.StartTasks(ctx, p.Deps)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer taskEngine.GracefullyTerminate(time.Hour)
|
||||||
|
|
||||||
|
err = rpc.ListenAndServe(ctx, p.Deps, shutdownChan) // Monitor for shutdown.
|
||||||
|
require.NoError(n.t, err)
|
||||||
|
finishCh := node.MonitorShutdown(shutdownChan) //node.ShutdownHandler{Component: "rpc server", StopFunc: rpcStopper},
|
||||||
|
//node.ShutdownHandler{Component: "provider", StopFunc: stop},
|
||||||
|
|
||||||
|
<-finishCh
|
||||||
|
|
||||||
|
n.active.providernodes = append(n.active.providernodes, p)
|
||||||
|
}
|
||||||
// ---------------------
|
// ---------------------
|
||||||
// MISC
|
// MISC
|
||||||
// ---------------------
|
// ---------------------
|
||||||
|
@ -112,7 +112,7 @@ func EnsembleProvider(t *testing.T, opts ...interface{}) (*TestFullNode, *TestPr
|
|||||||
full TestFullNode
|
full TestFullNode
|
||||||
provider TestProviderNode
|
provider TestProviderNode
|
||||||
)
|
)
|
||||||
ens := NewEnsemble(t, eopts...).FullNode(&full, nopts...).Provider(&provider, &full, nopts...).Start()
|
ens := NewEnsemble(t, eopts...).FullNode(&full, nopts...).Provider(&provider, nopts...).Start()
|
||||||
return &full, &provider, ens
|
return &full, &provider, ens
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user