Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix the duplicate connection bug #599

Merged
merged 2 commits into from
Dec 21, 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
36 changes: 22 additions & 14 deletions network/src/p2p/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,17 @@ impl IoHandler<Message> for Handler {
remote_node_id,
token
);
assert_eq!(
None,
self.remote_node_ids_reverse.write().insert(remote_node_id, token),
"{}:{} is already registered",
remote_node_id,
token
);
// FIXME the if condition below is a hotfix.
// `self.remote_node_ids_reverse.write().contains_key(&remote_node_id)` always should be false
if !self.remote_node_ids_reverse.write().contains_key(&remote_node_id) {
assert_eq!(
None,
self.remote_node_ids_reverse.write().insert(remote_node_id, token),
"{}:{} is already registered",
remote_node_id,
token
);
}

let t = inbound_connections.insert(token, connection);
assert!(t.is_none());
Expand All @@ -546,13 +550,17 @@ impl IoHandler<Message> for Handler {
remote_node_id,
token
);
assert_eq!(
None,
self.remote_node_ids_reverse.write().insert(remote_node_id, token),
"{}:{} is already registered",
remote_node_id,
token
);
// FIXME the if condition below is a hotfix.
// `self.remote_node_ids_reverse.write().contains_key(&remote_node_id)` always should be false
if !self.remote_node_ids_reverse.write().contains_key(&remote_node_id) {
assert_eq!(
None,
self.remote_node_ids_reverse.write().insert(remote_node_id, token),
"{}:{} is already registered",
remote_node_id,
token
);
}

let mut network_message_size = 0;
for (name, versions) in self.client.extension_versions() {
Expand Down
27 changes: 18 additions & 9 deletions sync/src/block/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,22 +477,31 @@ impl NetworkExtension<Event> for Extension {
cinfo!(SYNC, "New peer detected #{}", id);
self.send_status(id);

let t = self.connected_nodes.insert(*id);
debug_assert!(t, "{} is already added to peer list", id);
// FIXME the if condition below is a hotfix.
// `self.connected_nodes.contains(id)` always should be false
if !self.connected_nodes.contains(id) {
let t = self.connected_nodes.insert(*id);
debug_assert!(t, "{} is already added to peer list", id);
}

let token = self.token_generator.gen().expect("Token generator is full");
let token_info = TokenInfo {
node_id: *id,
request_id: None,
};

let t = self.requests.insert(*id, Vec::new());
debug_assert_eq!(None, t);
let t = self.tokens_info.insert(token, token_info);
debug_assert_eq!(None, t);
let t = self.tokens.insert(*id, token);
debug_assert_eq!(None, t);
debug_assert!(t.is_none());
// FIXME the if condition below is a hotfix.
// `self.requests.contains(id)` always should be false
if !self.requests.contains_key(id) {
let t = self.requests.insert(*id, Vec::new());
debug_assert_eq!(None, t);
}
self.tokens_info.entry(token).or_insert(token_info);
if !self.tokens.contains_key(id) {
let t = self.tokens.insert(*id, token);
debug_assert_eq!(None, t);
debug_assert!(t.is_none());
}
}

fn on_node_removed(&mut self, id: &NodeId) {
Expand Down