better block_total accounting
This commit is contained in:
parent
4442497638
commit
82beb27a3c
|
@ -70,7 +70,7 @@ function spec() {
|
||||||
},
|
},
|
||||||
//show some (inacurate) status
|
//show some (inacurate) status
|
||||||
function(c) {
|
function(c) {
|
||||||
if (that.block_count++ % 1000 === 0) {
|
if (that.block_count % 1000 === 1) {
|
||||||
progress_bar('sync status:', that.block_count, that.block_total);
|
progress_bar('sync status:', that.block_count, that.block_total);
|
||||||
}
|
}
|
||||||
return c();
|
return c();
|
||||||
|
@ -91,7 +91,6 @@ function spec() {
|
||||||
//store it
|
//store it
|
||||||
function(c) {
|
function(c) {
|
||||||
if (existed) return c();
|
if (existed) return c();
|
||||||
|
|
||||||
that.sync.storeBlock(blockInfo.result, function(err) {
|
that.sync.storeBlock(blockInfo.result, function(err) {
|
||||||
existed = err && err.toString().match(/E11000/);
|
existed = err && err.toString().match(/E11000/);
|
||||||
if (err && ! existed) return c(err);
|
if (err && ! existed) return c(err);
|
||||||
|
@ -112,7 +111,7 @@ function spec() {
|
||||||
function (err){
|
function (err){
|
||||||
|
|
||||||
if (opts.uptoexisting && existed) {
|
if (opts.uptoexisting && existed) {
|
||||||
p('DONE. Found existing block: %s ', blockHash);
|
p('DONE. Found existing block: ', blockHash);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +119,7 @@ function spec() {
|
||||||
p('ERROR: @%s: %s [count: block_count: %d]', blockHash, err, that.block_count);
|
p('ERROR: @%s: %s [count: block_count: %d]', blockHash, err, that.block_count);
|
||||||
|
|
||||||
if (blockInfo && blockInfo.result) {
|
if (blockInfo && blockInfo.result) {
|
||||||
|
block_total++;
|
||||||
if (opts.prev && blockInfo.result.previousblockhash) {
|
if (opts.prev && blockInfo.result.previousblockhash) {
|
||||||
return that.getPrevNextBlock(blockInfo.result.previousblockhash, blockEnd, opts, cb);
|
return that.getPrevNextBlock(blockInfo.result.previousblockhash, blockEnd, opts, cb);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ function spec() {
|
||||||
},
|
},
|
||||||
function(cb) {
|
function(cb) {
|
||||||
that.rpc.getInfo(function(err, res) {
|
that.rpc.getInfo(function(err, res) {
|
||||||
if (err) cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
that.block_total = res.result.blocks;
|
that.block_total = res.result.blocks;
|
||||||
return cb();
|
return cb();
|
||||||
|
@ -188,7 +188,7 @@ function spec() {
|
||||||
if (!opts.reverse) return cb();
|
if (!opts.reverse) return cb();
|
||||||
|
|
||||||
that.rpc.getBlockCount(function(err, res) {
|
that.rpc.getBlockCount(function(err, res) {
|
||||||
if (err) cb(err);
|
if (err) return cb(err);
|
||||||
block_height = res.result;
|
block_height = res.result;
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
|
@ -197,7 +197,7 @@ function spec() {
|
||||||
if (!opts.reverse) return cb();
|
if (!opts.reverse) return cb();
|
||||||
|
|
||||||
that.rpc.getBlockHash(block_height, function(err, res) {
|
that.rpc.getBlockHash(block_height, function(err, res) {
|
||||||
if (err) cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
block_best = res.result;
|
block_best = res.result;
|
||||||
return cb();
|
return cb();
|
||||||
|
|
|
@ -14,6 +14,7 @@ var async = require('async');
|
||||||
program
|
program
|
||||||
.version(SYNC_VERSION)
|
.version(SYNC_VERSION)
|
||||||
.option('-N --network [livenet]', 'Set bitcoin network [testnet]', 'testnet')
|
.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('-D --destroy', 'Remove current DB (and start from there)', 0)
|
||||||
.option('-R --reverse', 'Sync backwards', 0)
|
.option('-R --reverse', 'Sync backwards', 0)
|
||||||
.option('-U --uptoexisting', 'Sync only until an existing block is found', 0)
|
.option('-U --uptoexisting', 'Sync only until an existing block is found', 0)
|
||||||
|
@ -37,6 +38,7 @@ async.series([
|
||||||
destroy: program.destroy,
|
destroy: program.destroy,
|
||||||
reverse: program.reverse,
|
reverse: program.reverse,
|
||||||
uptoexisting: program.uptoexisting,
|
uptoexisting: program.uptoexisting,
|
||||||
|
smart: program.smart,
|
||||||
}, function(err, count) {
|
}, function(err, count) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('CRITICAL ERROR: ', err);
|
console.log('CRITICAL ERROR: ', err);
|
||||||
|
|
Loading…
Reference in New Issue