Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle payment chanel ready to go #677

Merged
merged 1 commit into from Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/retrievalclient.mmd
Expand Up @@ -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
Expand Down
Binary file modified docs/retrievalclient.mmd.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/retrievalclient.mmd.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions retrievalmarket/impl/clientstates/client_fsm.go
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions retrievalmarket/impl/clientstates/client_states.go
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}

Expand Down
14 changes: 14 additions & 0 deletions retrievalmarket/impl/clientstates/client_states_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down