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

[Perf] Avoid fetching already seen Certificates #3439

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

vicsn
Copy link
Contributor

@vicsn vicsn commented Nov 18, 2024

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

  • Local network passed.
  • Deployed network passed

@vicsn vicsn changed the title Reduce fetching overhead [Perf] Reduce fetching overhead Nov 18, 2024
continue;
}
// If we have not fully processed the certificate yet, store it.
if let Some(certificate) = self.storage.get_unprocessed_certificate(*certificate_id) {
Copy link
Contributor Author

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.

@vicsn vicsn changed the title [Perf] Reduce fetching overhead [Perf] Avoid fetching already seen Certificates Nov 19, 2024
// 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())?;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@raychu86 raychu86 left a 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);

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.

2 participants