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

View File

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