From acaf0600e70ac712d81c021cd9f0f6e897e26157 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 18 Oct 2016 06:39:00 -0700 Subject: [PATCH] mempool: do not accept replace by fee. --- lib/mempool/mempool.js | 6 ++++++ lib/primitives/input.js | 9 +++++++++ lib/primitives/tx.js | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 6757c7a9..25a48abb 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -644,6 +644,12 @@ Mempool.prototype._addTX = co(function* _addTX(tx) { ret.reason, ret.score); } + if (tx.isRBF()) { + throw new VerifyError(tx, + 'nonstandard', + 'replace-by-fee', + 0); + } } result = yield this.chain.checkFinal(this.chain.tip, tx, lockFlags); diff --git a/lib/primitives/input.js b/lib/primitives/input.js index 1f8b3c9a..68b8cd1d 100644 --- a/lib/primitives/input.js +++ b/lib/primitives/input.js @@ -221,6 +221,15 @@ Input.prototype.isFinal = function isFinal() { return this.sequence === 0xffffffff; }; +/** + * Test to see if nSequence is less than 0xfffffffe. + * @returns {Boolean} + */ + +Input.prototype.isRBF = function isRBF() { + return this.sequence < 0xfffffffe; +}; + /** * Test to see if outpoint is null. * @returns {Boolean} diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index 5e9cb075..06ed05d4 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -782,6 +782,31 @@ TX.prototype.isCoinbase = function isCoinbase() { return this.inputs.length === 1 && this.inputs[0].prevout.isNull(); }; +/** + * Test whether the transaction is a replacement. + * @returns {Boolean} + */ + +TX.prototype.isRBF = function isRBF() { + var i, input; + + for (i = 0; i < this.inputs.length; i++) { + input = this.inputs[i]; + + if (!input.isRBF()) + continue; + + if (this.version === 2) { + if (!(input.sequence & constants.sequence.DISABLE_FLAG)) + continue; + } + + return true; + } + + return false; +}; + /** * Calculate the fee for the transaction. * @returns {Amount} fee (zero if not all coins are available).