From c9e8f779f3bb9e38b00ec264de2eafb6c0010b2f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 25 Jul 2016 00:08:20 -0700 Subject: [PATCH] network: rename segwitHeight. --- lib/bcoin/chain.js | 4 ++-- lib/bcoin/network.js | 2 +- lib/bcoin/peer.js | 5 +++++ lib/bcoin/protocol/network.js | 14 +++++++------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 4b84274b..f1439382 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -641,7 +641,7 @@ Chain.prototype.getDeployments = function getDeployments(block, prev, ancestors, // Only allow version 5 blocks (bip141 - segnet3) // once the majority of blocks are using it. - if (this.network.segwitHeight !== -1 && height >= this.network.segwitHeight) { + if (this.network.oldWitness) { if (block.version < 5 && prev.isOutdated(5, ancestors)) return callback(new VerifyError(block, 'obsolete', 'bad-version', 0)); } @@ -668,7 +668,7 @@ Chain.prototype.getDeployments = function getDeployments(block, prev, ancestors, } // Segregrated witness is now usable (bip141 - segnet3) - if (this.network.segwitHeight !== -1 && height >= this.network.segwitHeight) { + if (this.network.oldWitness) { if (block.version >= 5 && prev.isUpgraded(5, ancestors)) { state.flags |= constants.flags.VERIFY_WITNESS; if (!this.state.hasWitness()) diff --git a/lib/bcoin/network.js b/lib/bcoin/network.js index 4cd7b8c4..cd7179c3 100644 --- a/lib/bcoin/network.js +++ b/lib/bcoin/network.js @@ -41,7 +41,7 @@ function Network(options) { this.pow = options.pow; this.block = options.block; this.witness = options.witness; - this.segwitHeight = options.segwitHeight; + this.oldWitness = options.oldWitness; this.activationThreshold = options.activationThreshold; this.minerWindow = options.minerWindow; this.deployments = options.deployments; diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 9e799c9c..6add8e65 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -1315,6 +1315,11 @@ Peer.prototype._handleVersion = function _handleVersion(version) { if (this.options.witness) { if (!version.hasWitness()) { + if (!this.network.oldWitness) { + this._error('Peer does not support segregated witness.'); + this.setMisbehavior(100); + return; + } this.request('havewitness', function(err) { if (err) { self._error('Peer does not support segregated witness.'); diff --git a/lib/bcoin/protocol/network.js b/lib/bcoin/protocol/network.js index 451c5865..06ea16d4 100644 --- a/lib/bcoin/protocol/network.js +++ b/lib/bcoin/protocol/network.js @@ -298,12 +298,12 @@ main.block = { main.witness = false; /** - * Height at which segwit is activated (segnet3). - * @const {Number} + * Whether to use segnet3-style segwit. + * @const {Boolean} * @default */ -main.segwitHeight = 2000000000; +main.oldWitness = false; /** * For versionbits. @@ -544,7 +544,7 @@ testnet.block = { testnet.witness = false; -testnet.segwitHeight = 2000000000; +testnet.oldWitness = false; testnet.activationThreshold = 1512; // 75% for testchains @@ -689,7 +689,7 @@ regtest.block = { regtest.witness = false; -regtest.segwitHeight = -1; +regtest.oldWitness = false; regtest.activationThreshold = 108; // 75% for testchains @@ -833,7 +833,7 @@ segnet3.block = { segnet3.witness = true; -segnet3.segwitHeight = 0; +segnet3.oldWitness = true; segnet3.activationThreshold = 108; @@ -956,7 +956,7 @@ segnet4.block = { segnet4.witness = true; -segnet4.segwitHeight = -1; +segnet4.oldWitness = false; segnet4.activationThreshold = 108;