Log sync status less frequently, and include the current height.
This commit is contained in:
parent
40c0275677
commit
747942cec1
@ -4,22 +4,22 @@ var BitcoindJS = require('..');
|
|||||||
var BitcoinNode = BitcoindJS.Node;
|
var BitcoinNode = BitcoindJS.Node;
|
||||||
var chainlib = require('chainlib');
|
var chainlib = require('chainlib');
|
||||||
var log = chainlib.log;
|
var log = chainlib.log;
|
||||||
//log.debug = function() {};
|
log.debug = function() {};
|
||||||
|
|
||||||
var configuration = {
|
var configuration = {
|
||||||
datadir: process.env.BITCOINDJS_DIR || '~/.bitcoin',
|
datadir: process.env.BITCOINDJS_DIR || '~/.bitcoin'
|
||||||
network: 'testnet'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var node = new BitcoinNode(configuration);
|
var node = new BitcoinNode(configuration);
|
||||||
|
|
||||||
var startHeight;
|
var count = 0;
|
||||||
var count = 100;
|
var interval;
|
||||||
var times = new Array(count);
|
|
||||||
|
|
||||||
node.on('ready', function() {
|
node.on('ready', function() {
|
||||||
times[node.chain.tip.__height % count] = Date.now();
|
interval = setInterval(function() {
|
||||||
startHeight = node.chain.tip.__height;
|
log.info('Sync Status: Tip:', node.chain.tip.hash, 'Height:', node.chain.tip.__height, 'Rate:', count/10, 'blocks per second');
|
||||||
|
count = 0;
|
||||||
|
}, 10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
node.on('error', function(err) {
|
node.on('error', function(err) {
|
||||||
@ -27,13 +27,5 @@ node.on('error', function(err) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.chain.on('addblock', function(block) {
|
node.chain.on('addblock', function(block) {
|
||||||
console.log('New Best Tip:', block.hash);
|
count++;
|
||||||
var startTime = times[node.chain.tip.__height % count];
|
|
||||||
|
|
||||||
if(startTime) {
|
|
||||||
var timeElapsed = (Date.now() - startTime) / 1000;
|
|
||||||
console.log(Math.round(count / timeElapsed) + ' blocks per second');
|
|
||||||
}
|
|
||||||
|
|
||||||
times[node.chain.tip.__height % count] = Date.now();
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user