Proto: fix level used when checking total attesting power of a block
What
Fixes the bug that prevents block 2401 from being baked on weeklynet. Also refactors parts of the code to make it easier to avoid similar issues elsewhere.
Why
How
Fix
The fix is the first commit.
When checking whether all-bakers-attest is active to know which kind of attesting power to use (Tenderbake's 7000 slots or baking power in mutez), the level to consider is not the level of the block being validated/applied, but the level for which rights are used, that is, the level written inside the attestations or preattestations.
The wrong level was used at two places:
- in
validate.mlwhen checking that the total attesting power of attestations in the block meet the required threshold - in
apply.mlwhen computing the bonus to baking rewards that the baker receives when it includes more attesting power than the required threshold
On weeklynet, all-bakers-attest was set to activate at level 2401. Bakers correctly attested the block at level 2400 and crafted blocks for level 2401, but when validating blocks at level 2401, the protocol wrongly considered all-bakers-attest to be active when checking these blocks' attesting power (even though the attestations pointed to level 2400, that is before all-bakers-attest activation), causing it to use nonsense attesting power values and reject the blocks for not including enough attestations. More details on attesting power values observed can be found here
Refactoring
All commits but the first are refactorings whose purpose is to make it clearer which level should be provided to various functions.
Manually testing the MR
-
adam@abaab-activation-teztadds a Tezt test that reproduces the issue observed on weeklynet - Step-by-step sandbox scenario that reproduces the weeklynet issue
Both should fail before the fix and succeed after it.