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

feat: support filter deals by SectorExpiration #404

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,11 @@ func (m *MarketNodeImpl) AssignUnPackedDeals(ctx context.Context, sid abi.Sector
return nil, err
}

return m.DealAssigner.AssignUnPackedDeals(ctx, sid, ssize, spec)
head, err := m.FullNode.ChainHead(ctx)
if err != nil {
log.Errorf("get chain head %w", err)
0x5459 marked this conversation as resolved.
Show resolved Hide resolved
}
return m.DealAssigner.AssignUnPackedDeals(ctx, sid, ssize, head.Height(), spec)
}

// ReleaseDeals is used to release the deals that have been assigned by AssignUnPackedDeals method.
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.12.0
github.com/filecoin-project/venus v1.12.1-0.20230811031541-56b36c6855f6
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,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.12.0 h1:ukMOqu/Zx25a8v1mKQ2gcA9Eb54/wKp/Sv3okGnuPJU=
github.com/filecoin-project/venus v1.12.0/go.mod h1:kSdkZVJp4DLktMrKKaXFQxDGhBmJwVNWMSwPyWASd7o=
github.com/filecoin-project/venus v1.12.1-0.20230811031541-56b36c6855f6 h1:OAzDZAnBX20Y0AacbN3mXmzDLCzGI6HsNOFWT5b2zaM=
github.com/filecoin-project/venus v1.12.1-0.20230811031541-56b36c6855f6/go.mod h1:kSdkZVJp4DLktMrKKaXFQxDGhBmJwVNWMSwPyWASd7o=
github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
Expand Down
16 changes: 15 additions & 1 deletion storageprovider/deal_assign_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/filecoin-project/go-commp-utils/zerocomm"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/market"

"github.com/filecoin-project/venus/venus-shared/types"
mtypes "github.com/filecoin-project/venus/venus-shared/types/market"
Expand All @@ -17,7 +18,7 @@ var (
errDealsUnOrdered = fmt.Errorf("deals un-ordered")
)

func pickAndAlign(deals []*mtypes.DealInfoIncludePath, ssize abi.SectorSize, spec *mtypes.GetDealSpec) ([]*mtypes.DealInfoIncludePath, error) {
func pickAndAlign(deals []*mtypes.DealInfoIncludePath, ssize abi.SectorSize, currentHeight abi.ChainEpoch, spec *mtypes.GetDealSpec) ([]*mtypes.DealInfoIncludePath, error) {
space := abi.PaddedPieceSize(ssize)

if err := space.Validate(); err != nil {
Expand All @@ -43,6 +44,19 @@ func pickAndAlign(deals []*mtypes.DealInfoIncludePath, ssize abi.SectorSize, spe
continue
}

// See: https://github.com/filecoin-project/builtin-actors/blob/c0aed11801cb434c989695ad67721c410b9ada33/actors/market/src/lib.rs#L1073-L1094
// https://github.com/filecoin-project/builtin-actors/blob/c0aed11801cb434c989695ad67721c410b9ada33/actors/verifreg/src/lib.rs#L1056-L1071
if spec.SectorExpiration != nil {
allocTermMin := deal.DealProposal.EndEpoch - deal.DealProposal.StartEpoch
allocTermMax := allocTermMin + market.MarketDefaultAllocationTermBuffer
if allocTermMax > types.MaximumVerifiedAllocationTerm {
allocTermMax = types.MaximumVerifiedAllocationTerm
}
sectorLifetime := *spec.SectorExpiration - currentHeight
if !(sectorLifetime >= allocTermMin && sectorLifetime <= allocTermMax) {
continue
}
}
picked = append(picked, deal)
}

Expand Down
2 changes: 1 addition & 1 deletion storageprovider/deal_assign_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func TestDealAssignPickAndAlign(t *testing.T) {
require.Lenf(t, c.expectedDealIDs, expectedPieceCount, "<%s> expected deal ids & piece sizes should be equal", c.name)

caseDeals := generateTestingDeals(c.sizes, c.lifetimes)
gotDeals, gotErr := pickAndAlign(caseDeals, c.sectorSize, c.spec)
gotDeals, gotErr := pickAndAlign(caseDeals, c.sectorSize, 0, c.spec)

if c.expectedErr != nil {
require.ErrorIsf(t, gotErr, c.expectedErr, "<%s> expected a specified error", c.name)
Expand Down
6 changes: 3 additions & 3 deletions storageprovider/deal_assigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type DealAssiger interface {
UpdateDealStatus(ctx context.Context, miner address.Address, dealID abi.DealID, pieceStatus types.PieceStatus, dealStatus storagemarket.StorageDealStatus) error
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)
AssignUnPackedDeals(ctx context.Context, sid abi.SectorID, ssize abi.SectorSize, currentHeight abi.ChainEpoch, spec *types.GetDealSpec) ([]*types.DealInfoIncludePath, error)
ReleaseDeals(ctx context.Context, miner address.Address, deals []abi.DealID) error
}

Expand Down Expand Up @@ -180,7 +180,7 @@ func (ps *dealAssigner) GetUnPackedDeals(ctx context.Context, miner address.Addr
return result, nil
}

func (ps *dealAssigner) AssignUnPackedDeals(ctx context.Context, sid abi.SectorID, ssize abi.SectorSize, spec *types.GetDealSpec) ([]*types.DealInfoIncludePath, error) {
func (ps *dealAssigner) AssignUnPackedDeals(ctx context.Context, sid abi.SectorID, ssize abi.SectorSize, currentHeight abi.ChainEpoch, spec *types.GetDealSpec) ([]*types.DealInfoIncludePath, error) {
maddr, err := address.NewIDAddress(uint64(sid.Miner))
if err != nil {
return nil, err
Expand Down Expand Up @@ -233,7 +233,7 @@ func (ps *dealAssigner) AssignUnPackedDeals(ctx context.Context, sid abi.SectorI
return left.StoragePricePerEpoch.GreaterThan(right.StoragePricePerEpoch)
})

pieces, err = pickAndAlign(deals, ssize, spec)
pieces, err = pickAndAlign(deals, ssize, currentHeight, spec)
if err != nil {
return fmt.Errorf("unable to pick and align pieces from deals: %w", err)
}
Expand Down