Database: Removed `runAllMempoolIndexes` method
Replaced with using `tx` and `txleave` to manage the state of the mempool indexes.
This commit is contained in:
parent
5ac3b1c61f
commit
a1bae366b3
|
@ -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:
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue