near / nearcore

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

feat: Introduce cutoff threshold for endorsement ratio #12047

Closed tayfunelmas closed 1 month ago

tayfunelmas commented 1 month ago

Issue: #11900.

This PR introduces a cutoff threshold for chunk endorsement ratio. We use the same kickout threshold as the cutoff threshold. It is currently 80, but we will make it 70 when stabilizing this feature.

If the endorsement ratio is less than the cutoff ratio, it is treated 0, otherwise treated 1, when computing the average uptime ratio (including block and chunk production and endorsement).

For this, we introduce a new struct ValidatorOnlineThresholds to contain online_min_threshold and online_max_threshold as well as endorsement_cutoff_threshold (initialized to the kickout threshold=70 if feature ChunkEndorsementsInBlockHeader is enabled). ValidatorOnlineThresholds is initialized from EpochConfig. We pass this struct to calculate_rewards, which then calls get_validator_online_ratio to apply the cutoff if present.

We performed simulation of last 5 epochs in mainnet, results are in this doc. Only the chunk validators with very low endorsement ratio are kicked out and do not get any reward.

Testing: We added some unittests for the basic logic. We will later add integration tests for the full behavior.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 93.61702% with 18 lines in your changes missing coverage. Please review.

Project coverage is 71.45%. Comparing base (3718df6) to head (1197e10). Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
chain/epoch-manager/src/lib.rs 38.88% 10 Missing and 1 partial :warning:
core/primitives/src/epoch_manager.rs 41.66% 5 Missing and 2 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #12047 +/- ## ========================================== + Coverage 71.40% 71.45% +0.04% ========================================== Files 814 814 Lines 163936 164177 +241 Branches 163936 164177 +241 ========================================== + Hits 117055 117305 +250 + Misses 41754 41744 -10 - Partials 5127 5128 +1 ``` | [Flag](https://app.codecov.io/gh/near/nearcore/pull/12047/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/12047/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/12047/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/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.27% <0.00%> (-0.01%)` | :arrow_down: | | [integration-tests](https://app.codecov.io/gh/near/nearcore/pull/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `38.53% <18.43%> (-0.04%)` | :arrow_down: | | [linux](https://app.codecov.io/gh/near/nearcore/pull/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.25% <93.61%> (+0.04%)` | :arrow_up: | | [linux-nightly](https://app.codecov.io/gh/near/nearcore/pull/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `71.02% <93.61%> (+0.03%)` | :arrow_up: | | [macos](https://app.codecov.io/gh/near/nearcore/pull/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `52.91% <93.61%> (+0.07%)` | :arrow_up: | | [pytests](https://app.codecov.io/gh/near/nearcore/pull/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `1.53% <0.00%> (-0.01%)` | :arrow_down: | | [sanity-checks](https://app.codecov.io/gh/near/nearcore/pull/12047/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/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `65.25% <93.61%> (+0.06%)` | :arrow_up: | | [upgradability](https://app.codecov.io/gh/near/nearcore/pull/12047/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=near) | `0.22% <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.