mempool: handle mined removal better.

This commit is contained in:
Christopher Jeffrey 2016-12-15 15:12:55 -08:00
parent 8b05ef2def
commit 559cc3592d
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 35 additions and 2 deletions

View File

@ -1612,11 +1612,13 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
} }
break; break;
case constants.thresholdStates.ACTIVE: case constants.thresholdStates.ACTIVE:
vbrules.push(name);
if (rules) { if (rules) {
if (rules.indexOf(name) === -1 && !deployment.force) if (rules.indexOf(name) === -1 && !deployment.force)
throw new RPCError('Client must support ' + name + '.'); throw new RPCError('Client must support ' + name + '.');
} }
if (!deployment.force)
name = '!' + name;
vbrules.push(name);
break; break;
} }
} }

View File

@ -580,7 +580,8 @@ HTTPServer.prototype._init = function _init() {
if (cmd.method !== 'getblocktemplate' && cmd.method !== 'getwork') { if (cmd.method !== 'getblocktemplate' && cmd.method !== 'getwork') {
this.logger.debug('Handling RPC call : %s.', cmd.method); this.logger.debug('Handling RPC call : %s.', cmd.method);
this.logger.debug(cmd.params); if (cmd.method !== 'submitblock')
this.logger.debug(cmd.params);
} }
try { try {

View File

@ -178,10 +178,12 @@ Mempool.prototype._addBlock = function addBlock(block, txs) {
if (!entry) { if (!entry) {
this.removeOrphan(hash); this.removeOrphan(hash);
this.resolveOrphans(tx); this.resolveOrphans(tx);
this.removeDoubleSpends(tx);
continue; continue;
} }
this.removeEntry(entry); this.removeEntry(entry);
this.removeDoubleSpends(tx);
this.emit('confirmed', tx, block); this.emit('confirmed', tx, block);
entries.push(entry); 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. * Calculate the memory usage of a transaction.
* Note that this only calculates the JS heap * Note that this only calculates the JS heap