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 1622db3
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 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,33 @@ 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
retry := RetryInterval

mcid, err := environment.Node().PublishDeals(ctx.Context(), smDeal)
if err != nil {
return ctx.Trigger(storagemarket.ProviderEventNodeErrored, xerrors.Errorf("publishing deal: %w", err))
}
for {
attempt++
retry *= 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, retry)
time.Sleep(retry)
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 1622db3

Please sign in to comment.