From 82beb27a3cd8f241dec123d74d15013dd3775c88 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 17 Jan 2014 10:44:14 -0300 Subject: [PATCH] better block_total accounting --- lib/HistoricSync.js | 12 ++++++------ util/sync.js | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 908f3414..49d67630 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -70,7 +70,7 @@ function spec() { }, //show some (inacurate) status function(c) { - if (that.block_count++ % 1000 === 0) { + if (that.block_count % 1000 === 1) { progress_bar('sync status:', that.block_count, that.block_total); } return c(); @@ -91,7 +91,6 @@ function spec() { //store it function(c) { if (existed) return c(); - that.sync.storeBlock(blockInfo.result, function(err) { existed = err && err.toString().match(/E11000/); if (err && ! existed) return c(err); @@ -112,7 +111,7 @@ function spec() { function (err){ if (opts.uptoexisting && existed) { - p('DONE. Found existing block: %s ', blockHash); + p('DONE. Found existing block: ', blockHash); return cb(err); } @@ -120,6 +119,7 @@ function spec() { p('ERROR: @%s: %s [count: block_count: %d]', blockHash, err, that.block_count); if (blockInfo && blockInfo.result) { + block_total++; if (opts.prev && blockInfo.result.previousblockhash) { return that.getPrevNextBlock(blockInfo.result.previousblockhash, blockEnd, opts, cb); } @@ -177,7 +177,7 @@ function spec() { }, function(cb) { that.rpc.getInfo(function(err, res) { - if (err) cb(err); + if (err) return cb(err); that.block_total = res.result.blocks; return cb(); @@ -188,7 +188,7 @@ function spec() { if (!opts.reverse) return cb(); that.rpc.getBlockCount(function(err, res) { - if (err) cb(err); + if (err) return cb(err); block_height = res.result; return cb(); }); @@ -197,7 +197,7 @@ function spec() { if (!opts.reverse) return cb(); that.rpc.getBlockHash(block_height, function(err, res) { - if (err) cb(err); + if (err) return cb(err); block_best = res.result; return cb(); diff --git a/util/sync.js b/util/sync.js index a4e3f441..6e531200 100755 --- a/util/sync.js +++ b/util/sync.js @@ -14,6 +14,7 @@ var async = require('async'); program .version(SYNC_VERSION) .option('-N --network [livenet]', 'Set bitcoin network [testnet]', 'testnet') + .option('-S --smart', 'genesis stored? uptoexisting = 1', 1) .option('-D --destroy', 'Remove current DB (and start from there)', 0) .option('-R --reverse', 'Sync backwards', 0) .option('-U --uptoexisting', 'Sync only until an existing block is found', 0) @@ -37,6 +38,7 @@ async.series([ destroy: program.destroy, reverse: program.reverse, uptoexisting: program.uptoexisting, + smart: program.smart, }, function(err, count) { if (err) { console.log('CRITICAL ERROR: ', err);