Skip to content

Commit

Permalink
Merge pull request #305 from 0x5459/feat/new-api-ReleaseDeals
Browse files Browse the repository at this point in the history
feat: new api ReleaseDeals
  • Loading branch information
diwufeiwen authored Mar 24, 2023
2 parents f63d5d5 + 08e0278 commit 012d2aa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
8 changes: 8 additions & 0 deletions api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
22 changes: 22 additions & 0 deletions storageprovider/deal_assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 012d2aa

Please sign in to comment.