txdb: reject rbf.

This commit is contained in:
Christopher Jeffrey 2016-10-18 07:03:35 -07:00
parent acaf0600e7
commit 9ed439b60c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 42 additions and 3 deletions

View File

@ -176,6 +176,9 @@ layout.txdb = {
},
Cc: function Cc(key) {
return this.ihii(key);
},
r: function r(hash) {
return this.ha('r', hash);
}
};

View File

@ -189,6 +189,9 @@ var layout = {
},
Cc: function Cc(key) {
return layout.ihii(key);
},
r: function r(hash) {
return layout.ha(0x72, hash);
}
};
@ -688,18 +691,30 @@ TXDB.prototype.add = co(function* add(tx) {
*/
TXDB.prototype._add = co(function* add(tx, info) {
var hash, path, account;
var hash = tx.hash('hex');
var path, account;
var i, result, input, output, coin;
var prevout, key, spender, raw;
assert(!tx.mutable, 'Cannot add mutable TX to wallet.');
if (tx.height === -1) {
// We ignore double spends from the mempool.
if (yield this.isDoubleSpend(tx))
return false;
// We ignore any unconfirmed txs
// that are replace-by-fee.
if (yield this.isRBF(tx)) {
this.put(layout.r(hash), DUMMY);
return false;
}
} else {
// This potentially removes double-spenders.
yield this.removeConflicts(tx, info);
// Delete the replace-by-fee record.
this.del(layout.r(hash));
}
// Attempt to confirm tx before adding it.
@ -709,8 +724,6 @@ TXDB.prototype._add = co(function* add(tx, info) {
if (result)
return true;
hash = tx.hash('hex');
this.put(layout.t(hash), tx.toExtended());
if (tx.height === -1)
@ -903,6 +916,29 @@ TXDB.prototype.isDoubleSpend = co(function* isDoubleSpend(tx) {
return false;
});
/**
* Test an entire transaction to see
* if any of its outpoints are replace by fee.
* @param {TX} tx
* @returns {Promise} - Returns Boolean.
*/
TXDB.prototype.isRBF = co(function* isRBF(tx) {
var i, input, prevout;
if (tx.isRBF())
return true;
for (i = 0; i < tx.inputs.length; i++) {
input = tx.inputs[i];
prevout = input.prevout;
if (yield this.has(layout.r(prevout.hash)))
return true;
}
return false;
});
/**
* Test a whether a coin has been spent.
* @param {Hash} hash