From ef44bf44f03addf8f7c859273bb74e351c5921fe Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 20 Jan 2016 13:35:16 -0800 Subject: [PATCH] more debugging. --- lib/bcoin.js | 6 +++++- lib/bcoin/chain.js | 2 +- lib/bcoin/pool.js | 27 +++++++++++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/bcoin.js b/lib/bcoin.js index ad09ee58..18e83527 100644 --- a/lib/bcoin.js +++ b/lib/bcoin.js @@ -10,7 +10,11 @@ var bn = require('bn.js'); var hash = require('hash.js'); var async = require('async'); -bcoin.debug = +process.env.BCOIN_DEBUG === 1; +if (process.env.BCOIN_DEBUG) { + bcoin.debug = process.env.BCOIN_DEBUG; + if (bcoin.debug === '0' || bcoin.debug === '1') + bcoin.debug = +bcoin.debug === 1; +} bcoin.ecdsa = elliptic.ec('secp256k1'); bcoin.utils = require('./bcoin/utils'); diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 74d2f87f..53d3e7eb 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -30,7 +30,7 @@ function Chain(options) { this.strict = this.options.strict || false; if (this.options.debug) - bcoin.debug = true; + bcoin.debug = this.options.debug; this.tip = null; diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index d890402b..e4a86f9a 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -30,7 +30,7 @@ function Pool(options) { this.options = options || {}; if (this.options.debug) - bcoin.debug = true; + bcoin.debug = this.options.debug; if (this.options.network) network.set(this.options.network); @@ -70,6 +70,7 @@ function Pool(options) { this.options.multiplePeers = false; this.syncing = false; + this.synced = false; this.backoff = { delta: options.backoffDelta || 500, @@ -174,10 +175,12 @@ Pool.prototype._init = function _init() { var self = this; var i; - this._addLoader(); + if (this.originalSeeds.length > 0) { + this._addLoader(); - for (i = 0; i < this.size; i++) - this._addPeer(0); + for (i = 0; i < this.size; i++) + this._addPeer(0); + } this.chain.on('block', function(block, peer) { self.emit('block', block, peer); @@ -216,7 +219,7 @@ Pool.prototype._init = function _init() { this.chain.on('invalid', function(data, peer) { utils.debug( - 'Invalid block at height: %d: hash=%s peer=%s', + 'Invalid block at height %d: hash=%s peer=%s', data.height, utils.revHex(data.hash), peer ? peer.host : '' @@ -233,6 +236,13 @@ Pool.prototype._init = function _init() { this.options.wallets.forEach(function(w) { self.addWallet(w); }); + + // Chain is full and up-to-date + if (this.chain.isFull()) { + this.synced = true; + this.emit('full'); + utils.debug('Chain is fully synced (height=%d).', this.chain.height()); + } }; Pool.prototype._startTimer = function _startTimer() { @@ -247,12 +257,16 @@ Pool.prototype._startTimer = function _startTimer() { // Chain is full and up-to-date if (self.chain.isFull()) { self._stopTimer(); + self.synced = true; self.emit('full'); + utils.debug('Chain is fully synced (height=%d).', self.chain.height()); return; } - if (self.peers.load) + if (self.peers.load) { self.peers.load.destroy(); + utils.debug('Timer ran out. Finding new loader peer.'); + } } this._timer = setTimeout(destroy, this.load.timeout); @@ -274,6 +288,7 @@ Pool.prototype._startInterval = function _startInterval() { function load() { if (!self.syncing) return; + utils.debug('Stall recovery: loading again.'); // self._load(); }