From d6bd0599207254b962f01f80d850c13707917e28 Mon Sep 17 00:00:00 2001 From: Alex Cruikshank <169613+acruikshank@users.noreply.github.com> Date: Fri, 15 May 2020 16:19:56 -0400 Subject: [PATCH] resolve miner id addres before passing to storage fsm (#4140) * resolve miner id addres before passing to storage fsm * remove unused test helper --- functional-tests/common.go | 25 ------------------- functional-tests/plege_sector_test.go | 15 ++++++++--- .../submodule/storage_mining_submodule.go | 18 ++++++++++++- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/functional-tests/common.go b/functional-tests/common.go index 1411220393..b5cc8756fd 100644 --- a/functional-tests/common.go +++ b/functional-tests/common.go @@ -9,17 +9,13 @@ import ( "time" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-filecoin/internal/app/go-filecoin/node" "github.com/filecoin-project/go-filecoin/internal/app/go-filecoin/node/test" - "github.com/filecoin-project/go-filecoin/internal/pkg/block" "github.com/filecoin-project/go-filecoin/internal/pkg/clock" "github.com/filecoin-project/go-filecoin/internal/pkg/constants" "github.com/filecoin-project/go-filecoin/internal/pkg/drand" - "github.com/filecoin-project/go-filecoin/internal/pkg/types" - "github.com/filecoin-project/go-filecoin/internal/pkg/vm" gengen "github.com/filecoin-project/go-filecoin/tools/gengen/util" ) @@ -90,24 +86,3 @@ func simulateBlockMining(ctx context.Context, t *testing.T, fakeClock clock.Fake } } } - -// send funds from one actor to another. The from account must be an address with a private key imported into the node. -// This function blocks until the message to lands on chain to avoid call sequence number races. -func transferFunds(ctx context.Context, t *testing.T, nd *node.Node, from address.Address, to address.Address, amount types.AttoFIL) { - mcid, errCh, err := nd.Messaging.Outbox.SendEncoded(ctx, - from, - to, - amount, - types.NewGasPrice(1), - 10000, - true, - builtin.MethodSend, - nil, - ) - require.NoError(t, err) - require.NoError(t, <-errCh) - - require.NoError(t, nd.PorcelainAPI.MessageWait(ctx, mcid, func(block *block.Block, message *types.SignedMessage, receipt *vm.MessageReceipt) error { - return nil - })) -} diff --git a/functional-tests/plege_sector_test.go b/functional-tests/plege_sector_test.go index aff45adeca..5365a4f20d 100644 --- a/functional-tests/plege_sector_test.go +++ b/functional-tests/plege_sector_test.go @@ -5,6 +5,9 @@ import ( "testing" "time" + commands "github.com/filecoin-project/go-filecoin/cmd/go-filecoin" + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/go-filecoin/internal/app/go-filecoin/node" "github.com/filecoin-project/go-filecoin/internal/pkg/clock" "github.com/filecoin-project/go-filecoin/internal/pkg/constants" @@ -45,7 +48,6 @@ func TestMiningPledgeSector(t *testing.T) { newMiner := makeNode(ctx, t, seed, chainClock, drandImpl) seed.GiveKey(t, newMiner, 1) - _, _ = seed.GiveMiner(t, newMiner, 1) err = bootstrapMiner.Start(ctx) require.NoError(t, err) @@ -59,9 +61,16 @@ func TestMiningPledgeSector(t *testing.T) { // Have bootstrap miner mine continuously so newMiner's pledgeSector can put multiple messages on chain. go simulateBlockMining(ctx, t, fakeClock, blockTime, bootstrapMiner) - // give the miner some collateral - transferFunds(ctx, t, newMiner, seed.Addr(t, 1), newMiner.Repo.Config().Mining.MinerAddress, types.NewAttoFILFromFIL(5)) + // create a miner + env := commands.CreateServerEnv(ctx, newMiner) + porcelainAPI := commands.GetPorcelainAPI(env) + peer := newMiner.Network().Network.GetPeerID() + + _, err = porcelainAPI.MinerCreate(ctx, seed.Addr(t, 1), types.NewAttoFILFromFIL(1), 10000, abi.RegisteredProof_StackedDRG2KiBSeal, peer, types.NewAttoFILFromFIL(5)) + require.NoError(t, err) + // setup mining with new miner address and start mining + require.NoError(t, newMiner.SetupMining(ctx)) err = newMiner.StorageMining.Start(ctx) require.NoError(t, err) diff --git a/internal/app/go-filecoin/internal/submodule/storage_mining_submodule.go b/internal/app/go-filecoin/internal/submodule/storage_mining_submodule.go index ee97d3e794..06a8d81120 100644 --- a/internal/app/go-filecoin/internal/submodule/storage_mining_submodule.go +++ b/internal/app/go-filecoin/internal/submodule/storage_mining_submodule.go @@ -84,8 +84,14 @@ func NewStorageMiningSubmodule( pcp := fsm.NewBasicPreCommitPolicy(&ccn, abi.ChainEpoch(2*60*24), ppStart%miner.WPoStProvingPeriod) + // FSM requires id address to work correctly. Resolve it now and hope it's stable + minerAddrID, err := resolveMinerAddress(context.TODO(), c, minerAddr, stateViewer) + if err != nil { + return nil, err + } + fsmConnector := fsmeventsconnector.New(chainThresholdScheduler, c.State) - fsm := fsm.New(ncn, fsmConnector, minerAddr, ds, mgr, sid, ffiwrapper.ProofVerifier, &pcp) + fsm := fsm.New(ncn, fsmConnector, minerAddrID, ds, mgr, sid, ffiwrapper.ProofVerifier, &pcp) bke := piecemanager.NewFiniteStateMachineBackEnd(fsm, sid) @@ -169,3 +175,13 @@ func getMinerProvingPeriod(c *ChainSubmodule, minerAddr address.Address, viewer view := viewer.StateView(root) return view.MinerProvingPeriodStart(context.Background(), minerAddr) } + +func resolveMinerAddress(ctx context.Context, c *ChainSubmodule, minerAddr address.Address, viewer *appstate.Viewer) (address.Address, error) { + tsk := c.ChainReader.GetHead() + root, err := c.ChainReader.GetTipSetStateRoot(tsk) + if err != nil { + return address.Undef, err + } + view := viewer.StateView(root) + return view.InitResolveAddress(ctx, minerAddr) +}