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: epoch analysis tool #11343

Merged
merged 10 commits into from
Jun 5, 2024
Merged

feat: epoch analysis tool #11343

merged 10 commits into from
Jun 5, 2024

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented May 17, 2024

Tool to analyse epoch infos in two modes:

  • check-consistency - regenerate next next epoch info based on two previous epochs and check that it matches the epoch info stored in DB;
  • backtest - regenerate epoch infos with existing proposals, rewards and kickouts as if PROTOCOL_VERSION was always in place.

The backtest was used to estimate new algorithm for chunk producer shard assignments and showed that on average there is only one state sync happening, if we use start epoch height >= 545. Epoch info for 544 can't be retrieved for some reason, see #11477.

Consistency check revealed that some epochs in the past can't be replayed, see #11476.
Expected output of it, note that epoch T generates epoch T+2:

$ neard view-state epoch-analysis --start-height 1359 check-consistency
HEIGHT | VERSION | STATE SYNCS
  1361 |      53 |           0
  1362 |      53 |           8
  1363 |      54 |           8
  1364 |      54 |           8
  1365 |      54 |          24
  1366 |      54 |          12
...

@Longarithm Longarithm changed the title draft: epoch analysis draft: epoch analysis tool May 17, 2024
pub struct EpochAnalysisCmd {
/// The height of the epoch to analyze.
#[clap(long)]
height: EpochHeight,
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be the start height of the epoch or any height in that epoch?

Copy link
Member Author

Choose a reason for hiding this comment

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

Start height of the epoch.

@tayfunelmas
Copy link
Contributor

WIP. cc @tayfunelmas if you are curious how it should work :)

Thanks for sharing, I was indeed curious about this part (how to iterate over the epoch-related info)

@Longarithm Longarithm changed the title draft: epoch analysis tool feat: epoch analysis tool Jun 4, 2024
@Longarithm Longarithm requested a review from wacban June 4, 2024 18:40
@Longarithm Longarithm marked this pull request as ready for review June 4, 2024 18:41
@Longarithm Longarithm requested a review from a team as a code owner June 4, 2024 18:41
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 5.36585% with 194 lines in your changes missing coverage. Please review.

Project coverage is 71.28%. Comparing base (aad30b5) to head (0375458).
Report is 1 commits behind head on master.

Files Patch % Lines
tools/state-viewer/src/commands.rs 0.00% 174 Missing ⚠️
core/primitives/src/epoch_manager.rs 0.00% 13 Missing ⚠️
tools/state-viewer/src/cli.rs 0.00% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11343      +/-   ##
==========================================
- Coverage   71.37%   71.28%   -0.10%     
==========================================
  Files         787      787              
  Lines      159091   159299     +208     
  Branches   159091   159299     +208     
==========================================
+ Hits       113554   113556       +2     
- Misses      40624    40828     +204     
- Partials     4913     4915       +2     
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.49% <5.36%> (+0.02%) ⬆️
linux 68.77% <5.36%> (-0.09%) ⬇️
linux-nightly 70.81% <5.36%> (-0.06%) ⬇️
macos 50.79% <5.36%> (-1.63%) ⬇️
pytests 1.58% <0.00%> (-0.01%) ⬇️
sanity-checks 1.38% <0.00%> (-0.01%) ⬇️
unittests 65.99% <5.36%> (-0.12%) ⬇️
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.

Copy link
Contributor

@wacban wacban left a comment

Choose a reason for hiding this comment

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

LGTM but I I want to understand the early return in get_initial_chunk_producer_assignment before approving - see the comment please.

@@ -51,12 +51,12 @@ pub fn proposals_to_epoch_info(
) -> Result<EpochInfo, EpochError> {
// For this protocol feature, switch happened two epochs after protocol upgrade.
// Keeping it this way for replayability.
if checked_feature!(
return if checked_feature!(
Copy link
Contributor

Choose a reason for hiding this comment

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

You can drop the return with the ; at the end also.

Comment on lines 140 to 142
chunk_producers.push(index);
if used_chunk_producers.contains(&index) {
return vec![vec![]; num_shards as usize];
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite confusing. Why do you return empty vectors if some index is repeated? If this was intended can you add a comment please?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually it was a leftover of implementation with some bug, removed.

let epoch_heights_to_validator_infos =
BTreeMap::from_iter(epoch_heights_to_ids.iter().filter_map(|(epoch_height, epoch_id)| {
if *epoch_height >= min_epoch_height
&& *epoch_height <= max_epoch_height.saturating_sub(4)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 4?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I can actually put 2 there, made it more clear.

let next_next_epoch_id = epoch_heights_to_ids.get(&next_next_epoch_height).unwrap();
let epoch_summary = epoch_heights_to_validator_infos.get(epoch_height).unwrap();

next_epoch_info = match mode {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a fun way to implement where you have multiple of those checks :) I'm totally fine with it but I'm curious how did you arrive at this and how does it compare to having two methods, one for each mode?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was just bad code, how about now?
These two modes really share a lot of code. The difference is - for the first one, I always take data from DB. For the second, I override some data with previously generated info to simulate new algorithm behaviour. But the rest stays the same, so I don't want to separate impls completely.

Copy link
Contributor

@wacban wacban left a comment

Choose a reason for hiding this comment

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

LGTM

@Longarithm Longarithm enabled auto-merge June 5, 2024 10:57
Merged via the queue into near:master with commit 23e22d5 Jun 5, 2024
24 checks passed
@Longarithm Longarithm deleted the epoch-analysis-2 branch June 5, 2024 12:27
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.

3 participants