Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit ad3bb50

Browse files
authored
[filler]: retry http calls before returning execution result (#242)
* [filler]: retry http calls before returning execution result * bump
1 parent ce324da commit ad3bb50

4 files changed

Lines changed: 297 additions & 131 deletions

File tree

packages/filler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hyperbridge/filler",
3-
"version": "0.1.10",
3+
"version": "0.1.11",
44
"description": "IntentGateway filler package for hyperbridge",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/filler/src/core/event-monitor.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventEmitter } from "events"
2-
import { ChainConfig, Order, orderCommitment, hexToString, DecodedOrderPlacedLog } from "@hyperbridge/sdk"
2+
import { ChainConfig, Order, orderCommitment, hexToString, DecodedOrderPlacedLog, retryPromise } from "@hyperbridge/sdk"
33
import { INTENT_GATEWAY_ABI } from "@/config/abis/IntentGateway"
44
import { PublicClient } from "viem"
55
import { ChainClientManager } from "@/services"
@@ -41,7 +41,11 @@ export class EventMonitor extends EventEmitter {
4141
)
4242
const intentGatewayAddress = this.configService.getIntentGatewayAddress(`EVM-${chainId}`)
4343

44-
const startBlock = await client.getBlockNumber()
44+
const startBlock = await retryPromise(() => client.getBlockNumber(), {
45+
maxRetries: 3,
46+
backoffMs: 250,
47+
logMessage: "Failed to get start block number",
48+
})
4549
this.lastScannedBlock.set(chainId, startBlock - 1n)
4650

4751
this.logger.info({ chainId, startBlock }, "Initializing block scanner")
@@ -51,7 +55,6 @@ export class EventMonitor extends EventEmitter {
5155
if (!mutex) return
5256

5357
if (mutex.isLocked()) {
54-
this.logger.warn({ chainId }, "Waiting for previous scan to complete")
5558
return
5659
}
5760

@@ -82,7 +85,11 @@ export class EventMonitor extends EventEmitter {
8285
const lastScanned = this.lastScannedBlock.get(chainId)
8386
if (!lastScanned) return
8487

85-
const currentBlock = await client.getBlockNumber()
88+
const currentBlock = await retryPromise(() => client.getBlockNumber(), {
89+
maxRetries: 3,
90+
backoffMs: 250,
91+
logMessage: "Failed to get current block number",
92+
})
8693

8794
if (currentBlock > lastScanned) {
8895
const fromBlock = lastScanned + 1n
@@ -96,12 +103,20 @@ export class EventMonitor extends EventEmitter {
96103
"Scanning blocks",
97104
)
98105

99-
const logs = await client.getLogs({
100-
address: intentGatewayAddress,
101-
event: orderPlacedEvent,
102-
fromBlock,
103-
toBlock: actualToBlock,
104-
})
106+
const logs = await retryPromise(
107+
() =>
108+
client.getLogs({
109+
address: intentGatewayAddress,
110+
event: orderPlacedEvent,
111+
fromBlock,
112+
toBlock: actualToBlock,
113+
}),
114+
{
115+
maxRetries: 3,
116+
backoffMs: 250,
117+
logMessage: "Failed to get logs for block scan",
118+
},
119+
)
105120

106121
if (logs.length > 0) {
107122
this.logger.info(

packages/filler/src/core/filler.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { chainIds } from "@hyperbridge/sdk"
1+
import { chainIds, retryPromise } from "@hyperbridge/sdk"
22
import { EventMonitor } from "./event-monitor"
33
import { FillerStrategy } from "@/strategies/base"
44
import { Order, FillerConfig, ChainConfig, DUMMY_PRIVATE_KEY, ADDRESS_ZERO, bytes20ToBytes32 } from "@hyperbridge/sdk"
@@ -86,9 +86,17 @@ export class IntentFiller {
8686
try {
8787
const sourceClient = this.chainClientManager.getPublicClient(order.sourceChain)
8888
const orderValue = await this.contractService.getTokenUsdValue(order)
89-
let currentConfirmations = await sourceClient.getTransactionConfirmations({
90-
hash: order.transactionHash!,
91-
})
89+
let currentConfirmations = await retryPromise(
90+
() =>
91+
sourceClient.getTransactionConfirmations({
92+
hash: order.transactionHash!,
93+
}),
94+
{
95+
maxRetries: 3,
96+
backoffMs: 250,
97+
logMessage: "Failed to get initial transaction confirmations",
98+
},
99+
)
92100
const requiredConfirmations = this.config.confirmationPolicy.getConfirmationBlocks(
93101
chainIds[order.sourceChain as keyof typeof chainIds],
94102
orderValue.inputUsdValue.toNumber(),
@@ -100,9 +108,17 @@ export class IntentFiller {
100108

101109
while (currentConfirmations < requiredConfirmations) {
102110
await new Promise((resolve) => setTimeout(resolve, 300)) // Wait 300ms
103-
currentConfirmations = await sourceClient.getTransactionConfirmations({
104-
hash: order.transactionHash!,
105-
})
111+
currentConfirmations = await retryPromise(
112+
() =>
113+
sourceClient.getTransactionConfirmations({
114+
hash: order.transactionHash!,
115+
}),
116+
{
117+
maxRetries: 3,
118+
backoffMs: 250,
119+
logMessage: "Failed to get transaction confirmations",
120+
},
121+
)
106122
this.logger.debug({ orderId: order.id, currentConfirmations }, "Order confirmation progress")
107123
}
108124

0 commit comments

Comments
 (0)