From e9fc3c816acf6019ee5b43ac4c88cdc468e98a62 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 23 Oct 2016 15:14:39 -0700 Subject: [PATCH] txdb: fix removeConflict. --- lib/wallet/txdb.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/wallet/txdb.js b/lib/wallet/txdb.js index f69c031f..fbe6b2e4 100644 --- a/lib/wallet/txdb.js +++ b/lib/wallet/txdb.js @@ -1042,11 +1042,11 @@ TXDB.prototype._add = co(function* add(tx, block) { if (!(yield this.removeConflicts(tx, true))) return; } else { - // Delete the replace-by-fee record. - this.del(layout.r(hash)); - // Potentially remove double-spenders. yield this.removeConflicts(tx, false); + + // Delete the replace-by-fee record. + this.del(layout.r(hash)); } // Finally we can do a regular insertion. @@ -1712,13 +1712,10 @@ TXDB.prototype.disconnect = co(function* disconnect(tx, block) { * @returns {Promise} - Returns Boolean. */ -TXDB.prototype.removeConflict = co(function* removeConflict(hash, ref) { - var tx = yield this.getTX(hash); +TXDB.prototype.removeConflict = co(function* removeConflict(tx) { var details; - assert(tx); - - this.logger.warning('Handling conflicting tx: %s.', utils.revHex(hash)); + this.logger.warning('Handling conflicting tx: %s.', tx.rhash); this.drop(); @@ -1745,7 +1742,7 @@ TXDB.prototype.removeConflict = co(function* removeConflict(hash, ref) { TXDB.prototype.removeConflicts = co(function* removeConflicts(tx, conf) { var hash = tx.hash('hex'); var spends = []; - var i, input, prevout, spent; + var i, input, prevout, spent, spender; if (tx.isCoinbase()) return true; @@ -1765,23 +1762,26 @@ TXDB.prototype.removeConflicts = co(function* removeConflicts(tx, conf) { if (spent.hash === hash) continue; - if (conf && tx.height !== -1) + spender = yield this.getTX(spent.hash); + assert(spender); + + if (conf && spender.height !== -1) return false; - spends[i] = spent; + spends[i] = spender; } // Once we know we're not going to // screw things up, remove the double // spenders. for (i = 0; i < tx.inputs.length; i++) { - spent = spends[i]; + spender = spends[i]; - if (!spent) + if (!spender) continue; // Remove the double spender. - yield this.removeConflict(spent.hash, tx); + yield this.removeConflict(spender); } return true;