From 814c18437dc52f09d2d25df88e35e04e4eaaad05 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 18 Nov 2016 06:47:09 -0800 Subject: [PATCH] miner: options. --- lib/miner/miner.js | 71 +++++++++++++++++++++++++++++++++++++--------- lib/net/peer.js | 1 - 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/lib/miner/miner.js b/lib/miner/miner.js index 3daeca06..bcdecf02 100644 --- a/lib/miner/miner.js +++ b/lib/miner/miner.js @@ -50,34 +50,77 @@ function Miner(options) { this.version = -1; this.addresses = []; - this.coinbaseFlags = options.coinbaseFlags || 'mined by bcoin'; + this.coinbaseFlags = new Buffer('mined by bcoin', 'ascii'); this.minWeight = 0; - this.maxWeight = 750000 * 4; - this.priorityWeight = 50000 * 4; + this.maxWeight = 750000 * constants.WITNESS_SCALE_FACTOR; + this.priorityWeight = 50000 * constants.WITNESS_SCALE_FACTOR; this.minPriority = constants.tx.FREE_THRESHOLD; - this._init(options); + this._initOptions(options); + this._init(); } utils.inherits(Miner, AsyncObject); +/** + * Initialize the miner options. + * @private + */ + +Miner.prototype._initOptions = function _initOptions(options) { + var i, flags; + + if (options.version != null) { + assert(utils.isNumber(options.version)); + this.version = options.version; + } + + if (options.address) + this.addAddress(options.address); + + if (options.addresses) { + assert(Array.isArray(options.addresses)); + for (i = 0; i < options.addresses.length; i++) + this.addAddress(options.addresses[i]); + } + + if (options.coinbaseFlags) { + flags = options.coinbaseFlags; + if (typeof flags === 'string') + flags = new Buffer(flags, 'utf8'); + assert(Buffer.isBuffer(flags)); + this.coinbaseFlags = flags; + } + + if (options.minWeight != null) { + assert(utils.isNumber(options.minWeight)); + this.minWeight = options.minWeight; + } + + if (options.maxWeight != null) { + assert(utils.isNumber(options.maxWeight)); + this.maxWeight = options.maxWeight; + } + + if (options.priorityWeight != null) { + assert(utils.isNumber(options.priorityWeight)); + this.priorityWeight = options.priorityWeight; + } + + if (options.minPriority != null) { + assert(utils.isNumber(options.minPriority)); + this.minPriority = options.minPriority; + } +}; + /** * Initialize the miner. * @private */ -Miner.prototype._init = function _init(options) { +Miner.prototype._init = function _init() { var self = this; - var i; - - if (options.address) - this.addAddress(options.address); - - if (options.addresses) { - for (i = 0; i < options.addresses.length; i++) - this.addAddress(options.addresses[i]); - } this.chain.on('tip', function(tip) { if (!self.attempt) diff --git a/lib/net/peer.js b/lib/net/peer.js index ff668bb2..08024529 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -113,7 +113,6 @@ function Peer(pool, addr, socket) { this.bip150 = null; this.lastSend = 0; this.lastRecv = 0; - this.outgoing = 0; this.challenge = null; this.lastPong = -1;