Skip to content

Commit 9d2cf9f

Browse files
authored
test(e2e): wait for archiver sync before asserting pipelining (#22997)
Alternative fix for flake in epochs_mbps.pipeline. See also https://gist.github.com/AztecBot/164f3e04bd74f48cafd6505433935421.
1 parent e62bd70 commit 9d2cf9f

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

yarn-project/end-to-end/src/e2e_epochs/epochs_mbps.pipeline.parallel.test.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { asyncMap } from '@aztec/foundation/async-map';
1212
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
1313
import { times, timesAsync } from '@aztec/foundation/collection';
1414
import { SecretValue } from '@aztec/foundation/config';
15+
import { retryUntil } from '@aztec/foundation/retry';
1516
import { bufferToHex } from '@aztec/foundation/string';
1617
import { executeTimeout } from '@aztec/foundation/timer';
1718
import { TestContract } from '@aztec/noir-test-contracts.js/Test';
@@ -113,8 +114,25 @@ describe('e2e_epochs/epochs_mbps_pipeline', () => {
113114
logger.warn(`Test setup completed.`, { validators: validators.map(v => v.attester.toString()) });
114115
}
115116

116-
/** Retrieves all checkpoints from the archiver, checks that one has the target block count, and returns its number. */
117-
async function assertMultipleBlocksPerSlot(targetBlockCount: number, logger: Logger): Promise<CheckpointNumber> {
117+
/**
118+
* Waits until the archiver's checkpointed chain tip has reached `targetBlockNumber`, then retrieves all checkpoints,
119+
* checks that one has the target block count, and returns its number.
120+
*/
121+
async function assertMultipleBlocksPerSlot(
122+
targetBlockCount: number,
123+
targetBlockNumber: BlockNumber,
124+
logger: Logger,
125+
): Promise<CheckpointNumber> {
126+
await retryUntil(
127+
async () => {
128+
const checkpointed = await archiver.getBlockNumber({ tag: 'checkpointed' });
129+
return checkpointed !== undefined && checkpointed >= targetBlockNumber;
130+
},
131+
`archiver checkpointed block ${targetBlockNumber}`,
132+
10,
133+
0.1,
134+
);
135+
118136
const checkpoints = await archiver.getCheckpoints({ from: CheckpointNumber(1), limit: 50 });
119137
logger.warn(`Retrieved ${checkpoints.length} checkpoints from archiver`, {
120138
checkpoints: checkpoints.map(pc => pc.checkpoint.getStats()),
@@ -253,14 +271,19 @@ describe('e2e_epochs/epochs_mbps_pipeline', () => {
253271

254272
// Wait until all txs are mined
255273
const timeout = test.L2_SLOT_DURATION_IN_S * 5;
256-
await executeTimeout(
274+
const receipts = await executeTimeout(
257275
() => Promise.all(txHashes.map(txHash => waitForTx(context.aztecNode, txHash, { timeout }))),
258276
timeout * 1000,
259277
);
260278
logger.warn(`All txs have been mined`);
261279

262-
// Verify MBPS works with pipelining
263-
const multiBlockCheckpoint = await assertMultipleBlocksPerSlot(EXPECTED_BLOCKS_PER_CHECKPOINT, logger);
280+
// Verify MBPS works with pipelining; target the highest block number across mined receipts
281+
const maxMinedBlockNumber = BlockNumber(Math.max(...receipts.map(r => r.blockNumber ?? 0)));
282+
const multiBlockCheckpoint = await assertMultipleBlocksPerSlot(
283+
EXPECTED_BLOCKS_PER_CHECKPOINT,
284+
maxMinedBlockNumber,
285+
logger,
286+
);
264287

265288
// Verify the pipelining offset: build slot N vs submission slot N+1
266289
await assertProposerPipelining(blockProposedEvents, logger);
@@ -348,14 +371,15 @@ describe('e2e_epochs/epochs_mbps_pipeline', () => {
348371

349372
// Wait for a new checkpoint (recovery) - where all txs end up mined
350373
const timeout = test.L2_SLOT_DURATION_IN_S * 5;
351-
await executeTimeout(
374+
const receipts = await executeTimeout(
352375
() => Promise.all(txHashes.map(txHash => waitForTx(context.aztecNode, txHash, { timeout }))),
353376
timeout * 1000,
354377
);
355378
logger.warn(`All txs have been mined`);
356379

357-
// Verify MBPS works with pipelining
358-
await assertMultipleBlocksPerSlot(EXPECTED_BLOCKS_PER_CHECKPOINT, logger);
380+
// Verify MBPS works with pipelining; target the highest block number across mined receipts
381+
const maxMinedBlockNumber = BlockNumber(Math.max(...receipts.map(r => r.blockNumber ?? 0)));
382+
await assertMultipleBlocksPerSlot(EXPECTED_BLOCKS_PER_CHECKPOINT, maxMinedBlockNumber, logger);
359383

360384
// Verify the pipelining offset: build slot N vs submission slot N+1
361385
await assertProposerPipelining(blockProposedEvents, logger);

0 commit comments

Comments
 (0)