pool: better stalling for compact blocks.

This commit is contained in:
Christopher Jeffrey 2017-03-07 20:54:44 -08:00
parent 4aecaf9158
commit 19525826e3
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 16 additions and 1 deletions

View File

@ -54,6 +54,7 @@ function CompactBlock(options) {
this.count = 0;
this.sipKey = null;
this.totalTX = 0;
this.now = 0;
if (options)
this.fromOptions(options);

View File

@ -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) {

View File

@ -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);