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

fix: chunk validator rewards #11498

Merged
merged 8 commits into from
Jun 6, 2024
Merged

fix: chunk validator rewards #11498

merged 8 commits into from
Jun 6, 2024

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented Jun 5, 2024

UPDATE: this only fixes EpochInfoAggregator::merge_common. Chunk validator threshold is a TODO.

Old motivation

Here we just introduce chunk_validator_only_kickout_threshold = 90 for mainnet. If node only validates chunks and number of endorsed chunks is less than threshold, it should be kicked out. It doesn't seem reasonable to apply this limit to block&chunk producers, see small discussion.

Actually, testing this revealed a serious oversight in stats computation: EpochInfoAggregator::merge_common didn't sum up endorsement stats which led to them always being low, which could lead to unpredictable kickouts. This is fixed as well.

Testing:

  • test_validator_kickout_sanity is extended to check that chunk producer is not kicked out for low endorsement stats, but chunk validator is.
  • test_chunk_validator_kickout checks that if too many chunks are missing but chunk producer threshold is low, only chunk validator is kicked out.

This required adding new variables to epoch_config(...) configuration and removing old ones, which leads to big diff, but reviewing only tests should be enough.
I also want to add a TestLoop test but this change is already big enough.

@Longarithm Longarithm marked this pull request as ready for review June 6, 2024 13:04
@Longarithm Longarithm requested a review from a team as a code owner June 6, 2024 13:04
@Longarithm Longarithm changed the title draft: chunk validator kickouts feat: chunk validator kickouts Jun 6, 2024
Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

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

chunk_validator_only_kickout_threshold

Should we lower it to 80? Today the threshold for chunk producer is 80

@Longarithm
Copy link
Member Author

Should we lower it to 80? Today the threshold for chunk producer is 80

Oh, okay. We really should do #11265 to make epoch configs less confusing.

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 82.78689% with 21 lines in your changes missing coverage. Please review.

Project coverage is 71.32%. Comparing base (cceb7b5) to head (cba8e49).
Report is 4 commits behind head on master.

Files Patch % Lines
core/chain-configs/src/genesis_config.rs 37.50% 5 Missing ⚠️
core/primitives/src/epoch_manager.rs 16.66% 5 Missing ⚠️
core/store/src/migrations.rs 0.00% 3 Missing ⚠️
tools/amend-genesis/src/lib.rs 40.00% 1 Missing and 2 partials ⚠️
...ols/genesis-csv-to-json/src/csv_to_json_configs.rs 0.00% 2 Missing ⚠️
core/chain-configs/src/test_genesis.rs 80.00% 1 Missing ⚠️
tools/amend-genesis/src/cli.rs 0.00% 1 Missing ⚠️
tools/fork-network/src/cli.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11498      +/-   ##
==========================================
- Coverage   71.35%   71.32%   -0.04%     
==========================================
  Files         787      787              
  Lines      159385   159417      +32     
  Branches   159385   159417      +32     
==========================================
- Hits       113734   113702      -32     
- Misses      40734    40768      +34     
- Partials     4917     4947      +30     
Flag Coverage Δ
backward-compatibility 0.23% <0.00%> (-0.01%) ⬇️
db-migration 0.23% <0.00%> (-0.01%) ⬇️
genesis-check 1.36% <0.00%> (-0.01%) ⬇️
integration-tests 37.48% <33.60%> (-0.05%) ⬇️
linux 68.75% <80.32%> (+<0.01%) ⬆️
linux-nightly 70.85% <82.78%> (-0.04%) ⬇️
macos 52.32% <77.04%> (+1.53%) ⬆️
pytests 1.58% <2.32%> (-0.01%) ⬇️
sanity-checks 1.38% <2.32%> (-0.01%) ⬇️
unittests 66.03% <77.86%> (-0.04%) ⬇️
upgradability 0.28% <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.

@@ -52,6 +52,9 @@ pub const BLOCK_PRODUCER_KICKOUT_THRESHOLD: u8 = 90;
/// Criterion for kicking out chunk producers.
pub const CHUNK_PRODUCER_KICKOUT_THRESHOLD: u8 = 90;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also make them 80 given that the default is 80 in mainnet?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to break existing logic. Moreover, there may be tests checking that at genesis threshold was at 90 and then it was lowered to 80...

entry.endorsement_stats_mut().expected +=
stat.endorsement_stats().expected;
entry.endorsement_stats_mut().produced +=
stat.endorsement_stats().produced;
Copy link
Contributor

Choose a reason for hiding this comment

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

oh one more place to fix. thanks for catching this!

@@ -291,6 +288,10 @@ impl EpochInfoAggregator {
.and_modify(|entry| {
*entry.expected_mut() += stat.expected();
*entry.produced_mut() += stat.produced();
entry.endorsement_stats_mut().expected +=
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching this!

@Longarithm Longarithm changed the title feat: chunk validator kickouts fix: chunk validator rewards Jun 6, 2024
@Longarithm Longarithm added this pull request to the merge queue Jun 6, 2024
Merged via the queue into near:master with commit 9a6820b Jun 6, 2024
24 checks passed
@Longarithm Longarithm deleted the cv-kickouts branch June 6, 2024 22:55
github-merge-queue bot pushed a commit that referenced this pull request Jun 7, 2024
Separating chunk validator kickouts out of #11498 so we can decide on
that separately. [More Zulip
discussion](https://near.zulipchat.com/#narrow/stream/295558-core/topic/chunk.20validator.20rewards.26kickouts/near/443126357)

Adds `chunk_validator_only_kickout_threshold = 80` which kicks out chunk
validator-only nodes for which < 80% chunks were not included.

Testing:

* `test_validator_kickout_sanity` is extended to check that chunk
producer is not kicked out for low endorsement stats, but chunk
validator is.
* `test_chunk_validator_kickout` checks that if too many chunks are
missing but chunk producer threshold is low, only chunk validator is
kicked out.
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.

Implement kickout mechanism for chunk validators missing endorsements
4 participants