From d338f62078113527b3cd41cf5cf94f154ca61887 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 10 Jan 2017 04:57:41 -0800 Subject: [PATCH] protocol: constants changes. --- lib/blockchain/chain.js | 2 +- lib/mempool/mempool.js | 124 +++++++++++++++++++++++++++++++--------- lib/net/common.js | 2 +- lib/script/common.js | 2 +- 4 files changed, 99 insertions(+), 31 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 004fedeb..c2ff9d6b 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -297,7 +297,7 @@ Chain.prototype.verify = co(function* verify(block, prev) { // Skip any blocks below the // last checkpoint. - if (!this.options.segwit) { + if (!this.options.witness) { // We can't skip this with segwit // enabled since the block may have // been malleated: we don't know diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 1bc51617..dd77458a 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -97,26 +97,99 @@ function Mempool(options) { this.freeCount = 0; this.lastTime = 0; - this.limitFree = this.options.limitFree !== false; - this.limitFreeRelay = this.options.limitFreeRelay || 15; - this.relayPriority = this.options.relayPriority !== false; - this.requireStandard = this.options.requireStandard != null - ? this.options.requireStandard - : this.network.requireStandard; - this.rejectAbsurdFees = this.options.rejectAbsurdFees !== false; - this.prematureWitness = !!this.options.prematureWitness; - this.paranoid = !!this.options.paranoid; - this.replaceByFee = !!this.options.replaceByFee; + this.limitFree = true; + this.limitFreeRelay = 15; + this.relayPriority = true; + this.requireStandard = this.network.requireStandard; + this.rejectAbsurdFees = true; + this.prematureWitness = false; + this.paranoidChecks = false; + this.replaceByFee = false; - this.maxSize = options.maxSize || policy.MEMPOOL_MAX_SIZE; - this.maxOrphans = options.maxOrphans || policy.MEMPOOL_MAX_ORPHANS; - this.maxAncestors = options.maxAncestors || policy.MEMPOOL_MAX_ANCESTORS; - this.expiryTime = options.expiryTime || policy.MEMPOOL_EXPIRY_TIME; + this.maxSize = policy.MEMPOOL_MAX_SIZE; + this.maxOrphans = policy.MEMPOOL_MAX_ORPHANS; + this.maxAncestors = policy.MEMPOOL_MAX_ANCESTORS; + this.expiryTime = policy.MEMPOOL_EXPIRY_TIME; this.minRelay = this.network.minRelay; + + this._initOptions(options); } util.inherits(Mempool, AsyncObject); +/** + * Initialize options. + * @param {Object} options + * @private + */ + +Mempool.prototype._initOptions = function _initOptions(options) { + if (options.limitFree != null) { + assert(typeof options.limitFree === 'boolean'); + this.limitFree = options.limitFree; + } + + if (options.limitFreeRelay != null) { + assert(util.isNumber(options.limitFreeRelay)); + this.limitFreeRelay = options.limitFreeRelay; + } + + if (options.relayPriority != null) { + assert(typeof options.relayPriority === 'boolean'); + this.relayPriority = options.relayPriority; + } + + if (options.requireStandard != null) { + assert(typeof options.requireStandard === 'boolean'); + this.requireStandard = options.requireStandard; + } + + if (options.rejectAbsurdFees != null) { + assert(typeof options.rejectAbsurdFees === 'boolean'); + this.rejectAbsurdFees = options.rejectAbsurdFees; + } + + if (options.prematureWitness != null) { + assert(typeof options.prematureWitness === 'boolean'); + this.prematureWitness = options.prematureWitness; + } + + if (options.paranoidChecks != null) { + assert(typeof options.paranoidChecks === 'boolean'); + this.paranoidChecks = options.paranoidChecks; + } + + if (options.replaceByFee != null) { + assert(typeof options.replaceByFee === 'boolean'); + this.replaceByFee = options.replaceByFee; + } + + if (options.maxSize != null) { + assert(util.isNumber(options.maxSize)); + this.maxSize = options.maxSize; + } + + if (options.maxOrphans != null) { + assert(util.isNumber(options.maxOrphans)); + this.maxOrphans = options.maxOrphans; + } + + if (options.maxAncestors != null) { + assert(util.isNumber(options.maxAncestors)); + this.maxAncestors = options.maxAncestors; + } + + if (options.expiryTime != null) { + assert(util.isNumber(options.expiryTime)); + this.expiryTime = options.expiryTime; + } + + if (options.minRelay != null) { + assert(util.isNumber(options.minRelay)); + this.minRelay = options.minRelay; + } +}; + /** * Open the chain, wait for the database to load. * @alias Mempool#open @@ -921,7 +994,7 @@ Mempool.prototype.verify = co(function* verify(entry, view) { } // Paranoid checks. - if (this.paranoid) { + if (this.paranoidChecks) { flags = Script.flags.MANDATORY_VERIFY_FLAGS; result = yield this.verifyResult(tx, view, flags); assert(result, 'BUG: Verify failed for mandatory but not standard.'); @@ -961,20 +1034,15 @@ Mempool.prototype.verifyInputs = co(function* verifyInputs(tx, view, flags) { if (yield tx.verifyAsync(view, flags)) return; - if (!(flags & Script.flags.UNSTANDARD_VERIFY_FLAGS)) { - throw new VerifyError(tx, - 'nonstandard', - 'non-mandatory-script-verify-flag', - 0); - } + if (flags & Script.flags.ONLY_STANDARD_VERIFY_FLAGS) { + flags &= ~Script.flags.ONLY_STANDARD_VERIFY_FLAGS; - flags &= ~Script.flags.UNSTANDARD_VERIFY_FLAGS; - - if (yield tx.verifyAsync(view, flags)) { - throw new VerifyError(tx, - 'nonstandard', - 'non-mandatory-script-verify-flag', - 0); + if (yield tx.verifyAsync(view, flags)) { + throw new VerifyError(tx, + 'nonstandard', + 'non-mandatory-script-verify-flag', + 0); + } } throw new VerifyError(tx, diff --git a/lib/net/common.js b/lib/net/common.js index 0a60ae82..9ddc63a3 100644 --- a/lib/net/common.js +++ b/lib/net/common.js @@ -15,7 +15,7 @@ var pkg = require('../../package.json'); * @default */ -exports.PROTOCOL_VERSION = 70014; +exports.PROTOCOL_VERSION = 70015; /** * Minimum protocol version we're willing to talk to. diff --git a/lib/script/common.js b/lib/script/common.js index c43ecc29..fa63e177 100644 --- a/lib/script/common.js +++ b/lib/script/common.js @@ -222,7 +222,7 @@ exports.flags.STANDARD_VERIFY_FLAGS = 0 * @default */ -exports.flags.UNSTANDARD_VERIFY_FLAGS = +exports.flags.ONLY_STANDARD_VERIFY_FLAGS = exports.flags.STANDARD_VERIFY_FLAGS & ~exports.flags.MANDATORY_VERIFY_FLAGS; /**