priority calculation.
This commit is contained in:
parent
fec9f2e308
commit
af4e9921b9
@ -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;
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user