Repository navigation
Ignore subset aggregates #10674
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
Ignore subset aggregates #10674
Changes from 21 commits
54ee83a
9d8f6d6
9735917
6fa31aa
0e69037
e1368e9
677b2e1
7271561
b1f7eeb
dcb6ce0
417187f
31bba12
1613754
ee2c910
18c2fcb
2e98bd5
d18079a
592db2b
ae6568e
78a4a5b
ba75634
58a86fb
1307233
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,11 @@ func (s *Service) validateSyncContributionAndProof(ctx context.Context, pid peer | |
| return result, err | ||
| } | ||
|
|
||
| s.setSyncContributionIndexSlotSeen(m.Message.Contribution.Slot, m.Message.AggregatorIndex, types.CommitteeIndex(m.Message.Contribution.SubcommitteeIndex)) | ||
| con := m.Message.Contribution | ||
| if err := s.setSyncContributionBits(con); err != nil { | ||
| return pubsub.ValidationIgnore, err | ||
| } | ||
| s.setSyncContributionIndexSlotSeen(con.Slot, m.Message.AggregatorIndex, types.CommitteeIndex(con.SubcommitteeIndex)) | ||
|
|
||
| msg.ValidatorData = m | ||
|
|
||
|
|
@@ -149,7 +153,15 @@ func rejectEmptyContribution(m *ethpb.SignedContributionAndProof) validationFn { | |
|
|
||
| func (s *Service) ignoreSeenSyncContribution(m *ethpb.SignedContributionAndProof) validationFn { | ||
| return func(ctx context.Context) (pubsub.ValidationResult, error) { | ||
| seen := s.hasSeenSyncContributionIndexSlot(m.Message.Contribution.Slot, m.Message.AggregatorIndex, types.CommitteeIndex(m.Message.Contribution.SubcommitteeIndex)) | ||
| c := m.Message.Contribution | ||
| seen, err := s.hasSeenSyncContributionBits(c) | ||
| if err != nil { | ||
| return pubsub.ValidationIgnore, err | ||
| } | ||
| if seen { | ||
| return pubsub.ValidationIgnore, nil | ||
| } | ||
| seen = s.hasSeenSyncContributionIndexSlot(c.Slot, m.Message.AggregatorIndex, types.CommitteeIndex(c.SubcommitteeIndex)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is copying
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, I removed |
||
| if seen { | ||
| return pubsub.ValidationIgnore, nil | ||
| } | ||
|
|
@@ -318,6 +330,68 @@ func (s *Service) setSyncContributionIndexSlotSeen(slot types.Slot, aggregatorIn | |
| s.seenSyncContributionCache.Add(string(b), true) | ||
| } | ||
|
|
||
| // Set sync contribution's slot, root, committee index and bits. | ||
| func (s *Service) setSyncContributionBits(c *ethpb.SyncCommitteeContribution) error { | ||
| s.syncContributionBitsOverlapLock.Lock() | ||
| defer s.syncContributionBitsOverlapLock.Unlock() | ||
| // Copying due to how pb unmarshalling is carried out, prevent mutation. | ||
| b := append(bytesutil.SafeCopyBytes(c.BlockRoot), bytesutil.Bytes32(uint64(c.Slot))...) | ||
| b = append(b, bytesutil.Bytes32(c.SubcommitteeIndex)...) | ||
| v, ok := s.syncContributionBitsOverlapCache.Get(string(b)) | ||
| if !ok { | ||
| s.syncContributionBitsOverlapCache.Add(string(b), [][]byte{c.AggregationBits.Bytes()}) | ||
| return nil | ||
| } | ||
| bitsList, ok := v.([][]byte) | ||
| if !ok { | ||
| return errors.New("could not covert cached value to []bitfield.Bitvector") | ||
| } | ||
| has, err := bitListOverlaps(bitsList, c.AggregationBits) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if has { | ||
| return nil | ||
| } | ||
| s.syncContributionBitsOverlapCache.Add(string(b), append(bitsList, c.AggregationBits.Bytes())) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to check whether it contains a bitlist that already contains over what the contribution has.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed, thanks! |
||
| return nil | ||
| } | ||
|
|
||
| // Check sync contribution bits don't have an overlap with one's in cache. | ||
| func (s *Service) hasSeenSyncContributionBits(c *ethpb.SyncCommitteeContribution) (bool, error) { | ||
| s.syncContributionBitsOverlapLock.RLock() | ||
| defer s.syncContributionBitsOverlapLock.RUnlock() | ||
| b := append(c.BlockRoot, bytesutil.Bytes32(uint64(c.Slot))...) | ||
| b = append(b, bytesutil.Bytes32(c.SubcommitteeIndex)...) | ||
| v, ok := s.syncContributionBitsOverlapCache.Get(string(b)) | ||
| if !ok { | ||
| return false, nil | ||
| } | ||
| bitsList, ok := v.([][]byte) | ||
| if !ok { | ||
| return false, errors.New("could not covert cached value to []bitfield.Bitvector128") | ||
| } | ||
| return bitListOverlaps(bitsList, c.AggregationBits.Bytes()) | ||
| } | ||
|
|
||
| // bitListOverlaps returns true if there's an overlap between two bitlists. | ||
| func bitListOverlaps(bitLists [][]byte, b []byte) (bool, error) { | ||
| for _, bitList := range bitLists { | ||
| if bitList == nil { | ||
| return false, errors.New("nil bitfield") | ||
| } | ||
| bl := ethpb.ConvertToSyncContributionBitVector(bitList) | ||
| overlaps, err := bl.Overlaps(ethpb.ConvertToSyncContributionBitVector(b)) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| if overlaps { | ||
| return true, nil | ||
| } | ||
| } | ||
| return false, nil | ||
| } | ||
|
|
||
| // verifySyncSelectionData verifies that the provided sync contribution has a valid | ||
| // selection proof. | ||
| func (s *Service) verifySyncSelectionData(ctx context.Context, m *ethpb.ContributionAndProof) error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For simplicity, I opted in same cache size as
seenSyncContributionSize, open for other suggestions