diff --git a/app/service/BlockchainService.js b/app/service/BlockchainService.js index 9e2a2b4871d8757856691c63a3d9e6f6875901cf..a42703c718518a9ab5d304f9bdc5abd82a384165 100644 --- a/app/service/BlockchainService.js +++ b/app/service/BlockchainService.js @@ -178,7 +178,7 @@ function BlockchainService () { let blocksAdvance = constants.BRANCHES.SWITCH_ON_BRANCH_AHEAD_BY_X_MINUTES / (conf.avgGenTime / 60); let timeAdvance = constants.BRANCHES.SWITCH_ON_BRANCH_AHEAD_BY_X_MINUTES * 60; // We switch only to blockchain with X_MIN advance considering both theoretical time by block + written time - potentials = _.filter(potentials, (p) => p.number - current.number > blocksAdvance && p.medianTime - current.medianTime > timeAdvance); + potentials = _.filter(potentials, (p) => p.number - current.number >= blocksAdvance && p.medianTime - current.medianTime >= timeAdvance); logger.trace('SWITCH: %s branches...', branches.length); logger.trace('SWITCH: %s potential side chains...', potentials.length); for (let i = 0, len = potentials.length; i < len; i++) { diff --git a/test/integration/branches_switch.js b/test/integration/branches_switch.js index e4df44f8c16a990b6343543a5c8c80d803159af8..503fb15ea34f2f0a856ee6a27c8d4e2a3ef59523 100644 --- a/test/integration/branches_switch.js +++ b/test/integration/branches_switch.js @@ -9,6 +9,7 @@ var rp = require('request-promise'); var httpTest = require('./tools/http'); var commit = require('./tools/commit'); var sync = require('./tools/sync'); +var constants = require('./../../app/lib/constants'); var expectJSON = httpTest.expectJSON; var expectHttpCode = httpTest.expectHttpCode; @@ -20,6 +21,7 @@ var commonConf = { currency: 'bb', httpLogs: true, forksize: 3, + avgGenTime: 1, parcatipate: false, // TODO: to remove when startGeneration will be an explicit call sigQty: 1 }; @@ -80,7 +82,9 @@ describe("Switch", function() { // So we now have: // S1 01234 // S2 `3456789 + let oldVal = constants.BRANCHES.SWITCH_ON_BRANCH_AHEAD_BY_X_MINUTES = 0; yield sync(3, 8, s2, s1); + constants.BRANCHES.SWITCH_ON_BRANCH_AHEAD_BY_X_MINUTES = oldVal; // S1 should have switched to the other branch }); });