-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathgossip_network.test.ts
88 lines (75 loc) · 2.95 KB
/
gossip_network.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { type AztecNodeService } from '@aztec/aztec-node';
import { sleep } from '@aztec/aztec.js';
import fs from 'fs';
import { shouldCollectMetrics } from '../fixtures/fixtures.js';
import { type NodeContext, createNodes } from '../fixtures/setup_p2p_test.js';
import { P2PNetworkTest, WAIT_FOR_TX_TIMEOUT } from './p2p_network.js';
import { createPXEServiceAndSubmitTransactions } from './shared.js';
// Don't set this to a higher value than 9 because each node will use a different L1 publisher account and anvil seeds
const NUM_NODES = 4;
const NUM_TXS_PER_NODE = 2;
const BOOT_NODE_UDP_PORT = 40600;
const DATA_DIR = './data/gossip';
describe('e2e_p2p_network', () => {
let t: P2PNetworkTest;
let nodes: AztecNodeService[];
beforeEach(async () => {
t = await P2PNetworkTest.create({
testName: 'e2e_p2p_network',
numberOfNodes: NUM_NODES,
basePort: BOOT_NODE_UDP_PORT,
// To collect metrics - run in aztec-packages `docker compose --profile metrics up` and set COLLECT_METRICS=true
metricsPort: shouldCollectMetrics(),
});
await t.applyBaseSnapshots();
await t.setup();
});
afterEach(async () => {
await t.stopNodes(nodes);
await t.teardown();
for (let i = 0; i < NUM_NODES; i++) {
fs.rmSync(`${DATA_DIR}-${i}`, { recursive: true, force: true });
}
});
it('should rollup txs from all peers', async () => {
// create the bootstrap node for the network
if (!t.bootstrapNodeEnr) {
throw new Error('Bootstrap node ENR is not available');
}
t.ctx.aztecNodeConfig.validatorReexecute = true;
// create our network of nodes and submit txs into each of them
// the number of txs per node and the number of txs per rollup
// should be set so that the only way for rollups to be built
// is if the txs are successfully gossiped around the nodes.
const contexts: NodeContext[] = [];
t.logger.info('Creating nodes');
nodes = await createNodes(
t.ctx.aztecNodeConfig,
t.peerIdPrivateKeys,
t.bootstrapNodeEnr,
NUM_NODES,
BOOT_NODE_UDP_PORT,
DATA_DIR,
// To collect metrics - run in aztec-packages `docker compose --profile metrics up` and set COLLECT_METRICS=true
shouldCollectMetrics(),
);
// wait a bit for peers to discover each other
await sleep(4000);
t.logger.info('Submitting transactions');
for (const node of nodes) {
const context = await createPXEServiceAndSubmitTransactions(t.logger, node, NUM_TXS_PER_NODE);
contexts.push(context);
}
t.logger.info('Waiting for transactions to be mined');
// now ensure that all txs were successfully mined
await Promise.all(
contexts.flatMap((context, i) =>
context.txs.map(async (tx, j) => {
t.logger.info(`Waiting for tx ${i}-${j}: ${await tx.getTxHash()} to be mined`);
return tx.wait({ timeout: WAIT_FOR_TX_TIMEOUT });
}),
),
);
t.logger.info('All transactions mined');
});
});