Skip to content

Commit

Permalink
rpc: expose disabletx status in getpeerinfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
sdaftuar committed Mar 28, 2022
1 parent 44cf369 commit 41e8257
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/net_processing.cpp
Expand Up @@ -1381,6 +1381,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
stats.m_addr_processed = peer->m_addr_processed.load();
stats.m_addr_rate_limited = peer->m_addr_rate_limited.load();
stats.m_addr_relay_enabled = peer->m_addr_relay_enabled.load();
stats.m_received_disabletx = peer->m_disable_tx.load();

return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/net_processing.h
Expand Up @@ -34,6 +34,7 @@ struct CNodeStateStats {
uint64_t m_addr_processed = 0;
uint64_t m_addr_rate_limited = 0;
bool m_addr_relay_enabled{false};
bool m_received_disabletx{false}; // whether DISABLETX has been received from this peer (BIP 338)
};

class PeerManager : public CValidationInterface, public NetEventsInterface
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/net.cpp
Expand Up @@ -140,6 +140,7 @@ static RPCHelpMan getpeerinfo()
{RPCResult::Type::BOOL, "addr_relay_enabled", /*optional=*/true, "Whether we participate in address relay with this peer"},
{RPCResult::Type::NUM, "addr_processed", /*optional=*/true, "The total number of addresses processed, excluding those dropped due to rate limiting"},
{RPCResult::Type::NUM, "addr_rate_limited", /*optional=*/true, "The total number of addresses dropped due to rate limiting"},
{RPCResult::Type::BOOL, "disabletx_received", /*optional=*/true, "Whether transaction relay was disabled by this peer (BIP 338)"},
{RPCResult::Type::ARR, "permissions", "Any special permissions that have been granted to this peer",
{
{RPCResult::Type::STR, "permission_type", Join(NET_PERMISSIONS_DOC, ",\n") + ".\n"},
Expand Down Expand Up @@ -236,6 +237,7 @@ static RPCHelpMan getpeerinfo()
obj.pushKV("addr_relay_enabled", statestats.m_addr_relay_enabled);
obj.pushKV("addr_processed", statestats.m_addr_processed);
obj.pushKV("addr_rate_limited", statestats.m_addr_rate_limited);
obj.pushKV("disabletx_received", statestats.m_received_disabletx);
}
UniValue permissions(UniValue::VARR);
for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {
Expand Down
18 changes: 18 additions & 0 deletions test/functional/p2p_disabletx.py
Expand Up @@ -36,6 +36,7 @@
P2PInterface,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal


class DisableTxTest(BitcoinTestFramework):
Expand Down Expand Up @@ -156,6 +157,22 @@ def notfound_after_disabletx_test(self):
peer.send_message(msg_notfound(vec=[CInv(t=inv_type, h=0xdeadbeef)]))
peer.wait_for_disconnect()

def peerinfo_includes_disabletx_test(self):
self.log.info('Check that getpeerinfo() returns the disabletx status on a connection')

peer = self.nodes[0].add_p2p_connection(P2PInterface(disabletx=True))
peer.sync_with_ping()

assert_equal(self.nodes[0].getpeerinfo()[0]['disabletx_received'], True)
peer.peer_disconnect()
peer.wait_for_disconnect()

peer = self.nodes[0].add_p2p_connection(P2PInterface(disabletx=False))
peer.sync_with_ping()
assert_equal(self.nodes[0].getpeerinfo()[0]['disabletx_received'], False)
peer.peer_disconnect()
peer.wait_for_disconnect()

def run_test(self):
self.tip_hash = int(self.generate(self.nodes[0], 1)[0], 16)

Expand All @@ -169,6 +186,7 @@ def run_test(self):
self.bloom_filter_after_disabletx_test()
self.mempool_after_disabletx_test()
self.notfound_after_disabletx_test()
self.peerinfo_includes_disabletx_test()


if __name__ == '__main__':
Expand Down

0 comments on commit 41e8257

Please sign in to comment.