net: add forced_inbound to getpeerinfo

Github-Pull: #27600
Rebased-From: 8c2026848da910fdebff0a9f73e29f1f6ae81e43
This commit is contained in:
Matthew Zipkin 2023-11-09 11:14:38 -05:00 committed by Luke Dashjr
parent ae08cb4b89
commit 421566f7d0
5 changed files with 13 additions and 1 deletions

View File

@ -673,6 +673,7 @@ void CNode::CopyStats(CNodeStats& stats)
X(nRecvBytes);
}
X(m_permission_flags);
X(m_forced_inbound);
X(m_last_ping_time);
X(m_min_ping_time);

View File

@ -222,6 +222,8 @@ public:
Network m_network;
uint32_t m_mapped_as;
ConnectionType m_conn_type;
/** whether this peer forced its connection by evicting another */
bool m_forced_inbound;
};

View File

@ -146,6 +146,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", "",
{
@ -251,6 +252,7 @@ static RPCHelpMan getpeerinfo()
permissions.push_back(permission);
}
obj.pushKV("permissions", permissions);
obj.pushKV("forced_inbound", stats.m_forced_inbound);
obj.pushKV("minfeefilter", ValueFromAmount(statestats.m_fee_filter_received));
UniValue sendPerMsgType(UniValue::VOBJ);

View File

@ -147,7 +147,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)"]):

View File

@ -136,6 +136,7 @@ class NetTest(BitcoinTestFramework):
"minfeefilter": Decimal("0E-8"),
"network": "not_publicly_routable",
"permissions": [],
"forced_inbound": False,
"presynced_headers": -1,
"relaytxes": False,
"services": "0000000000000000",