8000 [stateless_validation] Hack sending chunk endorsement to self for single validator tests by shreyan-gupta · Pull Request #10501 · near/nearcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[stateless_validation] Hack sending chunk endorsement to self for single validator tests #10501

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

Merged

Conversation

shreyan-gupta
Copy link
Contributor
@shreyan-gupta shreyan-gupta commented Jan 25, 2024

This is extremely useful in 90% of the test cases that have just one validator. This way we don't need to explicitly handle network messages related to ChunkStateWitness and ChunkEndorsement

Created an issue to fix this in the future: #10508

@shreyan-gupta shreyan-gupta added the A-stateless-validation Area: stateless validation label Jan 25, 2024
@shreyan-gupta shreyan-gupta requested a review from a team as a code owner January 25, 2024 20:13
Copy link
codecov bot commented Jan 25, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (7ccc492) 71.97% compared to head (b30b637) 71.98%.
Report is 2 commits behind head on master.

Files Patch % Lines
chain/client/src/chunk_validation.rs 66.66% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10501      +/-   ##
==========================================
+ Coverage   71.97%   71.98%   +0.01%     
==========================================
  Files         720      720              
  Lines      146260   146269       +9     
  Branches   146260   146269       +9     
==========================================
+ Hits       105264   105286      +22     
+ Misses      36163    36150      -13     
  Partials     4833     4833              
Flag Coverage Δ
backward-compatibility 0.08% <0.00%> (ø)
db-migration 0.08% <0.00%> (ø)
genesis-check 1.26% <0.00%> (-0.01%) ⬇️
integration-tests 36.92% <66.66%> (+0.02%) ⬆️
linux 71.26% <0.00%> (-0.03%) ⬇️
linux-nightly 71.55% <66.66%> (+0.03%) ⬆️
macos 53.46% <0.00%> (-1.75%) ⬇️
pytests 1.48% <0.00%> (-0.01%) ⬇️
sanity-checks 1.27% <0.00%> (-0.01%) ⬇️
unittests 67.90% <55.55%> (+0.01%) ⬆️
upgradability 0.13% <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.

let witness =
self.create_state_witness(prev_chunk_header, chunk, transactions_storage_proof)?;

if let Some(my_signer) = self.validator_signer.clone() {
// Since we've created the state witness, we can directly send the chunk endorsement to ourselves.
Copy link
Contributor

Choose a reason for hiding this comment

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

but should we send the chunk endorsement to ourselves? Shouldn't we send it to the block producer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolute brain fart... Update the logic to send the block producers. I'm keeping the logic to send chunk endorsement to self tho, useful for tests

chunk_validators.retain(|account_id| account_id != my_signer.validator_id());

// Additionally send a copy of the chunk endorsement to ourselves.
// Mainly useful in tests where we don't have a good way to handle network messages and there's
Copy link
Contributor
@robin-near robin-near Jan 26, 2024

Choose a reason for hiding this comment

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

Ah... this makes me a bit uncomfortable :( If a test doesn't handle network messages causing the endorsements to not propagate, the correct thing to do should be to fix the test, not to change production behavior. A similar problem happened when the ShardsManager was refactored out, which broke a ton of tests because they weren't handling network messages, and the solution there was to make a SynchronousShardsManagerAdapter. It's not great, really, but if we can do something like that for the problem here, I'd prefer that to hacking the code here.

If we must hack the code here then may I suggest that we only send ourselves the endorsement, if we are a block producer?

Btw I'm also not super comfortable with just skipping the validation of our own witness. It doesn't save any latency (as we still have to wait for others to validate), and if our witness somehow turns out to be incorrect, we're going to be signing an invalid state witness just because we produced it. So that makes me think that this is purely a change to ease testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I see... In that case we can consider skipping over this optimization and for the short term measure of getting in changes for the MVP, send the endorsement to ourselves and add a major TODO for refactoring?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, sounds reasonable. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shreyan-gupta shreyan-gupta changed the title [stateless_validation] Bypass chunk state witness validation for chunks proposed by us [stateless_validation] Hack sending chunk endorsement to self for single validator tests Jan 26, 2024
@shreyan-gupta shreyan-gupta added this pull request to the merge queue Jan 26, 2024
Merged via the queue into master with commit fa39f59 Jan 26, 2024 8000
@shreyan-gupta shreyan-gupta deleted the shreyan/stateless_validation/optimize_self_validate branch January 26, 2024 01:35
github-merge-queue bot pushed a commit that referenced this pull request Jan 26, 2024
…10507)

This PR uncomments two checks
- We now filter chunks based on whether they have enough stake endorsed
or not.
- We validate chunk endorsements in block header.

Enabling this breaks a bunch of tests mainly for two reasons
- Some tests are handled by mocking out parts/doing manual block
production which doesn't take care of chunk endorsement signatures
- A number of tests that work with multiple validators don't have the
appropriate network request handlers for chunk endorsement and state
witness processing.

These tests are impossible to explore and fix in a single PR and I've
created a task list to help with this here:
#10506

Note that we need to merge in the changes from
#10501 ,
#10503 and
#10504 before we can merge this.
Till then probably the tests would keep failing

Tip: Probably a good idea to review PR commit by commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stateless-validation Area: stateless validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0