@aztec/end-to-end 0.0.1-commit.3469e52 → 0.0.1-commit.381b1a9

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.
Files changed (202) hide show
  1. package/dest/bench/client_flows/client_flows_benchmark.d.ts +2 -2
  2. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
  3. package/dest/bench/client_flows/client_flows_benchmark.js +46 -24
  4. package/dest/bench/client_flows/config.d.ts +2 -2
  5. package/dest/bench/client_flows/config.d.ts.map +1 -1
  6. package/dest/bench/client_flows/config.js +18 -0
  7. package/dest/bench/utils.d.ts +5 -4
  8. package/dest/bench/utils.d.ts.map +1 -1
  9. package/dest/bench/utils.js +13 -8
  10. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +4 -2
  11. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  12. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +27 -18
  13. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +2 -2
  14. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  15. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +3 -2
  16. package/dest/e2e_deploy_contract/deploy_test.d.ts +2 -2
  17. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  18. package/dest/e2e_epochs/epochs_test.d.ts +15 -7
  19. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  20. package/dest/e2e_epochs/epochs_test.js +87 -39
  21. package/dest/e2e_fees/bridging_race.notest.js +1 -1
  22. package/dest/e2e_fees/fees_test.d.ts +2 -2
  23. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  24. package/dest/e2e_fees/fees_test.js +24 -17
  25. package/dest/e2e_l1_publisher/write_json.d.ts +4 -3
  26. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
  27. package/dest/e2e_l1_publisher/write_json.js +1 -7
  28. package/dest/e2e_nested_contract/nested_contract_test.js +4 -6
  29. package/dest/e2e_p2p/p2p_network.d.ts +2 -2
  30. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  31. package/dest/e2e_p2p/p2p_network.js +23 -6
  32. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  33. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  34. package/dest/e2e_p2p/reqresp/utils.js +177 -0
  35. package/dest/e2e_p2p/shared.d.ts +6 -6
  36. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  37. package/dest/e2e_p2p/shared.js +14 -17
  38. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
  39. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
  40. package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
  41. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
  42. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
  43. package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
  44. package/dest/e2e_token_contract/token_contract_test.d.ts +4 -2
  45. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  46. package/dest/e2e_token_contract/token_contract_test.js +20 -10
  47. package/dest/fixtures/authwit_proxy.d.ts +15 -0
  48. package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
  49. package/dest/fixtures/authwit_proxy.js +30 -0
  50. package/dest/fixtures/e2e_prover_test.d.ts +4 -4
  51. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
  52. package/dest/fixtures/e2e_prover_test.js +41 -45
  53. package/dest/fixtures/fixtures.d.ts +5 -1
  54. package/dest/fixtures/fixtures.d.ts.map +1 -1
  55. package/dest/fixtures/fixtures.js +6 -0
  56. package/dest/fixtures/ha_setup.d.ts +71 -0
  57. package/dest/fixtures/ha_setup.d.ts.map +1 -0
  58. package/dest/fixtures/ha_setup.js +116 -0
  59. package/dest/fixtures/index.d.ts +2 -1
  60. package/dest/fixtures/index.d.ts.map +1 -1
  61. package/dest/fixtures/index.js +1 -0
  62. package/dest/fixtures/setup.d.ts +48 -26
  63. package/dest/fixtures/setup.d.ts.map +1 -1
  64. package/dest/fixtures/setup.js +91 -169
  65. package/dest/fixtures/setup_p2p_test.d.ts +16 -9
  66. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  67. package/dest/fixtures/setup_p2p_test.js +40 -29
  68. package/dest/fixtures/token_utils.d.ts +1 -1
  69. package/dest/fixtures/token_utils.d.ts.map +1 -1
  70. package/dest/fixtures/token_utils.js +9 -6
  71. package/dest/shared/cross_chain_test_harness.d.ts +3 -4
  72. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  73. package/dest/shared/cross_chain_test_harness.js +24 -24
  74. package/dest/shared/gas_portal_test_harness.js +3 -3
  75. package/dest/shared/index.d.ts +2 -1
  76. package/dest/shared/index.d.ts.map +1 -1
  77. package/dest/shared/index.js +1 -0
  78. package/dest/shared/mock_state_view.d.ts +86 -0
  79. package/dest/shared/mock_state_view.d.ts.map +1 -0
  80. package/dest/shared/mock_state_view.js +186 -0
  81. package/dest/shared/submit-transactions.d.ts +4 -4
  82. package/dest/shared/submit-transactions.d.ts.map +1 -1
  83. package/dest/shared/submit-transactions.js +9 -11
  84. package/dest/shared/uniswap_l1_l2.d.ts +1 -1
  85. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  86. package/dest/shared/uniswap_l1_l2.js +27 -28
  87. package/dest/simulators/lending_simulator.d.ts +1 -1
  88. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  89. package/dest/simulators/lending_simulator.js +4 -4
  90. package/dest/simulators/token_simulator.d.ts +1 -1
  91. package/dest/simulators/token_simulator.d.ts.map +1 -1
  92. package/dest/simulators/token_simulator.js +3 -24
  93. package/dest/spartan/setup_test_wallets.d.ts +12 -3
  94. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  95. package/dest/spartan/setup_test_wallets.js +107 -37
  96. package/dest/spartan/tx_metrics.d.ts +38 -2
  97. package/dest/spartan/tx_metrics.d.ts.map +1 -1
  98. package/dest/spartan/tx_metrics.js +178 -4
  99. package/dest/spartan/utils/bot.d.ts +28 -0
  100. package/dest/spartan/utils/bot.d.ts.map +1 -0
  101. package/dest/spartan/utils/bot.js +142 -0
  102. package/dest/spartan/utils/chaos.d.ts +79 -0
  103. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  104. package/dest/spartan/utils/chaos.js +142 -0
  105. package/dest/spartan/utils/clients.d.ts +39 -0
  106. package/dest/spartan/utils/clients.d.ts.map +1 -0
  107. package/dest/spartan/utils/clients.js +90 -0
  108. package/dest/spartan/utils/config.d.ts +39 -0
  109. package/dest/spartan/utils/config.d.ts.map +1 -0
  110. package/dest/spartan/utils/config.js +21 -0
  111. package/dest/spartan/utils/health.d.ts +63 -0
  112. package/dest/spartan/utils/health.d.ts.map +1 -0
  113. package/dest/spartan/utils/health.js +202 -0
  114. package/dest/spartan/utils/helm.d.ts +15 -0
  115. package/dest/spartan/utils/helm.d.ts.map +1 -0
  116. package/dest/spartan/utils/helm.js +47 -0
  117. package/dest/spartan/utils/index.d.ts +10 -0
  118. package/dest/spartan/utils/index.d.ts.map +1 -0
  119. package/dest/spartan/utils/index.js +20 -0
  120. package/dest/spartan/utils/k8s.d.ts +128 -0
  121. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  122. package/dest/spartan/utils/k8s.js +381 -0
  123. package/dest/spartan/utils/nodes.d.ts +41 -0
  124. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  125. package/dest/spartan/utils/nodes.js +461 -0
  126. package/dest/spartan/utils/scripts.d.ts +30 -0
  127. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  128. package/dest/spartan/utils/scripts.js +81 -0
  129. package/dest/spartan/utils.d.ts +2 -260
  130. package/dest/spartan/utils.d.ts.map +1 -1
  131. package/dest/spartan/utils.js +1 -942
  132. package/dest/test-wallet/test_wallet.d.ts +83 -0
  133. package/dest/test-wallet/test_wallet.d.ts.map +1 -0
  134. package/dest/test-wallet/test_wallet.js +214 -0
  135. package/dest/test-wallet/utils.d.ts +41 -0
  136. package/dest/test-wallet/utils.d.ts.map +1 -0
  137. package/dest/test-wallet/utils.js +71 -0
  138. package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
  139. package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
  140. package/dest/test-wallet/wallet_worker_script.js +48 -0
  141. package/dest/test-wallet/worker_wallet.d.ts +52 -0
  142. package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
  143. package/dest/test-wallet/worker_wallet.js +151 -0
  144. package/dest/test-wallet/worker_wallet_schema.d.ts +274 -0
  145. package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
  146. package/dest/test-wallet/worker_wallet_schema.js +10 -0
  147. package/package.json +43 -39
  148. package/src/bench/client_flows/client_flows_benchmark.ts +48 -58
  149. package/src/bench/client_flows/config.ts +9 -1
  150. package/src/bench/utils.ts +15 -8
  151. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +33 -23
  152. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +7 -8
  153. package/src/e2e_deploy_contract/deploy_test.ts +3 -3
  154. package/src/e2e_epochs/epochs_test.ts +130 -93
  155. package/src/e2e_fees/bridging_race.notest.ts +2 -5
  156. package/src/e2e_fees/fees_test.ts +28 -40
  157. package/src/e2e_l1_publisher/write_json.ts +3 -8
  158. package/src/e2e_nested_contract/nested_contract_test.ts +7 -7
  159. package/src/e2e_p2p/inactivity_slash_test.ts +4 -4
  160. package/src/e2e_p2p/p2p_network.ts +46 -17
  161. package/src/e2e_p2p/reqresp/utils.ts +235 -0
  162. package/src/e2e_p2p/shared.ts +22 -22
  163. package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
  164. package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
  165. package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
  166. package/src/e2e_token_contract/token_contract_test.ts +27 -12
  167. package/src/fixtures/authwit_proxy.ts +50 -0
  168. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  169. package/src/fixtures/e2e_prover_test.ts +43 -52
  170. package/src/fixtures/fixtures.ts +10 -0
  171. package/src/fixtures/ha_setup.ts +186 -0
  172. package/src/fixtures/index.ts +1 -0
  173. package/src/fixtures/setup.ts +125 -233
  174. package/src/fixtures/setup_p2p_test.ts +40 -44
  175. package/src/fixtures/token_utils.ts +9 -6
  176. package/src/guides/up_quick_start.sh +3 -3
  177. package/src/shared/cross_chain_test_harness.ts +24 -34
  178. package/src/shared/gas_portal_test_harness.ts +2 -2
  179. package/src/shared/index.ts +1 -0
  180. package/src/shared/mock_state_view.ts +188 -0
  181. package/src/shared/submit-transactions.ts +11 -16
  182. package/src/shared/uniswap_l1_l2.ts +49 -51
  183. package/src/simulators/lending_simulator.ts +6 -4
  184. package/src/simulators/token_simulator.ts +6 -30
  185. package/src/spartan/setup_test_wallets.ts +150 -25
  186. package/src/spartan/tx_metrics.ts +152 -7
  187. package/src/spartan/utils/bot.ts +188 -0
  188. package/src/spartan/utils/chaos.ts +253 -0
  189. package/src/spartan/utils/clients.ts +100 -0
  190. package/src/spartan/utils/config.ts +27 -0
  191. package/src/spartan/utils/health.ts +255 -0
  192. package/src/spartan/utils/helm.ts +84 -0
  193. package/src/spartan/utils/index.ts +68 -0
  194. package/src/spartan/utils/k8s.ts +535 -0
  195. package/src/spartan/utils/nodes.ts +538 -0
  196. package/src/spartan/utils/scripts.ts +99 -0
  197. package/src/spartan/utils.ts +1 -1246
  198. package/src/test-wallet/test_wallet.ts +306 -0
  199. package/src/test-wallet/utils.ts +112 -0
  200. package/src/test-wallet/wallet_worker_script.ts +60 -0
  201. package/src/test-wallet/worker_wallet.ts +213 -0
  202. package/src/test-wallet/worker_wallet_schema.ts +13 -0
@@ -1,10 +1,137 @@
1
1
  import type { AztecNode } from '@aztec/aztec.js/node';
2
- import type { L2BlockNew } from '@aztec/stdlib/block';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+ import type { L2Block } from '@aztec/stdlib/block';
3
4
  import type { TopicType } from '@aztec/stdlib/p2p';
4
- import { Tx, type TxReceipt, TxStatus } from '@aztec/stdlib/tx';
5
+ import { Tx, type TxReceipt } from '@aztec/stdlib/tx';
5
6
 
6
7
  import { createHistogram } from 'perf_hooks';
7
8
 
9
+ /** Metrics class for proving-related benchmarks. */
10
+ export class ProvingMetrics {
11
+ private successfulTxs: number | undefined;
12
+ private proofDuration: number | undefined;
13
+ private activeAgents: number | undefined;
14
+ private avgQueueTime: number | undefined;
15
+ private jobRetries: number | undefined;
16
+ private jobDuration: number | undefined;
17
+ private timedOutJobs: number | undefined;
18
+ private resolvedJobs: number | undefined;
19
+ private rejectedJobs: number | undefined;
20
+ private epochProvingDuration: number | undefined;
21
+ private provenTransactions: number | undefined;
22
+ private provenBlocks: number | undefined;
23
+
24
+ constructor(private prefix: string) {}
25
+
26
+ recordSuccessfulTxs(count: number): void {
27
+ this.successfulTxs = count;
28
+ }
29
+
30
+ recordProofDuration(seconds: number): void {
31
+ this.proofDuration = seconds;
32
+ }
33
+
34
+ recordActiveAgents(count: number): void {
35
+ this.activeAgents = count;
36
+ }
37
+
38
+ recordAvgQueueTime(ms: number): void {
39
+ this.avgQueueTime = ms;
40
+ }
41
+
42
+ recordJobRetries(count: number): void {
43
+ this.jobRetries = count;
44
+ }
45
+
46
+ recordJobDuration(ms: number): void {
47
+ this.jobDuration = ms;
48
+ }
49
+
50
+ recordTimedOutJobs(count: number): void {
51
+ this.timedOutJobs = count;
52
+ }
53
+
54
+ recordResolvedJobs(count: number): void {
55
+ this.resolvedJobs = count;
56
+ }
57
+
58
+ recordRejectedJobs(count: number): void {
59
+ this.rejectedJobs = count;
60
+ }
61
+
62
+ recordEpochProvingDuration(seconds: number): void {
63
+ this.epochProvingDuration = seconds;
64
+ }
65
+
66
+ recordProvenTransactions(count: number): void {
67
+ this.provenTransactions = count;
68
+ }
69
+
70
+ recordProvenBlocks(count: number): void {
71
+ this.provenBlocks = count;
72
+ }
73
+
74
+ toGithubActionBenchmarkJSON(): Array<{ name: string; unit: string; value: number }> {
75
+ const data: Array<{ name: string; unit: string; value: number }> = [];
76
+
77
+ if (this.successfulTxs !== undefined) {
78
+ data.push({ name: `${this.prefix}/successful_txs`, unit: 'count', value: this.successfulTxs });
79
+ }
80
+
81
+ if (this.proofDuration !== undefined) {
82
+ data.push({ name: `${this.prefix}/proof_duration`, unit: 's', value: this.proofDuration });
83
+ }
84
+
85
+ if (this.activeAgents !== undefined) {
86
+ data.push({ name: `${this.prefix}/active_agents`, unit: 'count', value: this.activeAgents });
87
+ }
88
+
89
+ if (this.avgQueueTime !== undefined) {
90
+ data.push({ name: `${this.prefix}/avg_queue_time`, unit: 'ms', value: this.avgQueueTime });
91
+ }
92
+
93
+ if (this.jobRetries !== undefined) {
94
+ data.push({ name: `${this.prefix}/job_retries`, unit: 'count', value: this.jobRetries });
95
+ }
96
+
97
+ if (this.jobDuration !== undefined) {
98
+ data.push({ name: `${this.prefix}/job_duration`, unit: 'ms', value: this.jobDuration });
99
+ }
100
+
101
+ if (this.timedOutJobs !== undefined) {
102
+ data.push({ name: `${this.prefix}/timed_out_jobs`, unit: 'count', value: this.timedOutJobs });
103
+ }
104
+
105
+ if (this.resolvedJobs !== undefined) {
106
+ data.push({ name: `${this.prefix}/resolved_jobs`, unit: 'count', value: this.resolvedJobs });
107
+ }
108
+
109
+ if (this.rejectedJobs !== undefined) {
110
+ data.push({ name: `${this.prefix}/rejected_jobs`, unit: 'count', value: this.rejectedJobs });
111
+ }
112
+
113
+ if (this.epochProvingDuration !== undefined) {
114
+ data.push({ name: `${this.prefix}/epoch_proving_duration`, unit: 's', value: this.epochProvingDuration });
115
+ }
116
+
117
+ if (this.provenTransactions !== undefined) {
118
+ data.push({ name: `${this.prefix}/proven_transactions`, unit: 'count', value: this.provenTransactions });
119
+ }
120
+
121
+ if (this.provenBlocks !== undefined) {
122
+ data.push({ name: `${this.prefix}/proven_blocks`, unit: 'count', value: this.provenBlocks });
123
+ }
124
+
125
+ const scenario = process.env.BENCH_SCENARIO?.trim();
126
+ if (!scenario) {
127
+ return data;
128
+ }
129
+
130
+ const scenarioPrefix = `scenario/${scenario}/`;
131
+ return data.map(entry => ({ ...entry, name: `${scenarioPrefix}${entry.name}` }));
132
+ }
133
+ }
134
+
8
135
  export type TxInclusionData = {
9
136
  txHash: string;
10
137
  sentAt: number;
@@ -20,7 +147,7 @@ export type TxInclusionData = {
20
147
  export class TxInclusionMetrics {
21
148
  private data = new Map<string, TxInclusionData>();
22
149
  private groups = new Set<string>();
23
- private blocks = new Map<number, Promise<L2BlockNew | undefined>>();
150
+ private blocks = new Map<number, Promise<L2Block | undefined>>();
24
151
 
25
152
  private p2pGossipLatencyByTopic: Partial<Record<TopicType, { p50: number; p95: number }>> = {};
26
153
 
@@ -32,12 +159,19 @@ export class TxInclusionMetrics {
32
159
  | { txP50: number; txP95: number; attestationP50: number; attestationP95: number }
33
160
  | undefined;
34
161
 
35
- constructor(private aztecNode: AztecNode) {}
162
+ constructor(
163
+ private aztecNode: AztecNode,
164
+ private logger?: Logger,
165
+ ) {}
36
166
 
37
167
  recordSentTx(tx: Tx, group: string): void {
38
168
  const txHash = tx.getTxHash().toString();
39
169
  const priorityFees = tx.getGasSettings().maxPriorityFeesPerGas;
40
170
 
171
+ if (this.data.has(txHash)) {
172
+ this.logger?.debug(`Overwriting tx inclusion data for ${txHash}`, { txHash, group });
173
+ }
174
+
41
175
  this.data.set(txHash, {
42
176
  txHash,
43
177
  sentAt: Math.trunc(Date.now() / 1000),
@@ -53,8 +187,13 @@ export class TxInclusionMetrics {
53
187
  }
54
188
 
55
189
  async recordMinedTx(txReceipt: TxReceipt): Promise<void> {
56
- const { status, txHash, blockNumber } = txReceipt;
57
- if (status !== TxStatus.SUCCESS || !blockNumber) {
190
+ const { txHash, blockNumber } = txReceipt;
191
+ if (!txReceipt.isMined() || !txReceipt.hasExecutionSucceeded() || !blockNumber) {
192
+ this.logger?.debug('Skipping mined tx record due to receipt status', {
193
+ txHash: txHash.toString(),
194
+ status: txReceipt.status,
195
+ blockNumber,
196
+ });
58
197
  return;
59
198
  }
60
199
 
@@ -64,9 +203,15 @@ export class TxInclusionMetrics {
64
203
 
65
204
  const block = await this.blocks.get(blockNumber)!;
66
205
  if (!block) {
206
+ this.logger?.warn('Failed to load block for mined tx receipt', { txHash: txHash.toString(), blockNumber });
67
207
  return;
68
208
  }
69
- const data = this.data.get(txHash.toString())!;
209
+ const data = this.data.get(txHash.toString());
210
+ if (!data) {
211
+ const message = `Missing sent tx record for mined tx ${txHash.toString()}`;
212
+ this.logger?.warn(message, { txHash: txHash.toString(), blockNumber });
213
+ throw new Error(message);
214
+ }
70
215
  data.blocknumber = blockNumber;
71
216
  data.minedAt = Number(block.header.globalVariables.timestamp);
72
217
  data.attestedAt = -1;
@@ -0,0 +1,188 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { sleep } from '@aztec/foundation/sleep';
3
+
4
+ import { exec } from 'child_process';
5
+ import { promisify } from 'util';
6
+
7
+ import { execHelmCommand, forceDeleteHelmReleaseRecord, getHelmReleaseStatus, hasDeployedHelmRelease } from './helm.js';
8
+ import { deleteResourceByLabel, getChartDir, waitForResourceByLabel } from './k8s.js';
9
+
10
+ const execAsync = promisify(exec);
11
+
12
+ export async function restartBot(namespace: string, log: Logger) {
13
+ log.info(`Restarting bot`);
14
+ await deleteResourceByLabel({ resource: 'pods', namespace, label: 'app.kubernetes.io/name=bot' });
15
+ await sleep(10 * 1000);
16
+ // Some bot images may take time to report Ready due to heavy boot-time proving.
17
+ // Waiting for PodReadyToStartContainers ensures the pod is scheduled and starting without blocking on full readiness.
18
+ await waitForResourceByLabel({
19
+ resource: 'pods',
20
+ namespace,
21
+ label: 'app.kubernetes.io/name=bot',
22
+ condition: 'PodReadyToStartContainers',
23
+ });
24
+ log.info(`Bot restarted`);
25
+ }
26
+
27
+ /**
28
+ * Installs or upgrades the transfer bot Helm release for the given namespace.
29
+ * Intended for test setup to enable L2 traffic generation only when needed.
30
+ */
31
+ export async function installTransferBot({
32
+ namespace,
33
+ spartanDir,
34
+ logger: log,
35
+ replicas = 1,
36
+ txIntervalSeconds = 10,
37
+ followChain = 'CHECKPOINTED',
38
+ pxeSyncChainTip = 'proposed',
39
+ mnemonic = process.env.LABS_INFRA_MNEMONIC ?? 'test test test test test test test test test test test junk',
40
+ mnemonicStartIndex,
41
+ botPrivateKey = process.env.BOT_TRANSFERS_L2_PRIVATE_KEY ?? '0xcafe01',
42
+ nodeUrl,
43
+ timeout = '15m',
44
+ reuseValues = true,
45
+ aztecSlotDuration = Number(process.env.AZTEC_SLOT_DURATION ?? 12),
46
+ }: {
47
+ namespace: string;
48
+ spartanDir: string;
49
+ logger: Logger;
50
+ replicas?: number;
51
+ txIntervalSeconds?: number;
52
+ followChain?: string;
53
+ pxeSyncChainTip?: string;
54
+ mnemonic?: string;
55
+ mnemonicStartIndex?: number | string;
56
+ botPrivateKey?: string;
57
+ nodeUrl?: string;
58
+ timeout?: string;
59
+ reuseValues?: boolean;
60
+ aztecSlotDuration?: number;
61
+ }) {
62
+ const instanceName = `${namespace}-bot-transfers`;
63
+ const helmChartDir = getChartDir(spartanDir, 'aztec-bot');
64
+ const resolvedNodeUrl = nodeUrl ?? `http://${namespace}-rpc-aztec-node.${namespace}.svc.cluster.local:8080`;
65
+
66
+ log.info(`Installing/upgrading transfer bot: replicas=${replicas}, followChain=${followChain}`);
67
+
68
+ const values: Record<string, string | number | boolean> = {
69
+ 'bot.replicaCount': replicas,
70
+ 'bot.txIntervalSeconds': txIntervalSeconds,
71
+ 'bot.followChain': followChain,
72
+ 'bot.pxeSyncChainTip': pxeSyncChainTip,
73
+ 'bot.botPrivateKey': botPrivateKey,
74
+ 'bot.nodeUrl': resolvedNodeUrl,
75
+ 'bot.mnemonic': mnemonic,
76
+ 'bot.feePaymentMethod': 'fee_juice',
77
+ 'aztec.slotDuration': aztecSlotDuration,
78
+ // Ensure bot can reach its own PXE started in-process (default rpc.port is 8080)
79
+ // Note: since aztec-bot depends on aztec-node with alias `bot`, env vars go under `bot.node.env`.
80
+ 'bot.node.env.BOT_PXE_URL': 'http://127.0.0.1:8080',
81
+ // Provide L1 execution RPC for bridging fee juice
82
+ 'bot.node.env.ETHEREUM_HOSTS': `http://${namespace}-eth-execution.${namespace}.svc.cluster.local:8545`,
83
+ // Provide L1 mnemonic for bridging (falls back to labs mnemonic)
84
+ 'bot.node.env.BOT_L1_MNEMONIC': mnemonic,
85
+
86
+ // The bot does not need Kubernetes API access. Disable RBAC + ServiceAccount creation so the chart
87
+ // can be installed by users without cluster-scoped RBAC permissions.
88
+ 'bot.rbac.create': false,
89
+ 'bot.serviceAccount.create': false,
90
+ 'bot.serviceAccount.name': 'default',
91
+ };
92
+ // Ensure we derive a funded L1 key (index 0 is funded on anvil default mnemonic)
93
+ if (mnemonicStartIndex === undefined) {
94
+ values['bot.mnemonicStartIndex'] = 0;
95
+ }
96
+ // Also pass a funded private key directly if available
97
+ if (process.env.FUNDING_PRIVATE_KEY) {
98
+ values['bot.node.env.BOT_L1_PRIVATE_KEY'] = process.env.FUNDING_PRIVATE_KEY;
99
+ }
100
+ // Align bot image with the running network image: prefer env var, else detect from a validator pod
101
+ let repositoryFromEnv: string | undefined;
102
+ let tagFromEnv: string | undefined;
103
+ const aztecDockerImage = process.env.AZTEC_DOCKER_IMAGE;
104
+ if (aztecDockerImage && aztecDockerImage.includes(':')) {
105
+ const lastColon = aztecDockerImage.lastIndexOf(':');
106
+ repositoryFromEnv = aztecDockerImage.slice(0, lastColon);
107
+ tagFromEnv = aztecDockerImage.slice(lastColon + 1);
108
+ }
109
+
110
+ let repository = repositoryFromEnv;
111
+ let tag = tagFromEnv;
112
+ if (!repository || !tag) {
113
+ try {
114
+ const { stdout } = await execAsync(
115
+ `kubectl get pods -l app.kubernetes.io/name=validator -n ${namespace} -o jsonpath='{.items[0].spec.containers[?(@.name=="aztec")].image}' | cat`,
116
+ );
117
+ const image = stdout.trim().replace(/^'|'$/g, '');
118
+ if (image && image.includes(':')) {
119
+ const lastColon = image.lastIndexOf(':');
120
+ repository = image.slice(0, lastColon);
121
+ tag = image.slice(lastColon + 1);
122
+ }
123
+ } catch (err) {
124
+ log.warn(`Could not detect aztec image from validator pod: ${String(err)}`);
125
+ }
126
+ }
127
+ if (repository && tag) {
128
+ values['global.aztecImage.repository'] = repository;
129
+ values['global.aztecImage.tag'] = tag;
130
+ }
131
+ if (mnemonicStartIndex !== undefined) {
132
+ values['bot.mnemonicStartIndex'] =
133
+ typeof mnemonicStartIndex === 'string' ? mnemonicStartIndex : Number(mnemonicStartIndex);
134
+ }
135
+
136
+ // If a previous install attempt left the release in a non-deployed state (e.g. FAILED),
137
+ // `helm upgrade --install` can error with "has no deployed releases".
138
+ // In that case, clear the release record and do a clean install.
139
+ const existingStatus = await getHelmReleaseStatus(instanceName, namespace);
140
+ if (existingStatus && existingStatus.toLowerCase() !== 'deployed') {
141
+ log.warn(`Transfer bot release ${instanceName} is in status '${existingStatus}'. Reinstalling cleanly.`);
142
+ await execAsync(`helm uninstall ${instanceName} --namespace ${namespace} --wait --ignore-not-found`).catch(
143
+ () => undefined,
144
+ );
145
+ // If helm left the release in `uninstalling`, force-delete the record so we can reinstall.
146
+ const afterUninstallStatus = await getHelmReleaseStatus(instanceName, namespace);
147
+ if (afterUninstallStatus?.toLowerCase() === 'uninstalling') {
148
+ await forceDeleteHelmReleaseRecord(instanceName, namespace, log);
149
+ }
150
+ }
151
+
152
+ // `--reuse-values` fails if the release has never successfully deployed (e.g. first install, or a previous failed install).
153
+ // Only reuse values when we have a deployed release to reuse from.
154
+ const effectiveReuseValues = reuseValues && (await hasDeployedHelmRelease(instanceName, namespace));
155
+
156
+ await execHelmCommand({
157
+ instanceName,
158
+ helmChartDir,
159
+ namespace,
160
+ valuesFile: undefined,
161
+ timeout,
162
+ values: values as unknown as Record<string, string | number | boolean>,
163
+ reuseValues: effectiveReuseValues,
164
+ });
165
+
166
+ if (replicas > 0) {
167
+ await waitForResourceByLabel({
168
+ resource: 'pods',
169
+ namespace,
170
+ label: 'app.kubernetes.io/name=bot',
171
+ condition: 'PodReadyToStartContainers',
172
+ });
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Uninstalls the transfer bot Helm release from the given namespace.
178
+ * Intended for test teardown to clean up bot resources.
179
+ */
180
+ export async function uninstallTransferBot(namespace: string, log: Logger) {
181
+ const instanceName = `${namespace}-bot-transfers`;
182
+ log.info(`Uninstalling transfer bot release ${instanceName}`);
183
+ await execAsync(`helm uninstall ${instanceName} --namespace ${namespace} --wait --ignore-not-found`);
184
+ // Ensure any leftover pods are removed
185
+ await deleteResourceByLabel({ resource: 'pods', namespace, label: 'app.kubernetes.io/name=bot' }).catch(
186
+ () => undefined,
187
+ );
188
+ }
@@ -0,0 +1,253 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+
3
+ import { exec } from 'child_process';
4
+ import { promisify } from 'util';
5
+
6
+ import { execHelmCommand } from './helm.js';
7
+ import { deleteResourceByLabel, getChartDir } from './k8s.js';
8
+
9
+ const execAsync = promisify(exec);
10
+
11
+ export async function uninstallChaosMesh(instanceName: string, namespace: string, log: Logger) {
12
+ // uninstall the helm chart if it exists
13
+ log.info(`Uninstalling helm chart ${instanceName}`);
14
+ await execAsync(`helm uninstall ${instanceName} --namespace ${namespace} --wait --ignore-not-found`);
15
+ // and delete the chaos-mesh resources created by this release
16
+ const deleteByLabel = async (resource: string) => {
17
+ const args = {
18
+ resource,
19
+ namespace: namespace,
20
+ label: `app.kubernetes.io/instance=${instanceName}`,
21
+ } as const;
22
+ log.info(`Deleting ${resource} resources for release ${instanceName}`);
23
+ await deleteResourceByLabel(args).catch(e => {
24
+ log.error(`Error deleting ${resource}: ${e}`);
25
+ log.info(`Force deleting ${resource}`);
26
+ return deleteResourceByLabel({ ...args, force: true });
27
+ });
28
+ };
29
+
30
+ await deleteByLabel('podchaos');
31
+ await deleteByLabel('networkchaos');
32
+ await deleteByLabel('podnetworkchaos');
33
+ await deleteByLabel('workflows');
34
+ await deleteByLabel('workflownodes');
35
+ }
36
+
37
+ /**
38
+ * Installs a Helm chart with the given parameters.
39
+ * @param instanceName - The name of the Helm chart instance.
40
+ * @param targetNamespace - The namespace with the resources to be affected by the Helm chart.
41
+ * @param valuesFile - The values file to use for the Helm chart.
42
+ * @param chaosMeshNamespace - The namespace to install the Helm chart in.
43
+ * @param timeout - The timeout for the Helm command.
44
+ * @param clean - Whether to clean up the Helm chart before installing it.
45
+ * @returns The stdout of the Helm command.
46
+ * @throws If the Helm command fails.
47
+ *
48
+ * Example usage:
49
+ * ```typescript
50
+ * const stdout = await installChaosMeshChart({ instanceName: 'force-reorg', targetNamespace: 'smoke', valuesFile: 'prover-failure.yaml'});
51
+ * console.log(stdout);
52
+ * ```
53
+ */
54
+ export async function installChaosMeshChart({
55
+ instanceName,
56
+ targetNamespace,
57
+ valuesFile,
58
+ helmChartDir,
59
+ timeout = '10m',
60
+ clean = true,
61
+ values = {},
62
+ logger: log,
63
+ }: {
64
+ instanceName: string;
65
+ targetNamespace: string;
66
+ valuesFile: string;
67
+ helmChartDir: string;
68
+ chaosMeshNamespace?: string;
69
+ timeout?: string;
70
+ clean?: boolean;
71
+ values?: Record<string, string | number>;
72
+ logger: Logger;
73
+ }) {
74
+ if (clean) {
75
+ await uninstallChaosMesh(instanceName, targetNamespace, log);
76
+ }
77
+
78
+ return execHelmCommand({
79
+ instanceName,
80
+ helmChartDir,
81
+ namespace: targetNamespace,
82
+ valuesFile,
83
+ timeout,
84
+ values: { ...values, 'global.targetNamespace': targetNamespace },
85
+ });
86
+ }
87
+
88
+ export function applyProverFailure({
89
+ namespace,
90
+ spartanDir,
91
+ durationSeconds,
92
+ logger: log,
93
+ }: {
94
+ namespace: string;
95
+ spartanDir: string;
96
+ durationSeconds: number;
97
+ logger: Logger;
98
+ }) {
99
+ return installChaosMeshChart({
100
+ instanceName: 'prover-failure',
101
+ targetNamespace: namespace,
102
+ valuesFile: 'prover-failure.yaml',
103
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
104
+ values: {
105
+ 'proverFailure.duration': `${durationSeconds}s`,
106
+ },
107
+ logger: log,
108
+ });
109
+ }
110
+
111
+ export function applyValidatorFailure({
112
+ namespace,
113
+ spartanDir,
114
+ logger: log,
115
+ values,
116
+ instanceName,
117
+ }: {
118
+ namespace: string;
119
+ spartanDir: string;
120
+ logger: Logger;
121
+ values?: Record<string, string | number>;
122
+ instanceName?: string;
123
+ }) {
124
+ return installChaosMeshChart({
125
+ instanceName: instanceName ?? 'validator-failure',
126
+ targetNamespace: namespace,
127
+ valuesFile: 'validator-failure.yaml',
128
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
129
+ values,
130
+ logger: log,
131
+ });
132
+ }
133
+
134
+ export function applyProverKill({
135
+ namespace,
136
+ spartanDir,
137
+ logger: log,
138
+ values,
139
+ }: {
140
+ namespace: string;
141
+ spartanDir: string;
142
+ logger: Logger;
143
+ values?: Record<string, string | number>;
144
+ }) {
145
+ return installChaosMeshChart({
146
+ instanceName: 'prover-kill',
147
+ targetNamespace: namespace,
148
+ valuesFile: 'prover-kill.yaml',
149
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
150
+ chaosMeshNamespace: namespace,
151
+ clean: true,
152
+ logger: log,
153
+ values,
154
+ });
155
+ }
156
+
157
+ export function applyProverBrokerKill({
158
+ namespace,
159
+ spartanDir,
160
+ logger: log,
161
+ values,
162
+ }: {
163
+ namespace: string;
164
+ spartanDir: string;
165
+ logger: Logger;
166
+ values?: Record<string, string | number>;
167
+ }) {
168
+ return installChaosMeshChart({
169
+ instanceName: 'prover-broker-kill',
170
+ targetNamespace: namespace,
171
+ valuesFile: 'prover-broker-kill.yaml',
172
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
173
+ clean: true,
174
+ logger: log,
175
+ values,
176
+ });
177
+ }
178
+
179
+ export function applyBootNodeFailure({
180
+ instanceName = 'boot-node-failure',
181
+ namespace,
182
+ spartanDir,
183
+ durationSeconds,
184
+ logger: log,
185
+ values,
186
+ }: {
187
+ instanceName?: string;
188
+ namespace: string;
189
+ spartanDir: string;
190
+ durationSeconds: number;
191
+ logger: Logger;
192
+ values?: Record<string, string | number>;
193
+ }) {
194
+ return installChaosMeshChart({
195
+ instanceName,
196
+ targetNamespace: namespace,
197
+ valuesFile: 'boot-node-failure.yaml',
198
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
199
+ values: {
200
+ 'bootNodeFailure.duration': `${durationSeconds}s`,
201
+ ...(values ?? {}),
202
+ },
203
+ logger: log,
204
+ });
205
+ }
206
+
207
+ export function applyValidatorKill({
208
+ instanceName = 'validator-kill',
209
+ namespace,
210
+ spartanDir,
211
+ logger: log,
212
+ values,
213
+ clean = true,
214
+ }: {
215
+ instanceName?: string;
216
+ namespace: string;
217
+ spartanDir: string;
218
+ logger: Logger;
219
+ values?: Record<string, string | number>;
220
+ clean?: boolean;
221
+ }) {
222
+ return installChaosMeshChart({
223
+ instanceName: instanceName ?? 'validator-kill',
224
+ targetNamespace: namespace,
225
+ valuesFile: 'validator-kill.yaml',
226
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
227
+ clean,
228
+ logger: log,
229
+ values,
230
+ });
231
+ }
232
+
233
+ export function applyNetworkShaping({
234
+ instanceName = 'network-shaping',
235
+ valuesFile,
236
+ namespace,
237
+ spartanDir,
238
+ logger: log,
239
+ }: {
240
+ instanceName?: string;
241
+ valuesFile: string;
242
+ namespace: string;
243
+ spartanDir: string;
244
+ logger: Logger;
245
+ }) {
246
+ return installChaosMeshChart({
247
+ instanceName,
248
+ targetNamespace: namespace,
249
+ valuesFile,
250
+ helmChartDir: getChartDir(spartanDir, 'aztec-chaos-scenarios'),
251
+ logger: log,
252
+ });
253
+ }