chain/gen tests now pass!

This commit is contained in:
whyrusleeping 2020-02-20 00:37:10 -08:00
parent 35d14788d3
commit 00d7bd1a77
13 changed files with 74 additions and 57 deletions

View File

@ -140,7 +140,7 @@ type FullNode interface {
PaychList(context.Context) ([]address.Address, error)
PaychStatus(context.Context, address.Address) (*PaychStatus, error)
PaychClose(context.Context, address.Address) (cid.Cid, error)
PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error)
PaychAllocateLane(ctx context.Context, ch address.Address) (int64, error)
PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []VoucherSpec) (*PaymentInfo, error)
PaychVoucherCheckValid(context.Context, address.Address, *types.SignedVoucher) error
PaychVoucherCheckSpendable(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error)
@ -193,7 +193,7 @@ type Message struct {
type ChainSectorInfo struct {
Info miner.SectorOnChainInfo
ID abi.SectorNumber
ID abi.SectorNumber
}
type ActorState struct {

View File

@ -132,7 +132,7 @@ type FullNodeStruct struct {
PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
PaychStatus func(context.Context, address.Address) (*api.PaychStatus, error) `perm:"read"`
PaychClose func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"`
PaychAllocateLane func(context.Context, address.Address) (uint64, error) `perm:"sign"`
PaychAllocateLane func(context.Context, address.Address) (int64, error) `perm:"sign"`
PaychNewPayment func(ctx context.Context, from, to address.Address, vouchers []api.VoucherSpec) (*api.PaymentInfo, error) `perm:"sign"`
PaychVoucherCheck func(context.Context, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckValid func(context.Context, address.Address, *types.SignedVoucher) error `perm:"read"`
@ -537,7 +537,7 @@ func (c *FullNodeStruct) PaychClose(ctx context.Context, a address.Address) (cid
return c.Internal.PaychClose(ctx, a)
}
func (c *FullNodeStruct) PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error) {
func (c *FullNodeStruct) PaychAllocateLane(ctx context.Context, ch address.Address) (int64, error) {
return c.Internal.PaychAllocateLane(ctx, ch)
}

View File

@ -158,7 +158,7 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
}
reward := vm.MiningReward(rewardActor.Balance)
for tsi, b := range blks {
for _, b := range blks {
rewardActor, err = vmi.StateTree().GetActor(actors.RewardActor)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
@ -178,24 +178,6 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
if err := vm.Transfer(rewardActor, act, reward); err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to deduct funds from network actor: %w", err)
}
// all block miners created a valid post, go update the actor state
postSubmitMsg := &types.Message{
From: actors.SystemAddress,
Nonce: rewardActor.Nonce,
To: b.Miner,
Method: builtin.MethodsMiner.SubmitWindowedPoSt,
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(10000000000),
Value: types.NewInt(0),
}
ret, err := vmi.ApplyMessage(ctx, postSubmitMsg)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("submit election post message for block %s (miner %s) invocation failed: %w", b.Cid(), b.Miner, err)
}
if ret.ExitCode != 0 {
return cid.Undef, cid.Undef, xerrors.Errorf("submit election post invocation returned nonzero exit code: %d (err = %s, block = %s, miner = %s, tsi = %d)", ret.ExitCode, ret.ActorErr, b.Cid(), b.Miner, tsi)
}
}
// TODO: can't use method from chainstore because it doesnt let us know who the block miners were
@ -264,14 +246,14 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
}
// TODO: this nonce-getting is a tiny bit ugly
ca, err := vmi.StateTree().GetActor(actors.CronAddress)
ca, err := vmi.StateTree().GetActor(actors.SystemAddress)
if err != nil {
return cid.Undef, cid.Undef, err
}
ret, err := vmi.ApplyMessage(ctx, &types.Message{
To: actors.CronAddress,
From: actors.CronAddress,
From: actors.SystemAddress,
Nonce: ca.Nonce,
Value: types.NewInt(0),
GasPrice: types.NewInt(0),

View File

@ -168,7 +168,7 @@ var stateSectorsCmd = &cli.Command{
}
for _, s := range sectors {
fmt.Printf("%d: %x %x\n", s.SectorID, s.CommR, s.CommD)
fmt.Printf("%d: %x\n", s.Info.Info.SectorNumber, s.Info.Info.SealedCID)
}
return nil
@ -207,7 +207,7 @@ var stateProvingSetCmd = &cli.Command{
}
for _, s := range sectors {
fmt.Printf("%d: %x %x\n", s.SectorID, s.CommR, s.CommD)
fmt.Printf("%d: %x\n", s.Info.Info.SectorNumber, s.Info.Info.SealedCID)
}
return nil

View File

@ -8,6 +8,7 @@ import (
payapi "github.com/filecoin-project/lotus/node/impl/paych"
"github.com/filecoin-project/lotus/paychmgr"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
)
type retrievalClientNode struct {
@ -31,14 +32,14 @@ func (rcn *retrievalClientNode) GetOrCreatePaymentChannel(ctx context.Context, c
// Allocate late creates a lane within a payment channel so that calls to
// CreatePaymentVoucher will automatically make vouchers only for the difference
// in total
func (rcn *retrievalClientNode) AllocateLane(paymentChannel address.Address) (uint64, error) {
func (rcn *retrievalClientNode) AllocateLane(paymentChannel address.Address) (int64, error) {
return rcn.pmgr.AllocateLane(paymentChannel)
}
// CreatePaymentVoucher creates a new payment voucher in the given lane for a
// given payment channel so that all the payment vouchers in the lane add up
// to the given amount (so the payment voucher will be for the difference)
func (rcn *retrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64) (*paychmgr.SignedVoucher, error) {
func (rcn *retrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64) (*paych.SignedVoucher, error) {
voucher, err := rcn.payapi.PaychVoucherCreate(ctx, paymentChannel, amount, lane)
if err != nil {
return nil, err

View File

@ -7,7 +7,10 @@ import (
"context"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
samarket "github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/crypto"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -21,6 +24,7 @@ import (
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/markets/utils"
"github.com/filecoin-project/lotus/node/impl/full"
)
@ -88,6 +92,10 @@ func (n *ClientNodeAdapter) ListStorageProviders(ctx context.Context) ([]*storag
return out, nil
}
func (n *ClientNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool {
panic("TODO")
}
func (n *ClientNodeAdapter) ListClientDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
allDeals, err := n.StateMarketDeals(ctx, nil)
if err != nil {
@ -119,7 +127,7 @@ func (n *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address,
Value: amount,
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1000000),
Method: actors.SMAMethods.AddBalance,
Method: builtin.MethodsMarket.AddBalance,
})
if err != nil {
return err
@ -173,7 +181,7 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor
return 0, xerrors.Errorf("deal publish message wasn't set to StorageMarket actor (to=%s)", pubmsg.To)
}
if pubmsg.Method != actors.SMAMethods.PublishStorageDeals {
if pubmsg.Method != builtin.MethodsMarket.PublishStorageDeals {
return 0, xerrors.Errorf("deal publish message called incorrect method (method=%s)", pubmsg.Method)
}
@ -273,7 +281,7 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider
return false, nil
}
if msg.Method != actors.MAMethods.ProveCommitSector {
if msg.Method != builtin.MethodsMiner.ProveCommitSector {
return false, nil
}
@ -300,9 +308,10 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider
return nil
}
func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal *storagemarket.StorageDealProposal) error {
func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal samarket.DealProposal) (*samarket.ClientDealProposal, error) {
// TODO: output spec signed proposal
return nil
panic("nyi")
return nil, nil
}
func (n *ClientNodeAdapter) GetDefaultWalletAddress(ctx context.Context) (address.Address, error) {
@ -323,7 +332,9 @@ func (n *ClientNodeAdapter) ValidateAskSignature(ask *storagemarket.SignedStorag
return xerrors.Errorf("failed to re-serialize ask")
}
return ask.Signature.Verify(w, sigb)
_ = w
_ = sigb
panic("verify signature")
}
var _ storagemarket.StorageClientNode = &ClientNodeAdapter{}

View File

@ -8,6 +8,7 @@ import (
"io"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/crypto"
@ -72,7 +73,7 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark
Value: types.NewInt(0),
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1000000),
Method: actors.SMAMethods.PublishStorageDeals,
Method: builtin.MethodsMarket.PublishStorageDeals,
Params: params,
})
if err != nil {
@ -93,11 +94,12 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark
return 0, cid.Undef, xerrors.Errorf("got unexpected number of DealIDs from")
}
return resp.IDs[0], smsg.Cid(), nil
// TODO: bad types here
return storagemarket.DealID(resp.IDs[0]), smsg.Cid(), nil
}
func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagemarket.MinerDeal, pieceSize uint64, pieceData io.Reader) error {
_, err := n.secb.AddPiece(ctx, abi.UnpaddedPieceSize(pieceSize), pieceData, deal.DealID)
func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagemarket.MinerDeal, pieceSize abi.UnpaddedPieceSize, pieceData io.Reader) error {
_, err := n.secb.AddPiece(ctx, abi.UnpaddedPieceSize(pieceSize), pieceData, abi.DealID(deal.DealID))
if err != nil {
return xerrors.Errorf("AddPiece failed: %s", err)
}
@ -106,6 +108,10 @@ func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagema
return nil
}
func (n *ProviderNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool {
panic("nyi")
}
func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
allDeals, err := n.StateMarketDeals(ctx, nil)
if err != nil {
@ -134,7 +140,7 @@ func (n *ProviderNodeAdapter) SignBytes(ctx context.Context, signer address.Addr
if err != nil {
return nil, err
}
return localSignature
return localSignature, nil
}
func (n *ProviderNodeAdapter) EnsureFunds(ctx context.Context, addr address.Address, amt abi.TokenAmount) error {
@ -154,7 +160,7 @@ func (n *ProviderNodeAdapter) AddFunds(ctx context.Context, addr address.Address
Value: amount,
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1000000),
Method: actors.SMAMethods.AddBalance,
Method: builtin.MethodsMarket.AddBalance,
})
if err != nil {
return err
@ -178,7 +184,7 @@ func (n *ProviderNodeAdapter) GetBalance(ctx context.Context, addr address.Addre
return storagemarket.Balance{}, err
}
return bal, nil
return utils.ToSharedBalance(bal), nil
}
func (n *ProviderNodeAdapter) LocatePieceForDealWithinSector(ctx context.Context, dealID uint64) (sectorID uint64, offset uint64, length uint64, err error) {
@ -267,7 +273,7 @@ func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provide
return false, nil
}
if msg.Method != actors.MAMethods.ProveCommitSector {
if msg.Method != builtin.MethodsMiner.ProveCommitSector {
return false, nil
}

View File

@ -1,7 +1,9 @@
package utils
import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/filecoin-project/go-address"
@ -16,3 +18,17 @@ func NewStorageProviderInfo(address address.Address, miner address.Address, sect
PeerID: peer,
}
}
func FromOnChainDeal(prop market.DealProposal, state market.DealState) storagemarket.StorageDeal {
return storagemarket.StorageDeal{
DealProposal: prop,
DealState: state,
}
}
func ToSharedBalance(bal api.MarketBalance) storagemarket.Balance {
return storagemarket.Balance{
Locked: bal.Locked,
Available: bal.Escrow,
}
}

View File

@ -40,7 +40,7 @@ func (a *PaychAPI) PaychGet(ctx context.Context, from, to address.Address, ensur
}, nil
}
func (a *PaychAPI) PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error) {
func (a *PaychAPI) PaychAllocateLane(ctx context.Context, ch address.Address) (int64, error) {
return a.PaychMgr.AllocateLane(ch)
}
@ -64,7 +64,7 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address
for i, v := range vouchers {
sv, err := a.paychVoucherCreate(ctx, ch.Channel, types.SignedVoucher{
Amount: v.Amount,
Lane: lane,
Lane: uint64(lane),
Extra: v.Extra,
TimeLock: v.TimeLock,

View File

@ -366,7 +366,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field")
}
t.NextLane = uint64(extra)
t.NextLane = int64(extra)
default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name)

View File

@ -53,11 +53,11 @@ func NewManager(sm *stmgr.StateManager, pchstore *Store, api ManagerApi) *Manage
}
}
func maxLaneFromState(st *actors.PaymentChannelActorState) (uint64, error) {
maxLane := uint64(math.MaxUint64)
func maxLaneFromState(st *actors.PaymentChannelActorState) (int64, error) {
maxLane := int64(math.MaxInt64)
for _, state := range st.LaneStates {
if uint64(state.ID)+1 > maxLane+1 {
maxLane = uint64(state.ID)
if int64(state.ID)+1 > maxLane+1 {
maxLane = int64(state.ID)
}
}
return maxLane, nil
@ -293,14 +293,14 @@ func (pm *Manager) AddVoucher(ctx context.Context, ch address.Address, sv *types
Proof: proof,
})
if ci.NextLane <= uint64(sv.Lane) {
ci.NextLane = uint64(sv.Lane + 1)
if ci.NextLane <= int64(sv.Lane) {
ci.NextLane = int64(sv.Lane + 1)
}
return delta, pm.store.putChannelInfo(ci)
}
func (pm *Manager) AllocateLane(ch address.Address) (uint64, error) {
func (pm *Manager) AllocateLane(ch address.Address) (int64, error) {
return pm.store.AllocateLane(ch)
}

View File

@ -51,7 +51,7 @@ type ChannelInfo struct {
Direction uint64
Vouchers []*VoucherInfo
NextLane uint64
NextLane int64
}
func dskeyForChannel(addr address.Address) datastore.Key {
@ -177,7 +177,7 @@ func (ps *Store) findChan(filter func(*ChannelInfo) bool) (address.Address, erro
return address.Undef, nil
}
func (ps *Store) AllocateLane(ch address.Address) (uint64, error) {
func (ps *Store) AllocateLane(ch address.Address) (int64, error) {
ps.lk.Lock()
defer ps.lk.Unlock()

View File

@ -220,10 +220,11 @@ func (s *FPoStScheduler) sortedSectorInfo(ctx context.Context, ts *types.TipSet)
sbsi := make([]ffi.PublicSectorInfo, len(sset))
for k, sector := range sset {
var commR [sectorbuilder.CommLen]byte
copy(commR[:], sector.CommR)
scid := sector.Info.Info.SealedCID.Bytes()
copy(commR[:], scid[len(scid)-32:])
sbsi[k] = ffi.PublicSectorInfo{
SectorNum: sector.SectorID,
SectorNum: sector.Info.Info.SectorNumber,
CommR: commR,
}
}