Skip to content

Commit

Permalink
fix: retry timeout in quicknode
Browse files Browse the repository at this point in the history
  • Loading branch information
nitinmittal23 committed Sep 20, 2023
1 parent d8ba737 commit 8e52f59
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/block_getters/quicknode_block_getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class QuickNodeBlockGetter extends BlockGetter implements IBlockGetter {
*
* @constructor
*/
constructor(eth: Eth, maxRetries: number = 0, private alternateEth?: Eth) {
constructor(eth: Eth, maxRetries: number = 0, private alternateEth?: Eth, private rpcTimeout?: number) {
super(eth, maxRetries);
}

Expand All @@ -39,7 +39,7 @@ export class QuickNodeBlockGetter extends BlockGetter implements IBlockGetter {
const response: IQuickNodeResponse = await new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error(`Request timed out for block: ${blockNumber}`));
}, 4000);
}, this.rpcTimeout || 4000);

let eth: Eth = this.eth;
if (retryCount > 0 && this.alternateEth) {
Expand Down
1 change: 1 addition & 0 deletions internal/block_getters/quicknode_block_getter_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const blockGetter = new QuickNodeBlockGetter(
}
)
),
workerData.rpcTimeout
);

parentPort.on("message", async (message: {
Expand Down
9 changes: 7 additions & 2 deletions internal/block_subscription/block_subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class BlockSubscription extends AbstractBlockSubscription {
* @param {number} maxRetries - Number of times to retry on failure before emitting an error.
* @param {"quicknode_block_getter" | "erigon_block_getter" | "block_getter"} blockGetterType - The type of block getter to be used for this subscription.
* @param {number} timeout - Timeout for which if there has been no event, connection must be restarted.
* @param {number} blockDelay - Block delay for chains not having safe blocks
* @param {number} alternateEndpoint - alternate endpoint which will be used when the logic to fetch transactions fails
* @param {number} rpcTimeout - time to wait before retrying again
*/
constructor(
eth: Eth,
Expand All @@ -32,7 +35,8 @@ export class BlockSubscription extends AbstractBlockSubscription {
private blockGetterType: "quicknode_block_getter" | "erigon_block_getter" | "block_getter" = "block_getter",
timeout?: number,
blockDelay?: number,
protected alternateEndpoint?: string
protected alternateEndpoint?: string,
protected rpcTimeout?: number
) {
super(eth, timeout, blockDelay);

Expand All @@ -57,7 +61,8 @@ export class BlockSubscription extends AbstractBlockSubscription {
const workerData = {
endpoint: this.rpcWsEndpoints[i],
maxRetries: this.maxRetries,
alternateEndpoint: this.alternateEndpoint ? this.alternateEndpoint : undefined
alternateEndpoint: this.alternateEndpoint ? this.alternateEndpoint : undefined,
rpcTimeout: this.rpcTimeout
};

const worker = new Worker(
Expand Down
3 changes: 2 additions & 1 deletion internal/interfaces/block_producer_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export interface IBlockProducerConfig extends IProducerConfig {
blockPollingTimeout?: number,
blockSubscriptionTimeout?: number,
blockDelay?: number,
alternateEndpoint?: string
alternateEndpoint?: string,
rpcTimeout?: number
}
6 changes: 5 additions & 1 deletion public/block_producers/quicknode_block_producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class QuickNodeBlockProducer extends BlockProducer {
const blockSubscriptionTimeout = config.blockSubscriptionTimeout;
const blockDelay = config.blockDelay || 0;
const alternateEndpoint = config.alternateEndpoint;
const rpcTimeout = config.rpcTimeout;

// Has to be done or Kafka complains later
delete config.rpcWsEndpoints;
Expand All @@ -42,6 +43,8 @@ export class QuickNodeBlockProducer extends BlockProducer {
delete config.blockSubscriptionTimeout;
delete config.blockDelay;
delete config.alternateEndpoint;
delete config.rpcTimeout;


//@ts-ignore
const eth = new Eth(
Expand Down Expand Up @@ -73,7 +76,8 @@ export class QuickNodeBlockProducer extends BlockProducer {
"quicknode_block_getter",
blockSubscriptionTimeout,
blockDelay,
alternateEndpoint
alternateEndpoint,
rpcTimeout
),
new BlockGetter(eth, maxRetries),
database,
Expand Down
1 change: 1 addition & 0 deletions tests/block_producer/quicknode_block_producer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ describe("Block Producer", () => {
"quicknode_block_getter",
60000,
0,
undefined,
undefined
);
});
Expand Down

0 comments on commit 8e52f59

Please sign in to comment.