From 2a6ee729a0829438abda647142a500244f7aec0d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 23 Jan 2017 15:01:55 -0800 Subject: [PATCH] pool: disable bip37 by default. --- etc/sample.conf | 1 + lib/net/common.js | 1 - lib/net/pool.js | 35 ++++++++++++++++++++++++++++++++--- lib/node/config.js | 1 + lib/node/fullnode.js | 1 + 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/etc/sample.conf b/etc/sample.conf index e63997e1..3ff5416b 100644 --- a/etc/sample.conf +++ b/etc/sample.conf @@ -53,6 +53,7 @@ replace-by-fee: false selfish: false compact: true +bip37: false bip151: true listen: true max-outbound: 8 diff --git a/lib/net/common.js b/lib/net/common.js index b86e188d..fcb103f1 100644 --- a/lib/net/common.js +++ b/lib/net/common.js @@ -105,7 +105,6 @@ exports.services = { exports.LOCAL_SERVICES = 0 | exports.services.NETWORK - | exports.services.BLOOM | exports.services.WITNESS; /** diff --git a/lib/net/pool.js b/lib/net/pool.js index d305de5a..7ad710e0 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -1527,6 +1527,14 @@ Pool.prototype.handleGetData = co(function* handleGetData(peer, packet) { break; case invTypes.FILTERED_BLOCK: case invTypes.WITNESS_FILTERED_BLOCK: + if (!this.options.bip37) { + this.logger.debug( + 'Peer requested a merkleblock without bip37 enabled (%s).', + peer.hostname()); + peer.destroy(); + return; + } + if (!peer.spvFilter) { notFound.push(item); continue; @@ -2188,6 +2196,14 @@ Pool.prototype.handleMempool = co(function* handleMempool(peer, packet) { if (this.options.selfish) return; + if (!this.options.bip37) { + this.logger.debug( + 'Peer requested mempool without bip37 enabled (%s).', + peer.hostname()); + peer.destroy(); + return; + } + hashes = this.mempool.getSnapshot(); for (i = 0; i < hashes.length; i++) { @@ -3194,8 +3210,9 @@ function PoolOptions(options) { this.checkpoints = true; this.spv = false; + this.bip37 = false; this.listen = false; - this.compact = false; + this.compact = true; this.noRelay = false; this.host = '0.0.0.0'; this.port = this.network.port; @@ -3272,6 +3289,11 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) { this.spv = this.chain.options.spv; } + if (options.bip37 != null) { + assert(typeof options.bip37 === 'boolean'); + this.bip37 = options.bip37; + } + if (options.listen != null) { assert(typeof options.listen === 'boolean'); this.listen = options.listen; @@ -3426,10 +3448,17 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) { this.services &= ~common.services.NETWORK; this.noRelay = true; this.checkpoints = true; + this.compact = false; + this.bip37 = false; } - if (this.selfish) + if (this.selfish) { this.services &= ~common.services.NETWORK; + this.bip37 = false; + } + + if (this.bip37) + this.services |= common.services.BLOOM; if (options.services != null) { assert(util.isUInt32(options.services)); @@ -3484,7 +3513,7 @@ PoolOptions.prototype.isFull = function isFull() { */ PoolOptions.prototype.getRequiredServices = function getRequiredServices() { - var services = this.options.requiredServices; + var services = this.requiredServices; if (this.hasWitness()) services |= common.services.WITNESS; return services; diff --git a/lib/node/config.js b/lib/node/config.js index d0082747..1e947662 100644 --- a/lib/node/config.js +++ b/lib/node/config.js @@ -188,6 +188,7 @@ config.parseData = function parseData(data, prefix, dirname) { // Pool options.selfish = bool(data.selfish); options.compact = bool(data.compact); + options.bip37 = bool(data.bip37); options.bip151 = bool(data.bip151); options.bip150 = bool(data.bip150); options.identityKey = key(data.identitykey); diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 8daffe3a..12530b55 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -102,6 +102,7 @@ function FullNode(options) { mempool: this.mempool, selfish: this.options.selfish, compact: this.options.compact, + bip37: this.options.bip37, bip151: this.options.bip151, bip150: this.options.bip150, authPeers: this.options.authPeers,