Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

decoupled pub/sub and polling paradigms in contract deployment timeout #1414

Merged
merged 3 commits into from
Mar 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var promiEvent = require('web3-core-promievent');
var Subscriptions = require('web3-core-subscriptions').subscriptions;

var TIMEOUTBLOCK = 50;
var POLLINGTIMEOUT = 15 * TIMEOUTBLOCK; // ~average block time (seconds) * TIMEOUTBLOCK
var CONFIRMATIONBLOCKS = 24;

var Method = function Method(options) {
Expand Down Expand Up @@ -240,7 +241,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {


// fire "receipt" and confirmation events and resolve after
var checkConfirmation = function (err, blockHeader, sub, existingReceipt) {
var checkConfirmation = function (err, blockHeader, sub, existingReceipt, isPolling) {
if (!err) {
// create fake unsubscribe
if (!sub) {
Expand Down Expand Up @@ -369,10 +370,20 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
.catch(function () {
timeoutCount++;

if (timeoutCount - 1 >= TIMEOUTBLOCK) {
sub.unsubscribe();
promiseResolved = true;
return utils._fireError(new Error('Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject);
// check to see if we are http polling
if(!!isPolling) {
// polling timeout is different than TIMEOUTBLOCK blocks since we are triggering every second
if (timeoutCount - 1 >= POLLINGTIMEOUT) {
sub.unsubscribe();
promiseResolved = true;
return utils._fireError(new Error('Transaction was not mined within' + POLLINGTIMEOUT + ' seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject);
}
} else {
if (timeoutCount - 1 >= TIMEOUTBLOCK) {
sub.unsubscribe();
promiseResolved = true;
return utils._fireError(new Error('Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject);
}
}
});

Expand All @@ -390,7 +401,10 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
if (_.isFunction(this.requestManager.provider.on)) {
_ethereumCall.subscribe('newBlockHeaders', checkConfirmation);
} else {
intervalId = setInterval(checkConfirmation, 1000);
// if provider is http and polling
intervalId = setInterval(function() {
checkConfirmation(null, null, null, null, true);
}, 1000);
}
}.bind(this);

Expand Down