diff --git a/lib/common/defaults.js b/lib/common/defaults.js index c2c8f80..2a0af10 100644 --- a/lib/common/defaults.js +++ b/lib/common/defaults.js @@ -14,10 +14,10 @@ Defaults.MAX_KEYS = 100; Defaults.DELETE_LOCKTIME = 1 * 3600; // Allowed consecutive txp rejections before backoff is applied. -Defaults.BACKOFF_OFFSET = 3; +Defaults.BACKOFF_OFFSET = 10; -// Time a copayer need to wait to create a new TX after her tx previous proposal we rejected. (incremental). in Minutes. -Defaults.BACKOFF_TIME = 2; +// Time a copayer need to wait to create a new TX after her tx previous proposal we rejected. in seconds. +Defaults.BACKOFF_TIME = 1 * 3600; Defaults.MAX_MAIN_ADDRESS_GAP = 20; diff --git a/lib/server.js b/lib/server.js index 1eefa57..8809e19 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1532,7 +1532,7 @@ WalletService.prototype._canCreateTx = function(cb) { var lastTxTs = txs[0].createdOn; var now = Math.floor(Date.now() / 1000); var timeSinceLastRejection = now - lastTxTs; - var backoffTime = 60 * Math.pow(Defaults.BACKOFF_TIME, exceededRejections); + var backoffTime = Defaults.BACKOFF_TIME; if (timeSinceLastRejection <= backoffTime) log.debug('Not allowing to create TX: timeSinceLastRejection/backoffTime', timeSinceLastRejection, backoffTime); diff --git a/test/integration/server.js b/test/integration/server.js index c9f1832..a1ddbd2 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3116,9 +3116,10 @@ describe('Wallet service', function() { }); describe('Backoff time', function(done) { - var server, wallet, txid; - + var server, wallet, txid, clock; + var _oldBackoffOffset = Defaults.BACKOFF_OFFSET; beforeEach(function(done) { + Defaults.BACKOFF_OFFSET = 3; helpers.createAndJoinWallet(2, 2, function(s, w) { server = s; wallet = w; @@ -3127,8 +3128,14 @@ describe('Wallet service', function() { }); }); }); + afterEach(function(done) { + Defaults.BACKOFF_OFFSET = _oldBackoffOffset; + clock.restore(); + done(); + }); it('should follow backoff time after consecutive rejections', function(done) { + clock = sinon.useFakeTimers(Date.now(), 'Date'); async.series([ function(next) { @@ -3164,10 +3171,10 @@ describe('Wallet service', function() { }); }, function(next) { - var clock = sinon.useFakeTimers(Date.now() + (Defaults.BACKOFF_TIME + 2) * 60 * 1000, 'Date'); + clock.tick((Defaults.BACKOFF_TIME + 1) * 1000); var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 1, TestData.copayers[0].privKey_1H_0); server.createTxLegacy(txOpts, function(err, tx) { - clock.restore(); + should.not.exist(err); server.rejectTx({ txProposalId: tx.id, reason: 'some reason', @@ -3176,15 +3183,25 @@ describe('Wallet service', function() { }, function(next) { // Do not allow a 5th tx before backoff time - var clock = sinon.useFakeTimers(Date.now() + (Defaults.BACKOFF_TIME + 2) * 60 * 1000 + 1, 'Date'); + clock.tick((Defaults.BACKOFF_TIME - 1) * 1000); var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 1, TestData.copayers[0].privKey_1H_0); server.createTxLegacy(txOpts, function(err, tx) { - clock.restore(); should.exist(err); err.code.should.equal('TX_CANNOT_CREATE'); next(); }); }, + function(next) { + clock.tick(2000); + var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 1, TestData.copayers[0].privKey_1H_0); + server.createTxLegacy(txOpts, function(err, tx) { + should.not.exist(err); + server.rejectTx({ + txProposalId: tx.id, + reason: 'some reason', + }, next); + }); + }, ], function(err) { should.not.exist(err); done();