Skip to content

Commit b8689f8

Browse files
committed
fix: long retry for redstone in historic mode
1 parent 848fa4b commit b8689f8

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/sdk/market/pricefeeds/RedstoneUpdater.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { encodeAbiParameters, toBytes } from "viem";
88
import { SDKConstruct } from "../../base";
99
import type { GearboxSDK } from "../../GearboxSDK";
1010
import type { ILogger, RawTx } from "../../types";
11-
import { childLogger } from "../../utils";
11+
import { childLogger, retry } from "../../utils";
1212
import type { RedstonePriceFeedContract } from "./RedstonePriceFeed";
1313

1414
interface TimestampedCalldata {
@@ -194,7 +194,10 @@ export class RedstoneUpdater extends SDKConstruct {
194194
urls: this.#gateways,
195195
});
196196

197-
const dataPayload = await wrapper.prepareRedstonePayload(true);
197+
const dataPayload = await retry(
198+
() => wrapper.prepareRedstonePayload(true),
199+
{ attempts: 5, interval: this.#historicalTimestampMs ? 30_500 : 250 },
200+
);
198201

199202
const parsed = RedstonePayload.parse(toBytes(`0x${dataPayload}`));
200203
const packagesByDataFeedId = groupDataPackages(parsed.signedDataPackages);

src/sdk/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from "./filterDust";
77
export * from "./formatter";
88
export * from "./json";
99
export * from "./mappers";
10+
export * from "./retry";

src/sdk/utils/retry.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export interface RetryOptions {
2+
attempts?: number;
3+
interval?: number;
4+
}
5+
6+
export async function retry<T>(
7+
fn: () => Promise<T>,
8+
options: RetryOptions = {},
9+
): Promise<T> {
10+
const { attempts = 3, interval = 200 } = options;
11+
let cause: any;
12+
for (let i = 0; i < attempts; i++) {
13+
try {
14+
const result = await fn();
15+
return result;
16+
} catch (e) {
17+
cause = e;
18+
await new Promise(resolve => {
19+
setTimeout(resolve, interval);
20+
});
21+
}
22+
}
23+
throw new Error(`all attempts failed: ${cause}`);
24+
}

0 commit comments

Comments
 (0)