Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

network: add logging for extra requests #4625

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/network/src/protocol/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ impl<B: BlockT> ChainSync<B> {
best_queued_hash: info.best_hash,
best_queued_number: info.best_number,
best_imported_number: info.best_number,
extra_finality_proofs: ExtraRequests::new(),
extra_justifications: ExtraRequests::new(),
extra_finality_proofs: ExtraRequests::new("finality proof"),
extra_justifications: ExtraRequests::new("justification"),
role,
required_block_attributes,
queue_blocks: Default::default(),
Expand Down
43 changes: 35 additions & 8 deletions client/network/src/protocol/sync/extra_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use sp_blockchain::Error as ClientError;
use crate::protocol::sync::{PeerSync, PeerSyncState};
use fork_tree::ForkTree;
use libp2p::PeerId;
use log::{debug, warn};
use log::{debug, trace, warn};
use sp_runtime::traits::{Block as BlockT, NumberFor, Zero};
use std::collections::{HashMap, HashSet, VecDeque};
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -48,17 +48,20 @@ pub(crate) struct ExtraRequests<B: BlockT> {
failed_requests: HashMap<ExtraRequest<B>, Vec<(PeerId, Instant)>>,
/// successful requests
importing_requests: HashSet<ExtraRequest<B>>,
/// the name of this type of extra request (useful for logging.)
request_type_name: &'static str,
}

impl<B: BlockT> ExtraRequests<B> {
pub(crate) fn new() -> Self {
pub(crate) fn new(request_type_name: &'static str) -> Self {
ExtraRequests {
tree: ForkTree::new(),
best_seen_finalized_number: Zero::zero(),
pending_requests: VecDeque::new(),
active_requests: HashMap::new(),
failed_requests: HashMap::new(),
importing_requests: HashSet::new(),
request_type_name,
}
}

Expand Down Expand Up @@ -113,11 +116,28 @@ impl<B: BlockT> ExtraRequests<B> {
// messages to chain sync.
if let Some(request) = self.active_requests.remove(&who) {
if let Some(r) = resp {
trace!(target: "sync", "Queuing import of {} from {:?} for {:?}",
self.request_type_name,
who,
request,
);

self.importing_requests.insert(request);
return Some((who, request.0, request.1, r))
} else {
trace!(target: "sync", "Empty {} response from {:?} for {:?}",
self.request_type_name,
who,
request,
);
}
self.failed_requests.entry(request).or_insert(Vec::new()).push((who, Instant::now()));
self.pending_requests.push_front(request);
} else {
trace!(target: "sync", "No active {} request to {:?}",
self.request_type_name,
who,
);
}
None
}
Expand Down Expand Up @@ -265,6 +285,13 @@ impl<'a, B: BlockT> Matcher<'a, B> {
continue
}
self.extras.active_requests.insert(peer.clone(), request);

trace!(target: "sync", "Sending {} request to {:?} for {:?}",
self.extras.request_type_name,
peer,
request,
);

return Some((peer.clone(), request))
}

Expand Down Expand Up @@ -293,7 +320,7 @@ mod tests {
#[test]
fn requests_are_processed_in_order() {
fn property(mut peers: ArbitraryPeers) {
let mut requests = ExtraRequests::<Block>::new();
let mut requests = ExtraRequests::<Block>::new("test");

let num_peers_available = peers.0.values()
.filter(|s| s.state == PeerSyncState::Available).count();
Expand All @@ -319,7 +346,7 @@ mod tests {
#[test]
fn new_roots_schedule_new_request() {
fn property(data: Vec<BlockNumber>) {
let mut requests = ExtraRequests::<Block>::new();
let mut requests = ExtraRequests::<Block>::new("test");
for (i, number) in data.into_iter().enumerate() {
let hash = [i as u8; 32].into();
let pending = requests.pending_requests.len();
Expand All @@ -336,7 +363,7 @@ mod tests {
#[test]
fn disconnecting_implies_rescheduling() {
fn property(mut peers: ArbitraryPeers) -> bool {
let mut requests = ExtraRequests::<Block>::new();
let mut requests = ExtraRequests::<Block>::new("test");

let num_peers_available = peers.0.values()
.filter(|s| s.state == PeerSyncState::Available).count();
Expand Down Expand Up @@ -371,7 +398,7 @@ mod tests {
#[test]
fn no_response_reschedules() {
fn property(mut peers: ArbitraryPeers) {
let mut requests = ExtraRequests::<Block>::new();
let mut requests = ExtraRequests::<Block>::new("test");

let num_peers_available = peers.0.values()
.filter(|s| s.state == PeerSyncState::Available).count();
Expand Down Expand Up @@ -404,7 +431,7 @@ mod tests {
fn request_is_rescheduled_when_earlier_block_is_finalized() {
let _ = ::env_logger::try_init();

let mut finality_proofs = ExtraRequests::<Block>::new();
let mut finality_proofs = ExtraRequests::<Block>::new("test");

let hash4 = [4; 32].into();
let hash5 = [5; 32].into();
Expand Down Expand Up @@ -442,7 +469,7 @@ mod tests {

#[test]
fn anecstor_roots_are_finalized_when_finality_notification_is_missed() {
let mut finality_proofs = ExtraRequests::<Block>::new();
let mut finality_proofs = ExtraRequests::<Block>::new("test");

let hash4 = [4; 32].into();
let hash5 = [5; 32].into();
Expand Down