diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 81f78cfe..e4e85521 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -177,6 +177,7 @@ Mempool.prototype._addBlock = function addBlock(block, txs) { if (!entry) { this.removeOrphan(hash); + this.resolveOrphans(tx); continue; } @@ -192,6 +193,13 @@ Mempool.prototype._addBlock = function addBlock(block, txs) { // We need to reset the rejects filter periodically. // There may be a locktime in a TX that is now valid. this.rejects.reset(); + + if (entries.length === 0) + return; + + this.logger.debug( + 'Removed %d txs from mempool for block %d.', + entries.length, block.height); }; /** @@ -221,6 +229,7 @@ Mempool.prototype.removeBlock = co(function* removeBlock(block, txs) { */ Mempool.prototype._removeBlock = co(function* removeBlock(block, txs) { + var total = 0; var i, tx, hash; for (i = 1; i < txs.length; i++) { @@ -232,6 +241,7 @@ Mempool.prototype._removeBlock = co(function* removeBlock(block, txs) { try { yield this._addTX(tx); + total++; } catch (e) { this.emit('error', e); continue; @@ -241,6 +251,13 @@ Mempool.prototype._removeBlock = co(function* removeBlock(block, txs) { } this.rejects.reset(); + + if (total === 0) + return; + + this.logger.debug( + 'Added %d txs back into the mempool for block %d.', + total, block.height); }); /** @@ -1447,10 +1464,8 @@ Mempool.prototype.removeOrphan = function removeOrphan(hash) { hashes.splice(j, 1); - if (hashes.length === 0) { + if (hashes.length === 0) delete this.waiting[prev]; - continue; - } } delete this.orphans[hash];