Skip to content

Commit

Permalink
restore selector type
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Dec 18, 2023
1 parent b316c83 commit 680ae64
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 54 deletions.
7 changes: 4 additions & 3 deletions retrievalmarket/server/gsunpaidretrieval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ type testCase struct {
}

var providerCancelled = errors.New("provider cancelled")
var clientCancelled = errors.New("client cancelled")
var clientRejected = errors.New("client received reject response")

//var clientCancelled = errors.New("client cancelled")
//var clientRejected = errors.New("client received reject response")

func TestGS(t *testing.T) {
//t.Skip("refactor tests to use boost client")
t.Skip("refactor tests to use boost client")
//_ = logging.SetLogLevel("testgs", "debug")
_ = logging.SetLogLevel("testgs", "info")
_ = logging.SetLogLevel("dt-impl", "debug")
Expand Down
26 changes: 11 additions & 15 deletions retrievalmarket/server/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"github.com/filecoin-project/boost/datatransfer"
"github.com/filecoin-project/boost/retrievalmarket/types/legacyretrievaltypes/migrations"

"github.com/filecoin-project/boost/retrievalmarket/types/legacyretrievaltypes"
"github.com/hannahhoward/go-pubsub"
Expand Down Expand Up @@ -61,15 +62,15 @@ func (rv *requestValidator) validatePullRequest(isRestart bool, receiver peer.ID
Response: &response,
Error: err,
})
//if legacyProtocol {
// downgradedResponse := migrations.DealResponse0{
// Status: response.Status,
// ID: response.ID,
// Message: response.Message,
// PaymentOwed: response.PaymentOwed,
// }
// return &downgradedResponse, err
//}
if legacyProtocol {
downgradedResponse := migrations.DealResponse0{
Status: response.Status,
ID: response.ID,
Message: response.Message,
PaymentOwed: response.PaymentOwed,
}
return &downgradedResponse, err
}
return &response, err
}

Expand Down Expand Up @@ -104,12 +105,7 @@ func (rv *requestValidator) acceptDeal(receiver peer.ID, proposal *legacyretriev
}
bytesCompare := allSelectorBytes
if proposal.SelectorSpecified() {
w := new(bytes.Buffer)
err = proposal.Selector.MarshalCBOR(w)
if err != nil {
return err
}
bytesCompare = w.Bytes()
bytesCompare = proposal.Selector.Raw
}
if !bytes.Equal(buf.Bytes(), bytesCompare) {
return errors.New("incorrect selector for this proposal")
Expand Down
5 changes: 2 additions & 3 deletions retrievalmarket/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testutil

import (
"context"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -85,9 +84,9 @@ func NewLibp2pTestData(ctx context.Context, t *testing.T) *Libp2pTestData {
testData.DTStore1 = namespace.Wrap(testData.Ds1, datastore.NewKey("DataTransfer1"))
testData.DTStore2 = namespace.Wrap(testData.Ds1, datastore.NewKey("DataTransfer2"))

testData.DTTmpDir1, err = ioutil.TempDir("", "dt-tmp-1")
testData.DTTmpDir1, err = os.MkdirTemp("", "dt-tmp-1")
require.NoError(t, err)
testData.DTTmpDir2, err = ioutil.TempDir("", "dt-tmp-2")
testData.DTTmpDir2, err = os.MkdirTemp("", "dt-tmp-2")
require.NoError(t, err)
t.Cleanup(func() {
_ = os.RemoveAll(testData.DTTmpDir1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func MigrateQueryResponse0To1(oldQr QueryResponse0) legacyretrievaltypes.QueryRe
// MigrateParams0To1 migrates tuple encoded deal params to map encoded deal params
func MigrateParams0To1(oldParams Params0) legacyretrievaltypes.Params {
return legacyretrievaltypes.Params{
Selector: legacyretrievaltypes.CborGenCompatibleNode{Node: nil},
Selector: oldParams.Selector,
PieceCID: oldParams.PieceCID,
PricePerByte: oldParams.PricePerByte,
PaymentInterval: oldParams.PaymentInterval,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 21 additions & 22 deletions retrievalmarket/types/legacyretrievaltypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
bindnoderegistry "github.com/ipld/go-ipld-prime/node/bindnode/registry"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/net/context"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -266,8 +267,8 @@ func IsTerminalStatus(status DealStatus) bool {

// Params are the parameters requested for a retrieval deal proposal
type Params struct {
Selector CborGenCompatibleNode // V1
//Selector *cbg.Deferred
//Selector CborGenCompatibleNode // V1
Selector *cbg.Deferred
PieceCID *cid.Cid
PricePerByte abi.TokenAmount
PaymentInterval uint64 // when to request payment
Expand All @@ -283,7 +284,7 @@ var paramsBindnodeOptions = []bindnode.Option{
}

func (p Params) SelectorSpecified() bool {
return !p.Selector.IsNull()
return p.Selector != nil && !bytes.Equal(p.Selector.Raw, cbg.CborNull)
}

func (p Params) IntervalLowerBound(currentInterval uint64) uint64 {
Expand Down Expand Up @@ -332,9 +333,7 @@ func NewParamsV1(pricePerByte abi.TokenAmount, paymentInterval uint64, paymentIn
}

return Params{
Selector: CborGenCompatibleNode{
Node: sel,
},
Selector: &cbg.Deferred{Raw: buffer.Bytes()},
PieceCID: pieceCid,
PricePerByte: pricePerByte,
PaymentInterval: paymentInterval,
Expand Down Expand Up @@ -565,19 +564,19 @@ var dealPaymentBindnodeOptions = []bindnode.Option{
TokenAmountBindnodeOption,
}

func init() {
for _, r := range []struct {
typ interface{}
typName string
opts []bindnode.Option
}{
{(*Params)(nil), "Params", paramsBindnodeOptions},
{(*DealProposal)(nil), "DealProposal", dealProposalBindnodeOptions},
{(*DealResponse)(nil), "DealResponse", dealResponseBindnodeOptions},
{(*DealPayment)(nil), "DealPayment", dealPaymentBindnodeOptions},
} {
if err := BindnodeRegistry.RegisterType(r.typ, string(embedSchema), r.typName, r.opts...); err != nil {
panic(err.Error())
}
}
}
//func init() {
// for _, r := range []struct {
// typ interface{}
// typName string
// opts []bindnode.Option
// }{
// {(*Params)(nil), "Params", paramsBindnodeOptions},
// {(*DealProposal)(nil), "DealProposal", dealProposalBindnodeOptions},
// {(*DealResponse)(nil), "DealResponse", dealResponseBindnodeOptions},
// {(*DealPayment)(nil), "DealPayment", dealPaymentBindnodeOptions},
// } {
// if err := BindnodeRegistry.RegisterType(r.typ, string(embedSchema), r.typName, r.opts...); err != nil {
// panic(err.Error())
// }
// }
//}
9 changes: 5 additions & 4 deletions retrievalmarket/types/legacyretrievaltypes/types_cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 680ae64

Please sign in to comment.