diff --git a/plugins/net_plugin/include/eosio/net_plugin/auto_bp_peering.hpp b/plugins/net_plugin/include/eosio/net_plugin/auto_bp_peering.hpp index 40fa130438..b9f91dab92 100644 --- a/plugins/net_plugin/include/eosio/net_plugin/auto_bp_peering.hpp +++ b/plugins/net_plugin/include/eosio/net_plugin/auto_bp_peering.hpp @@ -55,6 +55,9 @@ class bp_connection_manager { uint32_t pending_schedule_version = 0; uint32_t active_schedule_version = 0; + // when leaving bp gossip group, set to false to prevent reconnecting + std::atomic connect_bp_gossip_peers = true; + fc::mutex mtx; gossip_buffer_initial_factory initial_gossip_msg_factory GUARDED_BY(mtx); name_set_t active_bps GUARDED_BY(mtx); @@ -256,6 +259,7 @@ class bp_connection_manager { } } } else { + connect_bp_gossip_peers = false; fc_wlog(p2p_log, "On-chain peer-key not found for configured BP ${a}", ("a", bp_account)); } } @@ -506,6 +510,11 @@ class bp_connection_manager { // thread-safe void connect_to_active_bp_peers() { + if (!connect_bp_gossip_peers) { + fc_dlog(p2p_conn_log, "Not in active bp gossip group, not connecting to any bp peers"); + return; + } + // do not hold mutexes when calling resolve_and_connect which acquires connections mutex since other threads // can be holding connections mutex when trying to acquire these mutexes address_set_t addresses; @@ -537,6 +546,10 @@ class bp_connection_manager { fc_dlog(p2p_conn_log, "pending_connections: ${c}", ("c", to_string(pending_connections))); + if (!pending_connections.empty()) { + connect_bp_gossip_peers = true; + } + // do not hold mutexes when calling resolve_and_connect which acquires connections mutex since other threads // can be holding connections mutex when trying to acquire these mutexes address_set_t addresses = find_gossip_bp_addresses(pending_connections, "connect"); @@ -592,6 +605,9 @@ class bp_connection_manager { bool disconnect_from_all = !config.my_bp_gossip_accounts.empty() && std::all_of(config.my_bp_gossip_accounts.begin(), config.my_bp_gossip_accounts.end(), [&](const auto& e) { return peers_to_drop.contains(e.first); }); + if (disconnect_from_all) { + connect_bp_gossip_peers = false; + } address_set_t addresses = disconnect_from_all ? all_gossip_bp_addresses("disconnect")