Put reportStatus on ProcessSerial.

This commit is contained in:
Chris Kleeschulte 2017-05-15 15:28:34 -04:00
parent b6f56fb02b
commit ce09b816bb

View File

@ -39,6 +39,7 @@ function ProcessSerial(highWaterMark, db, tip) {
this.db = db;
this.tip = tip;
this.processBlockStartTime = [];
this._lastReportedTime = Date.now();
}
inherits(ProcessSerial, Writable);
@ -65,7 +66,6 @@ function Sync(node, db) {
this.syncing = false;
this.paused = false; //we can't sync while one of our indexes is reading/writing separate from us
this.highWaterMark = 10;
this._lastReportedTime = Date.now();
}
inherits(Sync, EventEmitter);
@ -114,7 +114,6 @@ Sync.prototype._onFinish = function() {
}
self._startSubscriptions();
self._reportStatus(true);
self.emit('synced');
};
@ -129,7 +128,6 @@ Sync.prototype._startSubscriptions = function() {
self.bus = self.node.openBus({remoteAddress: 'localhost'});
self.bus.on('bitcoind/hashblock', function() {
self._reportStatus();
self.sync();
});
@ -138,13 +136,6 @@ Sync.prototype._startSubscriptions = function() {
};
Sync.prototype._reportStatus = function(override) {
if (((Date.now() - this._lastReportedTime) > 1000) || override) {
this._lastReportedTime = Date.now();
log.info('Sync: current height is: ' + this.db.tip.__height);
}
};
Sync.prototype._handleErrors = function(stream) {
var self = this;
@ -244,6 +235,13 @@ BlockStream.prototype._getBlocks = function(heights, callback) {
});
};
ProcessSerial.prototype._reportStatus = function() {
if ((Date.now() - this._lastReportedTime) > 1000) {
this._lastReportedTime = Date.now();
log.info('Sync: current height is: ' + this.db.tip.__height);
}
};
ProcessSerial.prototype._write = function(block, enc, callback) {
var self = this;
@ -288,6 +286,7 @@ ProcessSerial.prototype._process = function(block, callback) {
}
self.db.tip = block;
self._reportStatus();
self.db.emit('addblock');
callback();