Skip to content

Commit 28cce09

Browse files
authored
fix: retry failed HTTP calls and reduce check batch size (#4)
1 parent 28613fc commit 28cce09

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/contracts.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@ const xavAbi = ABIContract.ofAbi(XAllocationVoting__factory.abi)
1111
const rrpAbi = ABIContract.ofAbi(RelayerRewardsPool__factory.abi)
1212
const vrAbi = ABIContract.ofAbi(VoterRewards__factory.abi)
1313

14+
const CALL_RETRIES = 3
15+
const CALL_RETRY_MS = 500
16+
1417
async function call(thor: ThorClient, address: string, abi: any, method: string, args: any[] = []): Promise<any[]> {
15-
const res = await thor.contracts.executeCall(address, abi.getFunction(method), args)
16-
if (!res.success) {
17-
throw new Error(`Call ${method} reverted: ${res.result?.errorMessage || "unknown"}`)
18+
for (let attempt = 1; attempt <= CALL_RETRIES; attempt++) {
19+
try {
20+
const res = await thor.contracts.executeCall(address, abi.getFunction(method), args)
21+
if (!res.success) {
22+
throw new Error(`Call ${method} reverted: ${res.result?.errorMessage || "unknown"}`)
23+
}
24+
return res.result?.array ?? []
25+
} catch (err) {
26+
const msg = err instanceof Error ? err.message : String(err)
27+
const isRevert = msg.includes("reverted")
28+
if (isRevert || attempt === CALL_RETRIES) throw err
29+
await new Promise((r) => setTimeout(r, CALL_RETRY_MS * attempt))
30+
}
1831
}
19-
return res.result?.array ?? []
32+
throw new Error("Unreachable")
2033
}
2134

2235
// ── XAllocationVoting reads ─────────────────────────────────

src/relayer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export async function runCastVoteCycle(
211211
const unprocessed: string[] = []
212212
let voted = 0
213213
let ineligible = 0
214-
const CHECK_BATCH = 50
214+
const CHECK_BATCH = 10
215215
for (let i = 0; i < allUsers.length; i += CHECK_BATCH) {
216216
const chunk = allUsers.slice(i, i + CHECK_BATCH)
217217
const checks = await Promise.all(chunk.map((u) => hasVoted(thor, config.xAllocationVotingAddress, roundId, u)))
@@ -288,7 +288,7 @@ export async function runClaimRewardCycle(
288288
const unclaimed: string[] = []
289289
let didNotVote = 0
290290
let alreadyClaimed = 0
291-
const CHECK_BATCH = 50
291+
const CHECK_BATCH = 10
292292
for (let i = 0; i < allUsers.length; i += CHECK_BATCH) {
293293
const chunk = allUsers.slice(i, i + CHECK_BATCH)
294294
const checks = await Promise.all(chunk.map((u) => hasVoted(thor, config.xAllocationVotingAddress, previousRoundId, u)))

0 commit comments

Comments
 (0)