-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Perf] Avoid fetching already seen Certificates #3439
base: staging
Are you sure you want to change the base?
Conversation
continue; | ||
} | ||
// If we have not fully processed the certificate yet, store it. | ||
if let Some(certificate) = self.storage.get_unprocessed_certificate(*certificate_id) { |
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.
NOTE: we can additionally resolve any outstanding certificate requests for this particular certificate.
// Ensure storage does not already contain the certificate. | ||
if self.storage.contains_certificate(certificate.id()) { | ||
return Ok(()); | ||
// Otherwise, ensure ephemeral storage contains the certificate. | ||
} else if !self.storage.contains_unprocessed_certificate(certificate.id()) { | ||
self.storage.insert_unprocessed_certificate(certificate.clone())?; |
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.
Why is the certificate not removed from the unprocessed_certificates
cache when this function is completed?
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 is removed from the cache if the certificate is inserted into storage, so even sooner than waiting for the function to complete.
You might wonder whether a malicious validator could fill up the cache, and they could. The cache helps in the optimistic case to speed up processing.
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.
Overall code and concept LGTM!
I think some additional testing/brainstorming would give more confidence that this could not be exploited by malicious parties. Or if there are cases where it may be detrimental (regressions);
Motivation
To reduce the chance validators have to fetch any certificates, this PR ensures they don't just check their storage of confirmed certificates, but also a cache of certificates which are currently being processed.
This PR is meant not to change any consensus logic.
The second commit is a small optimization to reduce temporary allocations.
Test Plan