Skip to content

Commit

Permalink
block in Publish state when message sending fails due to lack of funds
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Oct 6, 2021
1 parent 35f3f12 commit fdbd21f
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions storagemarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"strings"
"time"

"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
Expand All @@ -29,6 +31,11 @@ import (

var log = logging.Logger("providerstates")

var (
RetryInterval = 2 * time.Minute
MaxAttempts = 10
)

// TODO: These are copied from spec-actors master, use spec-actors exports when we update
const DealMaxLabelSize = 256

Expand Down Expand Up @@ -274,20 +281,32 @@ func WaitForFunding(ctx fsm.Context, environment ProviderDealEnvironment, deal s

// PublishDeal sends a message to publish a deal on chain
func PublishDeal(ctx fsm.Context, environment ProviderDealEnvironment, deal storagemarket.MinerDeal) error {
smDeal := storagemarket.MinerDeal{
Client: deal.Client,
ClientDealProposal: deal.ClientDealProposal,
ProposalCid: deal.ProposalCid,
State: deal.State,
Ref: deal.Ref,
}
attempt := 0

mcid, err := environment.Node().PublishDeals(ctx.Context(), smDeal)
if err != nil {
return ctx.Trigger(storagemarket.ProviderEventNodeErrored, xerrors.Errorf("publishing deal: %w", err))
}
for {
attempt++
RetryInterval *= 2

smDeal := storagemarket.MinerDeal{
Client: deal.Client,
ClientDealProposal: deal.ClientDealProposal,
ProposalCid: deal.ProposalCid,
State: deal.State,
Ref: deal.Ref,
}

return ctx.Trigger(storagemarket.ProviderEventDealPublishInitiated, mcid)
mcid, err := environment.Node().PublishDeals(ctx.Context(), smDeal)
if err != nil {
if strings.Contains(err.Error(), "not enough funds") && attempt <= MaxAttempts {
log.Warnf("publishing deal failed due to lack of funds: %s; retrying again after backoff interval: %s", err, RetryInterval)
time.Sleep(RetryInterval)
continue
}
return ctx.Trigger(storagemarket.ProviderEventNodeErrored, xerrors.Errorf("publishing deal: %w", err))
}

return ctx.Trigger(storagemarket.ProviderEventDealPublishInitiated, mcid)
}
}

// WaitForPublish waits for the publish message on chain and saves the deal id
Expand Down

0 comments on commit fdbd21f

Please sign in to comment.