From 5b1e9f2b909130a6198f1c395fdf7a360c2ea0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Thu, 4 Jan 2024 16:40:14 +0100 Subject: [PATCH] fix: flaky e2e-p2p test (#3831) Fixes #3654 **Note**: Lasse had a good hunch that it's most likely caused by different nodes using the same l1 publisher private key. This PR changes this and uses different accounts for different nodes. I am quite confident that that is the culprit so I will close the issue. --- .../end-to-end/src/e2e_p2p_network.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts index 5c2d746aa6a..a5888f24dcb 100644 --- a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts +++ b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts @@ -17,8 +17,13 @@ import { TestContractArtifact } from '@aztec/noir-contracts/Test'; import { BootstrapNode, P2PConfig, createLibP2PPeerId } from '@aztec/p2p'; import { ConstantKeyPair, PXEService, createPXEService, getPXEServiceConfig as getRpcConfig } from '@aztec/pxe'; +import { mnemonicToAccount } from 'viem/accounts'; + +import { MNEMONIC } from './fixtures/fixtures.js'; import { setup } from './fixtures/utils.js'; +// Don't set this to a higher value than 9 because each node will use a different L1 publisher account and anvil seeds +// only 10 accounts with ETH (9 and not 10 because first account is used by sandbox). const NUM_NODES = 4; const NUM_TXS_PER_BLOCK = 4; const NUM_TXS_PER_NODE = 2; @@ -55,7 +60,7 @@ describe('e2e_p2p_network', () => { // is if the txs are successfully gossiped around the nodes. const contexts: NodeContext[] = []; for (let i = 0; i < NUM_NODES; i++) { - const node = await createNode(i + 1 + BOOT_NODE_TCP_PORT, bootstrapNodeAddress); + const node = await createNode(i + 1 + BOOT_NODE_TCP_PORT, bootstrapNodeAddress, i); const context = await createPXEServiceAndSubmitTransactions(node, NUM_TXS_PER_NODE); contexts.push(context); } @@ -107,7 +112,13 @@ describe('e2e_p2p_network', () => { }; // creates a P2P enabled instance of Aztec Node Service - const createNode = async (tcpListenPort: number, bootstrapNode: string) => { + const createNode = async (tcpListenPort: number, bootstrapNode: string, publisherAddressIndex: number) => { + // We use different L1 publisher accounts in order to avoid duplicate tx nonces. We start from + // publisherAddressIndex + 1 because index 0 was already used during sandbox setup. + const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: publisherAddressIndex + 1 }); + const publisherPrivKey = Buffer.from(hdAccount.getHdKey().privateKey!); + config.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`; + const newConfig: AztecNodeConfig = { ...config, tcpListenPort,