deals: wire up PaymentVerify

This commit is contained in:
Łukasz Magiera 2019-08-15 16:28:11 +02:00
parent fc69556817
commit eb962940bd
3 changed files with 47 additions and 13 deletions

View File

@ -19,6 +19,9 @@ func init() {
cbor.RegisterCborType(CommitSectorParams{}) cbor.RegisterCborType(CommitSectorParams{})
cbor.RegisterCborType(MinerInfo{}) cbor.RegisterCborType(MinerInfo{})
cbor.RegisterCborType(SubmitPoStParams{}) cbor.RegisterCborType(SubmitPoStParams{})
cbor.RegisterCborType(StorageVoucherData{})
cbor.RegisterCborType(StoragePaymentVerifyProof{})
cbor.RegisterCborType(PaymentVerifyParams{})
} }
var ProvingPeriodDuration = uint64(2 * 60) // an hour, for now var ProvingPeriodDuration = uint64(2 * 60) // an hour, for now

View File

@ -196,18 +196,25 @@ type ClientDealProposal struct {
MinerID peer.ID MinerID peer.ID
} }
func (c *Client) Start(ctx context.Context, p ClientDealProposal) (cid.Cid, error) { func (c *Client) VerifyParams(ctx context.Context, data cid.Cid) (*actors.StorageVoucherData, error) {
commP, size, err := c.commP(ctx, p.Data) commP, size, err := c.commP(ctx, data)
if err != nil { if err != nil {
return cid.Undef, err return nil, err
} }
return &actors.StorageVoucherData{
CommP: commP,
PieceSize: types.NewInt(uint64(size)),
}, nil
}
func (c *Client) Start(ctx context.Context, p ClientDealProposal, vd *actors.StorageVoucherData) (cid.Cid, error) {
// TODO: use data // TODO: use data
proposal := StorageDealProposal{ proposal := StorageDealProposal{
PieceRef: p.Data.String(), PieceRef: p.Data.String(),
SerializationMode: SerializationUnixFs, SerializationMode: SerializationUnixFs,
CommP: commP[:], CommP: vd.CommP[:],
Size: uint64(size), Size: vd.PieceSize.Uint64(),
TotalPrice: p.TotalPrice, TotalPrice: p.TotalPrice,
Duration: p.Duration, Duration: p.Duration,
Payment: p.Payment, Payment: p.Payment,

View File

@ -69,6 +69,16 @@ func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner a
return nil, err return nil, err
} }
vd, err := a.DealClient.VerifyParams(ctx, data)
if err != nil {
return nil, err
}
voucherData, err := cbor.DumpObject(vd)
if err != nil {
return nil, err
}
// setup payments // setup payments
total := types.BigMul(price, types.NewInt(blocksDuration)) total := types.BigMul(price, types.NewInt(blocksDuration))
@ -77,7 +87,20 @@ func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner a
if err != nil { if err != nil {
return nil, err return nil, err
} }
sv, err := a.PaychVoucherCreate(ctx, paych, total, 0)
voucher := types.SignedVoucher{
// TimeLock: 0, // TODO: do we want to use this somehow?
Extra: &types.ModVerifyParams{
Actor: miner,
Method: actors.MAMethods.PaymentVerify,
Data: voucherData,
},
Lane: 0,
Amount: total,
MinCloseHeight: blocksDuration, // TODO: some way to start this after initial piece inclusion by actor? (also, at least add current height)
}
sv, err := a.paychVoucherCreate(ctx, paych, voucher)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -97,7 +120,7 @@ func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner a
MinerID: pid, MinerID: pid,
} }
c, err := a.DealClient.Start(ctx, proposal) c, err := a.DealClient.Start(ctx, proposal, vd)
return &c, err return &c, err
} }
@ -584,21 +607,22 @@ func (a *FullNodeAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, s
// actual additional value of this voucher will only be the difference between // actual additional value of this voucher will only be the difference between
// the two. // the two.
func (a *FullNodeAPI) PaychVoucherCreate(ctx context.Context, pch address.Address, amt types.BigInt, lane uint64) (*types.SignedVoucher, error) { func (a *FullNodeAPI) PaychVoucherCreate(ctx context.Context, pch address.Address, amt types.BigInt, lane uint64) (*types.SignedVoucher, error) {
return a.paychVoucherCreate(ctx, pch, types.SignedVoucher{Amount: amt, Lane: lane})
}
func (a *FullNodeAPI) paychVoucherCreate(ctx context.Context, pch address.Address, voucher types.SignedVoucher) (*types.SignedVoucher, error) {
ci, err := a.PaychMgr.GetChannelInfo(pch) ci, err := a.PaychMgr.GetChannelInfo(pch)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nonce, err := a.PaychMgr.NextNonceForLane(ctx, pch, lane) nonce, err := a.PaychMgr.NextNonceForLane(ctx, pch, voucher.Lane)
if err != nil { if err != nil {
return nil, err return nil, err
} }
sv := &types.SignedVoucher{ sv := &voucher
Lane: lane, sv.Nonce = nonce
Nonce: nonce,
Amount: amt,
}
vb, err := sv.SigningBytes() vb, err := sv.SigningBytes()
if err != nil { if err != nil {