diff --git a/retrievalmarket/impl/client.go b/retrievalmarket/impl/client.go index 0e785390..d39b4a8c 100644 --- a/retrievalmarket/impl/client.go +++ b/retrievalmarket/impl/client.go @@ -13,7 +13,6 @@ import ( "github.com/filecoin-project/go-address" datatransfer "github.com/filecoin-project/go-data-transfer" - versioning "github.com/filecoin-project/go-ds-versioning/pkg" versionedfsm "github.com/filecoin-project/go-ds-versioning/pkg/fsm" "github.com/filecoin-project/go-multistore" "github.com/filecoin-project/go-state-types/abi" @@ -99,7 +98,7 @@ func NewClient( StateEntryFuncs: clientstates.ClientStateEntryFuncs, FinalityStates: clientstates.ClientFinalityStates, Notifier: c.notifySubscribers, - }, retrievalMigrations, versioning.VersionKey("1")) + }, retrievalMigrations, "2") if err != nil { return nil, err } diff --git a/retrievalmarket/impl/client_test.go b/retrievalmarket/impl/client_test.go index af5aba35..83259763 100644 --- a/retrievalmarket/impl/client_test.go +++ b/retrievalmarket/impl/client_test.go @@ -410,7 +410,7 @@ func TestMigrations(t *testing.T) { }, }, StoreID: storeIDs[i], - ChannelID: channelIDs[i], + ChannelID: &channelIDs[i], LastPaymentRequested: lastPaymentRequesteds[i], AllBlocksReceived: allBlocksReceiveds[i], TotalFunds: totalFundss[i], diff --git a/retrievalmarket/impl/clientstates/client_fsm.go b/retrievalmarket/impl/clientstates/client_fsm.go index 5d70b271..228f9c73 100644 --- a/retrievalmarket/impl/clientstates/client_fsm.go +++ b/retrievalmarket/impl/clientstates/client_fsm.go @@ -44,7 +44,7 @@ var ClientEvents = fsm.Events{ From(rm.DealStatusNew).To(rm.DealStatusWaitForAcceptance). From(rm.DealStatusRetryLegacy).To(rm.DealStatusWaitForAcceptanceLegacy). Action(func(deal *rm.ClientDealState, channelID datatransfer.ChannelID) error { - deal.ChannelID = channelID + deal.ChannelID = &channelID deal.Message = "" return nil }), diff --git a/retrievalmarket/impl/clientstates/client_states.go b/retrievalmarket/impl/clientstates/client_states.go index 39915d3f..3826f59c 100644 --- a/retrievalmarket/impl/clientstates/client_states.go +++ b/retrievalmarket/impl/clientstates/client_states.go @@ -125,7 +125,7 @@ func SendFunds(ctx fsm.Context, environment ClientDealEnvironment, deal rm.Clien } // send payment voucher (or fail) - err = environment.SendDataTransferVoucher(ctx.Context(), deal.ChannelID, &rm.DealPayment{ + err = environment.SendDataTransferVoucher(ctx.Context(), *deal.ChannelID, &rm.DealPayment{ ID: deal.DealProposal.ID, PaymentChannel: deal.PaymentInfo.PayCh, PaymentVoucher: voucher, @@ -164,10 +164,13 @@ func CheckFunds(ctx fsm.Context, environment ClientDealEnvironment, deal rm.Clie // CancelDeal clears a deal that went wrong for an unknown reason func CancelDeal(ctx fsm.Context, environment ClientDealEnvironment, deal rm.ClientDealState) error { - // Read next response (or fail) - err := environment.CloseDataTransfer(ctx.Context(), deal.ChannelID) - if err != nil { - return ctx.Trigger(rm.ClientEventDataTransferError, err) + // If the data transfer has started, cancel it + if deal.ChannelID != nil { + // Read next response (or fail) + err := environment.CloseDataTransfer(ctx.Context(), *deal.ChannelID) + if err != nil { + return ctx.Trigger(rm.ClientEventDataTransferError, err) + } } return ctx.Trigger(rm.ClientEventCancelComplete) diff --git a/retrievalmarket/impl/clientstates/client_states_test.go b/retrievalmarket/impl/clientstates/client_states_test.go index ccf86128..04a2cc65 100644 --- a/retrievalmarket/impl/clientstates/client_states_test.go +++ b/retrievalmarket/impl/clientstates/client_states_test.go @@ -330,6 +330,11 @@ func TestSendFunds(t *testing.T) { node := testnodes.NewTestRetrievalClientNode(nodeParams) environment := &fakeEnvironment{node, nil, sendDataTransferVoucherError, nil} fsmCtx := fsmtest.NewTestContext(ctx, eventMachine) + dealState.ChannelID = &datatransfer.ChannelID{ + Initiator: "initiator", + Responder: dealState.Sender, + ID: 1, + } err := clientstates.SendFunds(fsmCtx, environment, *dealState) require.NoError(t, err) fsmCtx.ReplayEvents(t, dealState) @@ -526,6 +531,11 @@ func TestCancelDeal(t *testing.T) { node := testnodes.NewTestRetrievalClientNode(testnodes.TestRetrievalClientNodeParams{}) environment := &fakeEnvironment{node, nil, nil, closeError} fsmCtx := fsmtest.NewTestContext(ctx, eventMachine) + dealState.ChannelID = &datatransfer.ChannelID{ + Initiator: "initiator", + Responder: dealState.Sender, + ID: 1, + } err := clientstates.CancelDeal(fsmCtx, environment, *dealState) require.NoError(t, err) fsmCtx.ReplayEvents(t, dealState) diff --git a/retrievalmarket/impl/provider_test.go b/retrievalmarket/impl/provider_test.go index 0ef4cfe6..4ece7013 100644 --- a/retrievalmarket/impl/provider_test.go +++ b/retrievalmarket/impl/provider_test.go @@ -496,7 +496,7 @@ func TestProviderMigrations(t *testing.T) { }, }, StoreID: storeIDs[i], - ChannelID: channelIDs[i], + ChannelID: &channelIDs[i], PieceInfo: &piecestore.PieceInfo{ PieceCID: *pieceCIDs[i], Deals: []piecestore.DealInfo{ diff --git a/retrievalmarket/impl/providerstates/provider_fsm.go b/retrievalmarket/impl/providerstates/provider_fsm.go index a0b0e70d..24db7794 100644 --- a/retrievalmarket/impl/providerstates/provider_fsm.go +++ b/retrievalmarket/impl/providerstates/provider_fsm.go @@ -33,7 +33,7 @@ var ProviderEvents = fsm.Events{ From(rm.DealStatusFundsNeededUnseal).ToNoChange(). From(rm.DealStatusNew).To(rm.DealStatusUnsealing). Action(func(deal *rm.ProviderDealState, channelID datatransfer.ChannelID) error { - deal.ChannelID = channelID + deal.ChannelID = &channelID return nil }), diff --git a/retrievalmarket/impl/providerstates/provider_states.go b/retrievalmarket/impl/providerstates/provider_states.go index 63584e3f..69b5becf 100644 --- a/retrievalmarket/impl/providerstates/provider_states.go +++ b/retrievalmarket/impl/providerstates/provider_states.go @@ -69,9 +69,11 @@ func UnpauseDeal(ctx fsm.Context, environment ProviderDealEnvironment, deal rm.P if err != nil { return ctx.Trigger(rm.ProviderEventDataTransferError, err) } - err = environment.ResumeDataTransfer(ctx.Context(), deal.ChannelID) - if err != nil { - return ctx.Trigger(rm.ProviderEventDataTransferError, err) + if deal.ChannelID != nil { + err = environment.ResumeDataTransfer(ctx.Context(), *deal.ChannelID) + if err != nil { + return ctx.Trigger(rm.ProviderEventDataTransferError, err) + } } return nil } @@ -87,9 +89,11 @@ func CancelDeal(ctx fsm.Context, environment ProviderDealEnvironment, deal rm.Pr if err != nil { return ctx.Trigger(rm.ProviderEventMultiStoreError, err) } - err = environment.CloseDataTransfer(ctx.Context(), deal.ChannelID) - if err != nil && !errors.Is(err, statemachine.ErrTerminated) { - return ctx.Trigger(rm.ProviderEventDataTransferError, err) + if deal.ChannelID != nil { + err = environment.CloseDataTransfer(ctx.Context(), *deal.ChannelID) + if err != nil && !errors.Is(err, statemachine.ErrTerminated) { + return ctx.Trigger(rm.ProviderEventDataTransferError, err) + } } return ctx.Trigger(rm.ProviderEventCancelComplete) } diff --git a/retrievalmarket/impl/providerstates/provider_states_test.go b/retrievalmarket/impl/providerstates/provider_states_test.go index df41a7dc..fe9404b9 100644 --- a/retrievalmarket/impl/providerstates/provider_states_test.go +++ b/retrievalmarket/impl/providerstates/provider_states_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" + datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-statemachine/fsm" @@ -112,6 +113,11 @@ func TestUnpauseDeal(t *testing.T) { environment := rmtesting.NewTestProviderDealEnvironment(node) setupEnv(environment) fsmCtx := fsmtest.NewTestContext(ctx, eventMachine) + dealState.ChannelID = &datatransfer.ChannelID{ + Initiator: "initiator", + Responder: dealState.Receiver, + ID: 1, + } err := providerstates.UnpauseDeal(fsmCtx, environment, *dealState) require.NoError(t, err) node.VerifyExpectations(t) @@ -155,6 +161,11 @@ func TestCancelDeal(t *testing.T) { environment := rmtesting.NewTestProviderDealEnvironment(node) setupEnv(environment) fsmCtx := fsmtest.NewTestContext(ctx, eventMachine) + dealState.ChannelID = &datatransfer.ChannelID{ + Initiator: "initiator", + Responder: dealState.Receiver, + ID: 1, + } err := providerstates.CancelDeal(fsmCtx, environment, *dealState) require.NoError(t, err) node.VerifyExpectations(t) diff --git a/retrievalmarket/impl/requestvalidation/revalidator.go b/retrievalmarket/impl/requestvalidation/revalidator.go index dfebf3f8..e404a8ab 100644 --- a/retrievalmarket/impl/requestvalidation/revalidator.go +++ b/retrievalmarket/impl/requestvalidation/revalidator.go @@ -5,6 +5,8 @@ import ( "errors" "sync" + logging "github.com/ipfs/go-log/v2" + datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -14,6 +16,8 @@ import ( "github.com/filecoin-project/go-fil-markets/retrievalmarket/migrations" ) +var log = logging.Logger("retrieval-revalidator") + // RevalidatorEnvironment are the dependencies needed to // build the logic of revalidation -- essentially, access to the node at statemachines type RevalidatorEnvironment interface { @@ -52,9 +56,15 @@ func NewProviderRevalidator(env RevalidatorEnvironment) *ProviderRevalidator { // a given channel ID with a retrieval deal, so that checks run for data sent // on the channel func (pr *ProviderRevalidator) TrackChannel(deal rm.ProviderDealState) { + // Sanity check + if deal.ChannelID == nil { + log.Errorf("cannot track deal %s: channel ID is nil", deal.ID) + return + } + pr.trackedChannelsLk.Lock() defer pr.trackedChannelsLk.Unlock() - pr.trackedChannels[deal.ChannelID] = &channelData{ + pr.trackedChannels[*deal.ChannelID] = &channelData{ dealID: deal.Identifier(), } pr.writeDealState(deal) @@ -63,9 +73,15 @@ func (pr *ProviderRevalidator) TrackChannel(deal rm.ProviderDealState) { // UntrackChannel indicates a retrieval deal is finish and no longer is tracked // by this provider func (pr *ProviderRevalidator) UntrackChannel(deal rm.ProviderDealState) { + // Sanity check + if deal.ChannelID == nil { + log.Errorf("cannot untrack deal %s: channel ID is nil", deal.ID) + return + } + pr.trackedChannelsLk.Lock() defer pr.trackedChannelsLk.Unlock() - delete(pr.trackedChannels, deal.ChannelID) + delete(pr.trackedChannels, *deal.ChannelID) } func (pr *ProviderRevalidator) loadDealState(channel *channelData) error { @@ -82,7 +98,7 @@ func (pr *ProviderRevalidator) loadDealState(channel *channelData) error { } func (pr *ProviderRevalidator) writeDealState(deal rm.ProviderDealState) { - channel := pr.trackedChannels[deal.ChannelID] + channel := pr.trackedChannels[*deal.ChannelID] channel.totalSent = deal.TotalSent if !deal.PricePerByte.IsZero() { channel.totalPaidFor = big.Div(big.Max(big.Sub(deal.FundsReceived, deal.UnsealPrice), big.Zero()), deal.PricePerByte).Uint64() diff --git a/retrievalmarket/impl/requestvalidation/revalidator_test.go b/retrievalmarket/impl/requestvalidation/revalidator_test.go index 21a5feda..36492810 100644 --- a/retrievalmarket/impl/requestvalidation/revalidator_test.go +++ b/retrievalmarket/impl/requestvalidation/revalidator_test.go @@ -55,7 +55,7 @@ func TestOnPullDataSent(t *testing.T) { }, "record block": { deal: deal, - channelID: deal.ChannelID, + channelID: *deal.ChannelID, expectedID: deal.Identifier(), expectedEvent: rm.ProviderEventBlockSent, expectedArgs: []interface{}{deal.TotalSent + uint64(500)}, @@ -64,7 +64,7 @@ func TestOnPullDataSent(t *testing.T) { }, "record block zero price per byte": { deal: dealZeroPricePerByte, - channelID: dealZeroPricePerByte.ChannelID, + channelID: *dealZeroPricePerByte.ChannelID, expectedID: dealZeroPricePerByte.Identifier(), expectedEvent: rm.ProviderEventBlockSent, expectedArgs: []interface{}{dealZeroPricePerByte.TotalSent + uint64(500)}, @@ -73,7 +73,7 @@ func TestOnPullDataSent(t *testing.T) { }, "request payment": { deal: deal, - channelID: deal.ChannelID, + channelID: *deal.ChannelID, expectedID: deal.Identifier(), expectedEvent: rm.ProviderEventPaymentRequested, expectedArgs: []interface{}{deal.TotalSent + defaultCurrentInterval}, @@ -88,7 +88,7 @@ func TestOnPullDataSent(t *testing.T) { }, "request payment, legacy": { deal: legacyDeal, - channelID: legacyDeal.ChannelID, + channelID: *legacyDeal.ChannelID, expectedID: legacyDeal.Identifier(), expectedEvent: rm.ProviderEventPaymentRequested, expectedArgs: []interface{}{legacyDeal.TotalSent + defaultCurrentInterval}, @@ -140,7 +140,7 @@ func TestOnComplete(t *testing.T) { dealZeroPricePerByte.PricePerByte = big.Zero() legacyDeal := deal legacyDeal.LegacyProtocol = true - channelID := deal.ChannelID + channelID := *deal.ChannelID testCases := map[string]struct { expectedEvents []eventSent deal rm.ProviderDealState @@ -296,6 +296,7 @@ func TestRevalidate(t *testing.T) { deal := *makeDealState(rm.DealStatusFundsNeeded) deal.TotalSent = defaultTotalSent + defaultCurrentInterval + channelID := *deal.ChannelID smallerPayment := abi.NewTokenAmount(400000) payment := &retrievalmarket.DealPayment{ ID: deal.ID, @@ -329,7 +330,7 @@ func TestRevalidate(t *testing.T) { }, "not a payment voucher": { deal: deal, - channelID: deal.ChannelID, + channelID: channelID, noSend: true, expectedError: errors.New("wrong voucher type"), }, @@ -338,7 +339,7 @@ func TestRevalidate(t *testing.T) { tn.ChainHeadError = errors.New("something went wrong") }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: payment, expectedError: errors.New("something went wrong"), expectedID: deal.Identifier(), @@ -355,7 +356,7 @@ func TestRevalidate(t *testing.T) { tn.ChainHeadError = errors.New("something went wrong") }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: legacyPayment, expectedError: errors.New("something went wrong"), expectedID: deal.Identifier(), @@ -372,7 +373,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, abi.NewTokenAmount(0), errors.New("your money's no good here")) }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: payment, expectedError: errors.New("your money's no good here"), expectedID: deal.Identifier(), @@ -389,7 +390,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, abi.NewTokenAmount(0), errors.New("your money's no good here")) }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: legacyPayment, expectedError: errors.New("your money's no good here"), expectedID: deal.Identifier(), @@ -406,7 +407,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, smallerPayment, nil) }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: payment, expectedError: datatransfer.ErrPause, expectedID: deal.Identifier(), @@ -423,7 +424,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, smallerPayment, nil) }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: legacyPayment, expectedError: datatransfer.ErrPause, expectedID: deal.Identifier(), @@ -440,7 +441,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, defaultPaymentPerInterval, nil) }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: payment, expectedID: deal.Identifier(), expectedEvent: rm.ProviderEventPaymentReceived, @@ -452,7 +453,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, defaultPaymentPerInterval, nil) }, deal: lastPaymentDeal, - channelID: deal.ChannelID, + channelID: channelID, voucher: payment, expectedID: deal.Identifier(), expectedEvent: rm.ProviderEventPaymentReceived, @@ -467,7 +468,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, defaultPaymentPerInterval, nil) }, deal: lastPaymentDeal, - channelID: deal.ChannelID, + channelID: channelID, voucher: legacyPayment, expectedID: deal.Identifier(), expectedEvent: rm.ProviderEventPaymentReceived, @@ -482,7 +483,7 @@ func TestRevalidate(t *testing.T) { _ = tn.ExpectVoucher(payCh, voucher, nil, defaultPaymentPerInterval, big.Zero(), nil) }, deal: deal, - channelID: deal.ChannelID, + channelID: channelID, voucher: payment, expectedID: deal.Identifier(), expectedEvent: rm.ProviderEventPaymentReceived, @@ -565,7 +566,7 @@ func makeDealState(status retrievalmarket.DealStatus) *retrievalmarket.ProviderD TotalSent: defaultTotalSent, CurrentInterval: defaultCurrentInterval, FundsReceived: defaultFundsReceived, - ChannelID: channelID, + ChannelID: &channelID, Receiver: channelID.Initiator, DealProposal: retrievalmarket.DealProposal{ ID: dealID, diff --git a/retrievalmarket/migrations/maptypes/maptypes.go b/retrievalmarket/migrations/maptypes/maptypes.go new file mode 100644 index 00000000..ab87833f --- /dev/null +++ b/retrievalmarket/migrations/maptypes/maptypes.go @@ -0,0 +1,56 @@ +package maptypes + +import ( + "github.com/ipfs/go-cid" + "github.com/libp2p/go-libp2p-core/peer" + + "github.com/filecoin-project/go-address" + datatransfer "github.com/filecoin-project/go-data-transfer" + "github.com/filecoin-project/go-multistore" + "github.com/filecoin-project/go-state-types/abi" + + "github.com/filecoin-project/go-fil-markets/piecestore" + "github.com/filecoin-project/go-fil-markets/retrievalmarket" +) + +//go:generate cbor-gen-for --map-encoding ClientDealState1 ProviderDealState1 + +// Version 1 of the ClientDealState +type ClientDealState1 struct { + retrievalmarket.DealProposal + StoreID *multistore.StoreID + ChannelID datatransfer.ChannelID + LastPaymentRequested bool + AllBlocksReceived bool + TotalFunds abi.TokenAmount + ClientWallet address.Address + MinerWallet address.Address + PaymentInfo *retrievalmarket.PaymentInfo + Status retrievalmarket.DealStatus + Sender peer.ID + TotalReceived uint64 + Message string + BytesPaidFor uint64 + CurrentInterval uint64 + PaymentRequested abi.TokenAmount + FundsSpent abi.TokenAmount + UnsealFundsPaid abi.TokenAmount + WaitMsgCID *cid.Cid + VoucherShortfall abi.TokenAmount + LegacyProtocol bool +} + +// Version 1 of the ProviderDealState +type ProviderDealState1 struct { + retrievalmarket.DealProposal + StoreID multistore.StoreID + ChannelID datatransfer.ChannelID + PieceInfo *piecestore.PieceInfo + Status retrievalmarket.DealStatus + Receiver peer.ID + TotalSent uint64 + FundsReceived abi.TokenAmount + Message string + CurrentInterval uint64 + LegacyProtocol bool +} diff --git a/retrievalmarket/migrations/maptypes/maptypes_cbor_gen.go b/retrievalmarket/migrations/maptypes/maptypes_cbor_gen.go new file mode 100644 index 00000000..56089573 --- /dev/null +++ b/retrievalmarket/migrations/maptypes/maptypes_cbor_gen.go @@ -0,0 +1,1122 @@ +// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. + +package maptypes + +import ( + "fmt" + "io" + + piecestore "github.com/filecoin-project/go-fil-markets/piecestore" + retrievalmarket "github.com/filecoin-project/go-fil-markets/retrievalmarket" + multistore "github.com/filecoin-project/go-multistore" + peer "github.com/libp2p/go-libp2p-core/peer" + cbg "github.com/whyrusleeping/cbor-gen" + xerrors "golang.org/x/xerrors" +) + +var _ = xerrors.Errorf + +func (t *ClientDealState1) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write([]byte{181}); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.DealProposal (retrievalmarket.DealProposal) (struct) + if len("DealProposal") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"DealProposal\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealProposal"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("DealProposal")); err != nil { + return err + } + + if err := t.DealProposal.MarshalCBOR(w); err != nil { + return err + } + + // t.StoreID (multistore.StoreID) (uint64) + if len("StoreID") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"StoreID\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("StoreID"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("StoreID")); err != nil { + return err + } + + if t.StoreID == nil { + if _, err := w.Write(cbg.CborNull); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(*t.StoreID)); err != nil { + return err + } + } + + // t.ChannelID (datatransfer.ChannelID) (struct) + if len("ChannelID") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"ChannelID\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ChannelID"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("ChannelID")); err != nil { + return err + } + + if err := t.ChannelID.MarshalCBOR(w); err != nil { + return err + } + + // t.LastPaymentRequested (bool) (bool) + if len("LastPaymentRequested") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"LastPaymentRequested\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("LastPaymentRequested"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("LastPaymentRequested")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.LastPaymentRequested); err != nil { + return err + } + + // t.AllBlocksReceived (bool) (bool) + if len("AllBlocksReceived") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"AllBlocksReceived\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("AllBlocksReceived"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("AllBlocksReceived")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.AllBlocksReceived); err != nil { + return err + } + + // t.TotalFunds (big.Int) (struct) + if len("TotalFunds") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"TotalFunds\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TotalFunds"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("TotalFunds")); err != nil { + return err + } + + if err := t.TotalFunds.MarshalCBOR(w); err != nil { + return err + } + + // t.ClientWallet (address.Address) (struct) + if len("ClientWallet") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"ClientWallet\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ClientWallet"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("ClientWallet")); err != nil { + return err + } + + if err := t.ClientWallet.MarshalCBOR(w); err != nil { + return err + } + + // t.MinerWallet (address.Address) (struct) + if len("MinerWallet") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"MinerWallet\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("MinerWallet"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("MinerWallet")); err != nil { + return err + } + + if err := t.MinerWallet.MarshalCBOR(w); err != nil { + return err + } + + // t.PaymentInfo (retrievalmarket.PaymentInfo) (struct) + if len("PaymentInfo") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PaymentInfo\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PaymentInfo"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PaymentInfo")); err != nil { + return err + } + + if err := t.PaymentInfo.MarshalCBOR(w); err != nil { + return err + } + + // t.Status (retrievalmarket.DealStatus) (uint64) + if len("Status") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Status\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Status"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Status")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { + return err + } + + // t.Sender (peer.ID) (string) + if len("Sender") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Sender\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Sender"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Sender")); err != nil { + return err + } + + if len(t.Sender) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Sender was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Sender))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Sender)); err != nil { + return err + } + + // t.TotalReceived (uint64) (uint64) + if len("TotalReceived") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"TotalReceived\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TotalReceived"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("TotalReceived")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TotalReceived)); err != nil { + return err + } + + // t.Message (string) (string) + if len("Message") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Message\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Message"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Message")); err != nil { + return err + } + + if len(t.Message) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Message was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Message))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Message)); err != nil { + return err + } + + // t.BytesPaidFor (uint64) (uint64) + if len("BytesPaidFor") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"BytesPaidFor\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("BytesPaidFor"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("BytesPaidFor")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.BytesPaidFor)); err != nil { + return err + } + + // t.CurrentInterval (uint64) (uint64) + if len("CurrentInterval") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"CurrentInterval\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CurrentInterval"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("CurrentInterval")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.CurrentInterval)); err != nil { + return err + } + + // t.PaymentRequested (big.Int) (struct) + if len("PaymentRequested") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PaymentRequested\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PaymentRequested"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PaymentRequested")); err != nil { + return err + } + + if err := t.PaymentRequested.MarshalCBOR(w); err != nil { + return err + } + + // t.FundsSpent (big.Int) (struct) + if len("FundsSpent") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"FundsSpent\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("FundsSpent"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("FundsSpent")); err != nil { + return err + } + + if err := t.FundsSpent.MarshalCBOR(w); err != nil { + return err + } + + // t.UnsealFundsPaid (big.Int) (struct) + if len("UnsealFundsPaid") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"UnsealFundsPaid\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("UnsealFundsPaid"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("UnsealFundsPaid")); err != nil { + return err + } + + if err := t.UnsealFundsPaid.MarshalCBOR(w); err != nil { + return err + } + + // t.WaitMsgCID (cid.Cid) (struct) + if len("WaitMsgCID") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"WaitMsgCID\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("WaitMsgCID"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("WaitMsgCID")); err != nil { + return err + } + + if t.WaitMsgCID == nil { + if _, err := w.Write(cbg.CborNull); err != nil { + return err + } + } else { + if err := cbg.WriteCidBuf(scratch, w, *t.WaitMsgCID); err != nil { + return xerrors.Errorf("failed to write cid field t.WaitMsgCID: %w", err) + } + } + + // t.VoucherShortfall (big.Int) (struct) + if len("VoucherShortfall") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"VoucherShortfall\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("VoucherShortfall"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("VoucherShortfall")); err != nil { + return err + } + + if err := t.VoucherShortfall.MarshalCBOR(w); err != nil { + return err + } + + // t.LegacyProtocol (bool) (bool) + if len("LegacyProtocol") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"LegacyProtocol\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("LegacyProtocol"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("LegacyProtocol")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.LegacyProtocol); err != nil { + return err + } + return nil +} + +func (t *ClientDealState1) UnmarshalCBOR(r io.Reader) error { + *t = ClientDealState1{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("ClientDealState1: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.DealProposal (retrievalmarket.DealProposal) (struct) + case "DealProposal": + + { + + if err := t.DealProposal.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.DealProposal: %w", err) + } + + } + // t.StoreID (multistore.StoreID) (uint64) + case "StoreID": + + { + + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + typed := multistore.StoreID(extra) + t.StoreID = &typed + } + + } + // t.ChannelID (datatransfer.ChannelID) (struct) + case "ChannelID": + + { + + if err := t.ChannelID.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.ChannelID: %w", err) + } + + } + // t.LastPaymentRequested (bool) (bool) + case "LastPaymentRequested": + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.LastPaymentRequested = false + case 21: + t.LastPaymentRequested = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + // t.AllBlocksReceived (bool) (bool) + case "AllBlocksReceived": + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.AllBlocksReceived = false + case 21: + t.AllBlocksReceived = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + // t.TotalFunds (big.Int) (struct) + case "TotalFunds": + + { + + if err := t.TotalFunds.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.TotalFunds: %w", err) + } + + } + // t.ClientWallet (address.Address) (struct) + case "ClientWallet": + + { + + if err := t.ClientWallet.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.ClientWallet: %w", err) + } + + } + // t.MinerWallet (address.Address) (struct) + case "MinerWallet": + + { + + if err := t.MinerWallet.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.MinerWallet: %w", err) + } + + } + // t.PaymentInfo (retrievalmarket.PaymentInfo) (struct) + case "PaymentInfo": + + { + + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + t.PaymentInfo = new(retrievalmarket.PaymentInfo) + if err := t.PaymentInfo.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.PaymentInfo pointer: %w", err) + } + } + + } + // t.Status (retrievalmarket.DealStatus) (uint64) + case "Status": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.Status = retrievalmarket.DealStatus(extra) + + } + // t.Sender (peer.ID) (string) + case "Sender": + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + t.Sender = peer.ID(sval) + } + // t.TotalReceived (uint64) (uint64) + case "TotalReceived": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.TotalReceived = uint64(extra) + + } + // t.Message (string) (string) + case "Message": + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + t.Message = string(sval) + } + // t.BytesPaidFor (uint64) (uint64) + case "BytesPaidFor": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.BytesPaidFor = uint64(extra) + + } + // t.CurrentInterval (uint64) (uint64) + case "CurrentInterval": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.CurrentInterval = uint64(extra) + + } + // t.PaymentRequested (big.Int) (struct) + case "PaymentRequested": + + { + + if err := t.PaymentRequested.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.PaymentRequested: %w", err) + } + + } + // t.FundsSpent (big.Int) (struct) + case "FundsSpent": + + { + + if err := t.FundsSpent.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.FundsSpent: %w", err) + } + + } + // t.UnsealFundsPaid (big.Int) (struct) + case "UnsealFundsPaid": + + { + + if err := t.UnsealFundsPaid.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.UnsealFundsPaid: %w", err) + } + + } + // t.WaitMsgCID (cid.Cid) (struct) + case "WaitMsgCID": + + { + + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.WaitMsgCID: %w", err) + } + + t.WaitMsgCID = &c + } + + } + // t.VoucherShortfall (big.Int) (struct) + case "VoucherShortfall": + + { + + if err := t.VoucherShortfall.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.VoucherShortfall: %w", err) + } + + } + // t.LegacyProtocol (bool) (bool) + case "LegacyProtocol": + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.LegacyProtocol = false + case 21: + t.LegacyProtocol = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + + default: + return fmt.Errorf("unknown struct field %d: '%s'", i, name) + } + } + + return nil +} +func (t *ProviderDealState1) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write([]byte{171}); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.DealProposal (retrievalmarket.DealProposal) (struct) + if len("DealProposal") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"DealProposal\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealProposal"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("DealProposal")); err != nil { + return err + } + + if err := t.DealProposal.MarshalCBOR(w); err != nil { + return err + } + + // t.StoreID (multistore.StoreID) (uint64) + if len("StoreID") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"StoreID\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("StoreID"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("StoreID")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.StoreID)); err != nil { + return err + } + + // t.ChannelID (datatransfer.ChannelID) (struct) + if len("ChannelID") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"ChannelID\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ChannelID"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("ChannelID")); err != nil { + return err + } + + if err := t.ChannelID.MarshalCBOR(w); err != nil { + return err + } + + // t.PieceInfo (piecestore.PieceInfo) (struct) + if len("PieceInfo") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PieceInfo\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PieceInfo"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PieceInfo")); err != nil { + return err + } + + if err := t.PieceInfo.MarshalCBOR(w); err != nil { + return err + } + + // t.Status (retrievalmarket.DealStatus) (uint64) + if len("Status") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Status\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Status"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Status")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { + return err + } + + // t.Receiver (peer.ID) (string) + if len("Receiver") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Receiver\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Receiver"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Receiver")); err != nil { + return err + } + + if len(t.Receiver) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Receiver was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Receiver))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Receiver)); err != nil { + return err + } + + // t.TotalSent (uint64) (uint64) + if len("TotalSent") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"TotalSent\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TotalSent"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("TotalSent")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TotalSent)); err != nil { + return err + } + + // t.FundsReceived (big.Int) (struct) + if len("FundsReceived") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"FundsReceived\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("FundsReceived"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("FundsReceived")); err != nil { + return err + } + + if err := t.FundsReceived.MarshalCBOR(w); err != nil { + return err + } + + // t.Message (string) (string) + if len("Message") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Message\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Message"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Message")); err != nil { + return err + } + + if len(t.Message) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Message was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Message))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Message)); err != nil { + return err + } + + // t.CurrentInterval (uint64) (uint64) + if len("CurrentInterval") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"CurrentInterval\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CurrentInterval"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("CurrentInterval")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.CurrentInterval)); err != nil { + return err + } + + // t.LegacyProtocol (bool) (bool) + if len("LegacyProtocol") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"LegacyProtocol\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("LegacyProtocol"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("LegacyProtocol")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.LegacyProtocol); err != nil { + return err + } + return nil +} + +func (t *ProviderDealState1) UnmarshalCBOR(r io.Reader) error { + *t = ProviderDealState1{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("ProviderDealState1: map struct too large (%d)", extra) + } + + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.DealProposal (retrievalmarket.DealProposal) (struct) + case "DealProposal": + + { + + if err := t.DealProposal.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.DealProposal: %w", err) + } + + } + // t.StoreID (multistore.StoreID) (uint64) + case "StoreID": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.StoreID = multistore.StoreID(extra) + + } + // t.ChannelID (datatransfer.ChannelID) (struct) + case "ChannelID": + + { + + if err := t.ChannelID.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.ChannelID: %w", err) + } + + } + // t.PieceInfo (piecestore.PieceInfo) (struct) + case "PieceInfo": + + { + + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + t.PieceInfo = new(piecestore.PieceInfo) + if err := t.PieceInfo.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.PieceInfo pointer: %w", err) + } + } + + } + // t.Status (retrievalmarket.DealStatus) (uint64) + case "Status": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.Status = retrievalmarket.DealStatus(extra) + + } + // t.Receiver (peer.ID) (string) + case "Receiver": + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + t.Receiver = peer.ID(sval) + } + // t.TotalSent (uint64) (uint64) + case "TotalSent": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.TotalSent = uint64(extra) + + } + // t.FundsReceived (big.Int) (struct) + case "FundsReceived": + + { + + if err := t.FundsReceived.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.FundsReceived: %w", err) + } + + } + // t.Message (string) (string) + case "Message": + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + t.Message = string(sval) + } + // t.CurrentInterval (uint64) (uint64) + case "CurrentInterval": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.CurrentInterval = uint64(extra) + + } + // t.LegacyProtocol (bool) (bool) + case "LegacyProtocol": + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.LegacyProtocol = false + case 21: + t.LegacyProtocol = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + + default: + return fmt.Errorf("unknown struct field %d: '%s'", i, name) + } + } + + return nil +} diff --git a/retrievalmarket/migrations/migrations.go b/retrievalmarket/migrations/migrations.go index 53e1c8b7..c5838386 100644 --- a/retrievalmarket/migrations/migrations.go +++ b/retrievalmarket/migrations/migrations.go @@ -16,6 +16,7 @@ import ( "github.com/filecoin-project/go-fil-markets/piecestore" piecemigrations "github.com/filecoin-project/go-fil-markets/piecestore/migrations" "github.com/filecoin-project/go-fil-markets/retrievalmarket" + "github.com/filecoin-project/go-fil-markets/retrievalmarket/migrations/maptypes" ) //go:generate cbor-gen-for Query0 QueryResponse0 DealProposal0 DealResponse0 Params0 QueryParams0 DealPayment0 ClientDealState0 ProviderDealState0 PaymentInfo0 RetrievalPeer0 Ask0 @@ -247,8 +248,8 @@ func MigratePaymentInfo0To1(oldPi *PaymentInfo0) *retrievalmarket.PaymentInfo { } // MigrateClientDealState0To1 migrates a tuple encoded deal state to a map encoded deal state -func MigrateClientDealState0To1(oldDs *ClientDealState0) (*retrievalmarket.ClientDealState, error) { - return &retrievalmarket.ClientDealState{ +func MigrateClientDealState0To1(oldDs *ClientDealState0) (*maptypes.ClientDealState1, error) { + return &maptypes.ClientDealState1{ DealProposal: MigrateDealProposal0To1(oldDs.DealProposal0), StoreID: oldDs.StoreID, ChannelID: oldDs.ChannelID, @@ -273,8 +274,42 @@ func MigrateClientDealState0To1(oldDs *ClientDealState0) (*retrievalmarket.Clien }, nil } +// MigrateClientDealState1To2 migrates from v1 to v2 of a ClientDealState. +// The difference is that in v2 the ChannelID is a pointer, because the +// ChannelID is not set until the data transfer has started, so it should +// initially be nil. +func MigrateClientDealState1To2(oldDs *maptypes.ClientDealState1) (*retrievalmarket.ClientDealState, error) { + var chid *datatransfer.ChannelID + if oldDs.ChannelID.Initiator != "" && oldDs.ChannelID.Responder != "" { + chid = &oldDs.ChannelID + } + return &retrievalmarket.ClientDealState{ + DealProposal: oldDs.DealProposal, + StoreID: oldDs.StoreID, + ChannelID: chid, + LastPaymentRequested: oldDs.LastPaymentRequested, + AllBlocksReceived: oldDs.AllBlocksReceived, + TotalFunds: oldDs.TotalFunds, + ClientWallet: oldDs.ClientWallet, + MinerWallet: oldDs.MinerWallet, + PaymentInfo: oldDs.PaymentInfo, + Status: oldDs.Status, + Sender: oldDs.Sender, + TotalReceived: oldDs.TotalReceived, + Message: oldDs.Message, + BytesPaidFor: oldDs.BytesPaidFor, + CurrentInterval: oldDs.CurrentInterval, + PaymentRequested: oldDs.PaymentRequested, + FundsSpent: oldDs.FundsSpent, + UnsealFundsPaid: oldDs.UnsealFundsPaid, + WaitMsgCID: oldDs.WaitMsgCID, + VoucherShortfall: oldDs.VoucherShortfall, + LegacyProtocol: true, + }, nil +} + // MigrateProviderDealState0To1 migrates a tuple encoded deal state to a map encoded deal state -func MigrateProviderDealState0To1(oldDs *ProviderDealState0) (*retrievalmarket.ProviderDealState, error) { +func MigrateProviderDealState0To1(oldDs *ProviderDealState0) (*maptypes.ProviderDealState1, error) { var pieceInfo *piecestore.PieceInfo var err error if oldDs.PieceInfo != nil { @@ -283,7 +318,7 @@ func MigrateProviderDealState0To1(oldDs *ProviderDealState0) (*retrievalmarket.P return nil, err } } - return &retrievalmarket.ProviderDealState{ + return &maptypes.ProviderDealState1{ DealProposal: MigrateDealProposal0To1(oldDs.DealProposal0), StoreID: oldDs.StoreID, ChannelID: oldDs.ChannelID, @@ -298,6 +333,31 @@ func MigrateProviderDealState0To1(oldDs *ProviderDealState0) (*retrievalmarket.P }, nil } +// MigrateProviderDealState0To1 migrates from v1 to v2 of a +// MigrateProviderDealState. +// The difference is that in v2 the ChannelID is a pointer, because the +// ChannelID is not set until the data transfer has started, so it should +// initially be nil. +func MigrateProviderDealState1To2(oldDs *maptypes.ProviderDealState1) (*retrievalmarket.ProviderDealState, error) { + var chid *datatransfer.ChannelID + if oldDs.ChannelID.Initiator != "" && oldDs.ChannelID.Responder != "" { + chid = &oldDs.ChannelID + } + return &retrievalmarket.ProviderDealState{ + DealProposal: oldDs.DealProposal, + StoreID: oldDs.StoreID, + ChannelID: chid, + PieceInfo: oldDs.PieceInfo, + Status: oldDs.Status, + Receiver: oldDs.Receiver, + TotalSent: oldDs.TotalSent, + FundsReceived: oldDs.FundsReceived, + Message: oldDs.Message, + CurrentInterval: oldDs.CurrentInterval, + LegacyProtocol: oldDs.LegacyProtocol, + }, nil +} + // MigrateAsk0To1 migrates a tuple encoded deal state to a map encoded deal state func MigrateAsk0To1(oldAsk *Ask0) (*retrievalmarket.Ask, error) { return &retrievalmarket.Ask{ @@ -310,13 +370,15 @@ func MigrateAsk0To1(oldAsk *Ask0) (*retrievalmarket.Ask, error) { // ClientMigrations are migrations for the client's store of retrieval deals var ClientMigrations = versioned.BuilderList{ - versioned.NewVersionedBuilder(MigrateClientDealState0To1, versioning.VersionKey("1")), + versioned.NewVersionedBuilder(MigrateClientDealState0To1, "1"), + versioned.NewVersionedBuilder(MigrateClientDealState1To2, "2").OldVersion("1"), } // ProviderMigrations are migrations for the providers's store of retrieval deals var ProviderMigrations = versioned.BuilderList{ - versioned.NewVersionedBuilder(MigrateProviderDealState0To1, versioning.VersionKey("1")). + versioned.NewVersionedBuilder(MigrateProviderDealState0To1, "1"). FilterKeys([]string{"/retrieval-ask", "/retrieval-ask/latest", "/retrieval-ask/1/latest", "/retrieval-ask/versions/current"}), + versioned.NewVersionedBuilder(MigrateProviderDealState1To2, "2").OldVersion("1"), } // AskMigrations are migrations for the providers's retrieval ask diff --git a/retrievalmarket/migrations/migrations_test.go b/retrievalmarket/migrations/migrations_test.go new file mode 100644 index 00000000..854e5200 --- /dev/null +++ b/retrievalmarket/migrations/migrations_test.go @@ -0,0 +1,287 @@ +package migrations + +import ( + "context" + "io" + "testing" + + "github.com/ipfs/go-cid" + "github.com/ipfs/go-datastore" + dss "github.com/ipfs/go-datastore/sync" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/stretchr/testify/require" + + datatransfer "github.com/filecoin-project/go-data-transfer" + versionedfsm "github.com/filecoin-project/go-ds-versioning/pkg/fsm" + "github.com/filecoin-project/go-multistore" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-statemachine/fsm" + tutils "github.com/filecoin-project/specs-actors/v2/support/testing" + + "github.com/filecoin-project/go-fil-markets/piecestore/migrations" + "github.com/filecoin-project/go-fil-markets/retrievalmarket" + "github.com/filecoin-project/go-fil-markets/retrievalmarket/impl/clientstates" + "github.com/filecoin-project/go-fil-markets/retrievalmarket/impl/providerstates" +) + +func TestClientStateMigration(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Create a v0 client deal state + dealID := retrievalmarket.DealID(1) + storeID := multistore.StoreID(1) + dummyCid, err := cid.Parse("bafkqaaa") + require.NoError(t, err) + dealState := ClientDealState0{ + DealProposal0: DealProposal0{ + PayloadCID: dummyCid, + ID: dealID, + Params0: Params0{ + PieceCID: &dummyCid, + PricePerByte: abi.NewTokenAmount(0), + UnsealPrice: abi.NewTokenAmount(0), + }, + }, + TotalFunds: abi.NewTokenAmount(0), + ClientWallet: tutils.NewActorAddr(t, "client"), + MinerWallet: tutils.NewActorAddr(t, "miner"), + TotalReceived: 0, + CurrentInterval: 10, + BytesPaidFor: 0, + PaymentRequested: abi.NewTokenAmount(0), + FundsSpent: abi.NewTokenAmount(0), + Status: retrievalmarket.DealStatusNew, + Sender: peer.ID("sender"), + UnsealFundsPaid: big.Zero(), + StoreID: &storeID, + } + dealStateWithChannelID := dealState + chid := datatransfer.ChannelID{ + Initiator: "initiator", + Responder: "responder", + ID: 1, + } + dealStateWithChannelID.ChannelID = chid + + testCases := []struct { + name string + dealState0 *ClientDealState0 + expChannelID *datatransfer.ChannelID + }{{ + name: "from v0 - v2 with channel ID", + dealState0: &dealState, + expChannelID: nil, + }, { + name: "from v0 - v2 with no channel ID", + dealState0: &dealStateWithChannelID, + expChannelID: &chid, + }} + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + ds := dss.MutexWrap(datastore.NewMapDatastore()) + + // Store the v0 client deal state to the datastore + stateMachines0, err := fsm.New(ds, fsm.Parameters{ + Environment: &mockClientEnv{}, + StateType: ClientDealState0{}, + StateKeyField: "Status", + Events: fsm.Events{}, + StateEntryFuncs: fsm.StateEntryFuncs{}, + FinalityStates: []fsm.StateKey{}, + }) + require.NoError(t, err) + + err = stateMachines0.Begin(dealID, tc.dealState0) + require.NoError(t, err) + + // Prepare to run migration to v2 datastore + retrievalMigrations, err := ClientMigrations.Build() + require.NoError(t, err) + + stateMachines, migrateStateMachines, err := versionedfsm.NewVersionedFSM(ds, fsm.Parameters{ + Environment: &mockClientEnv{}, + StateType: retrievalmarket.ClientDealState{}, + StateKeyField: "Status", + Events: clientstates.ClientEvents, + StateEntryFuncs: clientstates.ClientStateEntryFuncs, + FinalityStates: clientstates.ClientFinalityStates, + }, retrievalMigrations, "2") + require.NoError(t, err) + + // Run migration to v2 datastore + err = migrateStateMachines(ctx) + require.NoError(t, err) + + var states []retrievalmarket.ClientDealState + err = stateMachines.List(&states) + require.NoError(t, err) + + require.Len(t, states, 1) + if tc.expChannelID == nil { + // Ensure that the channel ID is nil if it was not explicitly defined + require.Nil(t, states[0].ChannelID) + } else { + // Ensure that the channel ID is correct if it was defined + require.Equal(t, chid, *states[0].ChannelID) + } + }) + } +} + +func TestProviderStateMigration(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Create a v0 provider deal state + dealID := retrievalmarket.DealID(1) + storeID := multistore.StoreID(1) + dummyCid, err := cid.Parse("bafkqaaa") + require.NoError(t, err) + dealState := ProviderDealState0{ + DealProposal0: DealProposal0{ + PayloadCID: dummyCid, + ID: dealID, + Params0: Params0{ + PieceCID: &dummyCid, + PricePerByte: abi.NewTokenAmount(0), + UnsealPrice: abi.NewTokenAmount(0), + }, + }, + StoreID: storeID, + PieceInfo: &migrations.PieceInfo0{ + PieceCID: dummyCid, + Deals: nil, + }, + Status: retrievalmarket.DealStatusNew, + Receiver: peer.ID("receiver"), + TotalSent: 0, + FundsReceived: abi.NewTokenAmount(0), + Message: "hello", + CurrentInterval: 10, + } + dealStateWithChannelID := dealState + chid := datatransfer.ChannelID{ + Initiator: "initiator", + Responder: "responder", + ID: 1, + } + dealStateWithChannelID.ChannelID = chid + + testCases := []struct { + name string + dealState0 *ProviderDealState0 + expChannelID *datatransfer.ChannelID + }{{ + name: "from v0 - v2 with channel ID", + dealState0: &dealState, + expChannelID: nil, + }, { + name: "from v0 - v2 with no channel ID", + dealState0: &dealStateWithChannelID, + expChannelID: &chid, + }} + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + ds := dss.MutexWrap(datastore.NewMapDatastore()) + + // Store the v0 provider deal state to the datastore + stateMachines0, err := fsm.New(ds, fsm.Parameters{ + Environment: &mockProviderEnv{}, + StateType: ProviderDealState0{}, + StateKeyField: "Status", + Events: fsm.Events{}, + StateEntryFuncs: fsm.StateEntryFuncs{}, + FinalityStates: []fsm.StateKey{}, + }) + require.NoError(t, err) + + err = stateMachines0.Begin(dealID, tc.dealState0) + require.NoError(t, err) + + // Prepare to run migration to v2 datastore + retrievalMigrations, err := ProviderMigrations.Build() + require.NoError(t, err) + + stateMachines, migrateStateMachines, err := versionedfsm.NewVersionedFSM(ds, fsm.Parameters{ + Environment: &mockProviderEnv{}, + StateType: retrievalmarket.ProviderDealState{}, + StateKeyField: "Status", + Events: providerstates.ProviderEvents, + StateEntryFuncs: providerstates.ProviderStateEntryFuncs, + FinalityStates: providerstates.ProviderFinalityStates, + }, retrievalMigrations, "2") + require.NoError(t, err) + + // Run migration to v2 datastore + err = migrateStateMachines(ctx) + require.NoError(t, err) + + var states []retrievalmarket.ProviderDealState + err = stateMachines.List(&states) + require.NoError(t, err) + + require.Len(t, states, 1) + if tc.expChannelID == nil { + // Ensure that the channel ID is nil if it was not explicitly defined + require.Nil(t, states[0].ChannelID) + } else { + // Ensure that the channel ID is correct if it was defined + require.Equal(t, chid, *states[0].ChannelID) + } + }) + } +} + +type mockClientEnv struct { +} + +func (e *mockClientEnv) Node() retrievalmarket.RetrievalClientNode { + return nil +} + +func (e *mockClientEnv) OpenDataTransfer(ctx context.Context, to peer.ID, proposal *retrievalmarket.DealProposal, legacy bool) (datatransfer.ChannelID, error) { + return datatransfer.ChannelID{}, nil +} + +func (e *mockClientEnv) SendDataTransferVoucher(_ context.Context, _ datatransfer.ChannelID, _ *retrievalmarket.DealPayment, _ bool) error { + return nil +} + +func (e *mockClientEnv) CloseDataTransfer(_ context.Context, _ datatransfer.ChannelID) error { + return nil +} + +type mockProviderEnv struct { +} + +func (te *mockProviderEnv) Node() retrievalmarket.RetrievalProviderNode { + return nil +} + +func (te *mockProviderEnv) DeleteStore(storeID multistore.StoreID) error { + return nil +} + +func (te *mockProviderEnv) ReadIntoBlockstore(storeID multistore.StoreID, pieceData io.Reader) error { + return nil +} + +func (te *mockProviderEnv) TrackTransfer(deal retrievalmarket.ProviderDealState) error { + return nil +} + +func (te *mockProviderEnv) UntrackTransfer(deal retrievalmarket.ProviderDealState) error { + return nil +} + +func (te *mockProviderEnv) ResumeDataTransfer(_ context.Context, _ datatransfer.ChannelID) error { + return nil +} + +func (te *mockProviderEnv) CloseDataTransfer(_ context.Context, _ datatransfer.ChannelID) error { + return nil +} diff --git a/retrievalmarket/types.go b/retrievalmarket/types.go index e954679f..c89e0540 100644 --- a/retrievalmarket/types.go +++ b/retrievalmarket/types.go @@ -46,8 +46,9 @@ type PaymentInfo struct { // of a retrieval client type ClientDealState struct { DealProposal - StoreID *multistore.StoreID - ChannelID datatransfer.ChannelID + StoreID *multistore.StoreID + // Set when the data transfer is started + ChannelID *datatransfer.ChannelID LastPaymentRequested bool AllBlocksReceived bool TotalFunds abi.TokenAmount @@ -73,7 +74,7 @@ type ClientDealState struct { type ProviderDealState struct { DealProposal StoreID multistore.StoreID - ChannelID datatransfer.ChannelID + ChannelID *datatransfer.ChannelID PieceInfo *piecestore.PieceInfo Status DealStatus Receiver peer.ID diff --git a/retrievalmarket/types_cbor_gen.go b/retrievalmarket/types_cbor_gen.go index 8413261a..09bb26ea 100644 --- a/retrievalmarket/types_cbor_gen.go +++ b/retrievalmarket/types_cbor_gen.go @@ -6,6 +6,7 @@ import ( "fmt" "io" + datatransfer "github.com/filecoin-project/go-data-transfer" piecestore "github.com/filecoin-project/go-fil-markets/piecestore" multistore "github.com/filecoin-project/go-multistore" paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" @@ -1697,8 +1698,18 @@ func (t *ClientDealState) UnmarshalCBOR(r io.Reader) error { { - if err := t.ChannelID.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.ChannelID: %w", err) + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + t.ChannelID = new(datatransfer.ChannelID) + if err := t.ChannelID.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.ChannelID pointer: %w", err) + } } } @@ -2225,8 +2236,18 @@ func (t *ProviderDealState) UnmarshalCBOR(r io.Reader) error { { - if err := t.ChannelID.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.ChannelID: %w", err) + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + t.ChannelID = new(datatransfer.ChannelID) + if err := t.ChannelID.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.ChannelID pointer: %w", err) + } } } diff --git a/shared_testutil/generators.go b/shared_testutil/generators.go index c2312b44..7007a8df 100644 --- a/shared_testutil/generators.go +++ b/shared_testutil/generators.go @@ -94,16 +94,6 @@ func MakeTestDealProposal() retrievalmarket.DealProposal { } } -// MakeTestDealResponse generates a valid, random DealResponse -func MakeTestDealResponse() retrievalmarket.DealResponse { - return retrievalmarket.DealResponse{ - Status: retrievalmarket.DealStatusOngoing, - ID: retrievalmarket.DealID(rand.Uint64()), - PaymentOwed: MakeTestTokenAmount(), - Message: "deal response message", - } -} - // MakeTestChannelID makes a new empty data transfer channel ID func MakeTestChannelID() datatransfer.ChannelID { testPeers := GeneratePeers(2) @@ -111,33 +101,6 @@ func MakeTestChannelID() datatransfer.ChannelID { return datatransfer.ChannelID{ID: transferID, Initiator: testPeers[0], Responder: testPeers[1]} } -// MakeTestRetrievalProviderDeal returns a random valid retrieval provider deal -func MakeTestRetrievalProviderDeal(status retrievalmarket.DealStatus) *retrievalmarket.ProviderDealState { - interval := rand.Uint64() - channelID := MakeTestChannelID() - return &retrievalmarket.ProviderDealState{ - Status: status, - ChannelID: channelID, - Receiver: channelID.Initiator, - TotalSent: interval, - CurrentInterval: interval, - FundsReceived: big.Zero(), - DealProposal: retrievalmarket.DealProposal{ - ID: retrievalmarket.DealID(rand.Uint64()), - Params: retrievalmarket.NewParamsV0(MakeTestTokenAmount(), interval, rand.Uint64()), - }, - } -} - -// MakeTestDealPayment generates a valid, random DealPayment -func MakeTestDealPayment() retrievalmarket.DealPayment { - return retrievalmarket.DealPayment{ - ID: retrievalmarket.DealID(rand.Uint64()), - PaymentChannel: address.TestAddress, - PaymentVoucher: MakeTestSignedVoucher(), - } -} - // MakeTestUnsignedDealProposal generates a deal proposal with no signature func MakeTestUnsignedDealProposal() market.DealProposal { start := uint64(rand.Int31())