Part of #36833
This PR adds local tracking of recent stale tips for BIP 332.
The feature is behind a new -staletips=<mode> option (default none). There is no P2P change yet: with -staletips=headers the node only tracks tips.
Key changes
- A new
AcceptedStaleTipvalidation notification feeds the staletips tracker. - The tracker is built from the block index at startup, keeping the tips with the most work.
- At most 10 tips are tracked. When the tracker is full, a new tip evicts the one with the least work, but only if the new tip has more work.
getchaintipsRPC updates- Add new options
max_depthandstaletips_only - Report
fork_pointfor each non-active tip.
- Add new options
Test networks get the stricter policies the BIP recommends:
- signet: only tips whose block has been validated, and one header variant per block.
- testnet3/4: only tips with a difficulty of at least about 1,000,000.
<details> <summary>Sample output (regtest, after a reorg replaced the tip at height 111)</summary>
$ bitcoin-cli getchaintips
[
{
"height": 112,
"hash": "544a1c7f23c96990e2db9f4415f498d1ee61effac8e7416ec53fb91f538b2d2c",
"branchlen": 0,
"status": "active"
},
{
"height": 111,
"hash": "3a0797803400d80abdbf34f73df33f760c1e24696531746f975e3041055b6967",
"branchlen": 1,
"fork_point": "43765e057b6cde12df1701595d90ae51cf80490fef1343edd2d3fbe2edf3958e",
"status": "valid-fork"
}
]
$ bitcoin-cli -named getchaintips staletips_only=true
[
{
"height": 111,
"hash": "3a0797803400d80abdbf34f73df33f760c1e24696531746f975e3041055b6967",
"branchlen": 1,
"fork_point": "43765e057b6cde12df1701595d90ae51cf80490fef1343edd2d3fbe2edf3958e",
"status": "valid-fork"
}
]
</details>