From 0404e75e96bb1c0661e46d9068f33e8780f152b0 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 17 Sep 2021 09:54:25 -0700 Subject: [PATCH] feat: make confirm transaction timeout configurable (#19954) --- web3.js/src/connection.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index 1cf5e2ebfd..610980a929 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -1979,6 +1979,8 @@ export type ConnectionConfig = { fetchMiddleware?: FetchMiddleware; /** Optional Disable retring calls when server responds with HTTP 429 (Too Many Requests) */ disableRetryOnRateLimit?: boolean; + /** time to allow for the server to initially process a transaction (in milliseconds) */ + confirmTransactionInitialTimeout?: number; }; /** @@ -1986,6 +1988,7 @@ export type ConnectionConfig = { */ export class Connection { /** @internal */ _commitment?: Commitment; + /** @internal */ _confirmTransactionInitialTimeout?: number; /** @internal */ _rpcEndpoint: string; /** @internal */ _rpcWsEndpoint: string; /** @internal */ _rpcClient: RpcClient; @@ -2070,6 +2073,8 @@ export class Connection { this._commitment = commitmentOrConfig; } else if (commitmentOrConfig) { this._commitment = commitmentOrConfig.commitment; + this._confirmTransactionInitialTimeout = + commitmentOrConfig.confirmTransactionInitialTimeout; wsEndpoint = commitmentOrConfig.wsEndpoint; httpHeaders = commitmentOrConfig.httpHeaders; fetchMiddleware = commitmentOrConfig.fetchMiddleware; @@ -2629,14 +2634,14 @@ export class Connection { } }); - let timeoutMs = 60 * 1000; + let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000; switch (subscriptionCommitment) { case 'processed': case 'recent': case 'single': case 'confirmed': case 'singleGossip': { - timeoutMs = 30 * 1000; + timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000; break; } // exhaust enums to ensure full coverage