Skip to content

Commit ed871e9

Browse files
authored
chore: (A-475) add load balancer flag (#19888)
- load balancers for eth-execution and rpc to red uce port flakiness - add new environment variable to enable load balancers for eth-execution and rpc - introduce getServiceEndpoint boilerplate wrapper to get ip (answers: is it external or port-forwarded?) and update tests to use new function
2 parents d44f1da + edc1a78 commit ed871e9

26 files changed

+400
-292
lines changed

spartan/environments/next-scenario.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ FUNDING_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf
1111
REDEPLOY_ROLLUP_CONTRACTS=true
1212
DESTROY_AZTEC_INFRA=true
1313
VERIFY_CONTRACTS=false
14+
USE_LOAD_BALANCERS=true
1415

1516
AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET=2
1617
AZTEC_LAG_IN_EPOCHS_FOR_RANDAO=2

spartan/scripts/deploy_network.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ BLOCK_TIME = ${ETHEREUM_BLOCK_TIME}
275275
GAS_LIMIT = ${ETHEREUM_GAS_LIMIT}
276276
PREFUNDED_MNEMONIC_INDICES = "${LABS_INFRA_INDICES}"
277277
RESOURCE_PROFILE = "${RESOURCE_PROFILE}"
278+
USE_LOAD_BALANCERS = ${USE_LOAD_BALANCERS:-false}
278279
EOF
279280

280281
"${SCRIPT_DIR}/override_terraform_backend.sh" "${DEPLOY_ETH_DEVNET_DIR}" "${CLUSTER}" "${BASE_STATE_PATH}/deploy-eth-devnet"

spartan/terraform/deploy-eth-devnet/main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ resource "null_resource" "generate_genesis" {
7171
}
7272
}
7373

74+
# Determine if this is a kind cluster (local) based on context name
75+
locals {
76+
is_kind = strcontains(var.K8S_CLUSTER_CONTEXT, "kind")
77+
use_lb = var.USE_LOAD_BALANCERS && !local.is_kind
78+
}
79+
7480
# Deploy eth-devnet helm chart
7581
resource "helm_release" "eth_devnet" {
7682
depends_on = [null_resource.generate_genesis]
@@ -97,6 +103,16 @@ resource "helm_release" "eth_devnet" {
97103
value = var.RELEASE_PREFIX
98104
}
99105

106+
set {
107+
name = "ethereum.execution.service.type"
108+
value = local.use_lb ? "LoadBalancer" : "ClusterIP"
109+
}
110+
111+
set {
112+
name = "ethereum.beacon.service.type"
113+
value = local.use_lb ? "LoadBalancer" : "ClusterIP"
114+
}
115+
100116
timeout = 1200
101117
wait = true
102118
wait_for_jobs = false

spartan/terraform/deploy-eth-devnet/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,9 @@ variable "RESOURCE_PROFILE" {
7676
}
7777
}
7878

79+
variable "USE_LOAD_BALANCERS" {
80+
description = "If true, use LoadBalancer service type for external access"
81+
type = bool
82+
default = false
83+
}
84+

yarn-project/end-to-end/src/spartan/1tps.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ import type { ProvenTx, TestWallet } from '@aztec/test-wallet/server';
88
import { proveInteraction } from '@aztec/test-wallet/server';
99

1010
import { jest } from '@jest/globals';
11-
import type { ChildProcess } from 'child_process';
1211

1312
import { getSponsoredFPCAddress } from '../fixtures/utils.js';
1413
import {
1514
type TestAccounts,
1615
createWalletAndAztecNodeClient,
1716
deploySponsoredTestAccountsWithTokens,
1817
} from './setup_test_wallets.js';
19-
import { setupEnvironment, startPortForwardForRPC } from './utils.js';
18+
import { type ServiceEndpoint, getRPCEndpoint, setupEnvironment } from './utils.js';
2019

2120
const config = { ...setupEnvironment(process.env) };
2221
describe('token transfer test', () => {
@@ -29,19 +28,19 @@ describe('token transfer test', () => {
2928

3029
let testAccounts: TestAccounts;
3130
let wallet: TestWallet;
32-
const forwardProcesses: ChildProcess[] = [];
31+
const endpoints: ServiceEndpoint[] = [];
3332
let cleanup: undefined | (() => Promise<void>);
3433

3534
afterAll(async () => {
3635
await cleanup?.();
37-
forwardProcesses.forEach(p => p.kill());
36+
endpoints.forEach(e => e.process?.kill());
3837
});
3938

4039
beforeAll(async () => {
41-
logger.info('Starting port forward for PXE');
42-
const { process: aztecRpcProcess, port: aztecRpcPort } = await startPortForwardForRPC(config.NAMESPACE);
43-
forwardProcesses.push(aztecRpcProcess);
44-
const rpcUrl = `http://127.0.0.1:${aztecRpcPort}`;
40+
logger.info('Connecting to RPC node');
41+
const rpcEndpoint = await getRPCEndpoint(config.NAMESPACE);
42+
endpoints.push(rpcEndpoint);
43+
const rpcUrl = rpcEndpoint.url;
4544

4645
const {
4746
wallet: _wallet,

yarn-project/end-to-end/src/spartan/4epochs.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import { DateProvider } from '@aztec/foundation/timer';
99
import { TestWallet, proveInteraction } from '@aztec/test-wallet/server';
1010

1111
import { jest } from '@jest/globals';
12-
import type { ChildProcess } from 'child_process';
1312

1413
import { getSponsoredFPCAddress } from '../fixtures/utils.js';
1514
import {
1615
type TestAccounts,
1716
createWalletAndAztecNodeClient,
1817
deploySponsoredTestAccountsWithTokens,
1918
} from './setup_test_wallets.js';
20-
import { ChainHealth, setupEnvironment, startPortForwardForEthereum, startPortForwardForRPC } from './utils.js';
19+
import { ChainHealth, type ServiceEndpoint, getEthereumEndpoint, getRPCEndpoint, setupEnvironment } from './utils.js';
2120

2221
const config = { ...setupEnvironment(process.env) };
2322

@@ -35,7 +34,7 @@ describe('token transfer test', () => {
3534

3635
let testAccounts: TestAccounts;
3736
let ETHEREUM_HOSTS: string[];
38-
const forwardProcesses: ChildProcess[] = [];
37+
const endpoints: ServiceEndpoint[] = [];
3938
let wallet: TestWallet;
4039
let aztecNode: AztecNode;
4140
let cleanup: undefined | (() => Promise<void>);
@@ -44,19 +43,18 @@ describe('token transfer test', () => {
4443
afterAll(async () => {
4544
await health.teardown();
4645
await cleanup?.();
47-
forwardProcesses.forEach(p => p.kill());
46+
endpoints.forEach(e => e.process?.kill());
4847
});
4948

5049
beforeAll(async () => {
5150
await health.setup();
52-
logger.info('Starting port forward for PXE and Ethereum');
53-
const { process: aztecRpcProcess, port: aztecRpcPort } = await startPortForwardForRPC(config.NAMESPACE);
54-
const { process: ethereumProcess, port: ethereumPort } = await startPortForwardForEthereum(config.NAMESPACE);
55-
forwardProcesses.push(aztecRpcProcess);
56-
forwardProcesses.push(ethereumProcess);
57-
58-
const rpcUrl = `http://127.0.0.1:${aztecRpcPort}`;
59-
ETHEREUM_HOSTS = [`http://127.0.0.1:${ethereumPort}`];
51+
logger.info('Connecting to RPC and Ethereum nodes');
52+
const rpcEndpoint = await getRPCEndpoint(config.NAMESPACE);
53+
const ethEndpoint = await getEthereumEndpoint(config.NAMESPACE);
54+
endpoints.push(rpcEndpoint, ethEndpoint);
55+
56+
const rpcUrl = rpcEndpoint.url;
57+
ETHEREUM_HOSTS = [ethEndpoint.url];
6058

6159
({ wallet, aztecNode, cleanup } = await createWalletAndAztecNodeClient(rpcUrl, config.REAL_VERIFIER, logger));
6260

yarn-project/end-to-end/src/spartan/gating-passive.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import { createLogger } from '@aztec/foundation/log';
66
import { DateProvider } from '@aztec/foundation/timer';
77

88
import { expect, jest } from '@jest/globals';
9-
import type { ChildProcess } from 'child_process';
109

1110
import { type AlertConfig, GrafanaClient } from '../quality_of_service/grafana_client.js';
1211
import {
1312
ChainHealth,
13+
type ServiceEndpoint,
1414
applyBootNodeFailure,
1515
applyNetworkShaping,
1616
applyValidatorKill,
1717
awaitCheckpointNumber,
1818
deleteResourceByLabel,
19+
getEthereumEndpoint,
1920
getGitProjectRoot,
21+
getRPCEndpoint,
2022
installTransferBot,
2123
restartBot,
2224
setupEnvironment,
2325
startPortForward,
24-
startPortForwardForEthereum,
25-
startPortForwardForRPC,
2626
uninstallTransferBot,
2727
} from './utils.js';
2828

@@ -54,7 +54,7 @@ describe('a test that passively observes the network in the presence of network
5454
let ETHEREUM_HOST: string;
5555
let alertChecker: GrafanaClient;
5656
let spartanDir: string;
57-
const forwardProcesses: ChildProcess[] = [];
57+
const endpoints: ServiceEndpoint[] = [];
5858
const podChaosInstances: string[] = [];
5959
const networkShapingInstance = `${NAMESPACE}-network-shaping`;
6060
const health = new ChainHealth(NAMESPACE, debugLogger);
@@ -63,7 +63,7 @@ describe('a test that passively observes the network in the presence of network
6363
await health.setup();
6464
// Try Prometheus in a dedicated metrics namespace first; if not present, fall back to the network namespace
6565
let promPort = 0;
66-
let promProc: ChildProcess | undefined;
66+
let promProc: ServiceEndpoint['process'];
6767
{
6868
const { process: p, port } = await startPortForward({
6969
resource: `svc/metrics-prometheus-server`,
@@ -89,7 +89,7 @@ describe('a test that passively observes the network in the presence of network
8989
}
9090

9191
if (promProc && promPort !== 0) {
92-
forwardProcesses.push(promProc);
92+
endpoints.push({ url: `http://127.0.0.1:${promPort}`, process: promProc });
9393
const grafanaEndpoint = `http://127.0.0.1:${promPort}/api/v1`;
9494
const grafanaCredentials = '';
9595
alertChecker = new GrafanaClient(debugLogger, { grafanaEndpoint, grafanaCredentials });
@@ -126,17 +126,17 @@ describe('a test that passively observes the network in the presence of network
126126

127127
// Teardown transfer bot installed for this test
128128
await uninstallTransferBot(NAMESPACE, debugLogger);
129-
forwardProcesses.forEach(p => p.kill());
129+
endpoints.forEach(e => e.process?.kill());
130130
});
131131

132132
it('survives network chaos', async () => {
133-
const { process: aztecRpcProcess, port: aztecRpcPort } = await startPortForwardForRPC(NAMESPACE);
134-
forwardProcesses.push(aztecRpcProcess);
135-
const nodeUrl = `http://127.0.0.1:${aztecRpcPort}`;
133+
const rpcEndpoint = await getRPCEndpoint(NAMESPACE);
134+
endpoints.push(rpcEndpoint);
135+
const nodeUrl = rpcEndpoint.url;
136136

137-
const { process: ethProcess, port: ethPort } = await startPortForwardForEthereum(NAMESPACE);
138-
forwardProcesses.push(ethProcess);
139-
ETHEREUM_HOST = `http://127.0.0.1:${ethPort}`;
137+
const ethEndpoint = await getEthereumEndpoint(NAMESPACE);
138+
endpoints.push(ethEndpoint);
139+
ETHEREUM_HOST = ethEndpoint.url;
140140

141141
const node = createAztecNodeClient(nodeUrl);
142142
const ethCheatCodes = new EthCheatCodesWithState([ETHEREUM_HOST], new DateProvider());

yarn-project/end-to-end/src/spartan/invalidate_blocks.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
1010
import type { AztecNode, AztecNodeAdminConfig } from '@aztec/stdlib/interfaces/client';
1111

1212
import { jest } from '@jest/globals';
13-
import type { ChildProcess } from 'child_process';
1413

1514
import {
1615
ChainHealth,
16+
type ServiceEndpoint,
1717
getL1DeploymentAddresses,
1818
getNodeClient,
1919
getPublicViemClient,
@@ -34,7 +34,7 @@ describe('invalidate blocks test', () => {
3434

3535
const logger = createLogger(`e2e:invalidate-blocks`);
3636

37-
const forwardProcesses: ChildProcess[] = [];
37+
const endpoints: ServiceEndpoint[] = [];
3838

3939
let client: ViemPublicClient;
4040
let rollup: RollupContract;
@@ -59,15 +59,17 @@ describe('invalidate blocks test', () => {
5959
beforeAll(async () => {
6060
await health.setup();
6161
const deployAddresses = await getL1DeploymentAddresses(config);
62-
({ client } = await getPublicViemClient(config, forwardProcesses));
62+
const viemResult = await getPublicViemClient(config);
63+
client = viemResult.client;
64+
endpoints.push({ url: viemResult.url, process: viemResult.process });
6365
rollup = new RollupContract(client, deployAddresses.rollupAddress);
6466
monitor = new ChainMonitor(rollup, undefined, logger.createChild('chain-monitor'), 500).start();
6567
const c = await rollup.getRollupConstants();
6668
constants = { ...c, ethereumSlotDuration: ETHEREUM_SLOT_DURATION } as L1RollupConstants;
6769

68-
const { node: nodeClient, process } = await getNodeClient(config);
70+
const { node: nodeClient, process: nodeProcess, url: nodeUrl } = await getNodeClient(config);
6971
node = nodeClient;
70-
forwardProcesses.push(process);
72+
endpoints.push({ url: nodeUrl, process: nodeProcess });
7173
});
7274

7375
afterAll(async () => {
@@ -83,7 +85,7 @@ describe('invalidate blocks test', () => {
8385
await waitForSequencersToApplyConfig(restoreConfig, 'restore after invalidate-blocks');
8486
monitor.removeAllListeners();
8587
await monitor.stop();
86-
forwardProcesses.forEach(p => p.kill());
88+
endpoints.forEach(e => e.process?.kill());
8789
});
8890

8991
/** Waits for a CheckpointProposed event */

yarn-project/end-to-end/src/spartan/mempool_limit.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { TokenContract } from '@aztec/noir-contracts.js/Token';
2828
import { proveInteraction } from '@aztec/test-wallet/server';
2929

3030
import { jest } from '@jest/globals';
31-
import type { ChildProcess } from 'child_process';
3231

3332
import { getSponsoredFPCAddress } from '../fixtures/utils.js';
3433
import {
@@ -37,7 +36,14 @@ import {
3736
deploySponsoredTestAccounts,
3837
deploySponsoredTestAccountsWithTokens,
3938
} from './setup_test_wallets.js';
40-
import { ChainHealth, getExternalIP, getSequencersConfig, setupEnvironment, updateSequencersConfig } from './utils.js';
39+
import {
40+
ChainHealth,
41+
type ServiceEndpoint,
42+
getRPCEndpoint,
43+
getSequencersConfig,
44+
setupEnvironment,
45+
updateSequencersConfig,
46+
} from './utils.js';
4147

4248
const config = setupEnvironment(process.env);
4349

@@ -62,13 +68,14 @@ describe('mempool limiter test', () => {
6268
from: AztecAddress;
6369
}[] = [];
6470

65-
const forwardProcesses: ChildProcess[] = [];
71+
const endpoints: ServiceEndpoint[] = [];
6672
const health = new ChainHealth(config.NAMESPACE, debugLogger);
6773

6874
beforeAll(async () => {
6975
await health.setup();
70-
const rpcIP = await getExternalIP(config.NAMESPACE, 'rpc-aztec-node');
71-
rpcUrl = `http://${rpcIP}:8080`;
76+
const rpcEndpoint = await getRPCEndpoint(config.NAMESPACE);
77+
rpcUrl = rpcEndpoint.url;
78+
endpoints.push(rpcEndpoint);
7279
node = createAztecNodeClient(rpcUrl);
7380
const initialBlock = await node.getBlockNumber().catch(() => 0n);
7481
debugLogger.info(`Connected to RPC at ${rpcUrl}; initial L2 block: ${initialBlock}`);
@@ -188,7 +195,7 @@ describe('mempool limiter test', () => {
188195
for (const cleanup of cleanups) {
189196
await cleanup();
190197
}
191-
forwardProcesses.forEach(p => p.kill());
198+
endpoints.forEach(e => e.process?.kill());
192199
});
193200

194201
it('evicts txs to keep mempool under specified limit', async () => {

0 commit comments

Comments
 (0)