File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { encodeAbiParameters, toBytes } from "viem";
88import { SDKConstruct } from "../../base" ;
99import type { GearboxSDK } from "../../GearboxSDK" ;
1010import type { ILogger , RawTx } from "../../types" ;
11- import { childLogger } from "../../utils" ;
11+ import { childLogger , retry } from "../../utils" ;
1212import type { RedstonePriceFeedContract } from "./RedstonePriceFeed" ;
1313
1414interface 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 ) ;
Original file line number Diff line number Diff line change @@ -7,3 +7,4 @@ export * from "./filterDust";
77export * from "./formatter" ;
88export * from "./json" ;
99export * from "./mappers" ;
10+ export * from "./retry" ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments