From a1bae366b36d221d422e410d95782210593b460e Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 2 Nov 2015 17:17:03 -0500 Subject: [PATCH] Database: Removed `runAllMempoolIndexes` method Replaced with using `tx` and `txleave` to manage the state of the mempool indexes. --- docs/services/db.md | 10 ---------- lib/services/db.js | 29 ++--------------------------- test/services/db.unit.js | 2 -- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/docs/services/db.md b/docs/services/db.md index 305587a0..57439247 100644 --- a/docs/services/db.md +++ b/docs/services/db.md @@ -19,16 +19,6 @@ CustomService.prototype.blockHandler = function(block, add, callback) { Take a look at the Address Service implementation for more details about how to encode the key, value for the best efficiency and ways to format the keys for streaming reads. -Additionally the mempool can have an index, the mempool index will be updated once bitcoind and the db have both fully synced. A service can implement a `resetMempoolIndex` method that will be run during this time, and the "synced" event will wait until this task has been finished: - -```js -CustomService.prototype.resetMempoolIndex = function(callback) { - var transactionBuffers = this.node.services.bitcoind.getMempoolTransactions(); - // interact over the transactions asynchronously here - callback(); -}; -``` - ## API Documentation These methods are exposed over the JSON-RPC interface and can be called directly from a node via: diff --git a/lib/services/db.js b/lib/services/db.js index 8ad70bd5..0c655051 100644 --- a/lib/services/db.js +++ b/lib/services/db.js @@ -454,24 +454,6 @@ DB.prototype.disconnectBlock = function(block, callback) { this.runAllBlockHandlers(block, false, callback); }; -/** - * Will run all `resetMempoolIndex` methods implemented on sibling - * services to update the mempool indexes. - */ -DB.prototype.runAllMempoolIndexes = function(callback) { - async.eachSeries( - this.node.services, - function(service, next) { - if (service.resetMempoolIndex) { - service.resetMempoolIndex(next); - } else { - setImmediate(next); - } - }, - callback - ); -}; - /** * Will collect all database operations for a block from other services that implement * `blockHandler` methods and then save operations to the database. @@ -745,15 +727,8 @@ DB.prototype.sync = function() { } if (self.node.services.bitcoind.isSynced()) { - self.runAllMempoolIndexes(function(err) { - if (err) { - Error.captureStackTrace(err); - return self.node.emit('error', err); - } - - self.bitcoindSyncing = false; - self.node.emit('synced'); - }); + self.bitcoindSyncing = false; + self.node.emit('synced'); } else { self.bitcoindSyncing = false; } diff --git a/test/services/db.unit.js b/test/services/db.unit.js index 0d5ea257..bf4f0c4e 100644 --- a/test/services/db.unit.js +++ b/test/services/db.unit.js @@ -839,7 +839,6 @@ describe('DB Service', function() { var blockBuffer = new Buffer(blockData, 'hex'); var block = Block.fromBuffer(blockBuffer); db.node.services = {}; - db.runAllMempoolIndexes = sinon.stub().callsArg(0); db.node.services.bitcoind = { getBlock: sinon.stub().callsArgWith(1, null, blockBuffer), isSynced: sinon.stub().returns(true), @@ -858,7 +857,6 @@ describe('DB Service', function() { callback(); }; db.node.once('synced', function() { - db.runAllMempoolIndexes.callCount.should.equal(1); done(); }); db.sync();