more debugging.

This commit is contained in:
Christopher Jeffrey 2016-01-20 13:35:16 -08:00
parent 271ca1aa52
commit ef44bf44f0
3 changed files with 27 additions and 8 deletions

View File

@ -10,7 +10,11 @@ var bn = require('bn.js');
var hash = require('hash.js'); var hash = require('hash.js');
var async = require('async'); 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.ecdsa = elliptic.ec('secp256k1');
bcoin.utils = require('./bcoin/utils'); bcoin.utils = require('./bcoin/utils');

View File

@ -30,7 +30,7 @@ function Chain(options) {
this.strict = this.options.strict || false; this.strict = this.options.strict || false;
if (this.options.debug) if (this.options.debug)
bcoin.debug = true; bcoin.debug = this.options.debug;
this.tip = null; this.tip = null;

View File

@ -30,7 +30,7 @@ function Pool(options) {
this.options = options || {}; this.options = options || {};
if (this.options.debug) if (this.options.debug)
bcoin.debug = true; bcoin.debug = this.options.debug;
if (this.options.network) if (this.options.network)
network.set(this.options.network); network.set(this.options.network);
@ -70,6 +70,7 @@ function Pool(options) {
this.options.multiplePeers = false; this.options.multiplePeers = false;
this.syncing = false; this.syncing = false;
this.synced = false;
this.backoff = { this.backoff = {
delta: options.backoffDelta || 500, delta: options.backoffDelta || 500,
@ -174,10 +175,12 @@ Pool.prototype._init = function _init() {
var self = this; var self = this;
var i; var i;
this._addLoader(); if (this.originalSeeds.length > 0) {
this._addLoader();
for (i = 0; i < this.size; i++) for (i = 0; i < this.size; i++)
this._addPeer(0); this._addPeer(0);
}
this.chain.on('block', function(block, peer) { this.chain.on('block', function(block, peer) {
self.emit('block', block, peer); self.emit('block', block, peer);
@ -216,7 +219,7 @@ Pool.prototype._init = function _init() {
this.chain.on('invalid', function(data, peer) { this.chain.on('invalid', function(data, peer) {
utils.debug( utils.debug(
'Invalid block at height: %d: hash=%s peer=%s', 'Invalid block at height %d: hash=%s peer=%s',
data.height, data.height,
utils.revHex(data.hash), utils.revHex(data.hash),
peer ? peer.host : '' peer ? peer.host : ''
@ -233,6 +236,13 @@ Pool.prototype._init = function _init() {
this.options.wallets.forEach(function(w) { this.options.wallets.forEach(function(w) {
self.addWallet(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() { Pool.prototype._startTimer = function _startTimer() {
@ -247,12 +257,16 @@ Pool.prototype._startTimer = function _startTimer() {
// Chain is full and up-to-date // Chain is full and up-to-date
if (self.chain.isFull()) { if (self.chain.isFull()) {
self._stopTimer(); self._stopTimer();
self.synced = true;
self.emit('full'); self.emit('full');
utils.debug('Chain is fully synced (height=%d).', self.chain.height());
return; return;
} }
if (self.peers.load) if (self.peers.load) {
self.peers.load.destroy(); self.peers.load.destroy();
utils.debug('Timer ran out. Finding new loader peer.');
}
} }
this._timer = setTimeout(destroy, this.load.timeout); this._timer = setTimeout(destroy, this.load.timeout);
@ -274,6 +288,7 @@ Pool.prototype._startInterval = function _startInterval() {
function load() { function load() {
if (!self.syncing) if (!self.syncing)
return; return;
utils.debug('Stall recovery: loading again.');
// self._load(); // self._load();
} }