Skip to content

Commit 76aa1a9

Browse files
Add AWS KMS support to EOA benchmark script
1 parent bcc5c4c commit 76aa1a9

File tree

1 file changed

+103
-31
lines changed

1 file changed

+103
-31
lines changed

scripts/benchmarks/eoa.ts

Lines changed: 103 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ interface ImportMeta {
1111

1212
// Types based on events.rs
1313
interface WebhookEvent {
14-
transactionId: string;
15-
executorName: string;
14+
transactionId: string;
15+
executorName: string;
1616
stageName: string; // "send" | "confirm"
1717
eventType: string; // "Success" | "Nack" | "Failure"
1818
payload: any;
@@ -37,9 +37,12 @@ interface BenchmarkConfig {
3737
from: string;
3838
chainId: number;
3939
secretKey: string;
40-
vaultAccessToken: string;
40+
vaultAccessToken?: string;
4141
concurrentRequests: number;
4242
totalRequests: number;
43+
awsAccessKeyId?: string;
44+
awsKmsArn?: string;
45+
awsSecretAccessKey?: string;
4346
}
4447

4548
interface AggregateResults {
@@ -98,14 +101,19 @@ const config: BenchmarkConfig = {
98101
from: process.env.FROM!,
99102
chainId: parseInt(process.env.CHAIN_ID || "1337"),
100103
secretKey: process.env.SECRET_KEY!,
101-
vaultAccessToken: process.env.VAULT_ACCESS_TOKEN!,
104+
vaultAccessToken: process.env.VAULT_ACCESS_TOKEN,
105+
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
106+
awsKmsArn: process.env.AWS_KMS_ARN,
107+
awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
102108
concurrentRequests: parseInt(process.env.CONCURRENT_REQUESTS || "10"),
103109
totalRequests: parseInt(process.env.TOTAL_REQUESTS || "100"),
104110
};
105111

106112
// Validate required env vars
107-
if (!config.from || !config.secretKey || !config.vaultAccessToken) {
108-
console.error("❌ Missing required environment variables: FROM, SECRET_KEY, VAULT_ACCESS_TOKEN");
113+
if (!config.from || !config.secretKey) {
114+
console.error(
115+
"❌ Missing required environment variables: FROM, SECRET_KEY"
116+
);
109117
process.exit(1);
110118
}
111119

@@ -127,7 +135,9 @@ const webhookServer = Bun.serve({
127135
},
128136
});
129137

130-
console.log(`🎣 Webhook server listening on http://localhost:${webhookServer.port}`);
138+
console.log(
139+
`🎣 Webhook server listening on http://localhost:${webhookServer.port}`
140+
);
131141

132142
// Handle webhook events
133143
function handleWebhookEvent(event: WebhookEvent) {
@@ -147,12 +157,20 @@ function handleWebhookEvent(event: WebhookEvent) {
147157
metrics.submittedTime = now;
148158
metrics.sentToSubmittedMs = now - metrics.sentTime;
149159
metrics.status = "submitted";
150-
console.log(`✅ Transaction ${txId.slice(0, 8)}... submitted (${metrics.sentToSubmittedMs}ms)`);
160+
console.log(
161+
`✅ Transaction ${txId.slice(0, 8)}... submitted (${
162+
metrics.sentToSubmittedMs
163+
}ms)`
164+
);
151165
} else if (event.eventType === "Failure") {
152166
metrics.status = "failed";
153167
metrics.error = JSON.stringify(event.payload);
154168
pendingTransactions.delete(txId);
155-
console.log(`❌ Transaction ${txId.slice(0, 8)}... failed at send stage (pending: ${pendingTransactions.size})`);
169+
console.log(
170+
`❌ Transaction ${txId.slice(0, 8)}... failed at send stage (pending: ${
171+
pendingTransactions.size
172+
})`
173+
);
156174
}
157175
} else if (event.stageName === "confirm") {
158176
if (event.eventType === "SUCCESS") {
@@ -163,12 +181,23 @@ function handleWebhookEvent(event: WebhookEvent) {
163181
metrics.totalTimeMs = now - metrics.sentTime;
164182
metrics.status = "confirmed";
165183
pendingTransactions.delete(txId);
166-
console.log(`🎉 Transaction ${txId.slice(0, 8)}... confirmed (total: ${metrics.totalTimeMs}ms, pending: ${pendingTransactions.size})`);
167-
} else if (event.eventType === "FAIL" || event.eventType === "NACK") {
184+
console.log(
185+
`🎉 Transaction ${txId.slice(0, 8)}... confirmed (total: ${
186+
metrics.totalTimeMs
187+
}ms, pending: ${pendingTransactions.size})`
188+
);
189+
} else if (event.eventType === "FAIL") {
168190
metrics.status = "failed";
169191
metrics.error = JSON.stringify(event.payload);
170192
pendingTransactions.delete(txId);
171-
console.log(`❌ Transaction ${txId.slice(0, 8)}... failed at confirmation stage (pending: ${pendingTransactions.size})`);
193+
console.log(
194+
`❌ Transaction ${txId.slice(
195+
0,
196+
8
197+
)}... failed at confirmation stage (pending: ${
198+
pendingTransactions.size
199+
})`
200+
);
172201
}
173202
}
174203
}
@@ -183,7 +212,20 @@ async function sendTransaction(): Promise<TransactionMetrics> {
183212
headers: {
184213
"Content-Type": "application/json",
185214
"x-thirdweb-secret-key": config.secretKey,
186-
"x-vault-access-token": config.vaultAccessToken,
215+
...(config.vaultAccessToken
216+
? {
217+
"x-vault-access-token": config.vaultAccessToken,
218+
}
219+
: {}),
220+
...(config.awsAccessKeyId &&
221+
config.awsKmsArn &&
222+
config.awsSecretAccessKey
223+
? {
224+
"x-aws-access-key-id": config.awsAccessKeyId,
225+
"x-aws-kms-arn": config.awsKmsArn,
226+
"x-aws-secret-access-key": config.awsSecretAccessKey,
227+
}
228+
: {}),
187229
},
188230
body: JSON.stringify({
189231
executionOptions: {
@@ -214,17 +256,20 @@ async function sendTransaction(): Promise<TransactionMetrics> {
214256
throw new Error(`HTTP ${response.status}: ${errorText}`);
215257
}
216258

217-
const res = await response.json() as {
218-
result: {
219-
transactions: {
220-
id: string;
221-
}[]
222-
}
259+
const res = (await response.json()) as {
260+
result: {
261+
transactions: {
262+
id: string;
263+
}[];
264+
};
223265
};
224266
const transactionId = res.result.transactions[0]?.id;
225267

226268
if (!transactionId) {
227-
console.error("❌ No transaction ID in response:", JSON.stringify(response, null, 2));
269+
console.error(
270+
"❌ No transaction ID in response:",
271+
JSON.stringify(response, null, 2)
272+
);
228273
throw new Error("No transaction ID in response");
229274
}
230275

@@ -241,8 +286,13 @@ async function sendTransaction(): Promise<TransactionMetrics> {
241286

242287
transactions.set(transactionId, metrics);
243288
pendingTransactions.add(transactionId);
244-
245-
console.log(`📝 Added transaction ${transactionId.slice(0, 8)}... to pending (total: ${pendingTransactions.size})`);
289+
290+
console.log(
291+
`📝 Added transaction ${transactionId.slice(
292+
0,
293+
8
294+
)}... to pending (total: ${pendingTransactions.size})`
295+
);
246296

247297
return metrics;
248298
} catch (error) {
@@ -256,7 +306,11 @@ async function sendTransaction(): Promise<TransactionMetrics> {
256306
error: error instanceof Error ? error.message : String(error),
257307
};
258308
transactions.set(errorMetrics.transactionId, errorMetrics);
259-
console.error(`❌ Transaction request failed: ${error instanceof Error ? error.message : String(error)}`);
309+
console.error(
310+
`❌ Transaction request failed: ${
311+
error instanceof Error ? error.message : String(error)
312+
}`
313+
);
260314
return errorMetrics;
261315
}
262316
}
@@ -293,7 +347,11 @@ async function runBenchmark() {
293347

294348
// Progress indicator
295349
if ((i + 1) % 10 === 0) {
296-
console.log(`📤 Sent ${i + 1}/${config.totalRequests} requests... (in-flight: ${inFlight.size})`);
350+
console.log(
351+
`📤 Sent ${i + 1}/${config.totalRequests} requests... (in-flight: ${
352+
inFlight.size
353+
})`
354+
);
297355
}
298356
}
299357

@@ -313,15 +371,19 @@ async function runBenchmark() {
313371
waited += pollInterval;
314372

315373
if (waited % 5000 === 0) {
316-
console.log(` Still waiting for ${pendingTransactions.size} transactions...`);
374+
console.log(
375+
` Still waiting for ${pendingTransactions.size} transactions...`
376+
);
317377
}
318378
}
319379

320380
const endTime = Date.now();
321381
const duration = endTime - startTime;
322382

323383
if (pendingTransactions.size > 0) {
324-
console.warn(`\n⚠️ Timeout: ${pendingTransactions.size} transactions still pending`);
384+
console.warn(
385+
`\n⚠️ Timeout: ${pendingTransactions.size} transactions still pending`
386+
);
325387
} else {
326388
console.log(`\n🎉 All transactions completed!`);
327389
}
@@ -411,14 +473,21 @@ async function writeCSV(outputDir: string, timestamp: string) {
411473
m.error || "",
412474
]);
413475

414-
const csvContent = [headers.join(","), ...rows.map((row) => row.join(","))].join("\n");
476+
const csvContent = [
477+
headers.join(","),
478+
...rows.map((row) => row.join(",")),
479+
].join("\n");
415480

416481
await Bun.write(csvPath, csvContent);
417482
console.log(`📄 CSV written to: ${csvPath}`);
418483
}
419484

420485
// Write JSON results
421-
async function writeJSON(outputDir: string, timestamp: string, results: AggregateResults) {
486+
async function writeJSON(
487+
outputDir: string,
488+
timestamp: string,
489+
results: AggregateResults
490+
) {
422491
const jsonPath = `${outputDir}/result-${timestamp}.json`;
423492
await Bun.write(jsonPath, JSON.stringify(results, null, 2));
424493
console.log(`📊 Results written to: ${jsonPath}`);
@@ -435,7 +504,9 @@ function printResults(results: AggregateResults) {
435504
console.log(` Successful: ${results.successfulRequests}`);
436505
console.log(` Failed: ${results.failedRequests}`);
437506
console.log(` Error Rate: ${results.errorRate.toFixed(2)}%`);
438-
console.log(` Duration: ${(results.duration / 1000).toFixed(2)}s`);
507+
console.log(
508+
` Duration: ${(results.duration / 1000).toFixed(2)}s`
509+
);
439510
console.log(` Throughput: ${results.throughput.toFixed(2)} req/s`);
440511

441512
console.log("\n⏱️ HTTP Response Times (ms):");
@@ -458,7 +529,9 @@ function printResults(results: AggregateResults) {
458529

459530
console.log("\n✅ Submitted to Confirmed Times (ms):");
460531
console.log(` Min: ${results.submittedToConfirmedTimes.min.toFixed(2)}`);
461-
console.log(` Mean: ${results.submittedToConfirmedTimes.mean.toFixed(2)}`);
532+
console.log(
533+
` Mean: ${results.submittedToConfirmedTimes.mean.toFixed(2)}`
534+
);
462535
console.log(` P50: ${results.submittedToConfirmedTimes.p50.toFixed(2)}`);
463536
console.log(` P90: ${results.submittedToConfirmedTimes.p90.toFixed(2)}`);
464537
console.log(` P95: ${results.submittedToConfirmedTimes.p95.toFixed(2)}`);
@@ -513,4 +586,3 @@ async function main() {
513586

514587
// Run the benchmark
515588
main();
516-

0 commit comments

Comments
 (0)