diff --git a/api/impl/venus_market.go b/api/impl/venus_market.go index 84e833be..089f52b7 100644 --- a/api/impl/venus_market.go +++ b/api/impl/venus_market.go @@ -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 { + return nil, fmt.Errorf("get chain head %w", err) + } + return m.DealAssigner.AssignUnPackedDeals(ctx, sid, ssize, head.Height(), spec) } // ReleaseDeals is used to release the deals that have been assigned by AssignUnPackedDeals method. diff --git a/go.mod b/go.mod index dc340005..6c0dcb1f 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.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 diff --git a/go.sum b/go.sum index 0da558e8..07d64d6c 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/storageprovider/deal_assign_util.go b/storageprovider/deal_assign_util.go index 771dcb9b..5ec004c6 100644 --- a/storageprovider/deal_assign_util.go +++ b/storageprovider/deal_assign_util.go @@ -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" @@ -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 { @@ -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) } diff --git a/storageprovider/deal_assign_util_test.go b/storageprovider/deal_assign_util_test.go index fa3bd2c7..006fff84 100644 --- a/storageprovider/deal_assign_util_test.go +++ b/storageprovider/deal_assign_util_test.go @@ -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) diff --git a/storageprovider/deal_assigner.go b/storageprovider/deal_assigner.go index 23f81ce0..e99735ca 100644 --- a/storageprovider/deal_assigner.go +++ b/storageprovider/deal_assigner.go @@ -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 } @@ -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 @@ -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) }