priority calculation.

This commit is contained in:
Christopher Jeffrey 2016-03-31 04:22:20 -07:00
parent fec9f2e308
commit af4e9921b9
3 changed files with 34 additions and 17 deletions

View File

@ -685,7 +685,10 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) {
size = 0; size = 0;
witness = false; witness = false;
assert(input.coin); if (!input.coin) {
total += 110;
continue;
}
// Get the previous output's subscript // Get the previous output's subscript
prev = input.coin.script; prev = input.coin.script;

View File

@ -207,7 +207,6 @@ exports.tx = {
minFee: 10000, minFee: 10000,
bareMultisig: true, bareMultisig: true,
freeThreshold: exports.coin.muln(144).divn(250), freeThreshold: exports.coin.muln(144).divn(250),
maxFreeSize: 1000,
maxSigops: exports.block.maxSigops / 5, maxSigops: exports.block.maxSigops / 5,
coinbaseMaturity: 100 coinbaseMaturity: 100
}; };

View File

@ -988,27 +988,51 @@ TX.prototype.maxSize = function maxSize() {
return this.getVirtualSize(); 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) { TX.prototype.getPriority = function getPriority(height, size) {
var sum, i, input, age; var sum, i, input, age;
if (this.isCoinbase())
return new bn(0);
if (height == null) { if (height == null) {
height = this.height; height = this.height;
if (height === -1) if (height === -1)
height = network.height + 1; height = network.height + 1;
} }
if (!this.hasCoins())
return new bn(0);
if (size == null) if (size == null)
size = this.maxSize(); size = this.getModifiedSize();
sum = new bn(0); sum = new bn(0);
for (i = 0; i < this.inputs.length; i++) { for (i = 0; i < this.inputs.length; i++) {
input = this.inputs[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); return sum.divn(size);
@ -1017,21 +1041,12 @@ TX.prototype.getPriority = function getPriority(height, size) {
TX.prototype.isFree = function isFree(height, size) { TX.prototype.isFree = function isFree(height, size) {
var priority; var priority;
if (!this.hasCoins())
return false;
if (height == null) { if (height == null) {
height = this.height; height = this.height;
if (height === -1) if (height === -1)
height = network.height + 1; height = network.height + 1;
} }
if (size == null)
size = this.maxSize();
if (size >= constants.tx.maxFreeSize)
return false;
priority = this.getPriority(height, size); priority = this.getPriority(height, size);
return priority.cmp(constants.tx.freeThreshold) > 0; return priority.cmp(constants.tx.freeThreshold) > 0;