From eebce51848eb5f74755d5de00a63a5bcbc7598fe Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Wed, 6 Oct 2021 13:52:01 +0200 Subject: [PATCH 1/2] PublishDeal: do not return an error when lacking funds --- storagemarket/impl/provider.go | 4 ++++ storagemarket/impl/providerstates/provider_states.go | 6 ++++++ storagemarket/provider.go | 2 ++ 3 files changed, 12 insertions(+) diff --git a/storagemarket/impl/provider.go b/storagemarket/impl/provider.go index 709f232b..248afc0a 100644 --- a/storagemarket/impl/provider.go +++ b/storagemarket/impl/provider.go @@ -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 diff --git a/storagemarket/impl/providerstates/provider_states.go b/storagemarket/impl/providerstates/provider_states.go index f8c85130..8a127b14 100644 --- a/storagemarket/impl/providerstates/provider_states.go +++ b/storagemarket/impl/providerstates/provider_states.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "strings" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" @@ -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)) } diff --git a/storagemarket/provider.go b/storagemarket/provider.go index 2459fd5b..1c48a05f 100644 --- a/storagemarket/provider.go +++ b/storagemarket/provider.go @@ -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 } From 2bd4566d8bbd3c887fe1d5e3a3cf703726a3c28c Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 7 Oct 2021 14:53:44 +0200 Subject: [PATCH 2/2] unit test: make sure that we stay in StorageDealPublish state if PublishDeal errors with not enough funds error --- .../impl/providerstates/provider_states_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/storagemarket/impl/providerstates/provider_states_test.go b/storagemarket/impl/providerstates/provider_states_test.go index cf0d15c8..a87a39e4 100644 --- a/storagemarket/impl/providerstates/provider_states_test.go +++ b/storagemarket/impl/providerstates/provider_states_test.go @@ -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"),