Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deflake prover node epoch proof quote test #11773

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
);

Comment on lines +441 to +449
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix (sometimes the node would broadcast the proof quote before the other peer would connect).

The rest of the diff in this PR is to fix some error in the logs I due to mocking

// 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