Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retrieval client node interface passes tipset identifier to node #164

Merged
merged 3 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions retrievalmarket/impl/clientstates/client_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ type ClientDealEnvironment interface {

// SetupPaymentChannel sets up a payment channel for a deal
func SetupPaymentChannel(ctx fsm.Context, environment ClientDealEnvironment, deal rm.ClientDealState) error {
paych, err := environment.Node().GetOrCreatePaymentChannel(ctx.Context(), deal.ClientWallet, deal.MinerWallet, deal.TotalFunds)
tok, _, err := environment.Node().GetChainHead(ctx.Context())
if err != nil {
return ctx.Trigger(rm.ClientEventPaymentChannelErrored, err)
laser marked this conversation as resolved.
Show resolved Hide resolved
}

paych, err := environment.Node().GetOrCreatePaymentChannel(ctx.Context(), deal.ClientWallet, deal.MinerWallet, deal.TotalFunds, tok)
if err != nil {
return ctx.Trigger(rm.ClientEventPaymentChannelErrored, err)
}
Expand Down Expand Up @@ -56,7 +61,6 @@ func ProposeDeal(ctx fsm.Context, environment ClientDealEnvironment, deal rm.Cli

// ProcessPaymentRequested processes a request for payment from the provider
func ProcessPaymentRequested(ctx fsm.Context, environment ClientDealEnvironment, deal rm.ClientDealState) error {

// check that fundsSpent + paymentRequested <= totalFunds, or fail
if big.Add(deal.FundsSpent, deal.PaymentRequested).GreaterThan(deal.TotalFunds) {
expectedTotal := deal.TotalFunds.String()
Expand All @@ -74,10 +78,15 @@ func ProcessPaymentRequested(ctx fsm.Context, environment ClientDealEnvironment,
return ctx.Trigger(rm.ClientEventBadPaymentRequested, "too much money requested for bytes sent")
}

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

// create payment voucher with node (or fail) for (fundsSpent + paymentRequested)
// use correct payCh + lane
// (node will do subtraction back to paymentRequested... slightly odd behavior but... well anyway)
voucher, err := environment.Node().CreatePaymentVoucher(ctx.Context(), deal.PaymentInfo.PayCh, big.Add(deal.FundsSpent, deal.PaymentRequested), deal.PaymentInfo.Lane)
voucher, err := environment.Node().CreatePaymentVoucher(ctx.Context(), deal.PaymentInfo.PayCh, big.Add(deal.FundsSpent, deal.PaymentRequested), deal.PaymentInfo.Lane, tok)
if err != nil {
return ctx.Trigger(rm.ClientEventCreateVoucherFailed, err)
}
Expand Down
10 changes: 8 additions & 2 deletions retrievalmarket/impl/testnodes/test_retrieval_client_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package testnodes
import (
"context"

"github.com/filecoin-project/go-fil-markets/shared"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
Expand Down Expand Up @@ -56,7 +58,7 @@ func NewTestRetrievalClientNode(params TestRetrievalClientNodeParams) *TestRetri
}

// GetOrCreatePaymentChannel returns a mocked payment channel
func (trcn *TestRetrievalClientNode) GetOrCreatePaymentChannel(ctx context.Context, clientAddress address.Address, minerAddress address.Address, clientFundsAvailable abi.TokenAmount) (address.Address, error) {
func (trcn *TestRetrievalClientNode) GetOrCreatePaymentChannel(ctx context.Context, clientAddress address.Address, minerAddress address.Address, clientFundsAvailable abi.TokenAmount, tok shared.TipSetToken) (address.Address, error) {
if trcn.getCreatePaymentChannelRecorder != nil {
trcn.getCreatePaymentChannelRecorder(clientAddress, minerAddress, clientFundsAvailable)
}
Expand All @@ -72,9 +74,13 @@ func (trcn *TestRetrievalClientNode) AllocateLane(paymentChannel address.Address
}

// CreatePaymentVoucher creates a mock payment voucher based on a channel and lane
func (trcn *TestRetrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64) (*paych.SignedVoucher, error) {
func (trcn *TestRetrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64, tok shared.TipSetToken) (*paych.SignedVoucher, error) {
if trcn.createPaymentVoucherRecorder != nil {
trcn.createPaymentVoucherRecorder(trcn.voucher)
}
return trcn.voucher, trcn.voucherError
}

func (trcn *TestRetrievalClientNode) GetChainHead(ctx context.Context) (shared.TipSetToken, abi.ChainEpoch, error) {
return shared.TipSetToken{}, 0, nil
}
5 changes: 3 additions & 2 deletions retrievalmarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ type RetrievalClient interface {

// RetrievalClientNode are the node dependencies for a RetrievalClient
type RetrievalClientNode interface {
GetChainHead(ctx context.Context) (shared.TipSetToken, abi.ChainEpoch, error)

// GetOrCreatePaymentChannel sets up a new payment channel if one does not exist
// between a client and a miner and insures the client has the given amount of funds available in the channel
GetOrCreatePaymentChannel(ctx context.Context, clientAddress address.Address, minerAddress address.Address, clientFundsAvailable abi.TokenAmount) (address.Address, error)
GetOrCreatePaymentChannel(ctx context.Context, clientAddress address.Address, minerAddress address.Address, clientFundsAvailable abi.TokenAmount, tok shared.TipSetToken) (address.Address, error)

// Allocate late creates a lane within a payment channel so that calls to
// CreatePaymentVoucher will automatically make vouchers only for the difference
Expand All @@ -188,7 +189,7 @@ type RetrievalClientNode interface {
// 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)
CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64) (*paych.SignedVoucher, error)
CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64, tok shared.TipSetToken) (*paych.SignedVoucher, error)
}

// ProviderDealState is the current state of a deal from the point of view
Expand Down