From fdca7fd1a8a01b0b2636ffd53de8bbe3459a60b9 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Thu, 3 Dec 2015 08:11:58 +0100
Subject: [PATCH] Fix #248 initial sync won't check for rules to be quicker

---
 app/lib/sync.js |  8 +++++---
 bin/ucoind      | 10 +++++++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/app/lib/sync.js b/app/lib/sync.js
index 643c4a3b1..6213d37f6 100644
--- a/app/lib/sync.js
+++ b/app/lib/sync.js
@@ -43,8 +43,7 @@ module.exports = function Synchroniser (server, host, port, conf, interactive) {
     timeout: constants.NETWORK.SYNC_LONG_TIMEOUT
   };
 
-  this.sync = (to, nocautious, nopeers) => {
-    var cautious = !nocautious, logInterval;
+  this.sync = (to, askedCautious, nopeers) => {
     logger.info('Connecting remote host...');
     return co(function *() {
       var node = yield getVucoin(host, port, vucoinOptions);
@@ -61,8 +60,11 @@ module.exports = function Synchroniser (server, host, port, conf, interactive) {
       var localNumber = lCurrent ? lCurrent.number : -1;
       var remoteNumber = Math.min(rCurrent.number, to || rCurrent.number);
 
+      // We use cautious mode if it is asked, or not particulary asked but blockchain has been started
+      var cautious = (askedCautious === true || (askedCautious === undefined && localNumber >= 0));
+
       // Recurrent checking
-      logInterval = setInterval(() => {
+      setInterval(() => {
         if (remoteNumber > 1 && speed > 0) {
           var remain = (remoteNumber - (localNumber + 1 + blocksApplied));
           var secondsLeft = remain / speed;
diff --git a/bin/ucoind b/bin/ucoind
index cb11396b5..92df68f22 100755
--- a/bin/ucoind
+++ b/bin/ucoind
@@ -73,6 +73,7 @@ program
   .option('--nohttplogs',              'Disable HTTP logs')
   .option('--nointeractive',           'Disable interactive sync UI')
   .option('--nocautious',              'Do not check blocks validity during sync')
+  .option('--cautious',                'Check blocks validity during sync (overrides --nocautious option)')
   .option('--nopeers',                 'Do not retrieve peers during sync')
   .option('--isolate',                 'Avoid the node to send peering or status informations to the network')
   .option('--check',                   'With gen-next: just check validity of generated block')
@@ -135,7 +136,14 @@ program
 function sync(server, host, port, conf, to) {
   // Synchronize
   var remote = new Synchroniser(server, host, port, conf, !program.nointeractive);
-  return remote.sync(parseInt(to), program.nocautious, program.nopeers);
+  let cautious;
+  if (program.nocautious) {
+    cautious = false;
+  }
+  if (program.cautious) {
+    cautious = true;
+  }
+  return remote.sync(parseInt(to), cautious, program.nopeers);
 }
 
 program
-- 
GitLab