Skip to content

Commit

Permalink
fix: deflake prover node epoch proof quote test (#11773)
Browse files Browse the repository at this point in the history
This PR modifies one of the prover node tests to wait for peers to
connect before broadcasting proof quotes.
  • Loading branch information
alexghr authored Feb 6, 2025
1 parent 20f5653 commit 04e1061
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions yarn-project/prover-node/src/prover-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
} from '@aztec/circuit-types';
import { type ContractDataSource, EthAddress } from '@aztec/circuits.js';
import { type EpochCache } from '@aztec/epoch-cache';
import { times, timesParallel } from '@aztec/foundation/collection';
import { timesParallel } from '@aztec/foundation/collection';
import { Signature } from '@aztec/foundation/eth-signature';
import { makeBackoff, retry } from '@aztec/foundation/retry';
import { retryUntil } from '@aztec/foundation/retry';
import { sleep } from '@aztec/foundation/sleep';
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
import { type BootstrapNode, InMemoryTxPool, MemoryEpochProofQuotePool, P2PClient } from '@aztec/p2p';
Expand Down Expand Up @@ -147,8 +147,21 @@ describe('prover-node', () => {
blocks = await timesParallel(3, async i => await L2Block.random(i + 20, 1));

// Archiver returns a bunch of fake blocks
l2BlockSource.getBlocks.mockImplementation((from, limit) => {
const startBlockIndex = blocks.findIndex(b => b.number === from);
if (startBlockIndex > -1) {
return Promise.resolve(blocks.slice(startBlockIndex, startBlockIndex + limit));
} else {
return Promise.resolve([]);
}
});
l2BlockSource.getBlocksForEpoch.mockResolvedValue(blocks);
l2BlockSource.getL1Constants.mockResolvedValue(EmptyL1RollupConstants);
l2BlockSource.getL2Tips.mockResolvedValue({
latest: { number: blocks.at(-1)!.number, hash: (await blocks.at(-1)!.hash()).toString() },
proven: { number: 0, hash: undefined },
finalized: { number: 0, hash: undefined },
});

// Coordination plays along and returns a tx whenever requested
mockCoordination.getTxsByHash.mockImplementation(hashes =>
Expand Down Expand Up @@ -425,6 +438,15 @@ describe('prover-node', () => {
ts: BigInt(Date.now()),
});

await retryUntil(
async () => {
return (await proverNode.getP2P()!.getPeers()).length > 0;
},
'wait for peers to connect',
20,
1,
);

// Check that the p2p client receives the quote (casted as any to access private property)
const p2pEpochReceivedSpy = jest.spyOn((otherP2PClient as any).p2pService, 'processEpochProofQuoteFromPeer');

Expand All @@ -435,14 +457,15 @@ describe('prover-node', () => {
await proverNode.handleEpochCompleted(epochNumber);

// Wait for message to be propagated
await retry(
await retryUntil(
// eslint-disable-next-line require-await
async () => {
// Check the other node received a quote via p2p
expect(p2pEpochReceivedSpy).toHaveBeenCalledTimes(1);
return p2pEpochReceivedSpy.mock.calls.length > 0;
},
'Waiting for quote to be received',
makeBackoff(times(20, () => 1)),
20,
1,
);

// We should be able to retreive the quote from the other node
Expand Down

0 comments on commit 04e1061

Please sign in to comment.