ethcore-sync: fix connection to peers behind chain fork block (#8710)
This commit is contained in:
parent
79eb8f7ace
commit
2060ea5de3
@ -332,14 +332,6 @@ impl SyncHandler {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_peer_confirmed(sync: &mut ChainSync, io: &mut SyncIo, peer_id: PeerId) {
|
|
||||||
{
|
|
||||||
let peer = sync.peers.get_mut(&peer_id).expect("Is only called when peer is present in peers");
|
|
||||||
peer.confirmation = ForkConfirmation::Confirmed;
|
|
||||||
}
|
|
||||||
sync.sync_peer(io, peer_id, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_peer_fork_header(sync: &mut ChainSync, io: &mut SyncIo, peer_id: PeerId, r: &Rlp) -> Result<(), PacketDecodeError> {
|
fn on_peer_fork_header(sync: &mut ChainSync, io: &mut SyncIo, peer_id: PeerId, r: &Rlp) -> Result<(), PacketDecodeError> {
|
||||||
{
|
{
|
||||||
let peer = sync.peers.get_mut(&peer_id).expect("Is only called when peer is present in peers");
|
let peer = sync.peers.get_mut(&peer_id).expect("Is only called when peer is present in peers");
|
||||||
@ -349,24 +341,27 @@ impl SyncHandler {
|
|||||||
|
|
||||||
if item_count == 0 || item_count != 1 {
|
if item_count == 0 || item_count != 1 {
|
||||||
trace!(target: "sync", "{}: Chain is too short to confirm the block", peer_id);
|
trace!(target: "sync", "{}: Chain is too short to confirm the block", peer_id);
|
||||||
io.disable_peer(peer_id);
|
peer.confirmation = ForkConfirmation::TooShort;
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let header = r.at(0)?.as_raw();
|
} else {
|
||||||
if keccak(&header) != fork_hash {
|
let header = r.at(0)?.as_raw();
|
||||||
trace!(target: "sync", "{}: Fork mismatch", peer_id);
|
if keccak(&header) != fork_hash {
|
||||||
io.disable_peer(peer_id);
|
trace!(target: "sync", "{}: Fork mismatch", peer_id);
|
||||||
return Ok(());
|
io.disable_peer(peer_id);
|
||||||
}
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
trace!(target: "sync", "{}: Confirmed peer", peer_id);
|
trace!(target: "sync", "{}: Confirmed peer", peer_id);
|
||||||
if !io.chain_overlay().read().contains_key(&fork_number) {
|
peer.confirmation = ForkConfirmation::Confirmed;
|
||||||
trace!(target: "sync", "Inserting (fork) block {} header", fork_number);
|
|
||||||
io.chain_overlay().write().insert(fork_number, header.to_vec());
|
if !io.chain_overlay().read().contains_key(&fork_number) {
|
||||||
|
trace!(target: "sync", "Inserting (fork) block {} header", fork_number);
|
||||||
|
io.chain_overlay().write().insert(fork_number, header.to_vec());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SyncHandler::on_peer_confirmed(sync, io, peer_id);
|
|
||||||
|
sync.sync_peer(io, peer_id, false);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,7 +681,9 @@ impl SyncHandler {
|
|||||||
SyncRequester::request_fork_header(sync, io, peer_id, fork_block);
|
SyncRequester::request_fork_header(sync, io, peer_id, fork_block);
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
SyncHandler::on_peer_confirmed(sync, io, peer_id);
|
// when there's no `fork_block` defined we initialize the peer with
|
||||||
|
// `confirmation: ForkConfirmation::Confirmed`.
|
||||||
|
sync.sync_peer(io, peer_id, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +294,8 @@ pub enum BlockSet {
|
|||||||
pub enum ForkConfirmation {
|
pub enum ForkConfirmation {
|
||||||
/// Fork block confirmation pending.
|
/// Fork block confirmation pending.
|
||||||
Unconfirmed,
|
Unconfirmed,
|
||||||
|
/// Peer's chain is too short to confirm the fork.
|
||||||
|
TooShort,
|
||||||
/// Fork is confirmed.
|
/// Fork is confirmed.
|
||||||
Confirmed,
|
Confirmed,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user