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

block in Publish state when message sending fails due to lack of funds #638

Merged
merged 2 commits into from
Oct 11, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ func (p *Provider) GetStorageCollateral(ctx context.Context) (storagemarket.Bala
return p.spn.GetBalance(ctx, p.actor, tok)
}

func (p *Provider) RetryDealPublishing(propcid cid.Cid) error {
return p.deals.Send(propcid, storagemarket.ProviderEventRestart)
}

// ListLocalDeals lists deals processed by this storage provider
func (p *Provider) ListLocalDeals() ([]storagemarket.MinerDeal, error) {
var out []storagemarket.MinerDeal
Expand Down
6 changes: 6 additions & 0 deletions storagemarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"strings"

"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
Expand Down Expand Up @@ -284,6 +285,11 @@ func PublishDeal(ctx fsm.Context, environment ProviderDealEnvironment, deal stor

mcid, err := environment.Node().PublishDeals(ctx.Context(), smDeal)
if err != nil {
if strings.Contains(err.Error(), "not enough funds") {
log.Warnf("publishing deal failed due to lack of funds: %s", err)

return nil
}
return ctx.Trigger(storagemarket.ProviderEventNodeErrored, xerrors.Errorf("publishing deal: %w", err))
}

Expand Down
9 changes: 9 additions & 0 deletions storagemarket/impl/providerstates/provider_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ func TestPublishDeal(t *testing.T) {
tut.AssertDealState(t, storagemarket.StorageDealPublishing, deal.State)
},
},
"PublishDealsErrors returns not enough funds error": {
nodeParams: nodeParams{
PublishDealsError: errors.New("not enough funds"),
},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealPublish, deal.State)
require.Equal(t, "", deal.Message)
},
},
"PublishDealsErrors errors": {
nodeParams: nodeParams{
PublishDealsError: errors.New("could not post to chain"),
Expand Down
2 changes: 2 additions & 0 deletions storagemarket/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ type StorageProvider interface {

// SubscribeToEvents listens for events that happen related to storage deals on a provider
SubscribeToEvents(subscriber ProviderSubscriber) shared.Unsubscribe

RetryDealPublishing(propCid cid.Cid) error
}