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

P2P: Fix duplication connection logic #1108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
26 changes: 0 additions & 26 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3295,7 +3295,6 @@ namespace eosio {
peer_fork_db_head_block_num = msg.fork_db_head_num;
fc::unique_lock g_conn( conn_mtx );
last_handshake_recv = msg;
auto c_time = last_handshake_sent.time;
g_conn.unlock();

set_state(connection_state::connected);
Expand Down Expand Up @@ -3338,31 +3337,6 @@ namespace eosio {
fc_dlog( logger, "dup check: connected ${c}, ${l} =? ${r}",
("c", check->connected())("l", check->last_handshake_recv.node_id)("r", msg.node_id) );
if(check->connected() && check->last_handshake_recv.node_id == msg.node_id) {
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
if (net_version < proto_dup_goaway_resolution || msg.network_version < proto_dup_goaway_resolution) {
// It's possible that both peers could arrive here at relatively the same time, so
// we need to avoid the case where they would both tell a different connection to go away.
// Using the sum of the initial handshake times of the two connections, we will
// arbitrarily (but consistently between the two peers) keep one of them.

auto check_time = check->last_handshake_sent.time + check->last_handshake_recv.time;
g_check_conn.unlock();
if (msg.time + c_time <= check_time)
return false;
} else if (net_version < proto_dup_node_id_goaway || msg.network_version < proto_dup_node_id_goaway) {
if (listen_address < msg.p2p_address) {
fc_dlog( logger, "listen_address '${lhs}' < msg.p2p_address '${rhs}'",
("lhs", listen_address)( "rhs", msg.p2p_address ) );
// only the connection from lower p2p_address to higher p2p_address will be considered as a duplicate,
// so there is no chance for both connections to be closed
return false;
}
} else if (my_impl->node_id < msg.node_id) {
fc_dlog( logger, "not duplicate, my_impl->node_id '${lhs}' < msg.node_id '${rhs}'",
("lhs", my_impl->node_id)("rhs", msg.node_id) );
// only the connection from lower node_id to higher node_id will be considered as a duplicate,
// so there is no chance for both connections to be closed
return false;
}
return true;
}
return false;
Expand Down
Loading