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
This commit is contained in:
Gav Wood
2018-07-15 23:30:53 +02:00
committed by GitHub
parent 1e1ddf61f2
commit 0e40983f3b
3 changed files with 10 additions and 11 deletions
+7 -7
View File
@@ -355,7 +355,7 @@ impl PolkadotProtocol {
}; };
if !info.validator { if !info.validator {
ctx.disable_peer(peer_id); ctx.disable_peer(peer_id, "Unknown Polkadot-protocol reason");
return; return;
} }
@@ -395,7 +395,7 @@ impl PolkadotProtocol {
self.pending.push(req); self.pending.push(req);
self.dispatch_pending_requests(ctx); 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<Block> for PolkadotProtocol {
if let Some((ref acc_id, ref para_id)) = local_status.collating_for { if let Some((ref acc_id, ref para_id)) = local_status.collating_for {
if self.collator_peer_id(acc_id.clone()).is_some() { 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 return
} }
@@ -501,7 +501,7 @@ impl Specialization<Block> for PolkadotProtocol {
Ok(msg) => self.on_polkadot_message(ctx, peer_id, raw, msg), Ok(msg) => self.on_polkadot_message(ctx, peer_id, raw, msg),
Err(e) => { Err(e) => {
trace!(target: "p_net", "Bad message from {}: {}", peer_id, 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) { match self.peers.get(&from) {
None => ctx.disconnect_peer(from), None => ctx.disconnect_peer(from),
Some(peer_info) => match peer_info.status.collating_for { 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)) => { Some((ref acc_id, ref para_id)) => {
let structurally_valid = para_id == &collation_para && acc_id == &collated_acc; let structurally_valid = para_id == &collation_para && acc_id == &collated_acc;
if structurally_valid && collation.receipt.check_signature().is_ok() { if structurally_valid && collation.receipt.check_signature().is_ok() {
self.collators.on_collation(acc_id.clone(), relay_parent, collation) self.collators.on_collation(acc_id.clone(), relay_parent, collation)
} else { } 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. // disconnect a collator by account-id.
fn disconnect_bad_collator(&self, ctx: &mut Context<Block>, account_id: AccountId) { fn disconnect_bad_collator(&self, ctx: &mut Context<Block>, account_id: AccountId) {
if let Some(peer_id) = self.collator_peer_id(account_id) { 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")
} }
} }
} }
+1 -1
View File
@@ -41,7 +41,7 @@ impl Context<Block> for TestContext {
unimplemented!() unimplemented!()
} }
fn disable_peer(&mut self, peer: PeerId) { fn disable_peer(&mut self, peer: PeerId, _reason: &str) {
self.disabled.push(peer); self.disabled.push(peer);
} }
+2 -3
View File
@@ -216,7 +216,6 @@ impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
{ {
fn build_storage(mut self) -> ::std::result::Result<runtime_io::TestExternalities, String> { fn build_storage(mut self) -> ::std::result::Result<runtime_io::TestExternalities, String> {
use std::collections::HashMap; use std::collections::HashMap;
use runtime_io::twox_128;
use codec::Encode; use codec::Encode;
self.parachains.sort_unstable_by_key(|&(ref id, _)| id.clone()); self.parachains.sort_unstable_by_key(|&(ref id, _)| id.clone());
@@ -225,11 +224,11 @@ impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
let only_ids: Vec<_> = self.parachains.iter().map(|&(ref id, _)| id).cloned().collect(); let only_ids: Vec<_> = self.parachains.iter().map(|&(ref id, _)| id).cloned().collect();
let mut map: HashMap<_, _> = map![ let mut map: HashMap<_, _> = map![
twox_128(<Parachains<T>>::key()).to_vec() => only_ids.encode() Self::hash(<Parachains<T>>::key()).to_vec() => only_ids.encode()
]; ];
for (id, code) in self.parachains { for (id, code) in self.parachains {
let key = twox_128(&<Code<T>>::key_for(&id)).to_vec(); let key = Self::hash(&<Code<T>>::key_for(&id)).to_vec();
map.insert(key, code.encode()); map.insert(key, code.encode());
} }