diff --git a/docs/retrievalclient.mmd b/docs/retrievalclient.mmd index 88fb4116..cc951205 100644 --- a/docs/retrievalclient.mmd +++ b/docs/retrievalclient.mmd @@ -79,6 +79,7 @@ stateDiagram-v2 DealStatusCheckFunds --> DealStatusPaymentChannelAddingFunds : ClientEventPaymentChannelAddingFunds DealStatusPaymentChannelCreating --> DealStatusPaymentChannelAllocatingLane : ClientEventPaymentChannelReady DealStatusPaymentChannelAddingFunds --> DealStatusOngoing : ClientEventPaymentChannelReady + DealStatusAccepted --> DealStatusPaymentChannelAllocatingLane : ClientEventPaymentChannelReady DealStatusCheckFunds --> DealStatusOngoing : ClientEventPaymentChannelReady DealStatusPaymentChannelAddingInitialFunds --> DealStatusPaymentChannelAllocatingLane : ClientEventPaymentChannelReady DealStatusPaymentChannelAllocatingLane --> DealStatusFailing : ClientEventAllocateLaneErrored diff --git a/docs/retrievalclient.mmd.png b/docs/retrievalclient.mmd.png index 77d70853..8e8dd898 100644 Binary files a/docs/retrievalclient.mmd.png and b/docs/retrievalclient.mmd.png differ diff --git a/docs/retrievalclient.mmd.svg b/docs/retrievalclient.mmd.svg index fb48b079..260804b5 100644 --- a/docs/retrievalclient.mmd.svg +++ b/docs/retrievalclient.mmd.svg @@ -1,6 +1,6 @@ -ClientEventOpenClientEventDealProposedClientEventDealProposedClientEventDealRejectedClientEventDealRejectedClientEventDealNotFoundClientEventDealNotFoundClientEventDealAcceptedClientEventDealAcceptedClientEventPaymentChannelErroredClientEventPaymentChannelErroredClientEventPaymentChannelErroredClientEventPaymentChannelSkipClientEventPaymentChannelCreateInitiatedClientEventPaymentChannelAddingFundsClientEventPaymentChannelAddingFundsClientEventPaymentChannelReadyClientEventPaymentChannelReadyClientEventPaymentChannelReadyClientEventPaymentChannelReadyClientEventPaymentChannelReadyClientEventAllocateLaneErroredClientEventLaneAllocatedClientEventLastPaymentRequestedClientEventLastPaymentRequestedClientEventLastPaymentRequestedClientEventLastPaymentRequestedClientEventLastPaymentRequestedClientEventLastPaymentRequestedClientEventPaymentRequestedClientEventPaymentRequestedClientEventPaymentRequestedClientEventPaymentRequestedClientEventPaymentRequestedClientEventPaymentRequestedClientEventUnsealPaymentRequestedClientEventUnsealPaymentRequestedClientEventAllBlocksReceivedClientEventAllBlocksReceivedClientEventAllBlocksReceivedClientEventAllBlocksReceivedClientEventAllBlocksReceivedClientEventAllBlocksReceivedClientEventAllBlocksReceivedClientEventAllBlocksReceivedClientEventBlocksReceivedClientEventBlocksReceivedClientEventBlocksReceivedClientEventBlocksReceivedClientEventBlocksReceivedClientEventBlocksReceivedClientEventBlocksReceivedClientEventSendFundsClientEventSendFundsClientEventSendFundsClientEventSendFundsClientEventFundsExpendedClientEventBadPaymentRequestedClientEventBadPaymentRequestedClientEventCreateVoucherFailedClientEventCreateVoucherFailedClientEventVoucherShortfallClientEventVoucherShortfallClientEventPaymentNotSentClientEventPaymentNotSentClientEventPaymentSentClientEventPaymentSentClientEventPaymentSentClientEventPaymentSentClientEventPaymentSentClientEventPaymentSentClientEventCompleteClientEventCompleteClientEventCompleteClientEventCompleteClientEventCompleteClientEventCompleteClientEventCompleteClientEventCompleteVerifiedClientEventEarlyTerminationClientEventWaitForLastBlocksClientEventBlockstoreFinalizedClientEventBlockstoreFinalizedClientEventBlockstoreFinalizedClientEventBlockstoreFinalizedClientEventFinalizeBlockstoreErroredClientEventCancelCompleteClientEventCancelCompleteClientEventRecheckFundsDealStatusNewOn entry runs ProposeDealDealStatusWaitForAcceptanceDealStatusPaymentChannelCreatingOn entry runs WaitPaymentChannelReadyDealStatusPaymentChannelAddingFundsOn entry runs WaitPaymentChannelReadyDealStatusAcceptedOn entry runs SetupPaymentChannelStartDealStatusFailingOn entry runs CancelDealDealStatusRejectedDealStatusFundsNeededOn entry runs ProcessPaymentRequestedDealStatusSendFundsOn entry runs SendFundsDealStatusSendFundsLastPaymentOn entry runs SendFundsDealStatusOngoingOn entry runs OngoingDealStatusFundsNeededLastPaymentOn entry runs ProcessPaymentRequestedDealStatusCompletedDealStatusDealNotFoundDealStatusErroredDealStatusBlocksCompleteDealStatusFinalizingDealStatusCheckCompleteOn entry runs CheckCompleteDealStatusCheckFundsOn entry runs CheckFundsDealStatusInsufficientFundsDealStatusPaymentChannelAllocatingLaneOn entry runs AllocateLaneDealStatusCancellingOn entry runs CancelDealDealStatusCancelledDealStatusRetryLegacyOn entry runs ProposeDealDealStatusWaitForAcceptanceLegacyDealStatusWaitingForLastBlocksDealStatusPaymentChannelAddingInitialFundsOn entry runs WaitPaymentChannelReadyDealStatusErroringOn entry runs FailsafeFinalizeBlockstoreDealStatusRejectingOn entry runs FailsafeFinalizeBlockstoreDealStatusDealNotFoundCleanupOn entry runs FailsafeFinalizeBlockstoreDealStatusFinalizingBlockstoreOn entry runs FinalizeBlockstoreThe following events are not shown cause they can trigger from any state.ClientEventWriteDealProposalErrored - transitions state to DealStatusErroringClientEventUnknownResponseReceived - transitions state to DealStatusFailingClientEventDataTransferError - transitions state to DealStatusErroringClientEventWriteDealPaymentErrored - transitions state to DealStatusErroringClientEventProviderCancelled - transitions state to DealStatusCancellingClientEventCancel - transitions state to DealStatusCancellingThe following events only record in this state.ClientEventLastPaymentRequestedClientEventPaymentRequestedClientEventAllBlocksReceivedClientEventBlocksReceivedThe following events only record in this state.ClientEventLastPaymentRequestedClientEventPaymentRequestedClientEventAllBlocksReceivedClientEventBlocksReceivedThe following events only record in this state.ClientEventLastPaymentRequestedClientEventPaymentRequestedClientEventAllBlocksReceivedClientEventBlocksReceivedThe following events only record in this state.ClientEventProviderCancelledThe following events only record in this state.ClientEventPaymentNotSentClientEventPaymentSentThe following events only record in this state.ClientEventWaitForLastBlocksThe following events only record in this state.ClientEventLastPaymentRequestedClientEventPaymentRequestedClientEventAllBlocksReceivedClientEventBlocksReceivedThe following events only record in this state.ClientEventDealProposedClientEventProviderCancelledThe following events only record in this state.ClientEventLastPaymentRequestedClientEventPaymentRequestedClientEventAllBlocksReceivedClientEventBlocksReceivedThe following events only record in this state.ClientEventLastPaymentRequestedClientEventPaymentRequestedClientEventAllBlocksReceivedClientEventBlocksReceivedThe following events only record in this state.ClientEventWaitForLastBlocks \ No newline at end of file diff --git a/retrievalmarket/impl/clientstates/client_fsm.go b/retrievalmarket/impl/clientstates/client_fsm.go index 1b460cba..1eb1ba9d 100644 --- a/retrievalmarket/impl/clientstates/client_fsm.go +++ b/retrievalmarket/impl/clientstates/client_fsm.go @@ -119,8 +119,7 @@ var ClientEvents = fsm.Events{ // created for an earlier deal but the initial funding for this deal // was being added, then we still need to allocate a payment channel // lane - From(rm.DealStatusPaymentChannelCreating).To(rm.DealStatusPaymentChannelAllocatingLane). - From(rm.DealStatusPaymentChannelAddingInitialFunds).To(rm.DealStatusPaymentChannelAllocatingLane). + FromMany(rm.DealStatusPaymentChannelCreating, rm.DealStatusPaymentChannelAddingInitialFunds, rm.DealStatusAccepted).To(rm.DealStatusPaymentChannelAllocatingLane). // If the payment channel ran out of funds and needed to be topped up, // then the payment channel lane already exists so just move straight // to the ongoing state diff --git a/retrievalmarket/impl/clientstates/client_states.go b/retrievalmarket/impl/clientstates/client_states.go index 070ef3c8..4d55d7f5 100644 --- a/retrievalmarket/impl/clientstates/client_states.go +++ b/retrievalmarket/impl/clientstates/client_states.go @@ -3,6 +3,7 @@ package clientstates import ( "context" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" peer "github.com/libp2p/go-libp2p-core/peer" @@ -59,6 +60,9 @@ func SetupPaymentChannelStart(ctx fsm.Context, environment ClientDealEnvironment return ctx.Trigger(rm.ClientEventPaymentChannelCreateInitiated, msgCID) } + if msgCID == cid.Undef { + return ctx.Trigger(rm.ClientEventPaymentChannelReady, paych) + } return ctx.Trigger(rm.ClientEventPaymentChannelAddingFunds, msgCID, paych) } diff --git a/retrievalmarket/impl/clientstates/client_states_test.go b/retrievalmarket/impl/clientstates/client_states_test.go index abdbc973..028513c5 100644 --- a/retrievalmarket/impl/clientstates/client_states_test.go +++ b/retrievalmarket/impl/clientstates/client_states_test.go @@ -6,6 +6,7 @@ import ( "math/rand" "testing" + "github.com/ipfs/go-cid" peer "github.com/libp2p/go-libp2p-core/peer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -141,6 +142,19 @@ func TestSetupPaymentChannel(t *testing.T) { require.Equal(t, expectedPayCh, dealState.PaymentInfo.PayCh) }) + t.Run("payment channel fully ready", func(t *testing.T) { + envParams := testnodes.TestRetrievalClientNodeParams{ + AddFundsOnly: true, + PayCh: expectedPayCh, + AddFundsCID: cid.Undef, + } + dealState := makeDealState(retrievalmarket.DealStatusAccepted) + runSetupPaymentChannel(t, envParams, dealState) + require.Empty(t, dealState.Message) + require.Equal(t, dealState.Status, retrievalmarket.DealStatusPaymentChannelAllocatingLane) + require.Equal(t, expectedPayCh, dealState.PaymentInfo.PayCh) + }) + t.Run("when create payment channel fails", func(t *testing.T) { dealState := makeDealState(retrievalmarket.DealStatusAccepted) envParams := testnodes.TestRetrievalClientNodeParams{