rpc: expose node generation identity - #1578
Conversation
|
CI fails on the rpc fuzz target: new commands must be added to one of the allowlists in src/test/fuzz/rpc.cpp. Please add getnodegeneration to the ELEMENTS section of RPC_COMMANDS_SAFE_FOR_FUZZING. |
|
What is the immediate use case? Ideally, this could be added upstream to bitcoin first (but that of course would take longer to feed through if required sooner). If I understand correctly |
|
Generally looks fine. I initially would have preferred it to be added to getblockchaininfo, but that's a much heavier RPC and this is a cheap atomic snapshot meant to be sampled very frequently. Some small things:
|
|
@tomt1664 Immediate value for us is production hardening for a privacy protocol; I’ll also look to send this upstream to Bitcoin Core. |
Motivation
Clients that depend on a coherent direct-RPC view need to distinguish a stale response from a current response after daemon restart, and need to detect reorg-away/reorg-back ABA even when height and best block hash return to their prior values.
Change
Add a read-only
getnodegenerationRPC returning one atomic snapshot:{ "startup_id": "<64 lowercase hexadecimal characters>", "chainstate_revision": 1, "blocks": 0, "bestblockhash": "<64 lowercase hexadecimal characters>" }startup_idis a fresh process-local 256-bit value initialized from the node RNGchainstate_revisionadvances undercs_mainwhen the active chainstate tip or active chainstate identity changesThe RPC is observational only: it does not change consensus, persistence, P2P, wallet behavior, or startup arguments.
Local verification
test_elementsunit suite passed (607 cases)rpc_testssuite passed (15 cases)validation_chainstatemanager_testssuite passed (8 cases)rpc_getnodegeneration.pypassed with RPC documentation checksrpc_blockchain.py --v1transportpassedfeature_assumeutxo.pypassedThe functional coverage includes clean and forced restarts over the same data directory, exact connect/disconnect increments, reorg-away/reorg-back ABA, concurrent sampling, and rejection of arguments.