From becfc470a291c84881699584356ea5cacb6fadbf Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Mon, 11 Dec 2023 17:47:29 -0600 Subject: [PATCH] basic ensemble provider --- itests/kit/ensemble.go | 56 +++++++++++++++++++++++++++++----- itests/kit/ensemble_presets.go | 2 +- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/itests/kit/ensemble.go b/itests/kit/ensemble.go index 3c83ba896..12e2ce8aa 100644 --- a/itests/kit/ensemble.go +++ b/itests/kit/ensemble.go @@ -20,6 +20,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" + "github.com/urfave/cli/v2" "github.com/filecoin-project/go-address" 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/types" "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-worker/sealworker" "github.com/filecoin-project/lotus/gateway" @@ -120,15 +124,17 @@ type Ensemble struct { options *ensembleOpts inactive struct { - fullnodes []*TestFullNode - miners []*TestMiner - workers []*TestWorker + fullnodes []*TestFullNode + providernodes []*TestProviderNode + miners []*TestMiner + workers []*TestWorker } active struct { - fullnodes []*TestFullNode - miners []*TestMiner - workers []*TestWorker - bms map[*TestMiner]*BlockMiner + fullnodes []*TestFullNode + providernodes []*TestProviderNode + miners []*TestMiner + workers []*TestWorker + bms map[*TestMiner]*BlockMiner } genesis struct { version network.Version @@ -221,6 +227,20 @@ func (n *Ensemble) FullNode(full *TestFullNode, opts ...NodeOpt) *Ensemble { 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 // interactions. 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. 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 // --------------------- diff --git a/itests/kit/ensemble_presets.go b/itests/kit/ensemble_presets.go index 88f07b684..68b85fde0 100644 --- a/itests/kit/ensemble_presets.go +++ b/itests/kit/ensemble_presets.go @@ -112,7 +112,7 @@ func EnsembleProvider(t *testing.T, opts ...interface{}) (*TestFullNode, *TestPr full TestFullNode 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 }