-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Use New Cache Key For Unaggregated Attestations #14590
base: develop
Are you sure you want to change the base?
Conversation
@@ -328,3 +326,15 @@ func (s *Service) hasBlockAndState(ctx context.Context, blockRoot [32]byte) bool | |||
hasState := hasStateSummary || s.cfg.beaconDB.HasState(ctx, blockRoot) | |||
return hasState && s.cfg.chain.HasBlock(ctx, blockRoot) | |||
} | |||
|
|||
func seenAttCacheKey(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregationBits []byte) string { | |||
totalLen := 8 + 8 + len(aggregationBits) |
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.
It might be helpful to add an explanation of what these numbers represent for anyone unfamiliar with the code. Otherwise they just seem like magic numbers
@@ -328,3 +326,15 @@ func (s *Service) hasBlockAndState(ctx context.Context, blockRoot [32]byte) bool | |||
hasState := hasStateSummary || s.cfg.beaconDB.HasState(ctx, blockRoot) | |||
return hasState && s.cfg.chain.HasBlock(ctx, blockRoot) | |||
} | |||
|
|||
func seenAttCacheKey(slot primitives.Slot, committeeID primitives.CommitteeIndex, aggregationBits []byte) string { |
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.
A benchmark test would be nice so that we can see the before/after improvements.
|
||
// Avoid copying to reduce allocation when casting. It is guaranteed to be immutable as the | ||
// slice is only created in this method and isn't accessed/returned anywhere else. | ||
return unsafe.String(&key[0], len(key)) // #nosec G103 |
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.
Can you use the same bytesutil.UnsafeCastToString from #14591 ?
What type of PR is this?
Optimization
What does this PR do? Why is it needed?
This optimizes the cache key computation for specific attestation and reduces the amount of memory allocated. In certain networks, this is a high traffic path which leads to unnecessary allocation of memory.
Which issues(s) does this PR fix?
Fixes #
Other notes for review
Acknowledgements