pool: refactor logging.

This commit is contained in:
Christopher Jeffrey 2017-01-19 04:56:36 -08:00
parent 72e4ddc2b0
commit 0a756aba34
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -197,6 +197,7 @@ Pool.prototype._init = function _init() {
});
this.chain.on('reset', function() {
self.resetChain();
self.forceSync();
});
@ -263,7 +264,7 @@ Pool.prototype.resetChain = function resetChain() {
if (!this.options.headers)
return;
if (!this.options.useCheckpoints)
if (!this.chain.options.useCheckpoints)
return;
this.headersFirst = false;
@ -897,30 +898,7 @@ Pool.prototype._handleBlock = co(function* handleBlock(peer, block) {
throw err;
}
if (this.logger.level >= 4 && this.chain.total % 20 === 0) {
this.logger.debug('Status:'
+ ' ts=%s height=%d progress=%s'
+ ' blocks=%d orphans=%d active=%d'
+ ' target=%s peers=%d'
+ ' pending=%d jobs=%d',
util.date(block.ts),
this.chain.height,
(this.chain.getProgress() * 100).toFixed(2) + '%',
this.chain.total,
this.chain.orphanCount,
this.requestMap.size,
block.bits,
this.peers.size(),
this.locker.pending,
this.locker.jobs.length);
}
if (this.chain.total % 2000 === 0) {
this.logger.info(
'Received 2000 more blocks (height=%d, hash=%s).',
this.chain.height,
block.rhash());
}
this.logStatus(block);
if (!this.headersFirst)
return;
@ -947,6 +925,39 @@ Pool.prototype._handleBlock = co(function* handleBlock(peer, block) {
peer.sendGetBlocks([hash], null);
});
/**
* Log sync status.
* @private
* @param {Block} block
*/
Pool.prototype.logStatus = function logStatus(block) {
if (this.logger.level >= 4 && this.chain.total % 20 === 0) {
this.logger.debug('Status:'
+ ' ts=%s height=%d progress=%s'
+ ' blocks=%d orphans=%d active=%d'
+ ' target=%s peers=%d'
+ ' pending=%d jobs=%d',
util.date(block.ts),
this.chain.height,
(this.chain.getProgress() * 100).toFixed(2) + '%',
this.chain.total,
this.chain.orphanCount,
this.requestMap.size,
block.bits,
this.peers.size(),
this.locker.pending,
this.locker.jobs.length);
}
if (this.chain.total % 2000 === 0) {
this.logger.info(
'Received 2000 more blocks (height=%d, hash=%s).',
this.chain.height,
block.rhash());
}
};
/**
* Handle a transaction. Attempt to add to mempool.
* @private
@ -2114,7 +2125,6 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) {
if (this.spv) {
this.requiredServices |= common.services.BLOOM;
this.services &= ~common.services.NETWORK;
this.useCheckpoints = true;
this.noRelay = true;
}