WIP: fixing the tests by waiting for chain activity

This commit is contained in:
whyrusleeping 2019-11-06 23:57:10 -08:00
parent 90faa63f17
commit 54722a0d38
8 changed files with 85 additions and 1 deletions

View File

@ -109,6 +109,7 @@ type FullNode interface {
StateMarketBalance(context.Context, address.Address, *types.TipSet) (actors.StorageParticipantBalance, error)
StateMarketParticipants(context.Context, *types.TipSet) (map[string]actors.StorageParticipantBalance, error)
StateMarketDeals(context.Context, *types.TipSet) (map[string]actors.OnChainDeal, error)
StateMarketStorageDeal(context.Context, uint64, *types.TipSet) (*actors.OnChainDeal, error)
PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error)
PaychList(context.Context) ([]address.Address, error)

View File

@ -105,6 +105,7 @@ type FullNodeStruct struct {
StateMarketBalance func(context.Context, address.Address, *types.TipSet) (actors.StorageParticipantBalance, error) `perm:"read"`
StateMarketParticipants func(context.Context, *types.TipSet) (map[string]actors.StorageParticipantBalance, error) `perm:"read"`
StateMarketDeals func(context.Context, *types.TipSet) (map[string]actors.OnChainDeal, error) `perm:"read"`
StateMarketStorageDeal func(context.Context, uint64, *types.TipSet) (*actors.OnChainDeal, error) `perm:"read"`
PaychGet func(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) `perm:"sign"`
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
@ -413,6 +414,10 @@ func (c *FullNodeStruct) StateMarketDeals(ctx context.Context, ts *types.TipSet)
return c.Internal.StateMarketDeals(ctx, ts)
}
func (c *FullNodeStruct) StateMarketStorageDeal(ctx context.Context, dealid uint64, ts *types.TipSet) (*actors.OnChainDeal, error) {
return c.Internal.StateMarketStorageDeal(ctx, dealid, ts)
}
func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error) {
return c.Internal.PaychGet(ctx, from, to, ensureFunds)
}

View File

@ -18,6 +18,7 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/address"
"github.com/filecoin-project/lotus/chain/events"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
@ -34,6 +35,7 @@ type ClientDeal struct {
Proposal actors.StorageDealProposal
State api.DealState
Miner peer.ID
DealID uint64
s inet.Stream
}
@ -46,6 +48,7 @@ type Client struct {
dag dtypes.ClientDAG
discovery *discovery.Local
mpool full.MpoolAPI
events *events.Events
deals *statestore.StateStore
conns map[cid.Cid]inet.Stream

View File

@ -8,6 +8,7 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/types"
)
type clientHandlerFunc func(ctx context.Context, deal ClientDeal) error
@ -126,6 +127,51 @@ func (c *Client) staged(ctx context.Context, deal ClientDeal) error {
}
func (c *Client) sealing(ctx context.Context, deal ClientDeal) error {
//func (e *calledEvents) Called(check CheckFunc, hnd CalledHandler, rev RevertHandler, confidence int, timeout uint64, actor address.Address, method uint64) error {
checkFunc := func(ts *types.TipSet) (done bool, more bool, err error) {
sd, err := stmgr.GetStorageDeal(ctx, c.stmgr, deal.DealID, ts)
if err != nil {
return false, false, xerrors.Errorf("failed to look up deal on chain: %w", err)
}
if sd.ActivationEpoch > 0 {
// Deal is active already!
panic("handle me")
return true, false, nil
}
return false, true, nil
}
called := func(msg *types.Message, ts *types.TipSet, curH uint64) (bool, error) {
// To ask Magik: Does this trigger when the message in question is part of the parent state execution? Or just when its included in the block (aka, not executed)
// main thing i want to ensure is that ts.ParentState is the result of the execution of msg
if msg == nil {
log.Error("timed out waiting for deal activation... what now?")
return false, nil
}
// TODO: can check msg.Params to see if we should even bother checking the state
sd, err := stmgr.GetStorageDeal(ctx, c.stmgr, deal.DealID, ts)
if err != nil {
return false, false, xerrors.Errorf("failed to look up deal on chain: %w", err)
}
if sd.ActivationEpoch == 0 {
return true, nil
}
// Deal is active!
panic("handle me")
return false, nil
}
if err := c.events.Called(checkFunc, handler, rev, 3, 100, actors.StorageMarketAddress, actors.SMAMethods.ActivateStorageDeals); err != nil {
return xerrors.Errorf("failed to set up called handler")
}
resp, err := c.readStorageDealResp(deal)
if err != nil {
return err

View File

@ -247,6 +247,7 @@ func (p *Provider) sealing(ctx context.Context, deal MinerDeal) (func(*MinerDeal
log.Warnf("Sending deal response failed: %s", err)
}
log.Info("About to seal sector!", deal.ProposalCid, deal.SectorID)
if err := p.sminer.SealSector(ctx, deal.SectorID); err != nil {
return nil, xerrors.Errorf("sealing sector failed: %w", err)
}

View File

@ -193,6 +193,26 @@ func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet,
return minfo.SectorSize, nil
}
func GetStorageDeal(ctx context.Context, sm *StateManager, dealId uint64, ts *types.TipSet) (*actors.OnChainDeal, error) {
var state actors.StorageMarketState
if _, err := sm.LoadActorState(ctx, actors.StorageMarketAddress, &state, ts); err != nil {
return nil, err
}
blks := amt.WrapBlockstore(sm.ChainStore().Blockstore())
da, err := amt.LoadAMT(blks, state.Deals)
if err != nil {
return nil, err
}
var ocd actors.OnChainDeal
if err := da.Get(dealId, &ocd); err != nil {
return nil, err
}
return &ocd, nil
}
func LoadSectorsFromSet(ctx context.Context, bs blockstore.Blockstore, ssc cid.Cid) ([]*api.SectorInfo, error) {
blks := amt.WrapBlockstore(bs)
a, err := amt.LoadAMT(blks, ssc)

View File

@ -3,9 +3,10 @@ package full
import (
"bytes"
"context"
"github.com/filecoin-project/go-amt-ipld"
"strconv"
"github.com/filecoin-project/go-amt-ipld"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-hamt-ipld"
"github.com/libp2p/go-libp2p-core/peer"
@ -279,3 +280,7 @@ func (a *StateAPI) StateMarketDeals(ctx context.Context, ts *types.TipSet) (map[
}
return out, nil
}
func (a *StateAPI) StateMarketStorageDeal(ctx context.Context, dealId uint64, ts *types.TipSet) (*actors.OnChainDeal, error) {
return stmgr.GetStorageDeal(ctx, s.StateManager, dealId, ts)
}

View File

@ -2,6 +2,7 @@ package storage
import (
"context"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
@ -113,6 +114,7 @@ func (m *Miner) preCommit(ctx context.Context, sector SectorInfo) (func(*SectorI
func (m *Miner) preCommitted(ctx context.Context, sector SectorInfo) (func(*SectorInfo), error) {
// would be ideal to just use the events.Called handler, but it wouldnt be able to handle individual message timeouts
log.Info("Sector precommitted: ", sector.SectorID)
mw, err := m.api.StateWaitMsg(ctx, *sector.PreCommitMessage)
if err != nil {
return nil, err
@ -122,6 +124,7 @@ func (m *Miner) preCommitted(ctx context.Context, sector SectorInfo) (func(*Sect
log.Error("sector precommit failed: ", mw.Receipt.ExitCode)
return nil, err
}
log.Info("precommit message landed on chain: ", sector.SectorID)
randHeight := mw.TipSet.Height() + build.InteractivePoRepDelay - 1 // -1 because of how the messages are applied
log.Infof("precommit for sector %d made it on chain, will start proof computation at height %d", sector.SectorID, randHeight)