diff --git a/lib/net/bip152.js b/lib/net/bip152.js index 9d793fb8..8d92ba69 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -54,6 +54,7 @@ function CompactBlock(options) { this.count = 0; this.sipKey = null; this.totalTX = 0; + this.now = 0; if (options) this.fromOptions(options); diff --git a/lib/net/peer.js b/lib/net/peer.js index 3a99bc11..b9cfb326 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -1289,7 +1289,7 @@ Peer.prototype.fulfill = function fulfill(packet) { Peer.prototype.maybeTimeout = function maybeTimeout() { var keys = this.responseMap.keys(); var now = util.ms(); - var i, key, entry, name, ts, mult; + var i, key, entry, name, ts, block, mult; for (i = 0; i < keys.length; i++) { key = keys[i]; @@ -1343,6 +1343,18 @@ Peer.prototype.maybeTimeout = function maybeTimeout() { return; } } + + keys = this.compactBlocks.keys(); + + for (i = 0; i < keys.length; i++) { + key = keys[i]; + block = this.compactBlocks.get(key); + if (now > block.now + Peer.RESPONSE_TIMEOUT) { + this.error('Peer is stalling (blocktxn).'); + this.destroy(); + return; + } + } } if (now > this.ts + 60000) { diff --git a/lib/net/pool.js b/lib/net/pool.js index 4a02a5aa..19da4b49 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -2842,6 +2842,8 @@ Pool.prototype.handleCmpctBlock = co(function* handleCmpctBlock(peer, packet) { } } + block.now = util.ms(); + assert(!peer.compactBlocks.has(hash)); peer.compactBlocks.set(hash, block);