Skip to content
Snippets Groups Projects
Commit c5669eb3 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix: follow a fork that with exact or more than 30 minutes of time advance

parent d7114652
No related branches found
No related tags found
No related merge requests found
...@@ -178,7 +178,7 @@ function BlockchainService () { ...@@ -178,7 +178,7 @@ function BlockchainService () {
let blocksAdvance = constants.BRANCHES.SWITCH_ON_BRANCH_AHEAD_BY_X_MINUTES / (conf.avgGenTime / 60); 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; 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 // 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 branches...', branches.length);
logger.trace('SWITCH: %s potential side chains...', potentials.length); logger.trace('SWITCH: %s potential side chains...', potentials.length);
for (let i = 0, len = potentials.length; i < len; i++) { for (let i = 0, len = potentials.length; i < len; i++) {
......
...@@ -9,6 +9,7 @@ var rp = require('request-promise'); ...@@ -9,6 +9,7 @@ var rp = require('request-promise');
var httpTest = require('./tools/http'); var httpTest = require('./tools/http');
var commit = require('./tools/commit'); var commit = require('./tools/commit');
var sync = require('./tools/sync'); var sync = require('./tools/sync');
var constants = require('./../../app/lib/constants');
var expectJSON = httpTest.expectJSON; var expectJSON = httpTest.expectJSON;
var expectHttpCode = httpTest.expectHttpCode; var expectHttpCode = httpTest.expectHttpCode;
...@@ -20,6 +21,7 @@ var commonConf = { ...@@ -20,6 +21,7 @@ var commonConf = {
currency: 'bb', currency: 'bb',
httpLogs: true, httpLogs: true,
forksize: 3, forksize: 3,
avgGenTime: 1,
parcatipate: false, // TODO: to remove when startGeneration will be an explicit call parcatipate: false, // TODO: to remove when startGeneration will be an explicit call
sigQty: 1 sigQty: 1
}; };
...@@ -80,7 +82,9 @@ describe("Switch", function() { ...@@ -80,7 +82,9 @@ describe("Switch", function() {
// So we now have: // So we now have:
// S1 01234 // S1 01234
// S2 `3456789 // S2 `3456789
let oldVal = constants.BRANCHES.SWITCH_ON_BRANCH_AHEAD_BY_X_MINUTES = 0;
yield sync(3, 8, s2, s1); yield sync(3, 8, s2, s1);
constants.BRANCHES.SWITCH_ON_BRANCH_AHEAD_BY_X_MINUTES = oldVal;
// S1 should have switched to the other branch // S1 should have switched to the other branch
}); });
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment