Skip to content

Commit

Permalink
feat(ipld): use new bindnode registry in go-ipld-prime
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 10, 2022
1 parent fcb7b35 commit 79bb329
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 189 deletions.
119 changes: 0 additions & 119 deletions bindnodeutils/bindnodeutils.go

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ require (
github.com/ipfs/go-unixfs v0.3.1
github.com/ipld/go-car v0.3.3
github.com/ipld/go-car/v2 v2.1.1
github.com/ipld/go-ipld-prime v0.16.1-0.20220524010812-a2c7491b1229
github.com/ipld/go-ipld-prime v0.16.1-0.20220610101408-9bfac86e6256
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
github.com/jpillora/backoff v1.0.0
github.com/libp2p/go-libp2p v0.20.0
github.com/libp2p/go-libp2p-core v0.16.1
github.com/libp2p/go-libp2p-mplex v0.6.0 // indirect
github.com/multiformats/go-multiaddr v0.5.0
github.com/multiformats/go-multibase v0.0.3
github.com/multiformats/go-multicodec v0.4.1
github.com/multiformats/go-multicodec v0.5.0
github.com/multiformats/go-multihash v0.1.0
github.com/multiformats/go-varint v0.0.6
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,8 @@ github.com/ipld/go-ipld-prime v0.14.3-0.20211207234443-319145880958/go.mod h1:Qc
github.com/ipld/go-ipld-prime v0.14.4/go.mod h1:QcE4Y9n/ZZr8Ijg5bGPT0GqYWgZ1704nH0RDcQtgTP0=
github.com/ipld/go-ipld-prime v0.16.0/go.mod h1:axSCuOCBPqrH+gvXr2w9uAOulJqBPhHPT2PjoiiU1qA=
github.com/ipld/go-ipld-prime v0.16.1-0.20220519105356-1f1151b69dba/go.mod h1:/bZAYlzT7SJS4UV0al4q67xgKvenm5hKrPCa2wNGN1U=
github.com/ipld/go-ipld-prime v0.16.1-0.20220524010812-a2c7491b1229 h1:A83oV+ZFzTNYLS1/XAyfOPTmtzEM0sMSK18GA0dEorU=
github.com/ipld/go-ipld-prime v0.16.1-0.20220524010812-a2c7491b1229/go.mod h1:IInaTjkNLKAZoliYXvjlB3CFQa7IPReVwxOb0oke/RA=
github.com/ipld/go-ipld-prime v0.16.1-0.20220610101408-9bfac86e6256 h1:LynWK6MPm4frKNcOoRs0XQciKSWBVcouJMmp0I9ukKg=
github.com/ipld/go-ipld-prime v0.16.1-0.20220610101408-9bfac86e6256/go.mod h1:aYcKm5TIvGfY8P3QBKz/2gKcLxzJ1zDaD+o0bOowhgs=
github.com/ipld/go-ipld-prime-proto v0.0.0-20191113031812-e32bd156a1e5/go.mod h1:gcvzoEDBjwycpXt3LBE061wT9f46szXGHAmj9uoP6fU=
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd73 h1:TsyATB2ZRRQGTwafJdgEUQkmjOExRV0DNokcihZxbnQ=
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd73/go.mod h1:2PJ0JgxyB08t0b2WKrcuqI3di0V+5n6RS/LTUJhkoxY=
Expand Down Expand Up @@ -1302,8 +1302,9 @@ github.com/multiformats/go-multicodec v0.3.0/go.mod h1:qGGaQmioCDh+TeFOnxrbU0DaI
github.com/multiformats/go-multicodec v0.3.1-0.20210902112759-1539a079fd61/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multicodec v0.3.1-0.20211210143421-a526f306ed2c/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multicodec v0.4.0/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multicodec v0.4.1 h1:BSJbf+zpghcZMZrwTYBGwy0CPcVZGWiC72Cp8bBd4R4=
github.com/multiformats/go-multicodec v0.4.1/go.mod h1:1Hj/eHRaVWSXiSNNfcEPcwZleTmdNP81xlxDLnWU9GQ=
github.com/multiformats/go-multicodec v0.5.0 h1:EgU6cBe/D7WRwQb1KmnBvU7lrcFGMggZVTPtOW9dDHs=
github.com/multiformats/go-multicodec v0.5.0/go.mod h1:DiY2HFaEp5EhEXb/iYzVAunmyX/aSFMxq2KMKfWEues=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po=
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
Expand Down
5 changes: 2 additions & 3 deletions retrievalmarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-statemachine/fsm"

"github.com/filecoin-project/go-fil-markets/bindnodeutils"
"github.com/filecoin-project/go-fil-markets/discovery"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/go-fil-markets/retrievalmarket/impl/clientstates"
Expand Down Expand Up @@ -405,12 +404,12 @@ func (c *clientDealEnvironment) OpenDataTransfer(ctx context.Context, to peer.ID
if proposal.SelectorSpecified() {
sel = proposal.Selector.Node
}
vouch := bindnodeutils.TypeToNode(proposal)
vouch := retrievalmarket.BindnodeRegistry.TypeToNode(proposal)
return c.c.dataTransfer.OpenPullDataChannel(ctx, to, datatransfer.TypedVoucher{Voucher: vouch, Type: retrievalmarket.DealProposalType}, proposal.PayloadCID, sel)
}

func (c *clientDealEnvironment) SendDataTransferVoucher(ctx context.Context, channelID datatransfer.ChannelID, payment *retrievalmarket.DealPayment) error {
vouch := bindnodeutils.TypeToNode(payment)
vouch := retrievalmarket.BindnodeRegistry.TypeToNode(payment)
return c.c.dataTransfer.SendVoucher(ctx, channelID, datatransfer.TypedVoucher{Voucher: vouch, Type: retrievalmarket.DealPaymentType})
}

Expand Down
9 changes: 4 additions & 5 deletions retrievalmarket/impl/dtutils/dtutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
datatransfer "github.com/filecoin-project/go-data-transfer/v2"
"github.com/filecoin-project/go-statemachine/fsm"

"github.com/filecoin-project/go-fil-markets/bindnodeutils"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
rm "github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/go-fil-markets/retrievalmarket/impl/dtutils"
Expand All @@ -25,7 +24,7 @@ import (

func TestProviderDataTransferSubscriber(t *testing.T) {
dealProposal := shared_testutil.MakeTestDealProposal()
node := bindnodeutils.TypeToNode(dealProposal)
node := rm.BindnodeRegistry.TypeToNode(dealProposal)
dealProposalVoucher := datatransfer.TypedVoucher{Voucher: node, Type: rm.DealProposalType}
testPeers := shared_testutil.GeneratePeers(2)
transferID := datatransfer.TransferID(rand.Uint64())
Expand Down Expand Up @@ -112,10 +111,10 @@ func TestProviderDataTransferSubscriber(t *testing.T) {
}
func TestClientDataTransferSubscriber(t *testing.T) {
dealProposal := shared_testutil.MakeTestDealProposal()
node := bindnodeutils.TypeToNode(dealProposal)
node := rm.BindnodeRegistry.TypeToNode(dealProposal)
dealProposalVoucher := datatransfer.TypedVoucher{Voucher: node, Type: retrievalmarket.DealProposalType}
dealResponseVoucher := func(dealResponse retrievalmarket.DealResponse) datatransfer.TypedVoucher {
node := bindnodeutils.TypeToNode(&dealResponse)
node := rm.BindnodeRegistry.TypeToNode(&dealResponse)
return datatransfer.TypedVoucher{Voucher: node, Type: retrievalmarket.DealResponseType}
}
paymentOwed := shared_testutil.MakeTestTokenAmount()
Expand Down Expand Up @@ -322,7 +321,7 @@ func TestTransportConfigurer(t *testing.T) {
thisPeer := expectedChannelID.Initiator
expectedPeer := expectedChannelID.Responder
dealProposalVoucher := func(proposal rm.DealProposal) datatransfer.TypedVoucher {
node := bindnodeutils.TypeToNode(&proposal)
node := rm.BindnodeRegistry.TypeToNode(&proposal)
return datatransfer.TypedVoucher{Voucher: node, Type: rm.DealProposalType}
}

Expand Down
13 changes: 6 additions & 7 deletions retrievalmarket/impl/ipld_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"

"github.com/filecoin-project/go-fil-markets/bindnodeutils"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
)

Expand Down Expand Up @@ -62,7 +61,7 @@ func TestIpldCompat_DealResponse(t *testing.T) {
nb := basicnode.Prototype.Any.NewBuilder()
assert.Nil(t, dagcbor.Decode(nb, &originalBuf))
node := nb.Build()
drBindnodeIface, err := bindnodeutils.TypeFromNode(node, &retrievalmarket.DealResponse{})
drBindnodeIface, err := retrievalmarket.BindnodeRegistry.TypeFromNode(node, &retrievalmarket.DealResponse{})
assert.Nil(t, err)
drBindnode, ok := drBindnodeIface.(*retrievalmarket.DealResponse)
assert.True(t, ok)
Expand All @@ -71,7 +70,7 @@ func TestIpldCompat_DealResponse(t *testing.T) {
compareDealResponse(t, testCase.dr, *drBindnode)

// encode the new DealResponse with bindnode to bytes
node = bindnodeutils.TypeToNode(drBindnode)
node = retrievalmarket.BindnodeRegistry.TypeToNode(drBindnode)
var bindnodeBuf bytes.Buffer
dagcbor.Encode(node.(schema.TypedNode).Representation(), &bindnodeBuf)
bindnodeBytes := bindnodeBuf.Bytes()
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestIpldCompat_DealProposal(t *testing.T) {
nb := basicnode.Prototype.Any.NewBuilder()
assert.Nil(t, dagcbor.Decode(nb, &originalBuf))
node := nb.Build()
dpBindnodeIface, err := bindnodeutils.TypeFromNode(node, &retrievalmarket.DealProposal{})
dpBindnodeIface, err := retrievalmarket.BindnodeRegistry.TypeFromNode(node, &retrievalmarket.DealProposal{})
assert.Nil(t, err)
dpBindnode, ok := dpBindnodeIface.(*retrievalmarket.DealProposal)
assert.True(t, ok)
Expand All @@ -162,7 +161,7 @@ func TestIpldCompat_DealProposal(t *testing.T) {
compareDealProposal(t, testCase.dp, *dpBindnode)

// encode the new DealProposal with bindnode to bytes
node = bindnodeutils.TypeToNode(dpBindnode)
node = retrievalmarket.BindnodeRegistry.TypeToNode(dpBindnode)
var bindnodeBuf bytes.Buffer
dagcbor.Encode(node.(schema.TypedNode).Representation(), &bindnodeBuf)
bindnodeBytes := bindnodeBuf.Bytes()
Expand Down Expand Up @@ -273,7 +272,7 @@ func TestIpldCompat_DealPayment(t *testing.T) {
nb := basicnode.Prototype.Any.NewBuilder()
assert.Nil(t, dagcbor.Decode(nb, &originalBuf))
node := nb.Build()
dpBindnodeIface, err := bindnodeutils.TypeFromNode(node, &retrievalmarket.DealPayment{})
dpBindnodeIface, err := retrievalmarket.BindnodeRegistry.TypeFromNode(node, &retrievalmarket.DealPayment{})
assert.Nil(t, err)
dpBindnode, ok := dpBindnodeIface.(*retrievalmarket.DealPayment)
assert.True(t, ok)
Expand All @@ -282,7 +281,7 @@ func TestIpldCompat_DealPayment(t *testing.T) {
compareDealPayment(t, testCase.dp, *dpBindnode)

// encode the new DealPayment with bindnode to bytes
node = bindnodeutils.TypeToNode(dpBindnode)
node = retrievalmarket.BindnodeRegistry.TypeToNode(dpBindnode)
var bindnodeBuf bytes.Buffer
dagcbor.Encode(node.(schema.TypedNode).Representation(), &bindnodeBuf)
bindnodeBytes := bindnodeBuf.Bytes()
Expand Down
5 changes: 2 additions & 3 deletions retrievalmarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/filecoin-project/go-statemachine"
"github.com/filecoin-project/go-statemachine/fsm"

"github.com/filecoin-project/go-fil-markets/bindnodeutils"
rm "github.com/filecoin-project/go-fil-markets/retrievalmarket"
)

Expand Down Expand Up @@ -138,7 +137,7 @@ func updateFunding(ctx fsm.Context,
DataLimit: deal.Params.NextInterval(totalPaid),
}
if voucherResult != nil {
node := bindnodeutils.TypeToNode(voucherResult)
node := rm.BindnodeRegistry.TypeToNode(voucherResult)
vr.VoucherResult = &datatransfer.TypedVoucher{Voucher: node, Type: rm.DealResponseType}
}
return vr
Expand Down Expand Up @@ -183,7 +182,7 @@ func errorDealResponse(dealID rm.ProviderDealIdentifier, errMsg error) datatrans
Message: errMsg.Error(),
Status: rm.DealStatusErrored,
}
node := bindnodeutils.TypeToNode(&dr)
node := rm.BindnodeRegistry.TypeToNode(&dr)
return datatransfer.ValidationResult{
Accepted: false,
VoucherResult: &datatransfer.TypedVoucher{Voucher: node, Type: rm.DealResponseType},
Expand Down
7 changes: 3 additions & 4 deletions retrievalmarket/impl/providerstates/provider_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
fsmtest "github.com/filecoin-project/go-statemachine/fsm/testutil"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"

"github.com/filecoin-project/go-fil-markets/bindnodeutils"
"github.com/filecoin-project/go-fil-markets/piecestore"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
rm "github.com/filecoin-project/go-fil-markets/retrievalmarket"
Expand Down Expand Up @@ -151,13 +150,13 @@ func TestUnpauseDeal(t *testing.T) {
func TestUpdateFunding(t *testing.T) {
ctx := context.Background()
emptyDealPayment := rm.DealPayment{}
emptyDealPaymentNode := bindnodeutils.TypeToNode(&emptyDealPayment)
emptyDealPaymentNode := rm.BindnodeRegistry.TypeToNode(&emptyDealPayment)
emptyDealPaymentVoucher := datatransfer.TypedVoucher{Voucher: emptyDealPaymentNode, Type: rm.DealPaymentType}
emptyDealProposal := rm.DealProposal{}
emptyDealProposalNode := bindnodeutils.TypeToNode(&emptyDealProposal)
emptyDealProposalNode := rm.BindnodeRegistry.TypeToNode(&emptyDealProposal)
emptyDealProposalVoucher := datatransfer.TypedVoucher{Voucher: emptyDealProposalNode, Type: rm.DealProposalType}
dealResponseVoucher := func(resp rm.DealResponse) *datatransfer.TypedVoucher {
node := bindnodeutils.TypeToNode(&resp)
node := rm.BindnodeRegistry.TypeToNode(&resp)
return &datatransfer.TypedVoucher{Voucher: node, Type: rm.DealResponseType}
}
eventMachine, err := fsm.NewEventProcessor(rm.ProviderDealState{}, "Status", providerstates.ProviderEvents)
Expand Down
7 changes: 3 additions & 4 deletions retrievalmarket/impl/requestvalidation/requestvalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"

"github.com/filecoin-project/go-fil-markets/bindnodeutils"
"github.com/filecoin-project/go-fil-markets/piecestore"
rm "github.com/filecoin-project/go-fil-markets/retrievalmarket"
)
Expand Down Expand Up @@ -70,7 +69,7 @@ func rejectProposal(proposal *rm.DealProposal, status rm.DealStatus, reason stri
Status: status,
Message: reason,
}
node := bindnodeutils.TypeToNode(&dr)
node := rm.BindnodeRegistry.TypeToNode(&dr)
return datatransfer.ValidationResult{
Accepted: false,
VoucherResult: &datatransfer.TypedVoucher{Voucher: node, Type: rm.DealResponseType},
Expand Down Expand Up @@ -153,7 +152,7 @@ func (rv *ProviderRequestValidator) validatePull(receiver peer.ID, proposal *rm.
Status: status,
PaymentOwed: deal.Params.OutstandingBalance(big.Zero(), 0, false),
}
node := bindnodeutils.TypeToNode(&dr)
node := rm.BindnodeRegistry.TypeToNode(&dr)
result := datatransfer.ValidationResult{
Accepted: true,
VoucherResult: &datatransfer.TypedVoucher{Voucher: node, Type: rm.DealResponseType},
Expand Down Expand Up @@ -207,7 +206,7 @@ func errorDealResponse(dealID rm.ProviderDealIdentifier, err error) (datatransfe
Message: err.Error(),
Status: rm.DealStatusErrored,
}
node := bindnodeutils.TypeToNode(&dr)
node := rm.BindnodeRegistry.TypeToNode(&dr)
return datatransfer.ValidationResult{
Accepted: false,
VoucherResult: &datatransfer.TypedVoucher{Voucher: node, Type: rm.DealResponseType},
Expand Down
Loading

0 comments on commit 79bb329

Please sign in to comment.