Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions app/pages/contract/[address].vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ watch(
immediate: true,
},
);
async function fetchCodeHashWithRetries(chain: Chain): Promise<void> {
const maxAttempts = 3;
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const codeHash = await getCodeHash(chain);
if (codeHash !== undefined) {
codeHashes.value[chain] = codeHash;
return;
}
if (attempt < maxAttempts - 1) {
continue;
}
codeHashes.value[chain] = undefined;
}
}
async function fetchCode(): Promise<void> {
codeHashes.value = {};
// Get cached code first
Expand All @@ -165,23 +179,21 @@ async function fetchCode(): Promise<void> {
const codeHash = cachedCodeHashes[chain];
codeHashes.value[chain] = codeHash;
}
// Split chains into batches to query contract code in parallel
const batchSize = 10;
const batchedChains: Chain[][] = [];
for (let i = 0; i < chains.value.length; i += batchSize) {
batchedChains.push(
chains.value.slice(i, i + batchSize).map((chain) => chain.id),
);
}
// Fetch contract code
for (const batch of batchedChains) {
await Promise.all(
batch.map(async (chain) => {
const codeHash = await getCodeHash(chain);
codeHashes.value[chain] = codeHash;
}),
);
// Fetch contract code with a concurrency pool
const concurrency = 10;
const pending = CHAINS.filter((chain) => !(chain in codeHashes.value));
let index = 0;
async function next(): Promise<void> {
while (index < pending.length) {
const chain = pending[index++]!;
await fetchCodeHashWithRetries(chain);
}
}
const workers = Array.from(
{ length: Math.min(concurrency, pending.length) },
() => next(),
);
await Promise.all(workers);
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion app/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ async function getCode(
}
const chainClient = createPublicClient({
chain: getChainData(chain),
transport: http(endpointUrl),
transport: http(endpointUrl, { timeout: 30_000 }),
});
try {
const code = await chainClient.getCode({
Expand Down