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
#638)

* PublishDeal: do not return an error when lacking funds

* unit test: make sure that we stay in StorageDealPublish state if PublishDeal errors with not enough funds error
  • Loading branch information
nonsense authored Oct 11, 2021
1 parent ea97d4e commit 679e33e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
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
}

0 comments on commit 679e33e

Please sign in to comment.