near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.32k stars 623 forks source link

feat: Do not use cutoff threshold and use stake when sorting validators for kickout-exemption #12092

Closed tayfunelmas closed 1 month ago

tayfunelmas commented 1 month ago

This change will only take effect with new protocol feature ChunkEndorsementsInBlockHeader.

We used the endorsement kickout threshold as the cutoff threshold for the endorsement ratio when computing the validator rewards. For context see this thread.

If the validator's endorsement ratio is above the cutoff threshold, the contribution of the endorsement ratio to the average uptime is 1, otherwise it is 0. Then the resulting average uptime is used in two places: 1) When calculating the validator rewards. 2) When sorting the validators by uptime ratio to get the validators exempted from kickout.

In the second case, for chunk validator-only nodes, the average uptime of the validator will be either 1 or 0. Then when calculating the exempted validators, the ordering of the validators will be based on the account id only. This is unfair. To alleviate this fairness, in this PR, we make two changes to break the tie:

1) We remove the use of cutoff threshold when computing the average uptime for the exempted validator calculation. As a result, the raw endorsement ratio is used to sort the validators. 2) If the raw endorsement ratios are equal, we also sort by the stake, before comparing the account ids. Thus, the validator with the higher stake is selected for exemption.

This change only impacts the ordering of validators when selecting the exempted ones; it does not affect other places, such as reward calculation.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 71.42857% with 12 lines in your changes missing coverage. Please review.

Project coverage is 71.58%. Comparing base (773aae7) to head (a0d31bc).

Files with missing lines Patch % Lines
core/primitives/src/epoch_info.rs 36.84% 12 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #12092 +/- ## ========================================== - Coverage 71.59% 71.58% -0.01% ========================================== Files 818 818 Lines 164532 164528 -4 Branches 164532 164528 -4 ========================================== - Hits 117792 117781 -11 - Misses 41597 41606 +9 + Partials 5143 5141 -2 ``` | [Flag](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | Coverage Δ | | |---|---|---| | [backward-compatibility](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.17% <0.00%> (-0.01%)` | :arrow_down: | | [db-migration](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.17% <0.00%> (-0.01%)` | :arrow_down: | | [genesis-check](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.26% <0.00%> (-0.01%)` | :arrow_down: | | [integration-tests](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `38.71% <61.90%> (+0.02%)` | :arrow_up: | | [linux](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.15% <14.28%> (-0.04%)` | :arrow_down: | | [linux-nightly](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.11% <71.42%> (-0.02%)` | :arrow_down: | | [macos](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `54.02% <14.28%> (+0.57%)` | :arrow_up: | | [pytests](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.52% <0.00%> (-0.01%)` | :arrow_down: | | [sanity-checks](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.33% <0.00%> (-0.01%)` | :arrow_down: | | [unittests](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `65.38% <71.42%> (-0.01%)` | :arrow_down: | | [upgradability](https://app.codecov.io/gh/near/nearcore/pull/12092/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.21% <0.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.