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

SubmitAggregateAndProof now prefers its own validator attestations #6566

Merged
merged 21 commits into from Jul 13, 2020

Conversation

prestonvanloon
Copy link
Member

What type of PR is this?

Feature

What does this PR do? Why is it needed?

When selected as an aggregator, the beacon node should be "greedy" in the validators favor. That is to say that the aggregator should prefer its own attestation for broadcasting above all other attestations to consider.

This implementation takes the first attestation as the "best" and then tries to find a better attestation by checking the following conditions:

Replace "best" IF

  • att is the same committee as the incoming request
  • att has the aggregation bit set for the given validator

In the case that the "best" attestation already has the validator aggregator bit set, we also do a bit count comparsion to choose the most aggregated attestation.

Which issues(s) does this PR fix?

Fixes #6565

Other notes for review

@prestonvanloon prestonvanloon requested a review from a team as a code owner July 13, 2020 00:07
@prestonvanloon prestonvanloon added the Ready For Review A pull request ready for code review label Jul 13, 2020
@prestonvanloon prestonvanloon removed the Ready For Review A pull request ready for code review label Jul 13, 2020
@prestonvanloon
Copy link
Member Author

Please hold off on review, I misunderstood a test helper and this test is not performing as I want it to do.

@prestonvanloon prestonvanloon added the Ready For Review A pull request ready for code review label Jul 13, 2020
@prestonvanloon
Copy link
Member Author

OK now it's ready.

@codecov
Copy link

codecov bot commented Jul 13, 2020

Codecov Report

Merging #6566 into master will increase coverage by 1.70%.
The diff coverage is 71.09%.

@@            Coverage Diff             @@
##           master    #6566      +/-   ##
==========================================
+ Coverage   60.07%   61.77%   +1.70%     
==========================================
  Files         323      366      +43     
  Lines       27422    28625    +1203     
==========================================
+ Hits        16473    17683    +1210     
+ Misses       8733     8534     -199     
- Partials     2216     2408     +192     

// The aggregator should prefer an attestation that they have signed. We check this by
// looking at the attestation's committee index against the validator's committee index
// and check the aggregate bits to ensure the validator's index is set.
if aggregatedAtt.Data.CommitteeIndex == req.CommitteeIndex &&
Copy link
Member

Choose a reason for hiding this comment

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

What happens here? Assume attestations are in the following order:

indexInCommittee=0
AggregationBits has a length 4
local aggregation bits is 0b0001
local head root is 0xA

First attestation: {HeadRoot: 0xA, AggregationBits: 0x0001} 
Second attestation: {HeadRoot: 0xB, AggregationBits: 0x1100}  // Best

Wouldn't second attestation overrides the first attestation because it has more bits? We want the first attestation to be test

Copy link
Member Author

Choose a reason for hiding this comment

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

The best is only replaced by an attestation where where 0b0001 is set, so the first attestation is considered the best.

Copy link
Member

Choose a reason for hiding this comment

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

When the second attestation comes, wouldn't you get:
aggregatedAtt.Data.CommitteeIndex == req.CommitteeIndex true
aggregatedAtt.AggregationBits.BitAt(indexInCommittee) false
!best.AggregationBits.BitAt(indexInCommittee) false
aggregatedAtt.AggregationBits.Count() > best.AggregationBits.Count()) true

true && false && false || true equals to true?

Copy link
Member Author

Choose a reason for hiding this comment

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

It’s true && false && (false || true)

Copy link
Member

Choose a reason for hiding this comment

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

Ah I missed the (), note to self dont review code sunday late.

What about this case?

local aggregation bits is 0b0001
local head root is 0xA

First attestation: {HeadRoot: 0xB, AggregationBits: 0x0010} 
Second attestation: {HeadRoot: 0xC, AggregationBits: 0x1100}  

Second attestation should be the best one but I don't think it'd be replaced given this condition?
true && false && (false || true)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that is correct. I figured that the aggregator would almost always have their attestation present, but let me see about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK this has been added. Please review 8827cb1

Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Thanks!

@prylabs-bulldozer prylabs-bulldozer bot merged commit 774b4b7 into master Jul 13, 2020
@delete-merged-branch delete-merged-branch bot deleted the prefer-own-attestation branch July 13, 2020 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aggregator should use self-attested attestation
3 participants