Sync corrections (#1034)

* Correct status re-request logic improve logging

* Prevent multiple dials of the same peer

* Discovery to obey max peers when connecting to new peers
This commit is contained in:
Age Manning
2020-04-22 00:29:19 +10:00
committed by GitHub
parent b88b3ffe40
commit 20b6baf11f
11 changed files with 247 additions and 161 deletions

View File

@@ -8,7 +8,7 @@ pub mod processor;
use crate::error;
use crate::service::NetworkMessage;
use beacon_chain::{AttestationType, BeaconChain, BeaconChainTypes};
use beacon_chain::{AttestationType, BeaconChain, BeaconChainTypes, BlockError};
use eth2_libp2p::{
rpc::{RPCError, RPCErrorResponse, RPCRequest, RPCResponse, RequestId, ResponseTermination},
MessageId, NetworkGlobals, PeerId, PubsubMessage, RPCEvent,
@@ -268,7 +268,9 @@ impl<T: BeaconChainTypes> Router<T> {
self.propagate_message(id, peer_id.clone());
self.processor.on_block_gossip(peer_id, verified_block);
}
Err(BlockError::ParentUnknown { .. }) => {} // performing a parent lookup
Err(e) => {
// performing a parent lookup
warn!(self.log, "Could not verify block for gossip";
"error" => format!("{:?}", e));
}

View File

@@ -495,9 +495,10 @@ impl<T: BeaconChainTypes> Processor<T> {
) -> Result<GossipVerifiedBlock<T>, BlockError> {
let result = self.chain.verify_block_for_gossip(*block.clone());
if let Err(BlockError::ParentUnknown(_)) = result {
if let Err(BlockError::ParentUnknown(block_hash)) = result {
// if we don't know the parent, start a parent lookup
// TODO: Modify the return to avoid the block clone.
debug!(self.log, "Unknown block received. Starting a parent lookup"; "block_slot" => block.message.slot, "block_hash" => format!("{}", block_hash));
self.send_to_sync(SyncMessage::UnknownBlock(peer_id.clone(), block));
}
result

View File

@@ -306,7 +306,6 @@ fn spawn_service<T: BeaconChainTypes>(
.map_err(|_| { debug!(log, "Failed to send peer disconnect to router");})?;
}
BehaviourEvent::StatusPeer(peer_id) => {
debug!(log, "Re-status peer"; "peer_id" => format!("{}", peer_id));
service.router_send
.try_send(RouterMessage::StatusPeer(peer_id))
.map_err(|_| { debug!(log, "Failed to send re-status peer to router");})?;

View File

@@ -58,7 +58,7 @@ use types::{EthSpec, Hash256, SignedBeaconBlock, Slot};
/// fully sync'd peer.
const SLOT_IMPORT_TOLERANCE: usize = 20;
/// How many attempts we try to find a parent of a block before we give up trying .
const PARENT_FAIL_TOLERANCE: usize = 3;
const PARENT_FAIL_TOLERANCE: usize = 5;
/// The maximum depth we will search for a parent block. In principle we should have sync'd any
/// canonical chain to its head once the peer connects. A chain should not appear where it's depth
/// is further back than the most recent head slot.
@@ -640,9 +640,16 @@ impl<T: BeaconChainTypes> SyncManager<T> {
if parent_request.failed_attempts >= PARENT_FAIL_TOLERANCE
|| parent_request.downloaded_blocks.len() >= PARENT_DEPTH_TOLERANCE
{
let error = if parent_request.failed_attempts >= PARENT_FAIL_TOLERANCE {
"too many failed attempts"
} else {
"reached maximum lookup-depth"
};
debug!(self.log, "Parent import failed";
"block" => format!("{:?}",parent_request.downloaded_blocks[0].canonical_root()),
"ancestors_found" => parent_request.downloaded_blocks.len()
"ancestors_found" => parent_request.downloaded_blocks.len(),
"reason" => error
);
return; // drop the request
}