diff --git a/lib/services/db/index.js b/lib/services/db/index.js index 19ee431b..1225cec8 100644 --- a/lib/services/db/index.js +++ b/lib/services/db/index.js @@ -134,9 +134,6 @@ DB.prototype.start = function(callback) { self.genesis = Block.fromBuffer(self.bitcoind.genesisBuffer); self.store = levelup(self.dataPath, { db: self.levelupStore, keyEncoding: 'binary', valueEncoding: 'binary'}); - self.node.on('stopping', function() { - }); - self.node.once('ready', function() { self.loadTips(function(err) { diff --git a/lib/services/db/sync.js b/lib/services/db/sync.js index 7f959ac4..4bb8915e 100644 --- a/lib/services/db/sync.js +++ b/lib/services/db/sync.js @@ -20,7 +20,6 @@ function BlockStream(highWaterMark, db, sync) { this.dbTip = this.db.tip; this.lastReadHeight = this.dbTip.__height; this.lastEmittedHash = this.dbTip.hash; - this.stopping = false; this.queue = []; this.processing = false; this.syncing = true; @@ -102,9 +101,8 @@ Sync.prototype.sync = function() { self.lastReportedBlock = self.db.tip.__height; - self.progressBar = new ProgressBar('[:bar] :percent :current blks, :blockspersec blks/sec, :elapsed secs', { - complete: green, - incomplete: red, + self.progressBar = new ProgressBar('[:bar] :percent :current blks, :blockspersec blks/sec', { + curr: self.lastReportedBlock, total: self.node.services.bitcoind.height, clear: true }); @@ -355,6 +353,10 @@ ProcessConcurrent.prototype._flush = function(callback) { WriteStream.prototype._write = function(obj, enc, callback) { var self = this; + if (self.db.node.stopping) { + return setImmediate(callback); + } + self.db.store.batch(obj.operations, function(err) { if(err) { return callback(err);