better fork handling for peers.

This commit is contained in:
Christopher Jeffrey 2016-01-20 12:44:36 -08:00
parent 704c95c90d
commit 271ca1aa52
2 changed files with 18 additions and 3 deletions

View File

@ -324,7 +324,7 @@ Chain.prototype.add = function add(block, peer) {
height: -1,
expected: this.orphan.map[prevHash].hash('hex'),
received: hash,
checkpoint: null
checkpoint: false
}, peer);
code = Chain.codes.forked;
break;
@ -384,7 +384,7 @@ Chain.prototype.add = function add(block, peer) {
height: prevHeight + 1,
expected: tip.hash,
received: hash,
checkpoint: null
checkpoint: false
}, peer);
code = Chain.codes.forked;
break;

View File

@ -193,10 +193,25 @@ Pool.prototype._init = function _init() {
peer ? peer.host : ''
);
self.emit('reorg', [data.expected, data.received]);
if (!peer)
return;
self.misbehaving(peer, 100);
// If we failed a checkpoint, peer is misbehaving.
if (data.checkpoint) {
self.misbehaving(peer, 100);
return;
}
// Only destroy peer here. Wait for higher chain.
peer.destroy();
// Remove the peers from the tried list after 5 seconds.
setTimeout(function() {
delete self.peers.tries.priority[peer.host];
delete self.peers.tries.regular[peer.host];
}, 5 * 1000);
});
this.chain.on('invalid', function(data, peer) {