diff --git a/lib/bcoin/mtx.js b/lib/bcoin/mtx.js index bfe7c0b3..f97c8948 100644 --- a/lib/bcoin/mtx.js +++ b/lib/bcoin/mtx.js @@ -685,7 +685,10 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) { size = 0; witness = false; - assert(input.coin); + if (!input.coin) { + total += 110; + continue; + } // Get the previous output's subscript prev = input.coin.script; diff --git a/lib/bcoin/protocol/constants.js b/lib/bcoin/protocol/constants.js index 45f6d271..e891d5b7 100644 --- a/lib/bcoin/protocol/constants.js +++ b/lib/bcoin/protocol/constants.js @@ -207,7 +207,6 @@ exports.tx = { minFee: 10000, bareMultisig: true, freeThreshold: exports.coin.muln(144).divn(250), - maxFreeSize: 1000, maxSigops: exports.block.maxSigops / 5, coinbaseMaturity: 100 }; diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 10451d1c..696d6da6 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -988,27 +988,51 @@ TX.prototype.maxSize = function maxSize() { return this.getVirtualSize(); }; +TX.prototype.getModifiedSize = function getModifiedSize(size) { + var i, offset; + + if (size == null) + size = this.maxSize(); + + for (i = 0; i < this.inputs.length; i++) { + offset = 41 + Math.min(110, this.inputs[i].script.getSize()); + if (size > offset) + size -= offset; + } + + return size; +}; + TX.prototype.getPriority = function getPriority(height, size) { var sum, i, input, age; + if (this.isCoinbase()) + return new bn(0); + if (height == null) { height = this.height; if (height === -1) height = network.height + 1; } - if (!this.hasCoins()) - return new bn(0); - if (size == null) - size = this.maxSize(); + size = this.getModifiedSize(); sum = new bn(0); for (i = 0; i < this.inputs.length; i++) { input = this.inputs[i]; - age = input.coin.getAge(height); - sum.iadd(input.coin.value.muln(age)); + + if (!input.coin) + continue; + + if (input.coin.height === -1) + continue; + + if (input.coin.height <= height) { + age = height - input.coin.height; + sum.iadd(input.coin.value.muln(age)); + } } return sum.divn(size); @@ -1017,21 +1041,12 @@ TX.prototype.getPriority = function getPriority(height, size) { TX.prototype.isFree = function isFree(height, size) { var priority; - if (!this.hasCoins()) - return false; - if (height == null) { height = this.height; if (height === -1) height = network.height + 1; } - if (size == null) - size = this.maxSize(); - - if (size >= constants.tx.maxFreeSize) - return false; - priority = this.getPriority(height, size); return priority.cmp(constants.tx.freeThreshold) > 0;