Commit 28c41813 authored by Gav Wood's avatar Gav Wood Committed by GitHub
Browse files

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
parent c014d085
......@@ -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<Block> 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<Block> 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<Block>, 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")
}
}
}
......@@ -41,7 +41,7 @@ impl Context<Block> for TestContext {
unimplemented!()
}
fn disable_peer(&mut self, peer: PeerId) {
fn disable_peer(&mut self, peer: PeerId, _reason: &str) {
self.disabled.push(peer);
}
......
......@@ -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> {
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<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
let only_ids: Vec<_> = self.parachains.iter().map(|&(ref id, _)| id).cloned().collect();
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 {
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());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment