Skip to content

Commit

Permalink
test: niporep: test for events and bad deadlines
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 21, 2024
1 parent d692e0b commit e453875
Showing 1 changed file with 63 additions and 14 deletions.
77 changes: 63 additions & 14 deletions itests/niporep_manual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ package itests

import (
"context"
"fmt"
"testing"
"time"

"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/codec/dagcbor"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/basicnode"
"github.com/multiformats/go-multicodec"
"github.com/stretchr/testify/require"

"github.com/filecoin-project/go-address"
Expand All @@ -16,7 +22,9 @@ import (

"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/lib/must"
)

func TestManualNISectorOnboarding(t *testing.T) {
Expand Down Expand Up @@ -94,6 +102,23 @@ func TestManualNISectorOnboarding(t *testing.T) {
bSectorNum, bRespCh, bWdPostCancelF = minerB.OnboardCCSector(ctx, sealProofType)
// Miner B should still not have power as power can only be gained after sector is activated i.e. the first WindowPost is submitted for it
minerB.AssertNoPower(ctx)

{
expectedEntries := []types.EventEntry{
{Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "$type", Value: must.One(ipld.Encode(basicnode.NewString("sector-activated"), dagcbor.Encode))},
{Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "sector", Value: must.One(ipld.Encode(basicnode.NewInt(int64(bSectorNum)), dagcbor.Encode))},
// TODO: should be a null CID but is currently an empty unsealed, needs fix in actors
// {Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "unsealed-cid", Value: must.One(ipld.Encode(datamodel.Null, dagcbor.Encode))},
{Flags: 0x03, Codec: uint64(multicodec.Cbor), Key: "unsealed-cid", Value: must.One(ipld.Encode(basicnode.NewLink(cidlink.Link{Cid: cid.MustParse("baga6ea4seaqpy7usqklokfx2vxuynmupslkeutzexe2uqurdg5vhtebhxqmpqmy")}), dagcbor.Encode))},
}
from := head.Height()
recentEvents, err := client.FullNode.GetActorEventsRaw(ctx, &types.ActorEventFilter{FromHeight: &from})
req.NoError(err)
t.Logf("Recent events: %+v", recentEvents)
req.Len(recentEvents, 1)
req.Equal(expectedEntries, recentEvents[0].Entries)
}

// Ensure that the block miner checks for and waits for posts during the appropriate proving window from our new miner with a sector
blockMiner.WatchMinerForPost(minerB.ActorAddr)

Expand Down Expand Up @@ -122,21 +147,31 @@ func verifyProveCommitSectorsNIErrorConditions(ctx context.Context, t *testing.T
req.NoError(err)
actorId := abi.ActorID(actorIdNum)

submitAndFail := func(params *miner14.ProveCommitSectorsNIParams, errMsg string) {
di, err := miner.FullNode.StateMinerProvingDeadline(ctx, miner.ActorAddr, head.Key())
req.NoError(err)

var provingDeadline uint64 = 7
// don't rely on di.Index because we haven't enrolled in cron so it's not ticking
currentDeadline := uint64((di.CurrentEpoch - di.PeriodStart) / di.WPoStChallengeWindow)
if currentDeadline == provingDeadline || currentDeadline == provingDeadline-1 {
// avoid immutable deadlines
provingDeadline = 5
}

submitAndFail := func(params *miner14.ProveCommitSectorsNIParams, errMsg string, errCode int) {
t.Helper()

_, err = miner.SubmitMessage(ctx, params, 1, builtin.MethodsMiner.ProveCommitSectorsNI)
req.Error(err)
t.Logf("Error: %+v", err)
req.Contains(err.Error(), errMsg)
if errMsg != "call ran out of gas" { // TODO: see below, this needs to be removed when actors is fixed
req.Contains(err.Error(), "(RetCode=16)")
if errCode > 0 {
req.Contains(err.Error(), fmt.Sprintf("(RetCode=%d)", errCode))
}
}

sn := abi.SectorNumber(5000)
mkSai := func() miner14.SectorNIActivationInfo {
sn += 1
sn++
return miner14.SectorNIActivationInfo{
SealingNumber: sn,
SealerID: actorId,
Expand All @@ -152,15 +187,15 @@ func verifyProveCommitSectorsNIErrorConditions(ctx context.Context, t *testing.T
AggregateProof: []byte{0xca, 0xfe, 0xbe, 0xef},
SealProofType: sealProofType,
AggregateProofType: abi.RegisteredAggregationProof_SnarkPackV2,
ProvingDeadline: 7,
ProvingDeadline: provingDeadline,
RequireActivationSuccess: true,
}
}

// Test message rejection on no sectors
params := mkParams()
params.Sectors = []miner14.SectorNIActivationInfo{}
submitAndFail(&params, "too few sectors")
submitAndFail(&params, "too few sectors", 16)

// Test message rejection on too many sectors
sectorInfos := make([]miner14.SectorNIActivationInfo, 66)
Expand All @@ -169,34 +204,48 @@ func verifyProveCommitSectorsNIErrorConditions(ctx context.Context, t *testing.T
}
params = mkParams()
params.Sectors = sectorInfos
submitAndFail(&params, "too many sectors")
submitAndFail(&params, "too many sectors", 16)

// Test bad aggregation proof type
params = mkParams()
params.AggregateProofType = abi.RegisteredAggregationProof_SnarkPackV1
submitAndFail(&params, "aggregate proof type")
submitAndFail(&params, "aggregate proof type", 16)

// Test bad SealerID
params = mkParams()
params.Sectors[1].SealerID = 1234
submitAndFail(&params, "invalid NI commit 1 while requiring activation success")
submitAndFail(&params, "invalid NI commit 1 while requiring activation success", 16)

// Test bad SealingNumber
params = mkParams()
params.Sectors[1].SealingNumber = 1234
submitAndFail(&params, "invalid NI commit 1 while requiring activation success")
submitAndFail(&params, "invalid NI commit 1 while requiring activation success", 16)

// Test bad SealedCID
params = mkParams()
params.Sectors[1].SealedCID = cid.MustParse("baga6ea4seaqjtovkwk4myyzj56eztkh5pzsk5upksan6f5outesy62bsvl4dsha")
submitAndFail(&params, "invalid NI commit 1 while requiring activation success")
submitAndFail(&params, "invalid NI commit 1 while requiring activation success", 16)

// Test bad SealRandEpoch
head, err = miner.FullNode.ChainHead(ctx)
req.NoError(err)
params = mkParams()
params.Sectors[1].SealRandEpoch = head.Height() + builtin.EpochsInDay
submitAndFail(&params, "call ran out of gas") // TODO: when actors is fixed, this should be: "invalid NI commit 1 while requiring activation success")
submitAndFail(&params, "call ran out of gas", -1) // TODO: when actors is fixed, this should be: "invalid NI commit 1 while requiring activation success", 16)
params.Sectors[1].SealRandEpoch = head.Height() - 190*builtin.EpochsInDay
submitAndFail(&params, "invalid NI commit 1 while requiring activation success")
submitAndFail(&params, "invalid NI commit 1 while requiring activation success", 16)

// Immutable/bad deadlines
di, err = miner.FullNode.StateMinerProvingDeadline(ctx, miner.ActorAddr, head.Key())
req.NoError(err)
// recalculate in case the chain has moved on
currentDeadline = uint64((di.CurrentEpoch - di.PeriodStart) / di.WPoStChallengeWindow)
params = mkParams()
params.ProvingDeadline = currentDeadline
submitAndFail(&params, fmt.Sprintf("proving deadline %d must not be the current or next deadline", currentDeadline), 18)
params.ProvingDeadline = currentDeadline + 1
submitAndFail(&params, fmt.Sprintf("proving deadline %d must not be the current or next deadline", currentDeadline+1), 18)
params.ProvingDeadline = di.WPoStPeriodDeadlines // too big
submitAndFail(&params, fmt.Sprintf("proving deadline index %d invalid", di.WPoStPeriodDeadlines), 16)

}

0 comments on commit e453875

Please sign in to comment.