From 559cc3592d6b12f39c9f67155c41bca38b0c3d00 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 15 Dec 2016 15:12:55 -0800 Subject: [PATCH] mempool: handle mined removal better. --- lib/http/rpc.js | 4 +++- lib/http/server.js | 3 ++- lib/mempool/mempool.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/http/rpc.js b/lib/http/rpc.js index d17b2ad6..7411e1df 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -1612,11 +1612,13 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) { } break; case constants.thresholdStates.ACTIVE: - vbrules.push(name); if (rules) { if (rules.indexOf(name) === -1 && !deployment.force) throw new RPCError('Client must support ' + name + '.'); } + if (!deployment.force) + name = '!' + name; + vbrules.push(name); break; } } diff --git a/lib/http/server.js b/lib/http/server.js index 78a69b6f..2784c751 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -580,7 +580,8 @@ HTTPServer.prototype._init = function _init() { if (cmd.method !== 'getblocktemplate' && cmd.method !== 'getwork') { this.logger.debug('Handling RPC call : %s.', cmd.method); - this.logger.debug(cmd.params); + if (cmd.method !== 'submitblock') + this.logger.debug(cmd.params); } try { diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index e4e85521..f4bca289 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -178,10 +178,12 @@ Mempool.prototype._addBlock = function addBlock(block, txs) { if (!entry) { this.removeOrphan(hash); this.resolveOrphans(tx); + this.removeDoubleSpends(tx); continue; } this.removeEntry(entry); + this.removeDoubleSpends(tx); this.emit('confirmed', tx, block); entries.push(entry); @@ -1706,6 +1708,34 @@ Mempool.prototype.removeSpenders = function removeSpenders(entry) { } }; +/** + * Recursively remove double spenders + * of a mined transaction's outpoints. + * @private + * @param {MempoolEntry} entry + * @param {Boolean} limit + * @returns {Promise} + */ + +Mempool.prototype.removeDoubleSpends = function removeDoubleSpends(tx) { + var i, input, prevout, spent; + + for (i = 0; i < tx.inputs.length; i++) { + input = tx.inputs[i]; + prevout = input.prevout; + spent = this.getSpent(prevout.hash, prevout.index); + + if (!spent) + continue; + + this.logger.debug( + 'Removing double spender from mempool: %s.', + spent.tx.rhash()); + + this.removeEntry(spent, true); + } +}; + /** * Calculate the memory usage of a transaction. * Note that this only calculates the JS heap