From 0e6da8991d12598b65a58b584c7b5dc3f7c7303c Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Wed, 10 Nov 2021 04:09:38 +0100 Subject: [PATCH] Improve timeout handling for the block polling for confirmation (#4527) * :art: Improve the block header timeout handling * Update comment web3.rst (#4511) * Update comment web3.rst * updating changelog Co-authored-by: Alex Co-authored-by: Anh Hong Co-authored-by: Alex --- CHANGELOG.md | 4 ++++ docs/web3.rst | 2 +- packages/web3-core-method/src/index.js | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23695ee8cc8..d1b68af24dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -479,3 +479,7 @@ Released with 1.0.0-beta.37 code base. ## [Unreleased] ## [1.6.2] + +### Changed + +- Correct `web3.rst` example in documentation (#4511) \ No newline at end of file diff --git a/docs/web3.rst b/docs/web3.rst index 5ae5666957f..668ae8e0b92 100644 --- a/docs/web3.rst +++ b/docs/web3.rst @@ -64,7 +64,7 @@ The Web3 class is an umbrella package to house all Ethereum related modules. var Web3 = require('web3'); - // "Web3.providers.givenProvider" will be set if in an Ethereum supported browser. + // "Web3.givenProvider" will be set if in an Ethereum supported browser. var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); > web3.eth diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index 7a504591767..afffc8560a1 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -205,6 +205,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { timeoutCount = 0, confirmationCount = 0, intervalId = null, + blockHeaderTimeoutId = null, lastBlock = null, receiptJSON = '', gasProvided = ((!!payload.params[0] && typeof payload.params[0] === 'object') && payload.params[0].gas) ? payload.params[0].gas : null, @@ -273,6 +274,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { sub = { unsubscribe: function () { clearInterval(intervalId); + clearTimeout(blockHeaderTimeoutId); } }; } @@ -572,7 +574,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { }); // Fallback to polling if tx receipt didn't arrived in "blockHeaderTimeout" [10 seconds] - setTimeout(() => { + blockHeaderTimeoutId = setTimeout(() => { if(!blockHeaderArrived) { startInterval(); }