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: count block approval towards chunk endorsement #11255

Merged

Conversation

bowenwang1996
Copy link
Collaborator

Count chunk producers who send block approvals towards chunk endorsements if they also happen to be chunk validator for a specific shard. Note that this change does not stop chunk producers from validating state witness if they are assigned also as a validator. That will be done separately.

@bowenwang1996 bowenwang1996 requested a review from a team as a code owner May 8, 2024 00:07
Copy link

codecov bot commented May 8, 2024

Codecov Report

Attention: Patch coverage is 83.83838% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 70.99%. Comparing base (8c25258) to head (f8472e2).

Files Patch % Lines
chain/client/src/client.rs 76.92% 0 Missing and 6 partials ⚠️
chain/epoch-manager/src/lib.rs 76.47% 1 Missing and 3 partials ⚠️
...hain/src/stateless_validation/chunk_endorsement.rs 90.47% 0 Missing and 2 partials ⚠️
chain/chain/src/test_utils/kv_runtime.rs 87.50% 0 Missing and 1 partial ⚠️
chain/client/src/chunk_inclusion_tracker.rs 83.33% 0 Missing and 1 partial ⚠️
chain/client/src/client_actor.rs 50.00% 0 Missing and 1 partial ⚠️
chain/epoch-manager/src/adapter.rs 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11255   +/-   ##
=======================================
  Coverage   70.99%   70.99%           
=======================================
  Files         781      781           
  Lines      155423   155505   +82     
  Branches   155423   155505   +82     
=======================================
+ Hits       110344   110403   +59     
- Misses      40311    40333   +22     
- Partials     4768     4769    +1     
Flag Coverage Δ
backward-compatibility 0.24% <0.00%> (-0.01%) ⬇️
db-migration 0.24% <0.00%> (-0.01%) ⬇️
genesis-check 1.40% <0.00%> (-0.01%) ⬇️
integration-tests 37.12% <83.83%> (-0.04%) ⬇️
linux 69.03% <54.54%> (-0.03%) ⬇️
linux-nightly 70.48% <83.83%> (+0.07%) ⬆️
macos 52.18% <54.54%> (-0.25%) ⬇️
pytests 1.62% <0.00%> (-0.01%) ⬇️
sanity-checks 1.42% <0.00%> (-0.01%) ⬇️
unittests 65.43% <83.83%> (+0.01%) ⬆️
upgradability 0.29% <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.

@@ -67,6 +77,7 @@ impl Chain {
// Verify that the signature in block body are valid for given chunk_validator.
// Signature can be either None, or Some(signature).
// We calculate the stake of the chunk_validators for who we have the signature present.
// We always include block producers who have sent approvals, since that indicate they have applied the corresponding chunk
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not get this. My understanding is in stateless validation, block producers do not apply chunks but only validate blocks (headers), so their approval will not be for the application of chunks. Even if they are also chunk validators how do we relate their approval with witness validation?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Below (L109-112) the approvals are filtered down to those from chunk producers for the shard. So if you are a chunk producer and also a block producer, your block approval is implictly an endorsement of the chunk.

The part I'm not sure I understand is this: the ultimate goal is to "stop chunk producers from validating state witness if they are assigned also as a validator". Would it be simpler to just send an endorsement without validating in that case instead of also adding this implicit endorsement logic?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok thanks Saketh, I missed that part. Maybe change comment to
// We always include chunk producers that are also block producers who have sent approvals, since that indicate they have applied the corresponding chunk


This (chunk producer sending endorsement right away) is already happening here:

// Bypass state witness validation if we created state witness. Endorse the chunk immediately.

(the missing piece is that this does not prevent chunk producer to send witness to itself and validate it)

is the concern that that endorsement may not reach all potential block producers (eg. in case of skips)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the ultimate goal is to "stop chunk producers from validating state witness if they are assigned also as a validator"

This is only part of the goal. The other part is to allow chunk producers to use block approvals as chunk endorsements so that their chunk endorsements would arrive earlier, which increases the likelihood of a chunk getting enough endorsements and being included in a block.

@bowenwang1996 bowenwang1996 added this pull request to the merge queue May 12, 2024
Merged via the queue into near:master with commit 0a61a29 May 12, 2024
28 of 29 checks passed
@bowenwang1996 bowenwang1996 deleted the chunk-endorsement-from-block-approval branch May 12, 2024 19:18
bowenwang1996 added a commit to bowenwang1996/nearcore that referenced this pull request May 16, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 16, 2024
#11330)

The logic in #11255 is not correct because chunk endorsement is
dependent on the chunk header included in the current block and endorses
that chunk header is valid. Block approvals cannot replace chunk
endorsements because when a block approval is sent, there is no
guarantee that the chunk producer has seen the new chunk header and
therefore a malicious attacker can still produce an invalid chunk with
correct block approvals. Thanks @pugachAG for catching this!
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.

None yet

3 participants