Skip to content

Commit

Permalink
Add TipSetToken to SavePaymentVoucher (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
laser authored Mar 18, 2020
1 parent 9176aec commit 6403a5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion retrievalmarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ func ProcessPayment(ctx fsm.Context, environment ProviderDealEnvironment, deal r
return ctx.Trigger(rm.ProviderEventReadPaymentFailed, xerrors.Errorf("reading payment: %w", err))
}

tok, _, err := environment.Node().GetChainHead(ctx.Context())
if err != nil {
return ctx.Trigger(rm.ProviderEventSaveVoucherFailed, err)
}

// attempt to redeem voucher
// (totalSent * pricePerbyte) - fundsReceived
paymentOwed := big.Sub(big.Mul(abi.NewTokenAmount(int64(deal.TotalSent)), deal.PricePerByte), deal.FundsReceived)
received, err := environment.Node().SavePaymentVoucher(ctx.Context(), payment.PaymentChannel, payment.PaymentVoucher, nil, paymentOwed)
received, err := environment.Node().SavePaymentVoucher(ctx.Context(), payment.PaymentChannel, payment.PaymentVoucher, nil, paymentOwed, tok)
if err != nil {
return ctx.Trigger(rm.ProviderEventSaveVoucherFailed, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func (trpn *TestRetrievalProviderNode) SavePaymentVoucher(
paymentChannel address.Address,
voucher *paych.SignedVoucher,
proof []byte,
expectedAmount abi.TokenAmount) (abi.TokenAmount, error) {
expectedAmount abi.TokenAmount,
tok shared.TipSetToken) (abi.TokenAmount, error) {
key, err := trpn.toExpectedVoucherKey(paymentChannel, voucher, proof, expectedAmount)
if err != nil {
return abi.TokenAmount{}, err
Expand Down
2 changes: 1 addition & 1 deletion retrievalmarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ type RetrievalProviderNode interface {
// returns the worker address associated with a miner
GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error)
UnsealSector(ctx context.Context, sectorID uint64, offset uint64, length uint64) (io.ReadCloser, error)
SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount) (abi.TokenAmount, error)
SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount, tok shared.TipSetToken) (abi.TokenAmount, error)
}

// PeerResolver is an interface for looking up providers that may have a piece
Expand Down

0 comments on commit 6403a5b

Please sign in to comment.