diff --git a/lib/mining/miner.js b/lib/mining/miner.js index 74529cd4..f19704b5 100644 --- a/lib/mining/miner.js +++ b/lib/mining/miner.js @@ -368,11 +368,14 @@ Miner.prototype.getAddress = function getAddress() { Miner.prototype.build = function build(attempt) { var depMap = {}; var block = attempt.block; - var queue = new Queue(cmpPriority); - var priority = true; + var queue = new Queue(cmpRate); + var priority = this.priorityWeight > 0; var i, j, entry, item, tx, hash, input; var prev, deps, hashes, weight, sigops; + if (priority) + queue.sort(cmpPriority); + if (!this.mempool) return []; @@ -433,10 +436,10 @@ Miner.prototype.build = function build(attempt) { if (priority) { if (weight > this.options.priorityWeight - || item.priority < this.options.minPriority) { + || item.priority < this.options.priorityThreshold) { // Todo: Compare descendant rate with // cumulative fees and cumulative vsize. - queue.cmp = cmpRate; + queue.sort(cmpRate); priority = false; queue.push(item); continue; @@ -495,8 +498,8 @@ function MinerOptions(options) { this.minWeight = policy.MIN_BLOCK_WEIGHT; this.maxWeight = policy.MAX_BLOCK_WEIGHT; - this.priorityWeight = policy.PRIORITY_BLOCK_WEIGHT; - this.minPriority = policy.MIN_BLOCK_PRIORITY; + this.priorityWeight = policy.BLOCK_PRIORITY_WEIGHT; + this.priorityThreshold = policy.BLOCK_PRIORITY_THRESHOLD; this.maxSigops = consensus.MAX_BLOCK_SIGOPS_COST; this.reservedWeight = 4000; this.reservedSigops = 400; @@ -585,9 +588,9 @@ MinerOptions.prototype.fromOptions = function fromOptions(options) { this.priorityWeight = options.priorityWeight; } - if (options.minPriority != null) { - assert(util.isNumber(options.minPriority)); - this.minPriority = options.minPriority; + if (options.priorityThreshold != null) { + assert(util.isNumber(options.priorityThreshold)); + this.priorityThreshold = options.priorityThreshold; } if (options.reservedWeight != null) { @@ -620,7 +623,7 @@ MinerOptions.fromOptions = function fromOptions(options) { */ function Queue(cmp) { - this.cmp = cmp; + this.cmp = cmp || null; this.items = []; } @@ -629,6 +632,7 @@ Queue.prototype.size = function size() { }; Queue.prototype.push = function push(item) { + assert(this.cmp, 'No comparator for queue.'); util.binaryInsert(this.items, item, this.cmp); }; @@ -636,6 +640,12 @@ Queue.prototype.pop = function pop() { return this.items.pop(); }; +Queue.prototype.sort = function sort(cmp) { + assert(cmp === null || typeof cmp === 'function', + 'Comparator must be a function.'); + this.cmp = cmp; +}; + /* * Helpers */ diff --git a/lib/protocol/policy.js b/lib/protocol/policy.js index 50fd0218..b850c934 100644 --- a/lib/protocol/policy.js +++ b/lib/protocol/policy.js @@ -172,9 +172,9 @@ exports.MEMPOOL_EXPIRY_TIME = 72 * 60 * 60; exports.MEMPOOL_MAX_ORPHANS = 100; /** - * Block weight to be reached before - * rejecting priority transactions during - * mining. + * Minimum block size to create. Block will be + * filled with free transactions until block + * reaches this weight. * @const {Number} * @default */ @@ -187,26 +187,26 @@ exports.MIN_BLOCK_WEIGHT = 0; * @default */ -exports.MAX_BLOCK_WEIGHT = 750000 * consensus.WITNESS_SCALE_FACTOR; +exports.MAX_BLOCK_WEIGHT = 1000000 * consensus.WITNESS_SCALE_FACTOR; /** - * Bottom priority threshold to be seen - * before ignoring priority transactions - * during mining. + * How much of the block should be dedicated to + * high-priority transactions (included regardless + * of fee rate). * @const {Number} * @default */ -exports.MIN_BLOCK_PRIORITY = 50000 * consensus.WITNESS_SCALE_FACTOR; +exports.BLOCK_PRIORITY_WEIGHT = 0; /** - * Weight to be reached before ignoring - * priority transactions during mining. + * Priority threshold to be reached before + * switching to fee rate comparison. * @const {Number} * @default */ -exports.PRIORITY_BLOCK_WEIGHT = exports.FREE_THRESHOLD; +exports.BLOCK_PRIORITY_THRESHOLD = exports.FREE_THRESHOLD; /** * Calculate minimum fee based on rate and size.