From 9716b2b90746143c8f9b335ebb841284e7355292 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Wed, 19 Jun 2024 15:46:48 +1000 Subject: [PATCH] fix: itest: fix wdpost proving epoch calculation Fixes: https://github.com/filecoin-project/lotus/issues/12091 --- itests/kit/blockminer.go | 5 ++++- itests/kit/node_unmanaged.go | 33 ++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/itests/kit/blockminer.go b/itests/kit/blockminer.go index 75842567819..32797182be7 100644 --- a/itests/kit/blockminer.go +++ b/itests/kit/blockminer.go @@ -100,6 +100,7 @@ func newPartitionTracker(ctx context.Context, t *testing.T, client v1api.FullNod parts, err := client.StateMinerPartitions(ctx, minerAddr, dlIdx, types.EmptyTSK) require.NoError(t, err) + return &partitionTracker{ minerAddr: minerAddr, partitions: parts, @@ -245,7 +246,9 @@ func (bm *BlockMiner) MineBlocksMustPost(ctx context.Context, blocktime time.Dur dlinfo, err := bm.miner.FullNode.StateMinerProvingDeadline(ctx, minerAddr, ts.Key()) require.NoError(bm.t, err) require.NotNil(bm.t, dlinfo, "no deadline info for miner %s", minerAddr) - impendingDeadlines = append(impendingDeadlines, minerDeadline{addr: minerAddr, deadline: *dlinfo}) + if dlinfo.Open < dlinfo.CurrentEpoch { + impendingDeadlines = append(impendingDeadlines, minerDeadline{addr: minerAddr, deadline: *dlinfo}) + } // else this is probably a new miner, not starting in this proving period } bm.postWatchMinersLk.Unlock() impendingDeadlines = impendingDeadlines.FilterByLast(ts.Height() + 5 + abi.ChainEpoch(nulls)) diff --git a/itests/kit/node_unmanaged.go b/itests/kit/node_unmanaged.go index 8f294046868..0b5d2f88101 100644 --- a/itests/kit/node_unmanaged.go +++ b/itests/kit/node_unmanaged.go @@ -551,6 +551,9 @@ func (tm *TestUnmanagedMiner) wdPostLoop(ctx context.Context, sectorNumber abi.S err = tm.submitWindowPost(ctx, sectorNumber, sealedCid, sealedPath, cacheDir) writeRespF(err) // send an error, or first post, or nothing if no error and this isn't the first post + if err != nil { + return + } postCount++ tm.t.Logf("Sector %d: WindowPoSt #%d submitted", sectorNumber, postCount) } @@ -772,14 +775,6 @@ func (tm *TestUnmanagedMiner) calculateNextPostEpoch( return 0, 0, fmt.Errorf("failed to get chain head: %w", err) } - // Fetch the sector partition for the given sector number - sp, err := tm.FullNode.StateSectorPartition(ctx, tm.ActorAddr, sectorNumber, head.Key()) - if err != nil { - return 0, 0, fmt.Errorf("failed to get sector partition: %w", err) - } - - tm.t.Logf("Miner %s: WindowPoST(%d): SectorPartition: %+v", tm.ActorAddr, sectorNumber, sp) - // Obtain the proving deadline information for the miner di, err := tm.FullNode.StateMinerProvingDeadline(ctx, tm.ActorAddr, head.Key()) if err != nil { @@ -788,6 +783,26 @@ func (tm *TestUnmanagedMiner) calculateNextPostEpoch( tm.t.Logf("Miner %s: WindowPoST(%d): ProvingDeadline: %+v", tm.ActorAddr, sectorNumber, di) + if di.Open > di.CurrentEpoch { + tm.t.Logf("Miner %s: WindowPoST(%d): Waiting for proving period to start...", tm.ActorAddr, sectorNumber) + // special case, first sector onboarded, cron hasn't run deadline tick yet, wait one challenge window + // and we'll get a cleaner dline.Info + _ = tm.FullNode.WaitTillChain(ctx, HeightAtLeast(di.CurrentEpoch+di.WPoStChallengeWindow)) + di, err = tm.FullNode.StateMinerProvingDeadline(ctx, tm.ActorAddr, head.Key()) + if err != nil { + return 0, 0, fmt.Errorf("failed to get proving deadline: %w", err) + } + tm.t.Logf("Miner %s: WindowPoST(%d): ProvingDeadline: %+v", tm.ActorAddr, sectorNumber, di) + } + + // Fetch the sector partition for the given sector number + sp, err := tm.FullNode.StateSectorPartition(ctx, tm.ActorAddr, sectorNumber, head.Key()) + if err != nil { + return 0, 0, fmt.Errorf("failed to get sector partition: %w", err) + } + + tm.t.Logf("Miner %s: WindowPoST(%d): SectorPartition: %+v", tm.ActorAddr, sectorNumber, sp) + // Calculate the start of the period, adjusting if the current deadline has passed periodStart := di.PeriodStart if di.PeriodStart < di.CurrentEpoch && sp.Deadline <= di.Index { @@ -796,7 +811,7 @@ func (tm *TestUnmanagedMiner) calculateNextPostEpoch( } // Calculate the exact epoch when proving should occur - provingEpoch := periodStart + (di.WPoStProvingPeriod/abi.ChainEpoch(di.WPoStPeriodDeadlines))*abi.ChainEpoch(sp.Deadline) + provingEpoch := periodStart + di.WPoStChallengeWindow*abi.ChainEpoch(sp.Deadline) tm.t.Logf("Miner %s: WindowPoST(%d): next ProvingEpoch: %d", tm.ActorAddr, sectorNumber, provingEpoch)