Skip to content

Commit

Permalink
Improve timeout handling for the block polling for confirmation (#4527)
Browse files Browse the repository at this point in the history
* 🎨 Improve the block header timeout handling

* Update comment web3.rst (#4511)

* Update comment web3.rst

* updating changelog

Co-authored-by: Alex <alex.luu@mail.utoronto.ca>

Co-authored-by: Anh Hong <hong4rc@gmail.com>
Co-authored-by: Alex <alex.luu@mail.utoronto.ca>
  • Loading branch information
3 people authored Nov 10, 2021
1 parent 144fbe4 commit 0e6da89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion docs/web3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -273,6 +274,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
sub = {
unsubscribe: function () {
clearInterval(intervalId);
clearTimeout(blockHeaderTimeoutId);
}
};
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 0e6da89

Please sign in to comment.