2020-04-07 22:26:07 +00:00
|
|
|
package sealing_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-18 06:14:18 +00:00
|
|
|
"testing"
|
2021-07-22 18:44:39 +00:00
|
|
|
"time"
|
2020-09-18 06:14:18 +00:00
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2024-01-25 14:15:55 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
2020-09-17 15:30:15 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-09-17 15:30:15 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2021-07-22 18:54:52 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
2024-04-04 21:16:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
2021-07-22 18:44:39 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
2022-06-16 09:12:33 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2022-08-09 11:43:08 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
2022-06-14 18:31:17 +00:00
|
|
|
pipeline "github.com/filecoin-project/lotus/storage/pipeline"
|
2024-01-25 14:15:55 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/pipeline/piece"
|
2022-06-14 17:41:59 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/pipeline/sealiface"
|
2020-04-07 22:26:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeChain struct {
|
|
|
|
h abi.ChainEpoch
|
|
|
|
}
|
|
|
|
|
2021-07-22 18:54:52 +00:00
|
|
|
type fakeConfigStub struct {
|
|
|
|
CCSectorLifetime time.Duration
|
|
|
|
}
|
|
|
|
|
2022-08-09 11:43:08 +00:00
|
|
|
func fakeConfigGetter(stub *fakeConfigStub) dtypes.GetSealingConfigFunc {
|
2021-07-22 18:44:39 +00:00
|
|
|
return func() (sealiface.Config, error) {
|
|
|
|
if stub == nil {
|
|
|
|
return sealiface.Config{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return sealiface.Config{
|
2021-07-22 18:54:52 +00:00
|
|
|
CommittedCapacitySectorLifetime: stub.CCSectorLifetime,
|
2021-07-22 18:44:39 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-17 09:20:33 +00:00
|
|
|
func (f *fakeChain) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) {
|
2022-11-16 01:57:23 +00:00
|
|
|
return build.TestNetworkVersion, nil
|
2020-09-17 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 14:15:55 +00:00
|
|
|
func makeBFTs(t *testing.T, basefee abi.TokenAmount, h abi.ChainEpoch) *types.TipSet {
|
|
|
|
dummyCid, _ := cid.Parse("bafkqaaa")
|
|
|
|
|
|
|
|
var ts, err = types.NewTipSet([]*types.BlockHeader{
|
|
|
|
{
|
|
|
|
Height: h,
|
|
|
|
Miner: builtin.SystemActorAddr,
|
|
|
|
|
|
|
|
Parents: []cid.Cid{},
|
|
|
|
|
|
|
|
Ticket: &types.Ticket{VRFProof: []byte{byte(h % 2)}},
|
|
|
|
|
|
|
|
ParentStateRoot: dummyCid,
|
|
|
|
Messages: dummyCid,
|
|
|
|
ParentMessageReceipts: dummyCid,
|
|
|
|
|
|
|
|
BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS},
|
|
|
|
BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS},
|
|
|
|
|
|
|
|
ParentBaseFee: basefee,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if t != nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ts
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTs(t *testing.T, h abi.ChainEpoch) *types.TipSet {
|
|
|
|
return makeBFTs(t, big.NewInt(0), h)
|
|
|
|
}
|
|
|
|
|
2022-06-16 11:15:49 +00:00
|
|
|
func (f *fakeChain) ChainHead(ctx context.Context) (*types.TipSet, error) {
|
|
|
|
return makeTs(nil, f.h), nil
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
func fakePieceCid(t *testing.T) cid.Cid {
|
|
|
|
comm := [32]byte{1, 2, 3}
|
|
|
|
fakePieceCid, err := commcid.ReplicaCommitmentV1ToCID(comm[:])
|
|
|
|
require.NoError(t, err)
|
|
|
|
return fakePieceCid
|
|
|
|
}
|
|
|
|
|
2024-01-25 14:15:55 +00:00
|
|
|
func cidPtr(c cid.Cid) *cid.Cid {
|
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:26:07 +00:00
|
|
|
func TestBasicPolicyEmptySector(t *testing.T) {
|
2021-07-22 18:54:52 +00:00
|
|
|
cfg := fakeConfigGetter(nil)
|
2021-07-22 18:44:39 +00:00
|
|
|
h := abi.ChainEpoch(55)
|
|
|
|
pBuffer := abi.ChainEpoch(2)
|
2022-06-14 18:31:17 +00:00
|
|
|
pcp := pipeline.NewBasicPreCommitPolicy(&fakeChain{h: h}, cfg, pBuffer)
|
2021-07-22 18:44:39 +00:00
|
|
|
exp, err := pcp.Expiration(context.Background())
|
2020-04-07 22:26:07 +00:00
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-22 18:44:39 +00:00
|
|
|
// as set when there are no deal pieces
|
2023-09-23 17:40:53 +00:00
|
|
|
maxExtension, err := policy.GetMaxSectorExpirationExtension(build.TestNetworkVersion)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
expected := h + maxExtension - pBuffer
|
2021-07-22 18:44:39 +00:00
|
|
|
assert.Equal(t, int(expected), int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 18:54:52 +00:00
|
|
|
func TestCustomCCSectorConfig(t *testing.T) {
|
|
|
|
customLifetime := 200 * 24 * time.Hour
|
2021-07-24 00:12:30 +00:00
|
|
|
customLifetimeEpochs := abi.ChainEpoch(int64(customLifetime.Seconds()) / builtin.EpochDurationSeconds)
|
2021-07-22 18:54:52 +00:00
|
|
|
cfgStub := fakeConfigStub{CCSectorLifetime: customLifetime}
|
|
|
|
cfg := fakeConfigGetter(&cfgStub)
|
|
|
|
h := abi.ChainEpoch(55)
|
|
|
|
pBuffer := abi.ChainEpoch(2)
|
2022-06-14 18:31:17 +00:00
|
|
|
pcp := pipeline.NewBasicPreCommitPolicy(&fakeChain{h: h}, cfg, pBuffer)
|
2021-07-22 18:54:52 +00:00
|
|
|
exp, err := pcp.Expiration(context.Background())
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// as set when there are no deal pieces
|
2021-07-11 17:57:09 +00:00
|
|
|
expected := h + customLifetimeEpochs - pBuffer
|
2021-07-22 18:54:52 +00:00
|
|
|
assert.Equal(t, int(expected), int(exp))
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:26:07 +00:00
|
|
|
func TestBasicPolicyMostConstrictiveSchedule(t *testing.T) {
|
2021-07-22 18:54:52 +00:00
|
|
|
cfg := fakeConfigGetter(nil)
|
2022-06-14 18:31:17 +00:00
|
|
|
policy := pipeline.NewBasicPreCommitPolicy(&fakeChain{
|
2020-04-07 22:26:07 +00:00
|
|
|
h: abi.ChainEpoch(55),
|
2021-07-11 17:57:09 +00:00
|
|
|
}, cfg, 2)
|
|
|
|
longestDealEpochEnd := abi.ChainEpoch(547300)
|
2024-01-25 14:15:55 +00:00
|
|
|
pieces := []pipeline.SafeSectorPiece{
|
|
|
|
pipeline.SafePiece(api.SectorPiece{
|
2020-04-07 22:26:07 +00:00
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
DealInfo: &piece.PieceDealInfo{
|
|
|
|
PublishCid: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
|
|
|
|
DealID: abi.DealID(42),
|
|
|
|
DealSchedule: piece.DealSchedule{
|
2020-04-07 22:26:07 +00:00
|
|
|
StartEpoch: abi.ChainEpoch(70),
|
2021-07-11 17:57:09 +00:00
|
|
|
EndEpoch: abi.ChainEpoch(547275),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
}),
|
|
|
|
pipeline.SafePiece(api.SectorPiece{
|
2020-04-07 22:26:07 +00:00
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
DealInfo: &piece.PieceDealInfo{
|
|
|
|
PublishCid: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
|
|
|
|
DealID: abi.DealID(43),
|
|
|
|
DealSchedule: piece.DealSchedule{
|
2020-04-07 22:26:07 +00:00
|
|
|
StartEpoch: abi.ChainEpoch(80),
|
2021-07-22 18:44:39 +00:00
|
|
|
EndEpoch: longestDealEpochEnd,
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
}),
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-11 17:57:09 +00:00
|
|
|
assert.Equal(t, int(longestDealEpochEnd), int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBasicPolicyIgnoresExistingScheduleIfExpired(t *testing.T) {
|
2021-07-22 18:54:52 +00:00
|
|
|
cfg := fakeConfigGetter(nil)
|
2023-09-23 17:40:53 +00:00
|
|
|
pcp := pipeline.NewBasicPreCommitPolicy(&fakeChain{
|
2020-04-07 22:26:07 +00:00
|
|
|
h: abi.ChainEpoch(55),
|
2021-07-11 17:57:09 +00:00
|
|
|
}, cfg, 0)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2024-01-25 14:15:55 +00:00
|
|
|
pieces := []pipeline.SafeSectorPiece{
|
|
|
|
pipeline.SafePiece(api.SectorPiece{
|
2020-04-07 22:26:07 +00:00
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
DealInfo: &piece.PieceDealInfo{
|
|
|
|
PublishCid: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
|
|
|
|
DealID: abi.DealID(44),
|
|
|
|
DealSchedule: piece.DealSchedule{
|
2020-04-07 22:26:07 +00:00
|
|
|
StartEpoch: abi.ChainEpoch(1),
|
|
|
|
EndEpoch: abi.ChainEpoch(10),
|
|
|
|
},
|
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
}),
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
2023-09-23 17:40:53 +00:00
|
|
|
exp, err := pcp.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
maxLifetime, err := policy.GetMaxSectorExpirationExtension(build.TestNetworkVersion)
|
2020-04-07 22:26:07 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-11 17:57:09 +00:00
|
|
|
// Treated as a CC sector, so expiration becomes currEpoch + maxLifetime = 55 + 1555200
|
2023-09-23 17:40:53 +00:00
|
|
|
assert.Equal(t, 55+maxLifetime, exp)
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMissingDealIsIgnored(t *testing.T) {
|
2021-07-22 18:54:52 +00:00
|
|
|
cfg := fakeConfigGetter(nil)
|
2022-06-14 18:31:17 +00:00
|
|
|
policy := pipeline.NewBasicPreCommitPolicy(&fakeChain{
|
2020-04-07 22:26:07 +00:00
|
|
|
h: abi.ChainEpoch(55),
|
2021-07-11 17:57:09 +00:00
|
|
|
}, cfg, 0)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2024-01-25 14:15:55 +00:00
|
|
|
pieces := []pipeline.SafeSectorPiece{
|
|
|
|
pipeline.SafePiece(api.SectorPiece{
|
2020-04-07 22:26:07 +00:00
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
DealInfo: &piece.PieceDealInfo{
|
|
|
|
PublishCid: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
|
|
|
|
DealID: abi.DealID(44),
|
|
|
|
DealSchedule: piece.DealSchedule{
|
2020-04-07 22:26:07 +00:00
|
|
|
StartEpoch: abi.ChainEpoch(1),
|
2021-07-11 17:57:09 +00:00
|
|
|
EndEpoch: abi.ChainEpoch(547300),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
},
|
2024-01-25 14:15:55 +00:00
|
|
|
}),
|
|
|
|
pipeline.SafePiece(api.SectorPiece{
|
2020-04-07 22:26:07 +00:00
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
DealInfo: nil,
|
2024-01-25 14:15:55 +00:00
|
|
|
}),
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-11 17:57:09 +00:00
|
|
|
assert.Equal(t, 547300, int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
2024-04-04 21:16:34 +00:00
|
|
|
|
|
|
|
func TestBasicPolicyDDO(t *testing.T) {
|
|
|
|
cfg := fakeConfigGetter(nil)
|
|
|
|
pcp := pipeline.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
|
|
|
}, cfg, 0)
|
|
|
|
|
|
|
|
pieces := []pipeline.SafeSectorPiece{
|
|
|
|
pipeline.SafePiece(api.SectorPiece{
|
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
|
|
|
PieceCID: fakePieceCid(t),
|
|
|
|
},
|
|
|
|
DealInfo: &piece.PieceDealInfo{
|
|
|
|
PublishCid: nil,
|
|
|
|
DealID: abi.DealID(44),
|
|
|
|
DealSchedule: piece.DealSchedule{
|
|
|
|
StartEpoch: abi.ChainEpoch(100_000),
|
|
|
|
EndEpoch: abi.ChainEpoch(1500_000),
|
|
|
|
},
|
|
|
|
PieceActivationManifest: &miner.PieceActivationManifest{
|
|
|
|
Size: 0,
|
|
|
|
VerifiedAllocationKey: nil,
|
|
|
|
Notify: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := pcp.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, abi.ChainEpoch(1500_000), exp)
|
|
|
|
}
|