Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce cutoff threshold for endorsement ratio #12047

Merged
merged 11 commits into from
Sep 9, 2024

Conversation

tayfunelmas
Copy link
Contributor

@tayfunelmas tayfunelmas commented Sep 5, 2024

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.

Copy link

codecov bot commented Sep 5, 2024

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 ⚠️
core/primitives/src/epoch_manager.rs 41.66% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            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 Coverage Δ
backward-compatibility 0.17% <0.00%> (-0.01%) ⬇️
db-migration 0.17% <0.00%> (-0.01%) ⬇️
genesis-check 1.27% <0.00%> (-0.01%) ⬇️
integration-tests 38.53% <18.43%> (-0.04%) ⬇️
linux 71.25% <93.61%> (+0.04%) ⬆️
linux-nightly 71.02% <93.61%> (+0.03%) ⬆️
macos 52.91% <93.61%> (+0.07%) ⬆️
pytests 1.53% <0.00%> (-0.01%) ⬇️
sanity-checks 1.33% <0.00%> (-0.01%) ⬇️
unittests 65.25% <93.61%> (+0.06%) ⬆️
upgradability 0.22% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tayfunelmas tayfunelmas marked this pull request as ready for review September 5, 2024 11:05
@tayfunelmas tayfunelmas requested a review from a team as a code owner September 5, 2024 11:05
#[derive(Clone, Debug)]
pub struct RewardCalculator {
pub max_inflation_rate: Rational32,
pub num_blocks_per_year: u64,
pub epoch_length: u64,
pub protocol_reward_rate: Rational32,
pub protocol_treasury_account: AccountId,
pub online_min_threshold: Rational32,
Copy link
Contributor Author

@tayfunelmas tayfunelmas Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved these to the ValidatorOnlineThresholds struct passed to calculate_reward.
In fact we do not re-initialize the RewardCalculator when there is a new epoch or protocol change, so this way it is safer as we will need to change the online thresholds (endorsement cutoff in this case) via protocol upgrades.

chain/epoch-manager/src/reward_calculator.rs Outdated Show resolved Hide resolved
@tayfunelmas tayfunelmas added this pull request to the merge queue Sep 9, 2024
Merged via the queue into near:master with commit 7c9a775 Sep 9, 2024
28 of 29 checks passed
@tayfunelmas tayfunelmas deleted the endorsement-ratio branch September 9, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants