better fork handling for peers.
This commit is contained in:
parent
704c95c90d
commit
271ca1aa52
@ -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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user