Ditch achieved work, reduce MaxReorgDepth#599
Conversation
n13
left a comment
There was a problem hiding this comment.
Looks great, but still having AI review it...
Review — Ditch achieved work, reduce MaxReorgDepthVerdict: Approve in principle — the consensus fix is correct — but please address the in-place upgrade hazard before merge (and a couple of nits). The core change is rightCrediting each block with the target difficulty it had to beat ( Main concern — nodes that upgrade without resyncingThe aux namespace moves That breaks fork choice in the unfinalized window until new work accumulates. A single freshly-imported block on an old parent gets candidate_work > current_work ||
(candidate_work == current_work && candidate_number > current_number)So a competing block from, say, 50 blocks back (parent work MaxReorgDepth 180 -> 100Reasonable given the fork-choice fix removes the deep-reorg driver, and it slightly shrinks the transition window above. Worth confirming this is an intentional finalization-margin change that every node must run identically — it's a compiled runtime constant, and divergent values across nodes can finalize conflicting blocks. Minor / nits
Nice cleanup overall — switching to target difficulty is the standard, correct metric. |
|
I don't think the reorg description is right but what is right is that we should make sure we don't throw the chain into chaos when we upgrade the runtime.. we could build off of previous achieved number, or else ... accept the chaos we're in testnet anyway |
This achieved work thing was causing these lucky (or malicious?) blocks to do deep temporary reorgs:
Neither Bitcoin nor Ethereum had this achieved difficulty thing. We just use target difficulty now.
Note
High Risk
Changes consensus fork-choice math, aux key namespace, and max reorg depth—operators must coordinate upgrades and may see different best-chain behavior until aux work is rebuilt.
Overview
Fork choice no longer credits blocks with work from
U512::MAX / nonce_hash, which let unusually low hashes swing cumulative totals and drive deep temporary reorgs. Import now callsverify_and_get_block_workand adds each block’s network target difficulty to the parent’s cumulative work (invalid seals get zero work).Client aux storage moves from
QPow:AchievedWork:toQPow:ChainWork:with renamed helpers (store_cumulative_work,initialize_genesis_work, etc.). Old values are not comparable; upgrading nodes should resync or purge legacy aux work entries.MaxReorgDepthin runtime config drops 180 → 100, tightening how far behind the tip finalization runs. Runtime API, pallet, tests, andRUNTIME_SURFACE.mdare updated for the new API name and semantics.Reviewed by Cursor Bugbot for commit deb046c. Configure here.