@aztec/end-to-end 0.0.1-commit.54489865 → 0.0.1-commit.592b9384
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
- package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
- package/dest/e2e_p2p/reqresp/utils.js +153 -0
- package/dest/fixtures/ha_setup.d.ts +71 -0
- package/dest/fixtures/ha_setup.d.ts.map +1 -0
- package/dest/fixtures/ha_setup.js +114 -0
- package/dest/fixtures/index.d.ts +2 -1
- package/dest/fixtures/index.d.ts.map +1 -1
- package/dest/fixtures/index.js +1 -0
- package/dest/spartan/utils/nodes.d.ts +1 -1
- package/dest/spartan/utils/nodes.d.ts.map +1 -1
- package/dest/spartan/utils/nodes.js +7 -1
- package/package.json +42 -39
- package/src/e2e_p2p/reqresp/utils.ts +207 -0
- package/src/fixtures/ha_setup.ts +184 -0
- package/src/fixtures/index.ts +1 -0
- package/src/spartan/utils/nodes.ts +3 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
+
import { P2PNetworkTest } from '../p2p_network.js';
|
|
3
|
+
export declare const NUM_VALIDATORS = 6;
|
|
4
|
+
export declare const NUM_TXS_PER_NODE = 2;
|
|
5
|
+
export declare const BOOT_NODE_UDP_PORT = 4500;
|
|
6
|
+
export declare const createReqrespDataDir: () => string;
|
|
7
|
+
type ReqrespOptions = {
|
|
8
|
+
disableStatusHandshake?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function createReqrespTest(options?: ReqrespOptions): Promise<P2PNetworkTest>;
|
|
11
|
+
export declare function cleanupReqrespTest(params: {
|
|
12
|
+
t: P2PNetworkTest;
|
|
13
|
+
nodes?: AztecNodeService[];
|
|
14
|
+
dataDir: string;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
export declare function runReqrespTxTest(params: {
|
|
17
|
+
t: P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CLE9BQU8sRUFBRSxNQUFNLENBQUM7SUFDaEIsc0JBQXNCLENBQUMsRUFBRSxPQUFPLENBQUM7Q0FDbEMsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQyxDQXdHOUIifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/e2e_p2p/reqresp/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAgB1D,OAAO,EAAE,cAAc,EAA8D,MAAM,mBAAmB,CAAC;AAI/G,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC,eAAO,MAAM,oBAAoB,cAA2D,CAAC;AAE7F,KAAK,cAAc,GAAG;IACpB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,cAAc,CAAC,CAoB7F;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE;IAAE,CAAC,EAAE,cAAc,CAAC;IAAC,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,iBASlH;AAID,wBAAsB,gBAAgB,CAAC,MAAM,EAAE;IAC7C,CAAC,EAAE,cAAc,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAwG9B"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
3
|
+
import { Tx } from '@aztec/aztec.js/tx';
|
|
4
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
5
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
|
+
import { timesAsync } from '@aztec/foundation/collection';
|
|
7
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
8
|
+
import { jest } from '@jest/globals';
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import os from 'os';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import { shouldCollectMetrics } from '../../fixtures/fixtures.js';
|
|
13
|
+
import { createNodes } from '../../fixtures/setup_p2p_test.js';
|
|
14
|
+
import { P2PNetworkTest, SHORTENED_BLOCK_TIME_CONFIG_NO_PRUNES, WAIT_FOR_TX_TIMEOUT } from '../p2p_network.js';
|
|
15
|
+
import { prepareTransactions } from '../shared.js';
|
|
16
|
+
// Don't set this to a higher value than 9 because each node will use a different L1 publisher account and anvil seeds
|
|
17
|
+
export const NUM_VALIDATORS = 6;
|
|
18
|
+
export const NUM_TXS_PER_NODE = 2;
|
|
19
|
+
export const BOOT_NODE_UDP_PORT = 4500;
|
|
20
|
+
export const createReqrespDataDir = ()=>fs.mkdtempSync(path.join(os.tmpdir(), 'reqresp-'));
|
|
21
|
+
export async function createReqrespTest(options = {}) {
|
|
22
|
+
const { disableStatusHandshake = false } = options;
|
|
23
|
+
const t = await P2PNetworkTest.create({
|
|
24
|
+
testName: 'e2e_p2p_reqresp_tx',
|
|
25
|
+
numberOfNodes: 0,
|
|
26
|
+
numberOfValidators: NUM_VALIDATORS,
|
|
27
|
+
basePort: BOOT_NODE_UDP_PORT,
|
|
28
|
+
// To collect metrics - run in aztec-packages `docker compose --profile metrics up`
|
|
29
|
+
metricsPort: shouldCollectMetrics(),
|
|
30
|
+
initialConfig: {
|
|
31
|
+
...SHORTENED_BLOCK_TIME_CONFIG_NO_PRUNES,
|
|
32
|
+
aztecSlotDuration: 24,
|
|
33
|
+
...disableStatusHandshake ? {
|
|
34
|
+
p2pDisableStatusHandshake: true
|
|
35
|
+
} : {},
|
|
36
|
+
listenAddress: '127.0.0.1',
|
|
37
|
+
aztecEpochDuration: 64
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await t.setup();
|
|
41
|
+
await t.applyBaseSetup();
|
|
42
|
+
return t;
|
|
43
|
+
}
|
|
44
|
+
export async function cleanupReqrespTest(params) {
|
|
45
|
+
const { t, nodes, dataDir } = params;
|
|
46
|
+
if (nodes) {
|
|
47
|
+
await t.stopNodes(nodes);
|
|
48
|
+
}
|
|
49
|
+
await t.teardown();
|
|
50
|
+
for(let i = 0; i < NUM_VALIDATORS; i++){
|
|
51
|
+
fs.rmSync(`${dataDir}-${i}`, {
|
|
52
|
+
recursive: true,
|
|
53
|
+
force: true,
|
|
54
|
+
maxRetries: 3
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const getNodePort = (nodeIndex)=>BOOT_NODE_UDP_PORT + 1 + nodeIndex;
|
|
59
|
+
export async function runReqrespTxTest(params) {
|
|
60
|
+
const { t, dataDir, disableStatusHandshake = false } = params;
|
|
61
|
+
if (!t.bootstrapNodeEnr) {
|
|
62
|
+
throw new Error('Bootstrap node ENR is not available');
|
|
63
|
+
}
|
|
64
|
+
t.logger.info('Creating nodes');
|
|
65
|
+
const aztecNodeConfig = disableStatusHandshake ? {
|
|
66
|
+
...t.ctx.aztecNodeConfig,
|
|
67
|
+
p2pDisableStatusHandshake: true
|
|
68
|
+
} : t.ctx.aztecNodeConfig;
|
|
69
|
+
const nodes = await createNodes(aztecNodeConfig, t.ctx.dateProvider, t.bootstrapNodeEnr, NUM_VALIDATORS, BOOT_NODE_UDP_PORT, t.prefilledPublicData, dataDir, shouldCollectMetrics());
|
|
70
|
+
t.logger.info('Waiting for nodes to connect');
|
|
71
|
+
await t.waitForP2PMeshConnectivity(nodes, NUM_VALIDATORS);
|
|
72
|
+
await t.setupAccount();
|
|
73
|
+
const targetBlockNumber = await t.ctx.aztecNodeService.getBlockNumber();
|
|
74
|
+
await retryUntil(async ()=>{
|
|
75
|
+
const blockNumbers = await Promise.all(nodes.map((node)=>node.getBlockNumber()));
|
|
76
|
+
return blockNumbers.every((blockNumber)=>blockNumber >= targetBlockNumber) ? true : undefined;
|
|
77
|
+
}, `validators to sync to L2 block ${targetBlockNumber}`, 60, 0.5);
|
|
78
|
+
t.logger.info('Preparing transactions to send');
|
|
79
|
+
const txBatches = await timesAsync(2, ()=>prepareTransactions(t.logger, t.ctx.aztecNodeService, NUM_TXS_PER_NODE, t.fundedAccount));
|
|
80
|
+
t.logger.info('Removing initial node');
|
|
81
|
+
await t.removeInitialNode();
|
|
82
|
+
t.logger.info('Starting fresh slot');
|
|
83
|
+
const [timestamp] = await t.ctx.cheatCodes.rollup.advanceToNextSlot();
|
|
84
|
+
t.ctx.dateProvider.setTime(Number(timestamp) * 1000);
|
|
85
|
+
const startSlotTimestamp = BigInt(timestamp);
|
|
86
|
+
const { proposerIndexes, nodesToTurnOffTxGossip } = await getProposerIndexes(t, startSlotTimestamp);
|
|
87
|
+
t.logger.info(`Turning off tx gossip for nodes: ${nodesToTurnOffTxGossip.map(getNodePort)}`);
|
|
88
|
+
t.logger.info(`Sending txs to proposer nodes: ${proposerIndexes.map(getNodePort)}`);
|
|
89
|
+
// Replace the p2p node implementation of some of the nodes with a spy such that it does not store transactions that are gossiped to it
|
|
90
|
+
// Original implementation of `handleGossipedTx` will store received transactions in the tx pool.
|
|
91
|
+
// We chose the first 2 nodes that will be the proposers for the next few slots
|
|
92
|
+
for (const nodeIndex of nodesToTurnOffTxGossip){
|
|
93
|
+
const logger = createLogger(`p2p:${getNodePort(nodeIndex)}`);
|
|
94
|
+
jest.spyOn(nodes[nodeIndex].p2pClient.p2pService, 'handleGossipedTx').mockImplementation((payloadData)=>{
|
|
95
|
+
const txHash = Tx.fromBuffer(payloadData).getTxHash();
|
|
96
|
+
logger.info(`Skipping storage of gossiped transaction ${txHash.toString()}`);
|
|
97
|
+
return Promise.resolve();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// We send the tx to the proposer nodes directly, ignoring the pxe and node in each context
|
|
101
|
+
// We cannot just call tx.send since they were created using a pxe wired to the first node which is now stopped
|
|
102
|
+
t.logger.info('Sending transactions through proposer nodes');
|
|
103
|
+
const submittedTxs = await Promise.all(txBatches.map(async (batch, batchIndex)=>{
|
|
104
|
+
const proposerNode = nodes[proposerIndexes[batchIndex]];
|
|
105
|
+
await Promise.all(batch.map(async (tx)=>{
|
|
106
|
+
try {
|
|
107
|
+
await proposerNode.sendTx(tx);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
t.logger.error(`Error sending tx: ${err}`);
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
return batch.map((tx)=>({
|
|
114
|
+
node: proposerNode,
|
|
115
|
+
txHash: tx.getTxHash()
|
|
116
|
+
}));
|
|
117
|
+
}));
|
|
118
|
+
t.logger.info('Waiting for all transactions to be mined');
|
|
119
|
+
await Promise.all(submittedTxs.flatMap((batch, batchIndex)=>batch.map(async (submittedTx, txIndex)=>{
|
|
120
|
+
t.logger.info(`Waiting for tx ${batchIndex}-${txIndex} ${submittedTx.txHash.toString()} to be mined`);
|
|
121
|
+
await waitForTx(submittedTx.node, submittedTx.txHash, {
|
|
122
|
+
timeout: WAIT_FOR_TX_TIMEOUT * 1.5
|
|
123
|
+
});
|
|
124
|
+
t.logger.info(`Tx ${batchIndex}-${txIndex} ${submittedTx.txHash.toString()} has been mined`);
|
|
125
|
+
})));
|
|
126
|
+
t.logger.info('All transactions mined');
|
|
127
|
+
return nodes;
|
|
128
|
+
}
|
|
129
|
+
async function getProposerIndexes(t, startSlotTimestamp) {
|
|
130
|
+
// Get the nodes for the next set of slots
|
|
131
|
+
const rollupContract = new RollupContract(t.ctx.deployL1ContractsValues.l1Client, t.ctx.deployL1ContractsValues.l1ContractAddresses.rollupAddress);
|
|
132
|
+
const attesters = await rollupContract.getAttesters();
|
|
133
|
+
const startSlot = await rollupContract.getSlotAt(startSlotTimestamp);
|
|
134
|
+
const proposers = await Promise.all(Array.from({
|
|
135
|
+
length: 3
|
|
136
|
+
}, async (_, i)=>{
|
|
137
|
+
const slot = SlotNumber(startSlot + i);
|
|
138
|
+
const slotTimestamp = await rollupContract.getTimestampForSlot(slot);
|
|
139
|
+
return await rollupContract.getProposerAt(slotTimestamp);
|
|
140
|
+
}));
|
|
141
|
+
// Get the indexes of the nodes that are responsible for the next two slots
|
|
142
|
+
const proposerIndexes = proposers.map((proposer)=>attesters.findIndex((a)=>a.equals(proposer)));
|
|
143
|
+
if (proposerIndexes.some((i)=>i === -1)) {
|
|
144
|
+
throw new Error(`Proposer index not found for proposer ` + `(proposers=${proposers.map((p)=>p.toString()).join(',')}, indices=${proposerIndexes.join(',')})`);
|
|
145
|
+
}
|
|
146
|
+
const nodesToTurnOffTxGossip = Array.from({
|
|
147
|
+
length: NUM_VALIDATORS
|
|
148
|
+
}, (_, i)=>i).filter((i)=>!proposerIndexes.includes(i));
|
|
149
|
+
return {
|
|
150
|
+
proposerIndexes,
|
|
151
|
+
nodesToTurnOffTxGossip
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
3
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
4
|
+
import { Pool } from 'pg';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for HA database connection
|
|
7
|
+
*/
|
|
8
|
+
export interface HADatabaseConfig {
|
|
9
|
+
/** PostgreSQL connection URL */
|
|
10
|
+
databaseUrl: string;
|
|
11
|
+
/** Node ID for HA coordination */
|
|
12
|
+
nodeId: string;
|
|
13
|
+
/** Enable HA signing */
|
|
14
|
+
haSigningEnabled: boolean;
|
|
15
|
+
/** Polling interval in ms */
|
|
16
|
+
pollingIntervalMs: number;
|
|
17
|
+
/** Signing timeout in ms */
|
|
18
|
+
signingTimeoutMs: number;
|
|
19
|
+
/** Max stuck duties age in ms */
|
|
20
|
+
maxStuckDutiesAgeMs: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get database configuration from environment variables
|
|
24
|
+
*/
|
|
25
|
+
export declare function createHADatabaseConfig(nodeId: string): HADatabaseConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Setup PostgreSQL database connection pool for HA tests
|
|
28
|
+
*
|
|
29
|
+
* Note: Database migrations should be run separately before starting tests,
|
|
30
|
+
* either via docker-compose entrypoint or manually with: aztec migrate-ha-db up
|
|
31
|
+
*/
|
|
32
|
+
export declare function setupHADatabase(databaseUrl: string, logger?: Logger): Pool;
|
|
33
|
+
/**
|
|
34
|
+
* Clean up HA database - drop all tables
|
|
35
|
+
* Use this between tests to ensure clean state
|
|
36
|
+
*/
|
|
37
|
+
export declare function cleanupHADatabase(pool: Pool, logger?: Logger): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Query validator duties from the database
|
|
40
|
+
*/
|
|
41
|
+
export declare function getValidatorDuties(pool: Pool, slot: bigint, dutyType?: 'ATTESTATION' | 'BLOCK_PROPOSAL' | 'GOVERNANCE_VOTE' | 'SLASHING_VOTE'): Promise<Array<{
|
|
42
|
+
slot: string;
|
|
43
|
+
dutyType: string;
|
|
44
|
+
validatorAddress: string;
|
|
45
|
+
nodeId: string;
|
|
46
|
+
startedAt: Date;
|
|
47
|
+
completedAt: Date | undefined;
|
|
48
|
+
}>>;
|
|
49
|
+
/**
|
|
50
|
+
* Convert private keys to Ethereum addresses
|
|
51
|
+
*/
|
|
52
|
+
export declare function getAddressesFromPrivateKeys(privateKeys: `0x${string}`[]): string[];
|
|
53
|
+
/**
|
|
54
|
+
* Create initial validators from private keys for L1 contract deployment
|
|
55
|
+
*/
|
|
56
|
+
export declare function createInitialValidatorsFromPrivateKeys(attesterPrivateKeys: `0x${string}`[]): Array<{
|
|
57
|
+
attester: EthAddress;
|
|
58
|
+
withdrawer: EthAddress;
|
|
59
|
+
privateKey: `0x${string}`;
|
|
60
|
+
bn254SecretKey: SecretValue<bigint>;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Verify no duplicate attestations per validator (HA coordination check)
|
|
64
|
+
* Groups duties by validator address and verifies each validator attested exactly once
|
|
65
|
+
*/
|
|
66
|
+
export declare function verifyNoDuplicateAttestations(attestationDuties: Array<{
|
|
67
|
+
validatorAddress: string;
|
|
68
|
+
nodeId: string;
|
|
69
|
+
completedAt: Date | undefined;
|
|
70
|
+
}>, logger?: Logger): Map<string, typeof attestationDuties>;
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFfc2V0dXAuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maXh0dXJlcy9oYV9zZXR1cC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sMkJBQTJCLENBQUM7QUFFdkQsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDbEQsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBRXZELE9BQU8sRUFBRSxJQUFJLEVBQUUsTUFBTSxJQUFJLENBQUM7QUFHMUI7O0dBRUc7QUFDSCxNQUFNLFdBQVcsZ0JBQWdCO0lBQy9CLGdDQUFnQztJQUNoQyxXQUFXLEVBQUUsTUFBTSxDQUFDO0lBQ3BCLGtDQUFrQztJQUNsQyxNQUFNLEVBQUUsTUFBTSxDQUFDO0lBQ2Ysd0JBQXdCO0lBQ3hCLGdCQUFnQixFQUFFLE9BQU8sQ0FBQztJQUMxQiw2QkFBNkI7SUFDN0IsaUJBQWlCLEVBQUUsTUFBTSxDQUFDO0lBQzFCLDRCQUE0QjtJQUM1QixnQkFBZ0IsRUFBRSxNQUFNLENBQUM7SUFDekIsaUNBQWl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ACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,IAAI,GAAG,SAAS,CAAC;CAC/B,CAAC,EACF,MAAM,CAAC,EAAE,MAAM,GACd,GAAG,CAAC,MAAM,EAAE,OAAO,iBAAiB,CAAC,CAmBvC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
4
|
+
import { Pool } from 'pg';
|
|
5
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
6
|
+
/**
|
|
7
|
+
* Get database configuration from environment variables
|
|
8
|
+
*/ export function createHADatabaseConfig(nodeId) {
|
|
9
|
+
const databaseUrl = process.env.DATABASE_URL || 'postgresql://aztec:aztec@localhost:5432/aztec_ha_test';
|
|
10
|
+
return {
|
|
11
|
+
databaseUrl,
|
|
12
|
+
nodeId,
|
|
13
|
+
haSigningEnabled: true,
|
|
14
|
+
pollingIntervalMs: 100,
|
|
15
|
+
signingTimeoutMs: 3000,
|
|
16
|
+
maxStuckDutiesAgeMs: 72000
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Setup PostgreSQL database connection pool for HA tests
|
|
21
|
+
*
|
|
22
|
+
* Note: Database migrations should be run separately before starting tests,
|
|
23
|
+
* either via docker-compose entrypoint or manually with: aztec migrate-ha-db up
|
|
24
|
+
*/ export function setupHADatabase(databaseUrl, logger) {
|
|
25
|
+
try {
|
|
26
|
+
// Create connection pool for test usage
|
|
27
|
+
// Migrations are already run by docker-compose entrypoint before tests start
|
|
28
|
+
const pool = new Pool({
|
|
29
|
+
connectionString: databaseUrl
|
|
30
|
+
});
|
|
31
|
+
logger?.info('Connected to HA database (migrations should already be applied)');
|
|
32
|
+
return pool;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
logger?.error(`Failed to connect to HA database: ${error}`);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Clean up HA database - drop all tables
|
|
40
|
+
* Use this between tests to ensure clean state
|
|
41
|
+
*/ export async function cleanupHADatabase(pool, logger) {
|
|
42
|
+
try {
|
|
43
|
+
// Drop all HA tables
|
|
44
|
+
await pool.query('DROP TABLE IF EXISTS validator_duties CASCADE');
|
|
45
|
+
await pool.query('DROP TABLE IF EXISTS slashing_protection CASCADE');
|
|
46
|
+
await pool.query('DROP TABLE IF EXISTS schema_version CASCADE');
|
|
47
|
+
logger?.info('HA database cleaned up successfully');
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logger?.error(`Failed to cleanup HA database: ${error}`);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Query validator duties from the database
|
|
55
|
+
*/ export async function getValidatorDuties(pool, slot, dutyType) {
|
|
56
|
+
const query = dutyType ? 'SELECT slot, duty_type, validator_address, node_id, started_at, completed_at FROM validator_duties WHERE slot = $1 AND duty_type = $2 ORDER BY started_at' : 'SELECT slot, duty_type, validator_address, node_id, started_at, completed_at FROM validator_duties WHERE slot = $1 ORDER BY started_at';
|
|
57
|
+
const params = dutyType ? [
|
|
58
|
+
slot.toString(),
|
|
59
|
+
dutyType
|
|
60
|
+
] : [
|
|
61
|
+
slot.toString()
|
|
62
|
+
];
|
|
63
|
+
const result = await pool.query(query, params);
|
|
64
|
+
return result.rows.map((row)=>({
|
|
65
|
+
slot: row.slot,
|
|
66
|
+
dutyType: row.duty_type,
|
|
67
|
+
validatorAddress: row.validator_address,
|
|
68
|
+
nodeId: row.node_id,
|
|
69
|
+
startedAt: row.started_at,
|
|
70
|
+
completedAt: row.completed_at
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Convert private keys to Ethereum addresses
|
|
75
|
+
*/ export function getAddressesFromPrivateKeys(privateKeys) {
|
|
76
|
+
return privateKeys.map((pk)=>{
|
|
77
|
+
const account = privateKeyToAccount(pk);
|
|
78
|
+
return account.address;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create initial validators from private keys for L1 contract deployment
|
|
83
|
+
*/ export function createInitialValidatorsFromPrivateKeys(attesterPrivateKeys) {
|
|
84
|
+
return attesterPrivateKeys.map((pk)=>{
|
|
85
|
+
const account = privateKeyToAccount(pk);
|
|
86
|
+
return {
|
|
87
|
+
attester: EthAddress.fromString(account.address),
|
|
88
|
+
withdrawer: EthAddress.fromString(account.address),
|
|
89
|
+
privateKey: pk,
|
|
90
|
+
bn254SecretKey: new SecretValue(Fr.random().toBigInt())
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Verify no duplicate attestations per validator (HA coordination check)
|
|
96
|
+
* Groups duties by validator address and verifies each validator attested exactly once
|
|
97
|
+
*/ export function verifyNoDuplicateAttestations(attestationDuties, logger) {
|
|
98
|
+
const dutiesByValidator = new Map();
|
|
99
|
+
for (const duty of attestationDuties){
|
|
100
|
+
const existing = dutiesByValidator.get(duty.validatorAddress) || [];
|
|
101
|
+
existing.push(duty);
|
|
102
|
+
dutiesByValidator.set(duty.validatorAddress, existing);
|
|
103
|
+
}
|
|
104
|
+
for (const [validatorAddress, validatorDuties] of dutiesByValidator.entries()){
|
|
105
|
+
if (validatorDuties.length !== 1) {
|
|
106
|
+
throw new Error(`Validator ${validatorAddress} attested ${validatorDuties.length} times (expected exactly once)`);
|
|
107
|
+
}
|
|
108
|
+
if (!validatorDuties[0].completedAt) {
|
|
109
|
+
throw new Error(`Validator ${validatorAddress} attestation duty not completed`);
|
|
110
|
+
}
|
|
111
|
+
logger?.info(`Validator ${validatorAddress} attested once via node ${validatorDuties[0].nodeId}`);
|
|
112
|
+
}
|
|
113
|
+
return dutiesByValidator;
|
|
114
|
+
}
|
package/dest/fixtures/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './fixtures.js';
|
|
2
|
+
export * from './ha_setup.js';
|
|
2
3
|
export * from './logging.js';
|
|
3
4
|
export * from './utils.js';
|
|
4
5
|
export * from './token_utils.js';
|
|
5
6
|
export * from './with_telemetry_utils.js';
|
|
6
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maXh0dXJlcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLGNBQWMsQ0FBQztBQUM3QixjQUFjLFlBQVksQ0FBQztBQUMzQixjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsMkJBQTJCLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixtures/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fixtures/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC"}
|
package/dest/fixtures/index.js
CHANGED
|
@@ -38,4 +38,4 @@ export declare function enableValidatorDynamicBootNode(instanceName: string, nam
|
|
|
38
38
|
* Defaults to false, which preserves the existing storage.
|
|
39
39
|
*/
|
|
40
40
|
export declare function rollAztecPods(namespace: string, clearState?: boolean): Promise<void>;
|
|
41
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
41
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9zcGFydGFuL3V0aWxzL25vZGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDN0QsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUdwRCxPQUFPLEVBQ0wsS0FBSyxjQUFjLEVBQ25CLEtBQUssb0JBQW9CLEVBRTFCLE1BQU0saUNBQWlDLENBQUM7QUFLekMsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBZTlDLHdCQUFzQixxQkFBcUIsQ0FDekMsZ0JBQWdCLEVBQUUsZ0JBQWdCLEVBQ2xDLGdCQUFnQixFQUFFLGdCQUFnQixFQUNsQyxjQUFjLEVBQUUsTUFBTSxFQUN0QixHQUFHLEVBQUUsTUFBTSxpQkFlWjtBQUVEOzs7Ozs7O0dBT0c7QUFDSCx3QkFBc0Isc0JBQXNCLENBQzFDLE1BQU0sRUFBRSxNQUFNLEVBQ2QsR0FBRyxFQUFFLE1BQU0sRUFDWCxjQUFjLEdBQUUsTUFBWSxFQUM1QixtQkFBbUIsR0FBRSxNQUFXLEdBQy9CLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0EwQ2Y7QUFFRCx3QkFBc0IsYUFBYSxDQUFDLFNBQV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QkFBc0IsYUFBYSxDQUFDLFNBQVMsRUFBRSxNQUFNLEVBQUUsVUFBVSxHQUFFLE9BQWUsaUJBMktqRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../../src/spartan/utils/nodes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAE1B,MAAM,iCAAiC,CAAC;AAKzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../../src/spartan/utils/nodes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAE1B,MAAM,iCAAiC,CAAC;AAKzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAe9C,wBAAsB,qBAAqB,CACzC,gBAAgB,EAAE,gBAAgB,EAClC,gBAAgB,EAAE,gBAAgB,EAClC,cAAc,EAAE,MAAM,EACtB,GAAG,EAAE,MAAM,iBAeZ;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,cAAc,GAAE,MAAY,EAC5B,mBAAmB,GAAE,MAAW,GAC/B,OAAO,CAAC,IAAI,CAAC,CA0Cf;AAED,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,qBA4BpD;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,oBAAoB,CAAC,mCAK5F;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,UAAU,mCAElD;AAED,wBAAsB,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CA4CpH;AAkCD,wBAAsB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0B/D;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,SAAS,EACT,OAAO,EACP,WAAW,EACX,MAAM,EAAE,GAAG,EACZ,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,iBAgCA;AAED,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,iBA+BrE;AAED,wBAAsB,8BAA8B,CAClD,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,iBAgBZ;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,GAAE,OAAe,iBA2KjF"}
|
|
@@ -6,7 +6,7 @@ import { createAztecNodeAdminClient } from '@aztec/stdlib/interfaces/client';
|
|
|
6
6
|
import { exec } from 'child_process';
|
|
7
7
|
import { promisify } from 'util';
|
|
8
8
|
import { execHelmCommand } from './helm.js';
|
|
9
|
-
import { deleteResourceByLabel, getChartDir, startPortForward, waitForResourceByLabel, waitForStatefulSetsReady } from './k8s.js';
|
|
9
|
+
import { deleteResourceByLabel, getChartDir, startPortForward, waitForResourceByLabel, waitForResourceByName, waitForStatefulSetsReady } from './k8s.js';
|
|
10
10
|
const execAsync = promisify(exec);
|
|
11
11
|
const logger = createLogger('e2e:k8s-utils');
|
|
12
12
|
export async function awaitCheckpointNumber(rollupCheatCodes, checkpointNumber, timeoutSeconds, log) {
|
|
@@ -99,6 +99,12 @@ export async function withSequencersAdmin(env, fn) {
|
|
|
99
99
|
const sequencers = await getSequencers(namespace);
|
|
100
100
|
const results = [];
|
|
101
101
|
for (const sequencer of sequencers){
|
|
102
|
+
// Ensure pod is Ready before attempting port-forward.
|
|
103
|
+
await waitForResourceByName({
|
|
104
|
+
resource: 'pods',
|
|
105
|
+
name: sequencer,
|
|
106
|
+
namespace
|
|
107
|
+
});
|
|
102
108
|
// Wrap port-forward + fetch in a retry to handle flaky port-forwards
|
|
103
109
|
const result = await retry(async ()=>{
|
|
104
110
|
const { process: process1, port } = await startPortForward({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/end-to-end",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.592b9384",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"inherits": [
|
|
@@ -22,47 +22,48 @@
|
|
|
22
22
|
"test:integration:run": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --no-cache --runInBand --config jest.integration.config.json",
|
|
23
23
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests src/fixtures",
|
|
24
24
|
"test:compose": "./scripts/run_test.sh compose",
|
|
25
|
+
"test:ha": "./scripts/run_test.sh ha",
|
|
25
26
|
"formatting": "run -T prettier --check ./src && run -T eslint ./src"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@aztec/accounts": "0.0.1-commit.
|
|
29
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
30
|
-
"@aztec/aztec": "0.0.1-commit.
|
|
31
|
-
"@aztec/aztec-node": "0.0.1-commit.
|
|
32
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
33
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
34
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
35
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
36
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
37
|
-
"@aztec/bot": "0.0.1-commit.
|
|
38
|
-
"@aztec/cli": "0.0.1-commit.
|
|
39
|
-
"@aztec/constants": "0.0.1-commit.
|
|
40
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
41
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
42
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
43
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
44
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
45
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
46
|
-
"@aztec/merkle-tree": "0.0.1-commit.
|
|
47
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
48
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
49
|
-
"@aztec/noir-noirc_abi": "0.0.1-commit.
|
|
50
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
51
|
-
"@aztec/noir-test-contracts.js": "0.0.1-commit.
|
|
52
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
53
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
54
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
55
|
-
"@aztec/prover-node": "0.0.1-commit.
|
|
56
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
57
|
-
"@aztec/sequencer-client": "0.0.1-commit.
|
|
58
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
59
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
60
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
61
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
62
|
-
"@aztec/test-wallet": "0.0.1-commit.
|
|
63
|
-
"@aztec/validator-client": "0.0.1-commit.
|
|
64
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
65
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
29
|
+
"@aztec/accounts": "0.0.1-commit.592b9384",
|
|
30
|
+
"@aztec/archiver": "0.0.1-commit.592b9384",
|
|
31
|
+
"@aztec/aztec": "0.0.1-commit.592b9384",
|
|
32
|
+
"@aztec/aztec-node": "0.0.1-commit.592b9384",
|
|
33
|
+
"@aztec/aztec.js": "0.0.1-commit.592b9384",
|
|
34
|
+
"@aztec/bb-prover": "0.0.1-commit.592b9384",
|
|
35
|
+
"@aztec/bb.js": "0.0.1-commit.592b9384",
|
|
36
|
+
"@aztec/blob-client": "0.0.1-commit.592b9384",
|
|
37
|
+
"@aztec/blob-lib": "0.0.1-commit.592b9384",
|
|
38
|
+
"@aztec/bot": "0.0.1-commit.592b9384",
|
|
39
|
+
"@aztec/cli": "0.0.1-commit.592b9384",
|
|
40
|
+
"@aztec/constants": "0.0.1-commit.592b9384",
|
|
41
|
+
"@aztec/entrypoints": "0.0.1-commit.592b9384",
|
|
42
|
+
"@aztec/epoch-cache": "0.0.1-commit.592b9384",
|
|
43
|
+
"@aztec/ethereum": "0.0.1-commit.592b9384",
|
|
44
|
+
"@aztec/foundation": "0.0.1-commit.592b9384",
|
|
45
|
+
"@aztec/kv-store": "0.0.1-commit.592b9384",
|
|
46
|
+
"@aztec/l1-artifacts": "0.0.1-commit.592b9384",
|
|
47
|
+
"@aztec/merkle-tree": "0.0.1-commit.592b9384",
|
|
48
|
+
"@aztec/node-keystore": "0.0.1-commit.592b9384",
|
|
49
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.592b9384",
|
|
50
|
+
"@aztec/noir-noirc_abi": "0.0.1-commit.592b9384",
|
|
51
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.592b9384",
|
|
52
|
+
"@aztec/noir-test-contracts.js": "0.0.1-commit.592b9384",
|
|
53
|
+
"@aztec/p2p": "0.0.1-commit.592b9384",
|
|
54
|
+
"@aztec/protocol-contracts": "0.0.1-commit.592b9384",
|
|
55
|
+
"@aztec/prover-client": "0.0.1-commit.592b9384",
|
|
56
|
+
"@aztec/prover-node": "0.0.1-commit.592b9384",
|
|
57
|
+
"@aztec/pxe": "0.0.1-commit.592b9384",
|
|
58
|
+
"@aztec/sequencer-client": "0.0.1-commit.592b9384",
|
|
59
|
+
"@aztec/simulator": "0.0.1-commit.592b9384",
|
|
60
|
+
"@aztec/slasher": "0.0.1-commit.592b9384",
|
|
61
|
+
"@aztec/stdlib": "0.0.1-commit.592b9384",
|
|
62
|
+
"@aztec/telemetry-client": "0.0.1-commit.592b9384",
|
|
63
|
+
"@aztec/test-wallet": "0.0.1-commit.592b9384",
|
|
64
|
+
"@aztec/validator-client": "0.0.1-commit.592b9384",
|
|
65
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.592b9384",
|
|
66
|
+
"@aztec/world-state": "0.0.1-commit.592b9384",
|
|
66
67
|
"@iarna/toml": "^2.2.5",
|
|
67
68
|
"@jest/globals": "^30.0.0",
|
|
68
69
|
"@noble/curves": "=1.0.0",
|
|
@@ -90,6 +91,7 @@
|
|
|
90
91
|
"lodash.every": "^4.6.0",
|
|
91
92
|
"lodash.omit": "^4.5.0",
|
|
92
93
|
"msgpackr": "^1.11.2",
|
|
94
|
+
"pg": "^8.17.1",
|
|
93
95
|
"process": "^0.11.10",
|
|
94
96
|
"snappy": "^7.2.2",
|
|
95
97
|
"stream-browserify": "^3.0.0",
|
|
@@ -108,6 +110,7 @@
|
|
|
108
110
|
"@types/jest": "^30.0.0",
|
|
109
111
|
"@types/js-yaml": "^4.0.9",
|
|
110
112
|
"@types/lodash.chunk": "^4.2.9",
|
|
113
|
+
"@types/pg": "^8",
|
|
111
114
|
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
112
115
|
"concurrently": "^7.6.0",
|
|
113
116
|
"jest": "^30.0.0",
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
3
|
+
import { waitForTx } from '@aztec/aztec.js/node';
|
|
4
|
+
import { Tx } from '@aztec/aztec.js/tx';
|
|
5
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
6
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
|
+
import { timesAsync } from '@aztec/foundation/collection';
|
|
8
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
9
|
+
|
|
10
|
+
import { jest } from '@jest/globals';
|
|
11
|
+
import fs from 'fs';
|
|
12
|
+
import os from 'os';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
|
|
15
|
+
import { shouldCollectMetrics } from '../../fixtures/fixtures.js';
|
|
16
|
+
import { createNodes } from '../../fixtures/setup_p2p_test.js';
|
|
17
|
+
import { P2PNetworkTest, SHORTENED_BLOCK_TIME_CONFIG_NO_PRUNES, WAIT_FOR_TX_TIMEOUT } from '../p2p_network.js';
|
|
18
|
+
import { prepareTransactions } from '../shared.js';
|
|
19
|
+
|
|
20
|
+
// Don't set this to a higher value than 9 because each node will use a different L1 publisher account and anvil seeds
|
|
21
|
+
export const NUM_VALIDATORS = 6;
|
|
22
|
+
export const NUM_TXS_PER_NODE = 2;
|
|
23
|
+
export const BOOT_NODE_UDP_PORT = 4500;
|
|
24
|
+
|
|
25
|
+
export const createReqrespDataDir = () => fs.mkdtempSync(path.join(os.tmpdir(), 'reqresp-'));
|
|
26
|
+
|
|
27
|
+
type ReqrespOptions = {
|
|
28
|
+
disableStatusHandshake?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export async function createReqrespTest(options: ReqrespOptions = {}): Promise<P2PNetworkTest> {
|
|
32
|
+
const { disableStatusHandshake = false } = options;
|
|
33
|
+
const t = await P2PNetworkTest.create({
|
|
34
|
+
testName: 'e2e_p2p_reqresp_tx',
|
|
35
|
+
numberOfNodes: 0,
|
|
36
|
+
numberOfValidators: NUM_VALIDATORS,
|
|
37
|
+
basePort: BOOT_NODE_UDP_PORT,
|
|
38
|
+
// To collect metrics - run in aztec-packages `docker compose --profile metrics up`
|
|
39
|
+
metricsPort: shouldCollectMetrics(),
|
|
40
|
+
initialConfig: {
|
|
41
|
+
...SHORTENED_BLOCK_TIME_CONFIG_NO_PRUNES,
|
|
42
|
+
aztecSlotDuration: 24,
|
|
43
|
+
...(disableStatusHandshake ? { p2pDisableStatusHandshake: true } : {}),
|
|
44
|
+
listenAddress: '127.0.0.1',
|
|
45
|
+
aztecEpochDuration: 64, // stable committee
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
await t.setup();
|
|
49
|
+
await t.applyBaseSetup();
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function cleanupReqrespTest(params: { t: P2PNetworkTest; nodes?: AztecNodeService[]; dataDir: string }) {
|
|
54
|
+
const { t, nodes, dataDir } = params;
|
|
55
|
+
if (nodes) {
|
|
56
|
+
await t.stopNodes(nodes);
|
|
57
|
+
}
|
|
58
|
+
await t.teardown();
|
|
59
|
+
for (let i = 0; i < NUM_VALIDATORS; i++) {
|
|
60
|
+
fs.rmSync(`${dataDir}-${i}`, { recursive: true, force: true, maxRetries: 3 });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const getNodePort = (nodeIndex: number) => BOOT_NODE_UDP_PORT + 1 + nodeIndex;
|
|
65
|
+
|
|
66
|
+
export async function runReqrespTxTest(params: {
|
|
67
|
+
t: P2PNetworkTest;
|
|
68
|
+
dataDir: string;
|
|
69
|
+
disableStatusHandshake?: boolean;
|
|
70
|
+
}): Promise<AztecNodeService[]> {
|
|
71
|
+
const { t, dataDir, disableStatusHandshake = false } = params;
|
|
72
|
+
|
|
73
|
+
if (!t.bootstrapNodeEnr) {
|
|
74
|
+
throw new Error('Bootstrap node ENR is not available');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
t.logger.info('Creating nodes');
|
|
78
|
+
const aztecNodeConfig = disableStatusHandshake
|
|
79
|
+
? { ...t.ctx.aztecNodeConfig, p2pDisableStatusHandshake: true }
|
|
80
|
+
: t.ctx.aztecNodeConfig;
|
|
81
|
+
|
|
82
|
+
const nodes = await createNodes(
|
|
83
|
+
aztecNodeConfig,
|
|
84
|
+
t.ctx.dateProvider!,
|
|
85
|
+
t.bootstrapNodeEnr,
|
|
86
|
+
NUM_VALIDATORS,
|
|
87
|
+
BOOT_NODE_UDP_PORT,
|
|
88
|
+
t.prefilledPublicData,
|
|
89
|
+
dataDir,
|
|
90
|
+
shouldCollectMetrics(),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
t.logger.info('Waiting for nodes to connect');
|
|
94
|
+
await t.waitForP2PMeshConnectivity(nodes, NUM_VALIDATORS);
|
|
95
|
+
|
|
96
|
+
await t.setupAccount();
|
|
97
|
+
|
|
98
|
+
const targetBlockNumber = await t.ctx.aztecNodeService!.getBlockNumber();
|
|
99
|
+
await retryUntil(
|
|
100
|
+
async () => {
|
|
101
|
+
const blockNumbers = await Promise.all(nodes.map(node => node.getBlockNumber()));
|
|
102
|
+
return blockNumbers.every(blockNumber => blockNumber >= targetBlockNumber) ? true : undefined;
|
|
103
|
+
},
|
|
104
|
+
`validators to sync to L2 block ${targetBlockNumber}`,
|
|
105
|
+
60,
|
|
106
|
+
0.5,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
t.logger.info('Preparing transactions to send');
|
|
110
|
+
const txBatches = await timesAsync(2, () =>
|
|
111
|
+
prepareTransactions(t.logger, t.ctx.aztecNodeService!, NUM_TXS_PER_NODE, t.fundedAccount),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
t.logger.info('Removing initial node');
|
|
115
|
+
await t.removeInitialNode();
|
|
116
|
+
|
|
117
|
+
t.logger.info('Starting fresh slot');
|
|
118
|
+
const [timestamp] = await t.ctx.cheatCodes.rollup.advanceToNextSlot();
|
|
119
|
+
t.ctx.dateProvider!.setTime(Number(timestamp) * 1000);
|
|
120
|
+
const startSlotTimestamp = BigInt(timestamp);
|
|
121
|
+
|
|
122
|
+
const { proposerIndexes, nodesToTurnOffTxGossip } = await getProposerIndexes(t, startSlotTimestamp);
|
|
123
|
+
t.logger.info(`Turning off tx gossip for nodes: ${nodesToTurnOffTxGossip.map(getNodePort)}`);
|
|
124
|
+
t.logger.info(`Sending txs to proposer nodes: ${proposerIndexes.map(getNodePort)}`);
|
|
125
|
+
|
|
126
|
+
// Replace the p2p node implementation of some of the nodes with a spy such that it does not store transactions that are gossiped to it
|
|
127
|
+
// Original implementation of `handleGossipedTx` will store received transactions in the tx pool.
|
|
128
|
+
// We chose the first 2 nodes that will be the proposers for the next few slots
|
|
129
|
+
for (const nodeIndex of nodesToTurnOffTxGossip) {
|
|
130
|
+
const logger = createLogger(`p2p:${getNodePort(nodeIndex)}`);
|
|
131
|
+
jest.spyOn((nodes[nodeIndex] as any).p2pClient.p2pService, 'handleGossipedTx').mockImplementation(((
|
|
132
|
+
payloadData: Buffer,
|
|
133
|
+
) => {
|
|
134
|
+
const txHash = Tx.fromBuffer(payloadData).getTxHash();
|
|
135
|
+
logger.info(`Skipping storage of gossiped transaction ${txHash.toString()}`);
|
|
136
|
+
return Promise.resolve();
|
|
137
|
+
}) as any);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// We send the tx to the proposer nodes directly, ignoring the pxe and node in each context
|
|
141
|
+
// We cannot just call tx.send since they were created using a pxe wired to the first node which is now stopped
|
|
142
|
+
t.logger.info('Sending transactions through proposer nodes');
|
|
143
|
+
const submittedTxs = await Promise.all(
|
|
144
|
+
txBatches.map(async (batch, batchIndex) => {
|
|
145
|
+
const proposerNode = nodes[proposerIndexes[batchIndex]];
|
|
146
|
+
await Promise.all(
|
|
147
|
+
batch.map(async tx => {
|
|
148
|
+
try {
|
|
149
|
+
await proposerNode.sendTx(tx);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
t.logger.error(`Error sending tx: ${err}`);
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
return batch.map(tx => ({ node: proposerNode, txHash: tx.getTxHash() }));
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
t.logger.info('Waiting for all transactions to be mined');
|
|
161
|
+
await Promise.all(
|
|
162
|
+
submittedTxs.flatMap((batch, batchIndex) =>
|
|
163
|
+
batch.map(async (submittedTx, txIndex) => {
|
|
164
|
+
t.logger.info(`Waiting for tx ${batchIndex}-${txIndex} ${submittedTx.txHash.toString()} to be mined`);
|
|
165
|
+
await waitForTx(submittedTx.node, submittedTx.txHash, { timeout: WAIT_FOR_TX_TIMEOUT * 1.5 });
|
|
166
|
+
t.logger.info(`Tx ${batchIndex}-${txIndex} ${submittedTx.txHash.toString()} has been mined`);
|
|
167
|
+
}),
|
|
168
|
+
),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
t.logger.info('All transactions mined');
|
|
172
|
+
|
|
173
|
+
return nodes;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function getProposerIndexes(t: P2PNetworkTest, startSlotTimestamp: bigint) {
|
|
177
|
+
// Get the nodes for the next set of slots
|
|
178
|
+
const rollupContract = new RollupContract(
|
|
179
|
+
t.ctx.deployL1ContractsValues.l1Client,
|
|
180
|
+
t.ctx.deployL1ContractsValues.l1ContractAddresses.rollupAddress,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const attesters = await rollupContract.getAttesters();
|
|
184
|
+
const startSlot = await rollupContract.getSlotAt(startSlotTimestamp);
|
|
185
|
+
|
|
186
|
+
const proposers = await Promise.all(
|
|
187
|
+
Array.from({ length: 3 }, async (_, i) => {
|
|
188
|
+
const slot = SlotNumber(startSlot + i);
|
|
189
|
+
const slotTimestamp = await rollupContract.getTimestampForSlot(slot);
|
|
190
|
+
return await rollupContract.getProposerAt(slotTimestamp);
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
193
|
+
// Get the indexes of the nodes that are responsible for the next two slots
|
|
194
|
+
const proposerIndexes = proposers.map(proposer => attesters.findIndex(a => a.equals(proposer)));
|
|
195
|
+
|
|
196
|
+
if (proposerIndexes.some(i => i === -1)) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
`Proposer index not found for proposer ` +
|
|
199
|
+
`(proposers=${proposers.map(p => p.toString()).join(',')}, indices=${proposerIndexes.join(',')})`,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const nodesToTurnOffTxGossip = Array.from({ length: NUM_VALIDATORS }, (_, i) => i).filter(
|
|
204
|
+
i => !proposerIndexes.includes(i),
|
|
205
|
+
);
|
|
206
|
+
return { proposerIndexes, nodesToTurnOffTxGossip };
|
|
207
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
4
|
+
import { SecretValue } from '@aztec/foundation/config';
|
|
5
|
+
|
|
6
|
+
import { Pool } from 'pg';
|
|
7
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for HA database connection
|
|
11
|
+
*/
|
|
12
|
+
export interface HADatabaseConfig {
|
|
13
|
+
/** PostgreSQL connection URL */
|
|
14
|
+
databaseUrl: string;
|
|
15
|
+
/** Node ID for HA coordination */
|
|
16
|
+
nodeId: string;
|
|
17
|
+
/** Enable HA signing */
|
|
18
|
+
haSigningEnabled: boolean;
|
|
19
|
+
/** Polling interval in ms */
|
|
20
|
+
pollingIntervalMs: number;
|
|
21
|
+
/** Signing timeout in ms */
|
|
22
|
+
signingTimeoutMs: number;
|
|
23
|
+
/** Max stuck duties age in ms */
|
|
24
|
+
maxStuckDutiesAgeMs: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get database configuration from environment variables
|
|
29
|
+
*/
|
|
30
|
+
export function createHADatabaseConfig(nodeId: string): HADatabaseConfig {
|
|
31
|
+
const databaseUrl = process.env.DATABASE_URL || 'postgresql://aztec:aztec@localhost:5432/aztec_ha_test';
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
databaseUrl,
|
|
35
|
+
nodeId,
|
|
36
|
+
haSigningEnabled: true,
|
|
37
|
+
pollingIntervalMs: 100,
|
|
38
|
+
signingTimeoutMs: 3000,
|
|
39
|
+
maxStuckDutiesAgeMs: 72000,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Setup PostgreSQL database connection pool for HA tests
|
|
45
|
+
*
|
|
46
|
+
* Note: Database migrations should be run separately before starting tests,
|
|
47
|
+
* either via docker-compose entrypoint or manually with: aztec migrate-ha-db up
|
|
48
|
+
*/
|
|
49
|
+
export function setupHADatabase(databaseUrl: string, logger?: Logger): Pool {
|
|
50
|
+
try {
|
|
51
|
+
// Create connection pool for test usage
|
|
52
|
+
// Migrations are already run by docker-compose entrypoint before tests start
|
|
53
|
+
const pool = new Pool({ connectionString: databaseUrl });
|
|
54
|
+
|
|
55
|
+
logger?.info('Connected to HA database (migrations should already be applied)');
|
|
56
|
+
|
|
57
|
+
return pool;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
logger?.error(`Failed to connect to HA database: ${error}`);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Clean up HA database - drop all tables
|
|
66
|
+
* Use this between tests to ensure clean state
|
|
67
|
+
*/
|
|
68
|
+
export async function cleanupHADatabase(pool: Pool, logger?: Logger): Promise<void> {
|
|
69
|
+
try {
|
|
70
|
+
// Drop all HA tables
|
|
71
|
+
await pool.query('DROP TABLE IF EXISTS validator_duties CASCADE');
|
|
72
|
+
await pool.query('DROP TABLE IF EXISTS slashing_protection CASCADE');
|
|
73
|
+
await pool.query('DROP TABLE IF EXISTS schema_version CASCADE');
|
|
74
|
+
|
|
75
|
+
logger?.info('HA database cleaned up successfully');
|
|
76
|
+
} catch (error) {
|
|
77
|
+
logger?.error(`Failed to cleanup HA database: ${error}`);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Query validator duties from the database
|
|
84
|
+
*/
|
|
85
|
+
export async function getValidatorDuties(
|
|
86
|
+
pool: Pool,
|
|
87
|
+
slot: bigint,
|
|
88
|
+
dutyType?: 'ATTESTATION' | 'BLOCK_PROPOSAL' | 'GOVERNANCE_VOTE' | 'SLASHING_VOTE',
|
|
89
|
+
): Promise<
|
|
90
|
+
Array<{
|
|
91
|
+
slot: string;
|
|
92
|
+
dutyType: string;
|
|
93
|
+
validatorAddress: string;
|
|
94
|
+
nodeId: string;
|
|
95
|
+
startedAt: Date;
|
|
96
|
+
completedAt: Date | undefined;
|
|
97
|
+
}>
|
|
98
|
+
> {
|
|
99
|
+
const query = dutyType
|
|
100
|
+
? 'SELECT slot, duty_type, validator_address, node_id, started_at, completed_at FROM validator_duties WHERE slot = $1 AND duty_type = $2 ORDER BY started_at'
|
|
101
|
+
: 'SELECT slot, duty_type, validator_address, node_id, started_at, completed_at FROM validator_duties WHERE slot = $1 ORDER BY started_at';
|
|
102
|
+
|
|
103
|
+
const params = dutyType ? [slot.toString(), dutyType] : [slot.toString()];
|
|
104
|
+
|
|
105
|
+
const result = await pool.query<{
|
|
106
|
+
slot: string;
|
|
107
|
+
duty_type: string;
|
|
108
|
+
validator_address: string;
|
|
109
|
+
node_id: string;
|
|
110
|
+
started_at: Date;
|
|
111
|
+
completed_at: Date | undefined;
|
|
112
|
+
}>(query, params);
|
|
113
|
+
|
|
114
|
+
return result.rows.map(row => ({
|
|
115
|
+
slot: row.slot,
|
|
116
|
+
dutyType: row.duty_type,
|
|
117
|
+
validatorAddress: row.validator_address,
|
|
118
|
+
nodeId: row.node_id,
|
|
119
|
+
startedAt: row.started_at,
|
|
120
|
+
completedAt: row.completed_at,
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Convert private keys to Ethereum addresses
|
|
126
|
+
*/
|
|
127
|
+
export function getAddressesFromPrivateKeys(privateKeys: `0x${string}`[]): string[] {
|
|
128
|
+
return privateKeys.map(pk => {
|
|
129
|
+
const account = privateKeyToAccount(pk);
|
|
130
|
+
return account.address;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create initial validators from private keys for L1 contract deployment
|
|
136
|
+
*/
|
|
137
|
+
export function createInitialValidatorsFromPrivateKeys(attesterPrivateKeys: `0x${string}`[]): Array<{
|
|
138
|
+
attester: EthAddress;
|
|
139
|
+
withdrawer: EthAddress;
|
|
140
|
+
privateKey: `0x${string}`;
|
|
141
|
+
bn254SecretKey: SecretValue<bigint>;
|
|
142
|
+
}> {
|
|
143
|
+
return attesterPrivateKeys.map(pk => {
|
|
144
|
+
const account = privateKeyToAccount(pk);
|
|
145
|
+
return {
|
|
146
|
+
attester: EthAddress.fromString(account.address),
|
|
147
|
+
withdrawer: EthAddress.fromString(account.address),
|
|
148
|
+
privateKey: pk,
|
|
149
|
+
bn254SecretKey: new SecretValue(Fr.random().toBigInt()),
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Verify no duplicate attestations per validator (HA coordination check)
|
|
156
|
+
* Groups duties by validator address and verifies each validator attested exactly once
|
|
157
|
+
*/
|
|
158
|
+
export function verifyNoDuplicateAttestations(
|
|
159
|
+
attestationDuties: Array<{
|
|
160
|
+
validatorAddress: string;
|
|
161
|
+
nodeId: string;
|
|
162
|
+
completedAt: Date | undefined;
|
|
163
|
+
}>,
|
|
164
|
+
logger?: Logger,
|
|
165
|
+
): Map<string, typeof attestationDuties> {
|
|
166
|
+
const dutiesByValidator = new Map<string, typeof attestationDuties>();
|
|
167
|
+
for (const duty of attestationDuties) {
|
|
168
|
+
const existing = dutiesByValidator.get(duty.validatorAddress) || [];
|
|
169
|
+
existing.push(duty);
|
|
170
|
+
dutiesByValidator.set(duty.validatorAddress, existing);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (const [validatorAddress, validatorDuties] of dutiesByValidator.entries()) {
|
|
174
|
+
if (validatorDuties.length !== 1) {
|
|
175
|
+
throw new Error(`Validator ${validatorAddress} attested ${validatorDuties.length} times (expected exactly once)`);
|
|
176
|
+
}
|
|
177
|
+
if (!validatorDuties[0].completedAt) {
|
|
178
|
+
throw new Error(`Validator ${validatorAddress} attestation duty not completed`);
|
|
179
|
+
}
|
|
180
|
+
logger?.info(`Validator ${validatorAddress} attested once via node ${validatorDuties[0].nodeId}`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return dutiesByValidator;
|
|
184
|
+
}
|
package/src/fixtures/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
getChartDir,
|
|
22
22
|
startPortForward,
|
|
23
23
|
waitForResourceByLabel,
|
|
24
|
+
waitForResourceByName,
|
|
24
25
|
waitForStatefulSetsReady,
|
|
25
26
|
} from './k8s.js';
|
|
26
27
|
|
|
@@ -154,6 +155,8 @@ export async function withSequencersAdmin<T>(env: TestConfig, fn: (node: AztecNo
|
|
|
154
155
|
const results = [];
|
|
155
156
|
|
|
156
157
|
for (const sequencer of sequencers) {
|
|
158
|
+
// Ensure pod is Ready before attempting port-forward.
|
|
159
|
+
await waitForResourceByName({ resource: 'pods', name: sequencer, namespace });
|
|
157
160
|
// Wrap port-forward + fetch in a retry to handle flaky port-forwards
|
|
158
161
|
const result = await retry(
|
|
159
162
|
async () => {
|