From 08e0278944af640913b7281170986c3b51afecbb Mon Sep 17 00:00:00 2001 From: 0x5459 <0x5459@protonmail.com> Date: Thu, 23 Mar 2023 17:05:22 +0800 Subject: [PATCH] feat: new api `ReleaseDeals` --- api/impl/venus_market.go | 8 ++++++++ go.mod | 2 +- go.sum | 4 ++-- storageprovider/deal_assigner.go | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/api/impl/venus_market.go b/api/impl/venus_market.go index 32fcd175..bbfee79c 100644 --- a/api/impl/venus_market.go +++ b/api/impl/venus_market.go @@ -1042,6 +1042,14 @@ func (m *MarketNodeImpl) AssignUnPackedDeals(ctx context.Context, sid abi.Sector return m.DealAssigner.AssignUnPackedDeals(ctx, sid, ssize, spec) } +// ReleaseDeals is used to release the deals that have been assigned by AssignUnPackedDeals method. +func (m *MarketNodeImpl) ReleaseDeals(ctx context.Context, miner address.Address, deals []abi.DealID) error { + if err := jwtclient.CheckPermissionByMiner(ctx, m.AuthClient, miner); err != nil { + return err + } + return m.DealAssigner.ReleaseDeals(ctx, miner, deals) +} + func (m *MarketNodeImpl) MarkDealsAsPacking(ctx context.Context, miner address.Address, deals []abi.DealID) error { if err := jwtclient.CheckPermissionByMiner(ctx, m.AuthClient, miner); err != nil { return err diff --git a/go.mod b/go.mod index 6da838e5..b232b4a5 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/filecoin-project/go-statestore v0.2.0 github.com/filecoin-project/specs-actors/v2 v2.3.6 github.com/filecoin-project/specs-actors/v7 v7.0.1 - github.com/filecoin-project/venus v1.10.2-0.20230323081631-db00ea0b125d + github.com/filecoin-project/venus v1.10.2-0.20230323084520-c7cd25dffe48 github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e github.com/filecoin-project/venus-messager v1.10.2-0.20230309071456-7cd8d49c6e9a github.com/golang/mock v1.6.0 diff --git a/go.sum b/go.sum index ce86af2c..e4eea619 100644 --- a/go.sum +++ b/go.sum @@ -461,8 +461,8 @@ github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893 github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893/go.mod h1:S7590oDimBvXMUtzWsBXoshu9HtYKwtXl47zAK9rcP8= github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E= github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0= -github.com/filecoin-project/venus v1.10.2-0.20230323081631-db00ea0b125d h1:dE+gdFiIPCgW089ER7ztGsDdkgJWbUU3t/mgabrj4gs= -github.com/filecoin-project/venus v1.10.2-0.20230323081631-db00ea0b125d/go.mod h1:d6XlyUBZd+SHydYimTTkUr3O5rjYOHQTsydI4Nxy6U8= +github.com/filecoin-project/venus v1.10.2-0.20230323084520-c7cd25dffe48 h1:BTEnQuk1Eq5O+buBb2k9/K4pZh1NlynuDMedJSZ6cVc= +github.com/filecoin-project/venus v1.10.2-0.20230323084520-c7cd25dffe48/go.mod h1:d6XlyUBZd+SHydYimTTkUr3O5rjYOHQTsydI4Nxy6U8= github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU= github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e h1:Bxpt1AzPeNxmUnFT2Y8rpabr9x0wIC0Q87DeRmjL2co= github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs= diff --git a/storageprovider/deal_assigner.go b/storageprovider/deal_assigner.go index 5b057c2e..112969ec 100644 --- a/storageprovider/deal_assigner.go +++ b/storageprovider/deal_assigner.go @@ -22,6 +22,7 @@ type DealAssiger interface { GetDeals(ctx context.Context, miner address.Address, pageIndex, pageSize int) ([]*types.DealInfo, error) GetUnPackedDeals(ctx context.Context, miner address.Address, spec *types.GetDealSpec) ([]*types.DealInfoIncludePath, error) AssignUnPackedDeals(ctx context.Context, sid abi.SectorID, ssize abi.SectorSize, spec *types.GetDealSpec) ([]*types.DealInfoIncludePath, error) + ReleaseDeals(ctx context.Context, miner address.Address, deals []abi.DealID) error } var _ DealAssiger = (*dealAssigner)(nil) @@ -265,6 +266,27 @@ func (ps *dealAssigner) AssignUnPackedDeals(ctx context.Context, sid abi.SectorI return pieces, nil } +func (ps *dealAssigner) ReleaseDeals(ctx context.Context, miner address.Address, deals []abi.DealID) error { + return ps.repo.Transaction(func(txRepo repo.TxRepo) error { + storageDealRepo := txRepo.StorageDealRepo() + for _, dealID := range deals { + deal, err := storageDealRepo.GetDealByDealID(ctx, miner, dealID) + if err != nil { + return fmt.Errorf("failed to get deal %d for miner %s: %w", dealID, miner.String(), err) + } + if deal.PieceStatus == types.Proving { + return fmt.Errorf("cannot release a deal that has been proving. miner: %s, deal: %d", miner.String(), dealID) + } + deal.PieceStatus = types.Undefine + deal.State = storagemarket.StorageDealAwaitingPreCommit + if err := storageDealRepo.SaveDeal(ctx, deal); err != nil { + return fmt.Errorf("failed to update deal %d piece status for miner %s: %w", dealID, miner.String(), err) + } + } + return nil + }) +} + type CombinedPieces struct { Pieces []*types.DealInfoIncludePath DealIDs []abi.DealID