txdb: fix removeConflict.

This commit is contained in:
Christopher Jeffrey 2016-10-23 15:14:39 -07:00
parent 8896ff9665
commit e9fc3c816a
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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;