archive-hardfork-toolbox: port the fork-candidate chain query fix from `release/mesa` to develop.

Merge-only port of #19057. Develop already carries the same fix (landed as `67c2decbac`): `chain_of_query` starts the recursive walk from `b.state_hash = $1` rather than matching a state hash against the integer `b.id` column. The mesa branch inlines the two CTEs where develop keeps the `chain_of_query_templated` helper, but both render identical SQL, so develop is unchanged by this merge. The commit exists to record the resolution and unblock the merge check on #19057.
