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
|
|
|
|
2020-09-17 15:30:15 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2021-06-01 09:45:34 +00:00
|
|
|
api "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"
|
2021-07-22 18:44:39 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
|
|
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
|
|
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-04-07 22:26:07 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func fakeConfigGetter(stub *fakeConfigStub) sealing.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-17 15:30:15 +00:00
|
|
|
func (f *fakeChain) StateNetworkVersion(ctx context.Context, tok sealing.TipSetToken) (network.Version, error) {
|
|
|
|
return build.NewestNetworkVersion, nil
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:26:07 +00:00
|
|
|
func (f *fakeChain) ChainHead(ctx context.Context) (sealing.TipSetToken, abi.ChainEpoch, error) {
|
|
|
|
return []byte{1, 2, 3}, f.h, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
pBoundary := abi.ChainEpoch(0)
|
|
|
|
pBuffer := abi.ChainEpoch(2)
|
|
|
|
pcp := sealing.NewBasicPreCommitPolicy(&fakeChain{h: h}, cfg, pBoundary, pBuffer)
|
|
|
|
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
|
|
|
|
expected := h + policy.GetMaxSectorExpirationExtension() - (pBuffer * 2)
|
|
|
|
// as set just before returning within Expiration()
|
|
|
|
expected += miner.WPoStProvingPeriod - (expected % miner.WPoStProvingPeriod) + pBoundary - 1
|
|
|
|
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)
|
|
|
|
pBoundary := abi.ChainEpoch(0)
|
|
|
|
pBuffer := abi.ChainEpoch(2)
|
|
|
|
pcp := sealing.NewBasicPreCommitPolicy(&fakeChain{h: h}, cfg, pBoundary, pBuffer)
|
|
|
|
exp, err := pcp.Expiration(context.Background())
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// as set when there are no deal pieces
|
|
|
|
expected := h + customLifetimeEpochs - (pBuffer * 2)
|
|
|
|
// as set just before returning within Expiration()
|
|
|
|
expected += miner.WPoStProvingPeriod - (expected % miner.WPoStProvingPeriod) + pBoundary - 1
|
|
|
|
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)
|
2021-07-22 18:44:39 +00:00
|
|
|
pPeriod := abi.ChainEpoch(11)
|
2020-04-07 22:26:07 +00:00
|
|
|
policy := sealing.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
2021-07-22 18:44:39 +00:00
|
|
|
}, cfg, pPeriod, 2)
|
|
|
|
longestDealEpochEnd := abi.ChainEpoch(100)
|
2020-04-08 14:52:20 +00:00
|
|
|
pieces := []sealing.Piece{
|
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
|
|
|
},
|
2021-06-01 09:45:34 +00:00
|
|
|
DealInfo: &api.PieceDealInfo{
|
2020-04-07 22:26:07 +00:00
|
|
|
DealID: abi.DealID(42),
|
2021-06-01 09:45:34 +00:00
|
|
|
DealSchedule: api.DealSchedule{
|
2020-04-07 22:26:07 +00:00
|
|
|
StartEpoch: abi.ChainEpoch(70),
|
|
|
|
EndEpoch: abi.ChainEpoch(75),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
|
|
},
|
2021-06-01 09:45:34 +00:00
|
|
|
DealInfo: &api.PieceDealInfo{
|
2020-04-07 22:26:07 +00:00
|
|
|
DealID: abi.DealID(43),
|
2021-06-01 09:45:34 +00:00
|
|
|
DealSchedule: api.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
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-22 18:44:39 +00:00
|
|
|
expected := longestDealEpochEnd + miner.WPoStProvingPeriod - (longestDealEpochEnd % miner.WPoStProvingPeriod) + pPeriod - 1
|
|
|
|
assert.Equal(t, int(expected), 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)
|
2020-04-07 22:26:07 +00:00
|
|
|
policy := sealing.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
2021-07-22 18:44:39 +00:00
|
|
|
}, cfg, 0, 0)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
pieces := []sealing.Piece{
|
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
|
|
|
},
|
2021-06-01 09:45:34 +00:00
|
|
|
DealInfo: &api.PieceDealInfo{
|
2020-04-07 22:26:07 +00:00
|
|
|
DealID: abi.DealID(44),
|
2021-06-01 09:45:34 +00:00
|
|
|
DealSchedule: api.DealSchedule{
|
2020-04-07 22:26:07 +00:00
|
|
|
StartEpoch: abi.ChainEpoch(1),
|
|
|
|
EndEpoch: abi.ChainEpoch(10),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-22 18:44:39 +00:00
|
|
|
assert.Equal(t, 1558079, int(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)
|
2020-04-07 22:26:07 +00:00
|
|
|
policy := sealing.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
2021-07-22 18:44:39 +00:00
|
|
|
}, cfg, 11, 0)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
pieces := []sealing.Piece{
|
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
|
|
|
},
|
2021-06-01 09:45:34 +00:00
|
|
|
DealInfo: &api.PieceDealInfo{
|
2020-04-07 22:26:07 +00:00
|
|
|
DealID: abi.DealID(44),
|
2021-06-01 09:45:34 +00:00
|
|
|
DealSchedule: api.DealSchedule{
|
2020-04-07 22:26:07 +00:00
|
|
|
StartEpoch: abi.ChainEpoch(1),
|
|
|
|
EndEpoch: abi.ChainEpoch(10),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-07-22 18:44:39 +00:00
|
|
|
assert.Equal(t, 1558090, int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|