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

test: produce chunks in resharding v3 test #12196

Merged
merged 8 commits into from
Oct 11, 2024

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented Oct 9, 2024

Improve the test by checking that all chunks are included, and the chain passes through one epoch after resharding.

For that, I need to properly skip chunk validation if resharding happened in the middle, as this is not a part of early MVP. One more useful and necessary change: on iterating over block range of state transition, I need to move from shard_id to prev_shard_id, so that we query proper chunk in a block.

Checked offline that without validation skip, chunks for shards 1-2 are not included.

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 86.02151% with 13 lines in your changes missing coverage. Please review.

Project coverage is 71.76%. Comparing base (99ecfa4) to head (15d6599).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...chain/src/stateless_validation/chunk_validation.rs 86.07% 4 Missing and 7 partials ⚠️
chain/chain/src/resharding/manager.rs 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12196      +/-   ##
==========================================
+ Coverage   71.69%   71.76%   +0.06%     
==========================================
  Files         825      825              
  Lines      165834   165747      -87     
  Branches   165834   165747      -87     
==========================================
+ Hits       118902   118952      +50     
+ Misses      41751    41608     -143     
- Partials     5181     5187       +6     
Flag Coverage Δ
backward-compatibility 0.17% <0.00%> (+<0.01%) ⬆️
db-migration 0.17% <0.00%> (+<0.01%) ⬆️
genesis-check 1.26% <0.00%> (+<0.01%) ⬆️
integration-tests 38.91% <86.02%> (+0.07%) ⬆️
linux 71.44% <74.19%> (+0.05%) ⬆️
linux-nightly 71.35% <86.02%> (+0.08%) ⬆️
macos 54.35% <68.81%> (+0.10%) ⬆️
pytests 1.57% <0.00%> (+<0.01%) ⬆️
sanity-checks 1.38% <0.00%> (+<0.01%) ⬆️
unittests 65.56% <68.81%> (+0.19%) ⬆️
upgradability 0.21% <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.

Comment on lines +51 to +53
let next_block_has_new_shard_layout =
self.epoch_manager.will_shard_layout_change(prev_hash)?
&& self.epoch_manager.is_next_block_epoch_start(block.hash())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

omg

// state transition covered by state witness. Won't happen in production
// until resharding release. Must be removed and replaced with proper
// resharding state transition validation.
ShardLayoutChange,
Copy link
Contributor

Choose a reason for hiding this comment

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

My thinking was that the resharding would be in addition to the existing MainTransition. I think we will first need to apply the chunk (if present) and only then validate resharding.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I mean that we can have both new chunk and resharding at the same time

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that what you mean by temporary? If so I'm happy to approve to unblock the progress, but still I'm curious about your thought of the proper structure for this logic.

Copy link
Member Author

@Longarithm Longarithm Oct 11, 2024

Choose a reason for hiding this comment

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

Yes, this is very temporary. It is just the easiest way to skip everything related to chunk validation in our case. Made a comment.

@@ -130,16 +130,30 @@ pub fn pre_validate_chunk_state_witness(
// Blocks from the last last new chunk (exclusive) to the last new chunk (inclusive).
let mut blocks_after_last_last_chunk = Vec::new();

{
let (last_chunk_shard_id, last_chunk_shard_index) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can this be moved to a helper method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 149 to 153
(current_shard_id, current_shard_index) =
epoch_manager.get_prev_shard_id(&block_hash, current_shard_id)?;

let chunks = block.chunks();
let Some(chunk) = chunks.get(shard_index) else {
let Some(chunk) = chunks.get(current_shard_index) else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that off by one block?
the shard_id and shard_index are from the prev block (that's what get_prev_shard_id gives)
the block.chunks() are from the current block

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 think it was correct. However, I made it more intuitive - by changing current_shard_id simultaneously with going to prev block.

(last_chunk_shard_id, last_chunk_shard_index)
};

let last_chunk_block = blocks_after_last_last_chunk.first().ok_or_else(|| {
Copy link
Contributor

Choose a reason for hiding this comment

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

sanity check for myself

  • the blocks in blocks_after_last_last_chunk are in reverse chronological order
  • the blocks include the last chunk block (it's inclusive)

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, nice

Comment on lines 127 to 129
state_witness: &ChunkStateWitness,
store: &ChainStore,
epoch_manager: &dyn EpochManagerAdapter,
Copy link
Contributor

Choose a reason for hiding this comment

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

min nit: It's nice to keep the arguments from most general to most specific. In this case I would make it
store,
epoch manager,
state witness,

It's nice to have a convention and this one is as good as any I guess.

@Longarithm Longarithm added this pull request to the merge queue Oct 11, 2024
Merged via the queue into near:master with commit 0febdb5 Oct 11, 2024
28 of 30 checks passed
@Longarithm Longarithm deleted the rv3-fix-test-2 branch October 11, 2024 14:45
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