Added better reporting when new blocks come in.
This commit is contained in:
parent
dcf1426221
commit
3383771b10
@ -28,7 +28,8 @@ var BlockService = function(options) {
|
|||||||
this._blockCount = 0;
|
this._blockCount = 0;
|
||||||
this.GENESIS_HASH = constants.BITCOIN_GENESIS_HASH[this.node.network];
|
this.GENESIS_HASH = constants.BITCOIN_GENESIS_HASH[this.node.network];
|
||||||
this._initialSync = true;
|
this._initialSync = true;
|
||||||
this._reorgBackToBlock = null;
|
this._reorgBackToBlock = null; // use this to rewind your indexes to a specific point by height or hash
|
||||||
|
this._timeOfLastBestBlockReport = Date.now() - 30000;
|
||||||
};
|
};
|
||||||
|
|
||||||
inherits(BlockService, BaseService);
|
inherits(BlockService, BaseService);
|
||||||
@ -264,7 +265,7 @@ BlockService.prototype._resetTip = function(callback) {
|
|||||||
return callback(err || new Error('headers required'));
|
return callback(err || new Error('headers required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info('Block Service: retrieved all the headers for lookups');
|
log.info('Block Service: retrieved all the headers for lookups.');
|
||||||
async.until(function() {
|
async.until(function() {
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
@ -352,7 +353,6 @@ BlockService.prototype.start = function(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self._blockProcessor = async.queue(self._onBlock.bind(self));
|
self._blockProcessor = async.queue(self._onBlock.bind(self));
|
||||||
self._setListeners();
|
|
||||||
self._setTip(tip);
|
self._setTip(tip);
|
||||||
self._bus = self.node.openBus({remoteAddress: 'localhost-block'});
|
self._bus = self.node.openBus({remoteAddress: 'localhost-block'});
|
||||||
|
|
||||||
@ -382,6 +382,11 @@ BlockService.prototype._queueBlock = function(block) {
|
|||||||
return self._handleError(err);
|
return self._handleError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Date.now() - self._timeOfLastBestBlockReport > 30000) { // 30 seconds
|
||||||
|
log.info('Block Service: The best block hash is: ' + self._tip.hash +
|
||||||
|
' at height: ' + self._tip.height);
|
||||||
|
}
|
||||||
|
|
||||||
log.debug('Block Service: completed processing block: ' + block.rhash() +
|
log.debug('Block Service: completed processing block: ' + block.rhash() +
|
||||||
' prev hash: ' + bcoin.util.revHex(block.prevBlock) + ' height: ' + self._tip.height);
|
' prev hash: ' + bcoin.util.revHex(block.prevBlock) + ' height: ' + self._tip.height);
|
||||||
|
|
||||||
@ -518,6 +523,8 @@ BlockService.prototype.onHeaders = function(callback) {
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
self._removeAllSubscriptions();
|
||||||
|
|
||||||
self._resetTip(function(err) {
|
self._resetTip(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -722,15 +729,6 @@ BlockService.prototype._saveBlock = function(block, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockService.prototype._onBestHeight = function(height) {
|
|
||||||
log.info('Block Service: Best Height is: ' + height);
|
|
||||||
this._removeAllSubscriptions();
|
|
||||||
};
|
|
||||||
|
|
||||||
BlockService.prototype._setListeners = function() {
|
|
||||||
this._p2p.on('bestHeight', this._onBestHeight.bind(this));
|
|
||||||
};
|
|
||||||
|
|
||||||
BlockService.prototype._handleError = function(err) {
|
BlockService.prototype._handleError = function(err) {
|
||||||
if (!this.node.stopping) {
|
if (!this.node.stopping) {
|
||||||
log.error('Block Service: ' + err);
|
log.error('Block Service: ' + err);
|
||||||
|
|||||||
16
package-lock.json
generated
16
package-lock.json
generated
@ -4233,6 +4233,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz",
|
||||||
"integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4="
|
"integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4="
|
||||||
},
|
},
|
||||||
|
"string_decoder": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"string-length": {
|
"string-length": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/string-length/-/string-length-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/string-length/-/string-length-1.0.1.tgz",
|
||||||
@ -4252,14 +4260,6 @@
|
|||||||
"strip-ansi": "3.0.1"
|
"strip-ansi": "3.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"string_decoder": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
|
|
||||||
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
|
|
||||||
"requires": {
|
|
||||||
"safe-buffer": "5.1.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"stringstream": {
|
"stringstream": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",
|
||||||
|
|||||||
@ -126,17 +126,6 @@ describe('Block Service', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#_setListeners', function() {
|
|
||||||
|
|
||||||
it('should set listeners for best height', function() {
|
|
||||||
var on = sandbox.stub();
|
|
||||||
blockService._p2p = { on: on };
|
|
||||||
blockService._setListeners();
|
|
||||||
expect(on.calledOnce).to.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#_setTip', function() {
|
describe('#_setTip', function() {
|
||||||
|
|
||||||
it('should set the tip if given a block', function() {
|
it('should set the tip if given a block', function() {
|
||||||
@ -165,7 +154,7 @@ describe('Block Service', function() {
|
|||||||
it('should get the prefix', function(done) {
|
it('should get the prefix', function(done) {
|
||||||
var getPrefix = sandbox.stub().callsArgWith(1, null, blockService._encoding);
|
var getPrefix = sandbox.stub().callsArgWith(1, null, blockService._encoding);
|
||||||
var getServiceTip = sandbox.stub().callsArgWith(1, null, { height: 1, hash: 'aa' });
|
var getServiceTip = sandbox.stub().callsArgWith(1, null, { height: 1, hash: 'aa' });
|
||||||
var setListeners = sandbox.stub(blockService, '_setListeners');
|
var performSanityCheck = sandbox.stub(blockService, '_performSanityCheck').callsArgWith(1, null, { hash: 'aa', height: 123 });
|
||||||
var setTip = sandbox.stub(blockService, '_setTip');
|
var setTip = sandbox.stub(blockService, '_setTip');
|
||||||
blockService.node = { openBus: sandbox.stub() };
|
blockService.node = { openBus: sandbox.stub() };
|
||||||
blockService._db = { getPrefix: getPrefix, getServiceTip: getServiceTip };
|
blockService._db = { getPrefix: getPrefix, getServiceTip: getServiceTip };
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user