mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-13 15:33:51 +02:00
cli, rpc: add -rpcid option for custom request IDs
Add a -rpcid CLI argument to bitcoin-cli that allows setting a custom string as the JSON-RPC request ID instead of the hardcoded default of 1. This enables correlating requests and responses when debugging or when multiple clients are making concurrent calls. On the server side, include the request ID in the RPC debug log line when it differs from the default value of 1, so that custom IDs are visible in the debug.log output.
This commit is contained in:
@@ -421,6 +421,18 @@ class TestBitcoinCli(BitcoinTestFramework):
|
||||
|
||||
self.test_netinfo()
|
||||
|
||||
self.log.info("Test -rpcid option sets custom JSON-RPC request ID")
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=['id=myrpcid']):
|
||||
self.nodes[0].cli('-rpcid=myrpcid').getblockcount()
|
||||
|
||||
self.log.info("Test default request logs default id=1")
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["ThreadRPCServer method=getblockcount", "id=1"]):
|
||||
self.nodes[0].cli.getblockcount()
|
||||
|
||||
self.log.info("Test that request ids with unsafe characters are sanitized in the log")
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["ThreadRPCServer method=getblockcount", "id=abcdef"]):
|
||||
self.nodes[0].cli('-rpcid=abc<\n>def').getblockcount()
|
||||
|
||||
self.log.info("Test -version with node stopped")
|
||||
self.stop_node(0)
|
||||
cli_response = self.nodes[0].cli('-version').send_cli()
|
||||
|
||||
Reference in New Issue
Block a user