Disable mempool until system is synchronized.

This commit is contained in:
Chris Kleeschulte 2017-10-25 15:17:11 -04:00
parent f6bbfa8b07
commit 2478795213
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F
2 changed files with 18 additions and 3 deletions

View File

@ -30,11 +30,12 @@ var BlockService = function(options) {
this._recentBlockHashesCount = options.recentBlockHashesCount || 50; // if you expect this chain to reorg deeper than 50, set this
this._recentBlockHashes = new LRU(this._recentBlockHashesCount);
this._readAheadBlockCount = options.readAheadBlockCount || 2; // this is the number of blocks to direct the p2p service to read aheead
this._mempool = this.node.services.mempool;
};
inherits(BlockService, BaseService);
BlockService.dependencies = [ 'timestamp', 'p2p', 'db', 'header' ];
BlockService.dependencies = [ 'timestamp', 'p2p', 'db', 'header', 'mempool' ];
// --- public prototype functions
BlockService.prototype.getAPIMethods = function() {
@ -914,6 +915,7 @@ BlockService.prototype._onSynced = function() {
self._initialSync = false;
self._startBlockSubscription();
self._logSynced(self._tip.hash);
self._mempool.enable();
};
BlockService.prototype._startSync = function() {

View File

@ -13,6 +13,7 @@ var MempoolService = function(options) {
this._p2p = this.node.services.p2p;
this._network = this.node.network;
this._flush = options.flush;
this._enabled = false;
if (this._network === 'livenet') {
this._network = 'main';
@ -87,10 +88,14 @@ MempoolService.prototype._flushMempool = function(callback) {
MempoolService.prototype.onReorg = function(args, callback) {
var oldBlockList = args[1];
var removalOps = [];
if (!this._enabled) {
return callback(null, removalOps);
}
var oldBlockList = args[1];
for(var i = 0; i < oldBlockList.length; i++) {
var block = oldBlockList[i];
@ -139,12 +144,20 @@ MempoolService.prototype._startSubscriptions = function() {
};
MempoolService.prototype.enable = function() {
this._enabled = true;
};
MempoolService.prototype.onBlock = function(block, callback) {
// remove this block's txs from mempool
var self = this;
var ops = [];
if (!self._enabled) {
return callback(null, ops);
}
for(var i = 0; i < block.txs.length; i++) {
var tx = block.txs[i];