Skip to content

Commit

Permalink
fix: flaky e2e-p2p test (#3831)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benesjan authored Jan 4, 2024
1 parent 2e0776a commit 5b1e9f2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions yarn-project/end-to-end/src/e2e_p2p_network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5b1e9f2

Please sign in to comment.