Skip to content

Commit 458360e

Browse files
authored
Parallelize Alchemy Webhook Calls. (#3124)
1 parent 99c7e6c commit 458360e

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

indexer/services/comlink/__tests__/helpers/alchemy-helpers.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ describe('alchemy-helpers', () => {
202202

203203
// Should still be called for all webhooks despite some failures
204204
// Failed webhooks will retry 3 times each, so: 1 + 3 + 3 + 3 + 1 + 1 = 12 calls
205-
expect(mockFetch).toHaveBeenCalledTimes(12); // 5 EVM chains + 1 Solana with retries
205+
// Plus 1 additional call from getKernelAddressFromECDSA for Avalanche chain = 13 calls
206+
expect(mockFetch).toHaveBeenCalledTimes(13);
206207
});
207208

208209
it('should handle missing EVM address', async () => {

indexer/services/comlink/src/helpers/alchemy-helpers.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,31 @@ export async function addAddressesToAlchemyWebhook(evm?: string, svm?: string):
6868
if (!record) {
6969
throw new Error(`EVM address does not exist in the database: ${evm}`);
7070
}
71-
// Iterate over all EVM networks and register the address with each webhook
72-
for (const [chainId, webhookId] of Object.entries(evmChainIdToAlchemyWebhookId)) {
73-
try {
74-
await registerAddressWithAlchemyWebhookWithRetry(evm, webhookId);
75-
logger.info({
76-
at: 'TurnkeyController#addAddressesToAlchemyWebhook',
77-
message: `Successfully registered EVM address with webhook for chain ${chainId}`,
78-
address: evm,
79-
chainId,
80-
webhookId,
81-
});
82-
} catch (error) {
83-
logger.error({
84-
at: 'TurnkeyController#addAddressesToAlchemyWebhook',
85-
message: `Failed to register EVM address with webhook for chain ${chainId} after retries`,
86-
error,
87-
address: evm,
88-
chainId,
89-
webhookId,
90-
});
91-
errors.push(`Failed to register EVM address with webhook for chain ${chainId} after retries`);
92-
}
93-
}
71+
// Register the address with all EVM webhooks in parallel
72+
await Promise.allSettled(
73+
Object.entries(evmChainIdToAlchemyWebhookId).map(async ([chainId, webhookId]) => {
74+
try {
75+
await registerAddressWithAlchemyWebhookWithRetry(evm, webhookId);
76+
logger.info({
77+
at: 'TurnkeyController#addAddressesToAlchemyWebhook',
78+
message: `Successfully registered EVM address with webhook for chain ${chainId}`,
79+
address: evm,
80+
chainId,
81+
webhookId,
82+
});
83+
} catch (error) {
84+
logger.error({
85+
at: 'TurnkeyController#addAddressesToAlchemyWebhook',
86+
message: `Failed to register EVM address with webhook for chain ${chainId} after retries`,
87+
error,
88+
address: evm,
89+
chainId,
90+
webhookId,
91+
});
92+
errors.push(`Failed to register EVM address with webhook for chain ${chainId} after retries`);
93+
}
94+
}),
95+
);
9496
}
9597

9698
// Add SVM address to webhook for monitoring

0 commit comments

Comments
 (0)