Skip to content

Commit

Permalink
resolve miner id addres before passing to storage fsm (filecoin-proje…
Browse files Browse the repository at this point in the history
…ct#4140)

* resolve miner id addres before passing to storage fsm

* remove unused test helper
  • Loading branch information
acruikshank authored May 15, 2020
1 parent 1b6ea79 commit d6bd059
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
25 changes: 0 additions & 25 deletions functional-tests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}))
}
15 changes: 12 additions & 3 deletions functional-tests/plege_sector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}

0 comments on commit d6bd059

Please sign in to comment.