From 0e40983f3b3c73ee2515c191d45c319b6d93dde7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 15 Jul 2018 23:30:53 +0200 Subject: [PATCH] Ensure any call to disable peer has a reason (#321) * Fix warnings in libp2p * Force a reason when you use the fatalist disable_peer * Print more information * Slightly more concise ref-fu * Tracing for figuring out what's going into genesis * Merge * Fxi test --- polkadot/network/src/lib.rs | 14 +++++++------- polkadot/network/src/tests.rs | 2 +- polkadot/runtime/src/parachains.rs | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/polkadot/network/src/lib.rs b/polkadot/network/src/lib.rs index fe320eeecc..b419c9c88d 100644 --- a/polkadot/network/src/lib.rs +++ b/polkadot/network/src/lib.rs @@ -355,7 +355,7 @@ impl PolkadotProtocol { }; if !info.validator { - ctx.disable_peer(peer_id); + ctx.disable_peer(peer_id, "Unknown Polkadot-protocol reason"); return; } @@ -395,7 +395,7 @@ impl PolkadotProtocol { self.pending.push(req); self.dispatch_pending_requests(ctx); } - None => ctx.disable_peer(peer_id), + None => ctx.disable_peer(peer_id, "Unknown Polkadot-protocol reason"), } } } @@ -415,7 +415,7 @@ impl Specialization for PolkadotProtocol { if let Some((ref acc_id, ref para_id)) = local_status.collating_for { if self.collator_peer_id(acc_id.clone()).is_some() { - ctx.disable_peer(peer_id); + ctx.disable_peer(peer_id, "Unknown Polkadot-protocol reason"); return } @@ -501,7 +501,7 @@ impl Specialization for PolkadotProtocol { Ok(msg) => self.on_polkadot_message(ctx, peer_id, raw, msg), Err(e) => { trace!(target: "p_net", "Bad message from {}: {}", peer_id, e); - ctx.disable_peer(peer_id); + ctx.disable_peer(peer_id, "Unknown Polkadot-protocol reason"); } } } @@ -546,13 +546,13 @@ impl PolkadotProtocol { match self.peers.get(&from) { None => ctx.disconnect_peer(from), Some(peer_info) => match peer_info.status.collating_for { - None => ctx.disable_peer(from), + None => ctx.disable_peer(from, "Unknown Polkadot-protocol reason"), Some((ref acc_id, ref para_id)) => { let structurally_valid = para_id == &collation_para && acc_id == &collated_acc; if structurally_valid && collation.receipt.check_signature().is_ok() { self.collators.on_collation(acc_id.clone(), relay_parent, collation) } else { - ctx.disable_peer(from) + ctx.disable_peer(from, "Unknown Polkadot-protocol reason") }; } }, @@ -583,7 +583,7 @@ impl PolkadotProtocol { // disconnect a collator by account-id. fn disconnect_bad_collator(&self, ctx: &mut Context, account_id: AccountId) { if let Some(peer_id) = self.collator_peer_id(account_id) { - ctx.disable_peer(peer_id) + ctx.disable_peer(peer_id, "Unknown Polkadot-protocol reason") } } } diff --git a/polkadot/network/src/tests.rs b/polkadot/network/src/tests.rs index 95c24ae071..deec3b8129 100644 --- a/polkadot/network/src/tests.rs +++ b/polkadot/network/src/tests.rs @@ -41,7 +41,7 @@ impl Context for TestContext { unimplemented!() } - fn disable_peer(&mut self, peer: PeerId) { + fn disable_peer(&mut self, peer: PeerId, _reason: &str) { self.disabled.push(peer); } diff --git a/polkadot/runtime/src/parachains.rs b/polkadot/runtime/src/parachains.rs index bd62f9895e..4ac5f3f2a1 100644 --- a/polkadot/runtime/src/parachains.rs +++ b/polkadot/runtime/src/parachains.rs @@ -216,7 +216,6 @@ impl runtime_primitives::BuildStorage for GenesisConfig { fn build_storage(mut self) -> ::std::result::Result { use std::collections::HashMap; - use runtime_io::twox_128; use codec::Encode; self.parachains.sort_unstable_by_key(|&(ref id, _)| id.clone()); @@ -225,11 +224,11 @@ impl runtime_primitives::BuildStorage for GenesisConfig let only_ids: Vec<_> = self.parachains.iter().map(|&(ref id, _)| id).cloned().collect(); let mut map: HashMap<_, _> = map![ - twox_128(>::key()).to_vec() => only_ids.encode() + Self::hash(>::key()).to_vec() => only_ids.encode() ]; for (id, code) in self.parachains { - let key = twox_128(&>::key_for(&id)).to_vec(); + let key = Self::hash(&>::key_for(&id)).to_vec(); map.insert(key, code.encode()); }