From ce09b816bbf417d2797453674f61a09c61d92f4c Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Mon, 15 May 2017 15:28:34 -0400 Subject: [PATCH] Put reportStatus on ProcessSerial. --- lib/services/db/sync.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/services/db/sync.js b/lib/services/db/sync.js index fa72cc6c..c9e873dd 100644 --- a/lib/services/db/sync.js +++ b/lib/services/db/sync.js @@ -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();