Skip to content

Commit

Permalink
Poll Provider for acceptance only till (deal start epoch + grace peri…
Browse files Browse the repository at this point in the history
…od) has elapsed (#516)

* poll only till deal elapses

* Apply suggestions from code review

Co-authored-by: dirkmc <[email protected]>

Co-authored-by: dirkmc <[email protected]>
  • Loading branch information
aarshkshah1992 and dirkmc authored Mar 30, 2021
1 parent 39a8025 commit 1203c12
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions storagemarket/impl/clientstates/client_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (

var log = logging.Logger("storagemarket_impl")

// MaxGraceEpochsForDealAcceptance is the maximum number of epochs we will wait for past the start epoch
// for the provider to publish a deal.
const MaxGraceEpochsForDealAcceptance = 10

// ClientDealEnvironment is an abstraction for interacting with
// dependencies from the storage client environment
type ClientDealEnvironment interface {
Expand Down Expand Up @@ -170,6 +174,13 @@ func InitiateDataTransfer(ctx fsm.Context, environment ClientDealEnvironment, de

// CheckForDealAcceptance is run until the deal is sealed and published by the provider, or errors
func CheckForDealAcceptance(ctx fsm.Context, environment ClientDealEnvironment, deal storagemarket.ClientDeal) error {
_, currEpoch, err := environment.Node().GetChainHead(ctx.Context())

if err == nil {
if currEpoch > deal.Proposal.StartEpoch+MaxGraceEpochsForDealAcceptance {
return ctx.Trigger(storagemarket.ClientEventDealRejected, deal.State, "start epoch already elapsed")
}
}

dealState, err := environment.GetProviderDealState(ctx.Context(), deal.ProposalCid)
if err != nil {
Expand Down
31 changes: 31 additions & 0 deletions storagemarket/impl/clientstates/client_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,27 @@ func TestCheckForDealAcceptance(t *testing.T) {
})
})

t.Run("stops polling if (start epoch + grace period) has elapsed", func(t *testing.T) {
startEpoch := abi.ChainEpoch(1)
maxEpoch := startEpoch + clientstates.MaxGraceEpochsForDealAcceptance

runAndInspect(t, storagemarket.StorageDealCheckForAcceptance, clientstates.CheckForDealAcceptance, testCase{
envParams: envParams{
providerDealState: makeProviderDealState(storagemarket.StorageDealVerifyData),
},
nodeParams: nodeParams{
CurrentEpoch: maxEpoch + 1,
},
stateParams: dealStateParams{
startEpoch: startEpoch,
},
inspector: func(deal storagemarket.ClientDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealFailing, deal.State)
assert.Contains(t, deal.Message, "start epoch already elapsed")
},
})
})

t.Run("continues polling with an indeterminate deal state", func(t *testing.T) {
runAndInspect(t, storagemarket.StorageDealCheckForAcceptance, clientstates.CheckForDealAcceptance, testCase{
envParams: envParams{
Expand Down Expand Up @@ -567,6 +588,7 @@ type dealStateParams struct {
addFundsCid *cid.Cid
reserveFunds bool
fastRetrieval bool
startEpoch abi.ChainEpoch
}

type executor func(t *testing.T,
Expand Down Expand Up @@ -597,6 +619,10 @@ func makeExecutor(ctx context.Context,
if dealParams.reserveFunds {
dealState.FundsReserved = clientDealProposal.Proposal.ClientBalanceRequirement()
}
if dealParams.startEpoch != 0 {
dealState.Proposal.StartEpoch = dealParams.startEpoch
}

environment := &fakeEnvironment{
node: node,
dealStream: envParams.dealStream,
Expand All @@ -623,6 +649,7 @@ func makeExecutor(ctx context.Context,
}

type nodeParams struct {
CurrentEpoch abi.ChainEpoch
AddFundsCid cid.Cid
ReserveFundsError error
VerifySignatureFails bool
Expand Down Expand Up @@ -651,6 +678,10 @@ type nodeParams struct {
func makeNode(params nodeParams) *testnodes.FakeClientNode {
var out testnodes.FakeClientNode
out.SMState = testnodes.NewStorageMarketState()
if params.CurrentEpoch != 0 {
out.SMState.Epoch = params.CurrentEpoch
}

out.DealFunds = tut.NewTestDealFunds()
out.AddFundsCid = params.AddFundsCid
out.ReserveFundsError = params.ReserveFundsError
Expand Down

0 comments on commit 1203c12

Please sign in to comment.