Skip to content

Commit

Permalink
Track PollErrorCount when polling for provider deal state
Browse files Browse the repository at this point in the history
  • Loading branch information
ingar committed Jun 26, 2020
1 parent fa873b4 commit eded9c7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion storagemarket/impl/clientstates/client_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ var ClientEvents = fsm.Events{
FromMany(storagemarket.StorageDealTransferring, storagemarket.StorageDealStartDataTransfer).To(storagemarket.StorageDealCheckForAcceptance),
fsm.Event(storagemarket.ClientEventWaitForDealState).
From(storagemarket.StorageDealCheckForAcceptance).ToNoChange().
Action(func(deal *storagemarket.ClientDeal) error {
Action(func(deal *storagemarket.ClientDeal, pollError bool) error {
deal.PollRetryCount += 1
if pollError {
deal.PollErrorCount += 1
}
return nil
}),
fsm.Event(storagemarket.ClientEventResponseDealDidNotMatch).
Expand Down
8 changes: 4 additions & 4 deletions storagemarket/impl/clientstates/client_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func CheckForDealAcceptance(ctx fsm.Context, environment ClientDealEnvironment,
dealState, err := environment.GetProviderDealState(ctx.Context(), deal.ProposalCid)
if err != nil {
log.Warnf("error when querying provider deal state: %w", err) // TODO: at what point do we fail the deal?
return waitAgain(ctx, environment, deal)
return waitAgain(ctx, environment, true)
}

if isFailed(dealState.State) {
Expand All @@ -160,16 +160,16 @@ func CheckForDealAcceptance(ctx fsm.Context, environment ClientDealEnvironment,
return ctx.Trigger(storagemarket.ClientEventDealAccepted, dealState.PublishCid)
}

return waitAgain(ctx, environment, deal)
return waitAgain(ctx, environment, false)
}

func waitAgain(ctx fsm.Context, environment ClientDealEnvironment, _ storagemarket.ClientDeal) error {
func waitAgain(ctx fsm.Context, environment ClientDealEnvironment, pollError bool) error {
t := time.NewTimer(environment.PollingInterval())

go func() {
select {
case <-t.C:
_ = ctx.Trigger(storagemarket.ClientEventWaitForDealState)
_ = ctx.Trigger(storagemarket.ClientEventWaitForDealState, pollError)
case <-ctx.Context().Done():
t.Stop()
return
Expand Down
1 change: 1 addition & 0 deletions storagemarket/impl/clientstates/client_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func TestCheckForDealAcceptance(t *testing.T) {
inspector: func(deal storagemarket.ClientDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealCheckForAcceptance, deal.State)
assert.Equal(t, uint64(1), deal.PollRetryCount)
assert.Equal(t, uint64(1), deal.PollErrorCount)
},
})
})
Expand Down
1 change: 1 addition & 0 deletions storagemarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type ClientDeal struct {
PublishMessage *cid.Cid
SlashEpoch abi.ChainEpoch
PollRetryCount uint64
PollErrorCount uint64
}

// StorageDeal is a local combination of a proposal and a current deal state
Expand Down
24 changes: 22 additions & 2 deletions storagemarket/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 eded9c7

Please sign in to comment.