-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(retrieval): add node implementations
add node adapters for client & provider so that retrieval can be extracted
- Loading branch information
1 parent
369a30d
commit 8cd06a5
Showing
7 changed files
with
95 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package retrievaladapter | ||
|
||
import ( | ||
"context" | ||
|
||
payapi "github.com/filecoin-project/lotus/node/impl/paych" | ||
"github.com/filecoin-project/lotus/paych" | ||
retrievalmarket "github.com/filecoin-project/lotus/retrieval" | ||
) | ||
|
||
type retrievalClientNode struct { | ||
pmgr *paych.Manager | ||
payapi payapi.PaychAPI | ||
} | ||
|
||
// NewRetrievalClientNode returns a new node adapter for a retrieval client that talks to the | ||
// Lotus Node | ||
func NewRetrievalClientNode(pmgr *paych.Manager, payapi payapi.PaychAPI) retrievalmarket.RetrievalClientNode { | ||
return &retrievalClientNode{pmgr: pmgr, payapi: payapi} | ||
} | ||
|
||
// 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 | ||
func (rcn *retrievalClientNode) GetOrCreatePaymentChannel(ctx context.Context, clientAddress retrievalmarket.Address, minerAddress retrievalmarket.Address, clientFundsAvailable retrievalmarket.BigInt) (retrievalmarket.Address, error) { | ||
paych, _, err := rcn.pmgr.GetPaych(ctx, clientAddress, minerAddress, clientFundsAvailable) | ||
return paych, err | ||
} | ||
|
||
// 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 retrievalmarket.Address) (uint64, 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 retrievalmarket.Address, amount retrievalmarket.BigInt, lane uint64) (*retrievalmarket.SignedVoucher, error) { | ||
return rcn.payapi.PaychVoucherCreate(ctx, paymentChannel, amount, lane) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package retrievaladapter | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/chain/address" | ||
retrievalmarket "github.com/filecoin-project/lotus/retrieval" | ||
) | ||
|
||
type retrievalProviderNode struct { | ||
full api.FullNode | ||
} | ||
|
||
// NewRetrievalProviderNode returns a new node adapter for a retrieval provider that talks to the | ||
// Lotus Node | ||
func NewRetrievalProviderNode(full api.FullNode) retrievalmarket.RetrievalProviderNode { | ||
return &retrievalProviderNode{full} | ||
} | ||
|
||
func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *retrievalmarket.SignedVoucher, proof []byte, expectedAmount retrievalmarket.BigInt) (retrievalmarket.BigInt, error) { | ||
return rpn.full.PaychVoucherAdd(ctx, paymentChannel, voucher, proof, expectedAmount) | ||
} |