Clean up.

This commit is contained in:
Chris Kleeschulte 2017-09-22 14:16:02 -04:00
parent a1db879fdc
commit b160814706
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F
2 changed files with 15 additions and 35 deletions

View File

@ -51,27 +51,18 @@ BlockService.prototype.getAPIMethods = function() {
BlockService.prototype.getInfo = function(callback) {
var self = this;
// check to ensure the header service is all up-to-date
async.retry(function(next) {
var ready = self._header.getBestHeight() < self.getTip().height;
next(ready);
}, function(err) {
if (err) {
return callback(err);
}
callback(null, {
blocks: self.getTip().height,
connections: self._p2p.getNumberOfPeers(),
timeoffset: 0,
proxy: '',
testnet: self.node.network === 'livenet' ? false: true,
errors: '',
network: self.node.network,
relayFee: 0,
version: 'bitcore-1.1.2',
protocolversion: 700001,
difficulty: self._header.getCurrentDifficulty()
});
callback(null, {
blocks: self.getTip().height,
connections: self._p2p.getNumberOfPeers(),
timeoffset: 0,
proxy: '',
testnet: self.node.network === 'livenet' ? false: true,
errors: '',
network: self.node.network,
relayFee: 0,
version: 'bitcore-1.1.2',
protocolversion: 700001,
difficulty: self._header.getCurrentDifficulty()
});
};
@ -434,9 +425,6 @@ BlockService.prototype._onAllHeaders = function() {
// once the header service has all of its headers, we know we can check our
// own tip for consistency and make sure our it is on the mainchain
var self = this;
if (self._syncing) {
return;
}
if (!self._initialSync) {
return self._sync();
@ -586,12 +574,10 @@ BlockService.prototype.onBlock = function(block, callback) {
BlockService.prototype.newBlock = function(block) {
if (this.node.stopping || this._tip.hash === block.rhash()) {
if (this.node.stopping || this._tip.hash === block.rhash()) {
return;
}
this._header.blockServiceSyncing = true;
// this service must receive blocks in order
var prevHash = bcoin.util.revHex(block.prevBlock);
@ -606,8 +592,7 @@ BlockService.prototype.newBlock = function(block) {
};
BlockService.prototype._setListeners = function() {
var self = this;
self._header.on('headers', self._onAllHeaders.bind(self));
this._header.on('headers', this._onAllHeaders.bind(this));
};
BlockService.prototype.newReorg = function(block, headers, callback) {
@ -681,6 +666,7 @@ BlockService.prototype._sync = function() {
// this will lead to duplicate transactions being sent
self._p2p.clearInventoryCache();
console.log('target hash: ' + targetHash);
self._p2p.getP2PBlock({
filter: {
startHash: self._tip.hash,
@ -694,7 +680,6 @@ BlockService.prototype._sync = function() {
}
this._syncing = false;
this._header.blockServiceSyncing = false;
this._initialSync = false;
log.info('Block Service: The best block hash is: ' + self._tip.hash +
' at height: ' + self._tip.height);

View File

@ -459,7 +459,6 @@ HeaderService.prototype._onHeadersSave = function(err) {
}
self._startBlockSubscription();
self._setBestHeader();
self._initialSync = false;
@ -488,11 +487,7 @@ HeaderService.prototype._syncComplete = function() {
};
HeaderService.prototype._setBestHeader = function() {
var bestHeader = this._lastHeader;
this._tip.height = bestHeader.height;
this._tip.hash = bestHeader.hash;
log.debug('Header Service: ' + bestHeader.hash + ' is the best block hash.');
};