fixing miner logic to make more tests pass

This commit is contained in:
whyrusleeping 2020-02-28 10:01:43 -08:00
parent 2a1253e45a
commit 0945d8725e
17 changed files with 78 additions and 37 deletions

View File

@ -136,7 +136,7 @@ type FullNode interface {
MsigGetAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error)
MarketEnsureAvailable(context.Context, address.Address, types.BigInt) error
MarketEnsureAvailable(context.Context, address.Address, address.Address, types.BigInt) error
// MarketFreeBalance
PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error)

View File

@ -101,7 +101,7 @@ type FullNodeStruct struct {
ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"`
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"`
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
StateMinerSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
@ -132,7 +132,7 @@ type FullNodeStruct struct {
MsigGetAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"`
MarketEnsureAvailable func(context.Context, address.Address, types.BigInt) error `perm:"sign"`
MarketEnsureAvailable func(context.Context, address.Address, address.Address, types.BigInt) error `perm:"sign"`
PaychGet func(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*api.ChannelInfo, error) `perm:"sign"`
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
@ -144,7 +144,7 @@ type FullNodeStruct struct {
PaychVoucherCheckValid func(context.Context, address.Address, *paych.SignedVoucher) error `perm:"read"`
PaychVoucherCheckSpendable func(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error) `perm:"read"`
PaychVoucherAdd func(context.Context, address.Address, *paych.SignedVoucher, []byte, types.BigInt) (types.BigInt, error) `perm:"write"`
PaychVoucherCreate func(context.Context, address.Address, big.Int, uint64) (*paych.SignedVoucher, error) `perm:"sign"`
PaychVoucherCreate func(context.Context, address.Address, big.Int, uint64) (*paych.SignedVoucher, error) `perm:"sign"`
PaychVoucherList func(context.Context, address.Address) ([]*paych.SignedVoucher, error) `perm:"write"`
PaychVoucherSubmit func(context.Context, address.Address, *paych.SignedVoucher) (cid.Cid, error) `perm:"sign"`
}
@ -519,8 +519,8 @@ func (c *FullNodeStruct) MsigGetAvailableBalance(ctx context.Context, a address.
return c.Internal.MsigGetAvailableBalance(ctx, a, tsk)
}
func (c *FullNodeStruct) MarketEnsureAvailable(ctx context.Context, addr address.Address, amt types.BigInt) error {
return c.Internal.MarketEnsureAvailable(ctx, addr, amt)
func (c *FullNodeStruct) MarketEnsureAvailable(ctx context.Context, addr, wallet address.Address, amt types.BigInt) error {
return c.Internal.MarketEnsureAvailable(ctx, addr, wallet, amt)
}
func (c *FullNodeStruct) PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*api.ChannelInfo, error) {

View File

@ -572,11 +572,16 @@ func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner add
return nil, nil
}
if pset[0].Info.Info.RegisteredProof == 0 {
panic("registered proof coming from proving set is 0")
}
var sinfos []abi.SectorInfo
for _, s := range pset {
sinfos = append(sinfos, abi.SectorInfo{
SectorNumber: s.ID,
SealedCID: s.Info.Info.SealedCID,
SectorNumber: s.ID,
SealedCID: s.Info.Info.SealedCID,
RegisteredProof: s.Info.Info.RegisteredProof,
})
}

View File

@ -201,11 +201,12 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
{
newSectorInfo := &miner.SectorOnChainInfo{
Info: miner.SectorPreCommitInfo{
SectorNumber: preseal.SectorID,
SealedCID: preseal.CommR,
SealRandEpoch: 0,
DealIDs: []abi.DealID{dealIDs[pi]},
Expiration: preseal.Deal.EndEpoch,
RegisteredProof: preseal.ProofType,
SectorNumber: preseal.SectorID,
SealedCID: preseal.CommR,
SealRandEpoch: 0,
DealIDs: []abi.DealID{dealIDs[pi]},
Expiration: preseal.Deal.EndEpoch,
},
ActivationEpoch: 0,
DealWeight: dealWeight,

View File

@ -5,6 +5,7 @@ import (
"sync"
"github.com/filecoin-project/specs-actors/actors/builtin"
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -14,6 +15,8 @@ import (
"github.com/filecoin-project/lotus/node/impl/full"
)
var log = logging.Logger("market_adapter")
type FundMgr struct {
sm *stmgr.StateManager
mpool full.MpoolAPI
@ -31,7 +34,8 @@ func NewFundMgr(sm *stmgr.StateManager, mpool full.MpoolAPI) *FundMgr {
}
}
func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, amt types.BigInt) error {
func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Address, amt types.BigInt) error {
log.Error("ensure available: ", addr, amt)
fm.lk.Lock()
avail, ok := fm.available[addr]
if !ok {
@ -64,7 +68,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, am
smsg, err := fm.mpool.MpoolPushMessage(ctx, &types.Message{
To: builtin.StorageMarketActorAddr,
From: addr,
From: wallet,
Value: toAdd,
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1000000),
@ -77,6 +81,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, am
_, r, err := fm.sm.WaitForMessage(ctx, smsg.Cid())
if err != nil {
log.Error("waiting for message: ", err)
return err
}

View File

@ -4,10 +4,11 @@ import (
"bytes"
"context"
"fmt"
"github.com/filecoin-project/specs-actors/actors/builtin"
"math/big"
"reflect"
"github.com/filecoin-project/specs-actors/actors/builtin"
block "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld"

View File

@ -101,9 +101,10 @@ func PreSeal(maddr address.Address, pt abi.RegisteredProof, offset abi.SectorNum
log.Warn("PreCommitOutput: ", sid, scid, ucid)
sealedSectors = append(sealedSectors, &genesis.PreSeal{
CommR: scid,
CommD: ucid,
SectorID: sid,
CommR: scid,
CommD: ucid,
SectorID: sid,
ProofType: pt,
})
}

View File

@ -18,10 +18,11 @@ const (
)
type PreSeal struct {
CommR cid.Cid
CommD cid.Cid
SectorID abi.SectorNumber
Deal market.DealProposal
CommR cid.Cid
CommD cid.Cid
SectorID abi.SectorNumber
Deal market.DealProposal
ProofType abi.RegisteredProof
}
type Miner struct {

6
go.mod
View File

@ -114,3 +114,9 @@ require (
replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
replace github.com/filecoin-project/go-sectorbuilder => ../go-sectorbuilder
replace github.com/filecoin-project/specs-actors => ../specs-actors
replace github.com/filecoin-project/go-fil-markets => ../go-fil-markets

View File

@ -146,7 +146,7 @@ func (n *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address,
}
func (n *ClientNodeAdapter) EnsureFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) error {
return n.fm.EnsureAvailable(ctx, addr, amount)
return n.fm.EnsureAvailable(ctx, addr, addr, amount)
}
func (n *ClientNodeAdapter) GetBalance(ctx context.Context, addr address.Address) (storagemarket.Balance, error) {

View File

@ -144,8 +144,8 @@ func (n *ProviderNodeAdapter) SignBytes(ctx context.Context, signer address.Addr
return localSignature, nil
}
func (n *ProviderNodeAdapter) EnsureFunds(ctx context.Context, addr address.Address, amt abi.TokenAmount) error {
return n.MarketEnsureAvailable(ctx, addr, amt)
func (n *ProviderNodeAdapter) EnsureFunds(ctx context.Context, addr, wallet address.Address, amt abi.TokenAmount) error {
return n.MarketEnsureAvailable(ctx, addr, wallet, amt)
}
func (n *ProviderNodeAdapter) MostRecentStateId(ctx context.Context) (storagemarket.StateKey, error) {

View File

@ -300,6 +300,10 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path
order.MinerPeerID = pid
}
if order.Size == 0 {
return xerrors.Errorf("cannot make retrieval deal for zero bytes")
}
retrievalResult := make(chan error, 1)
unsubscribe := a.Retrieval.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) {
@ -313,10 +317,12 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path
}
})
ppb := types.BigDiv(order.Total, types.NewInt(order.Size))
a.Retrieval.Retrieve(
ctx,
order.Root,
retrievalmarket.NewParamsV0(types.BigDiv(order.Total, types.NewInt(order.Size)), order.PaymentInterval, order.PaymentIntervalIncrease),
retrievalmarket.NewParamsV0(ppb, order.PaymentInterval, order.PaymentIntervalIncrease),
order.Total,
order.MinerPeerID,
order.Client,

View File

@ -16,6 +16,6 @@ type MarketAPI struct {
FMgr *market.FundMgr
}
func (a *MarketAPI) MarketEnsureAvailable(ctx context.Context, addr address.Address, amt types.BigInt) error {
return a.FMgr.EnsureAvailable(ctx, addr, amt)
func (a *MarketAPI) MarketEnsureAvailable(ctx context.Context, addr, wallet address.Address, amt types.BigInt) error {
return a.FMgr.EnsureAvailable(ctx, addr, wallet, amt)
}

View File

@ -134,7 +134,7 @@ func (epp *SectorBuilderEpp) GenerateCandidates(ctx context.Context, ssi []abi.S
cds, err := epp.sb.GenerateEPostCandidates(ssi, rand, faults)
if err != nil {
return nil, err
return nil, xerrors.Errorf("failed to generate candidates: %w", err)
}
log.Infof("Generate candidates took %s", time.Since(start))
return cds, nil

View File

@ -46,13 +46,15 @@ func (evt SectorForceState) applyGlobal(state *SectorInfo) bool {
// Normal path
type SectorStart struct {
id abi.SectorNumber
pieces []Piece
id abi.SectorNumber
sectorType abi.RegisteredProof
pieces []Piece
}
func (evt SectorStart) apply(state *SectorInfo) {
state.SectorID = evt.id
state.Pieces = evt.pieces
state.SectorType = evt.sectorType
}
type SectorPacked struct{ pieces []Piece }

View File

@ -8,6 +8,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/lib/nullreader"
)
@ -48,6 +49,12 @@ func (m *Sealing) PledgeSector() error {
size := abi.PaddedPieceSize(m.sb.SectorSize()).Unpadded()
rt, _, err := api.ProofTypeFromSectorSize(m.sb.SectorSize())
if err != nil {
log.Error(err)
return
}
sid, err := m.sb.AcquireSectorNumber()
if err != nil {
log.Errorf("%+v", err)
@ -60,7 +67,7 @@ func (m *Sealing) PledgeSector() error {
return
}
if err := m.newSector(sid, pieces); err != nil {
if err := m.newSector(sid, rt, pieces); err != nil {
log.Errorf("%+v", err)
return
}

View File

@ -121,7 +121,12 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i
return xerrors.Errorf("adding piece to sector: %w", err)
}
return m.newSector(sectorID, []Piece{
rt, _, err := api.ProofTypeFromSectorSize(m.sb.SectorSize())
if err != nil {
return xerrors.Errorf("bad sector size: %w", err)
}
return m.newSector(sectorID, rt, []Piece{
{
DealID: &dealID,
@ -131,10 +136,11 @@ func (m *Sealing) SealPiece(ctx context.Context, size abi.UnpaddedPieceSize, r i
})
}
func (m *Sealing) newSector(sid abi.SectorNumber, pieces []Piece) error {
func (m *Sealing) newSector(sid abi.SectorNumber, rt abi.RegisteredProof, pieces []Piece) error {
log.Infof("Start sealing %d", sid)
return m.sectors.Send(uint64(sid), SectorStart{
id: sid,
pieces: pieces,
id: sid,
pieces: pieces,
sectorType: rt,
})
}