diff --git a/src/net.cpp b/src/net.cpp index 030a2c4b19..c1bca89bd8 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -633,6 +633,7 @@ void CNode::CopyStats(CNodeStats& stats) if (info.session_id) stats.m_session_id = HexStr(*info.session_id); } X(m_permission_flags); + X(m_forced_inbound); X(m_last_ping_time); X(m_min_ping_time); diff --git a/src/net.h b/src/net.h index 493d9a3530..bd60a3251a 100644 --- a/src/net.h +++ b/src/net.h @@ -222,6 +222,8 @@ public: TransportProtocolType m_transport_type; /** BIP324 session id string in hex, if any. */ std::string m_session_id; + /** whether this peer forced its connection by evicting another */ + bool m_forced_inbound; }; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 1119a3e668..d816e11ef8 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -168,6 +168,7 @@ static RPCHelpMan getpeerinfo() { {RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"}, }}, + {RPCResult::Type::BOOL, "forced_inbound", "Whether this peer forced a connection by evicting another."}, {RPCResult::Type::NUM, "minfeefilter", "The minimum fee rate for transactions this peer accepts"}, {RPCResult::Type::OBJ_DYN, "bytessent_per_msg", "", { @@ -275,6 +276,7 @@ static RPCHelpMan getpeerinfo() permissions.push_back(permission); } obj.pushKV("permissions", std::move(permissions)); + obj.pushKV("forced_inbound", stats.m_forced_inbound); obj.pushKV("minfeefilter", ValueFromAmount(statestats.m_fee_filter_received)); UniValue sendPerMsgType(UniValue::VOBJ); diff --git a/test/functional/p2p_eviction.py b/test/functional/p2p_eviction.py index e41fbec16e..0ad3fe7582 100755 --- a/test/functional/p2p_eviction.py +++ b/test/functional/p2p_eviction.py @@ -148,7 +148,13 @@ class P2PEvict(BitcoinTestFramework): self.log.debug("ForceInbound whitebind inbound gets connected, even when full") allowed_peers.append(node.add_p2p_connection(P2PInterface(), dstport=30202)) - assert_equal(len(node.getpeerinfo()), 10) + peerinfo = node.getpeerinfo() + assert_equal(len(peerinfo), 10) + for peer in peerinfo: + if "30202" in peer["addrbind"]: + assert peer["forced_inbound"] + else: + assert not peer["forced_inbound"] self.log.debug("Generic inbound gets rejected when whitebind peer is filling inbound slot") with node.assert_debug_log(["failed to find an eviction candidate - connection dropped (full)"]): diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index b63059b1ee..77784c89c4 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -161,6 +161,7 @@ class NetTest(BitcoinTestFramework): "minfeefilter": Decimal("0E-8"), "network": "not_publicly_routable", "permissions": [], + "forced_inbound": False, "presynced_headers": -1, "relaytxes": False, "services": "0000000000000000",