Skip to content

Commit

Permalink
Merge pull request #1186 from AntelopeIO/revert-GH-1108-p2p-dup
Browse files Browse the repository at this point in the history
[1.1.1] Revert "P2P: Fix duplication connection logic #1108"
  • Loading branch information
heifner authored Feb 20, 2025
2 parents fdd0c71 + 16ca8a6 commit 51f47ac
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,7 @@ 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 @@ -3456,7 +3457,35 @@ namespace eosio {
fc::unique_lock g_check_conn( check->conn_mtx );
fc_dlog( logger, "dup check: connected ${c}, ${l} =? ${r}",
("c", check->connected())("l", check->last_handshake_recv.node_id)("r", msg.node_id) );
return check->connected() && check->last_handshake_recv.node_id == msg.node_id;
if(check->connected() && check->last_handshake_recv.node_id == msg.node_id) {
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;
};
if (my_impl->connections.any_of_connections(std::move(is_duplicate))) {
peer_dlog( this, "sending go_away duplicate, msg.p2p_address: ${add}", ("add", msg.p2p_address) );
Expand Down

0 comments on commit 51f47ac

Please sign in to comment.