lotus/storage/pipeline/precommit_policy_test.go
Łukasz Magiera 9e03fcab83
feat: sealing: Support nv22 DDO features in the sealing pipeline (#11226)
* Initial work supporting DDO pieces in lotus-miner

* sealing: Update pipeline input to operate on UniversalPiece

* sealing: Update pipeline checks/sealing states to operate on UniversalPiece

* sealing: Make pipeline build with UniversalPiece

* move PieceDealInfo out of api

* make gen

* make sealing pipeline unit tests pass

* fix itest ensemble build

* don't panic in SectorsStatus with deals

* stop linter from complaining about checkPieces

* fix sector import tests

* mod tidy

* sealing: Add logic for (pre)committing DDO sectors

* sealing: state-types with method defs

* DDO non-snap pipeline works(?), DDO Itests

* DDO support in snapdeals pipeline

* make gen

* update actor bundles

* update the gst market fix

* fix: chain: use PreCommitSectorsBatch2 when setting up genesis

* some bug fixes

* integration working changes

* update actor bundles

* Make TestOnboardRawPieceSnap pass

* Appease the linter

* Make deadlines test pass with v12 actors

* Update go-state-types, abstract market DealState

* make gen

* mod tidy, lint fixes

* Fix some more tests

* Bump version in master

Bump version in master

* Make gen

Make gen

* fix sender

* fix: lotus-provider: Fix winning PoSt

* fix: sql Scan cannot write to an object

* Actually show miner-addrs in info-log

Actually show miner-addrs in lotus-provider info-log

* [WIP] feat: Add nv22 skeleton

Addition of Network Version 22 skeleton

* update FFI

* ddo is now nv22

* make gen

* temp actor bundle with ddo

* use working go-state-types

* gst with v13 market migration

* update bundle, builtin.MethodsMiner.ProveCommitSectors2 -> 3

* actually working v13 migration, v13 migration itest

* Address review

* sealing: Correct DDO snap pledge math

* itests: Mixed ddo itest

* pipeline: Fix sectorWeight

* sealing: convert market deals into PAMs in mixed sectors

* sealing: make market to ddo conversion work

* fix lint

* update gst

* Update actors and GST to lastest integ branch

* commit batcher: Update ProveCommitSectors3Params builder logic

* make gen

* use builtin-actors master

* ddo: address review

* itests: Add commd assertions to ddo tests

* make gen

* gst with fixed types

* config knobs for RequireActivationSuccess

* storage: Drop obsolete flaky tasts

---------

Co-authored-by: Jennifer Wang <jiayingw703@gmail.com>
Co-authored-by: Aayush <arajasek94@gmail.com>
Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai>
Co-authored-by: Phi <orjan.roren@gmail.com>
Co-authored-by: Andrew Jackson (Ajax) <snadrus@gmail.com>
Co-authored-by: TippyFlits <james.bluett@protocol.ai>
2024-01-25 15:15:55 +01:00

245 lines
6.7 KiB
Go

package sealing_test
import (
"context"
"testing"
"time"
"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"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/policy"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"
pipeline "github.com/filecoin-project/lotus/storage/pipeline"
"github.com/filecoin-project/lotus/storage/pipeline/piece"
"github.com/filecoin-project/lotus/storage/pipeline/sealiface"
)
type fakeChain struct {
h abi.ChainEpoch
}
type fakeConfigStub struct {
CCSectorLifetime time.Duration
}
func fakeConfigGetter(stub *fakeConfigStub) dtypes.GetSealingConfigFunc {
return func() (sealiface.Config, error) {
if stub == nil {
return sealiface.Config{}, nil
}
return sealiface.Config{
CommittedCapacitySectorLifetime: stub.CCSectorLifetime,
}, nil
}
}
func (f *fakeChain) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) {
return build.TestNetworkVersion, nil
}
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)
}
func (f *fakeChain) ChainHead(ctx context.Context) (*types.TipSet, error) {
return makeTs(nil, f.h), nil
}
func fakePieceCid(t *testing.T) cid.Cid {
comm := [32]byte{1, 2, 3}
fakePieceCid, err := commcid.ReplicaCommitmentV1ToCID(comm[:])
require.NoError(t, err)
return fakePieceCid
}
func cidPtr(c cid.Cid) *cid.Cid {
return &c
}
func TestBasicPolicyEmptySector(t *testing.T) {
cfg := fakeConfigGetter(nil)
h := abi.ChainEpoch(55)
pBuffer := abi.ChainEpoch(2)
pcp := pipeline.NewBasicPreCommitPolicy(&fakeChain{h: h}, cfg, pBuffer)
exp, err := pcp.Expiration(context.Background())
require.NoError(t, err)
// as set when there are no deal pieces
maxExtension, err := policy.GetMaxSectorExpirationExtension(build.TestNetworkVersion)
assert.NoError(t, err)
expected := h + maxExtension - pBuffer
assert.Equal(t, int(expected), int(exp))
}
func TestCustomCCSectorConfig(t *testing.T) {
customLifetime := 200 * 24 * time.Hour
customLifetimeEpochs := abi.ChainEpoch(int64(customLifetime.Seconds()) / builtin.EpochDurationSeconds)
cfgStub := fakeConfigStub{CCSectorLifetime: customLifetime}
cfg := fakeConfigGetter(&cfgStub)
h := abi.ChainEpoch(55)
pBuffer := abi.ChainEpoch(2)
pcp := pipeline.NewBasicPreCommitPolicy(&fakeChain{h: h}, cfg, pBuffer)
exp, err := pcp.Expiration(context.Background())
require.NoError(t, err)
// as set when there are no deal pieces
expected := h + customLifetimeEpochs - pBuffer
assert.Equal(t, int(expected), int(exp))
}
func TestBasicPolicyMostConstrictiveSchedule(t *testing.T) {
cfg := fakeConfigGetter(nil)
policy := pipeline.NewBasicPreCommitPolicy(&fakeChain{
h: abi.ChainEpoch(55),
}, cfg, 2)
longestDealEpochEnd := abi.ChainEpoch(547300)
pieces := []pipeline.SafeSectorPiece{
pipeline.SafePiece(api.SectorPiece{
Piece: abi.PieceInfo{
Size: abi.PaddedPieceSize(1024),
PieceCID: fakePieceCid(t),
},
DealInfo: &piece.PieceDealInfo{
PublishCid: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
DealID: abi.DealID(42),
DealSchedule: piece.DealSchedule{
StartEpoch: abi.ChainEpoch(70),
EndEpoch: abi.ChainEpoch(547275),
},
},
}),
pipeline.SafePiece(api.SectorPiece{
Piece: abi.PieceInfo{
Size: abi.PaddedPieceSize(1024),
PieceCID: fakePieceCid(t),
},
DealInfo: &piece.PieceDealInfo{
PublishCid: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
DealID: abi.DealID(43),
DealSchedule: piece.DealSchedule{
StartEpoch: abi.ChainEpoch(80),
EndEpoch: longestDealEpochEnd,
},
},
}),
}
exp, err := policy.Expiration(context.Background(), pieces...)
require.NoError(t, err)
assert.Equal(t, int(longestDealEpochEnd), int(exp))
}
func TestBasicPolicyIgnoresExistingScheduleIfExpired(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: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
DealID: abi.DealID(44),
DealSchedule: piece.DealSchedule{
StartEpoch: abi.ChainEpoch(1),
EndEpoch: abi.ChainEpoch(10),
},
},
}),
}
exp, err := pcp.Expiration(context.Background(), pieces...)
require.NoError(t, err)
maxLifetime, err := policy.GetMaxSectorExpirationExtension(build.TestNetworkVersion)
require.NoError(t, err)
// Treated as a CC sector, so expiration becomes currEpoch + maxLifetime = 55 + 1555200
assert.Equal(t, 55+maxLifetime, exp)
}
func TestMissingDealIsIgnored(t *testing.T) {
cfg := fakeConfigGetter(nil)
policy := 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: cidPtr(fakePieceCid(t)), // pretend this is a valid builtin-market deal
DealID: abi.DealID(44),
DealSchedule: piece.DealSchedule{
StartEpoch: abi.ChainEpoch(1),
EndEpoch: abi.ChainEpoch(547300),
},
},
}),
pipeline.SafePiece(api.SectorPiece{
Piece: abi.PieceInfo{
Size: abi.PaddedPieceSize(1024),
PieceCID: fakePieceCid(t),
},
DealInfo: nil,
}),
}
exp, err := policy.Expiration(context.Background(), pieces...)
require.NoError(t, err)
assert.Equal(t, 547300, int(exp))
}