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

Exchange Head single-flight protection #229

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

IliaBulavintsev
Copy link

#154

Overview

This PR adds singleflight protection to prevent duplicate header requests in the Exchange component. The focus is on minimizing redundant requests, especially around the Head method, which is most likely to experience simultaneous calls.

@Wondertan
Copy link
Member

Hey @IliaBulavintsev, thanks for the contribution. Note that the issue this PR targets is meant to cover all the methods and not only Head.

@IliaBulavintsev
Copy link
Author

Hey @IliaBulavintsev, thanks for the contribution. Note that the issue this PR targets is meant to cover all the methods and not only Head.

Hey @Wondertan ! Thank you for your review. The implementation was meant to only cover Head for now, per @renaynay advice, as it’s the primary method with simultaneous requests. We can expand coverage later if needed.

Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

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

This is a great start :) just a few things

  • can you please remove the sync_getter from the syncer component as now the single flight protection has moved to the exchange instead?
  • re tests: they are comprehensive and have good coverage, but I think they may be a bit overkill. Testing 2 to max 3 simultaneous requests would be sufficient. Also the requestFromTrusted param in the tests would be more useful in terms of coverage if it was false for some cases.
  • nit: the tests could benefit from a bit of spacing between statements for readability :)

- test case with untrusted peer
@IliaBulavintsev
Copy link
Author

IliaBulavintsev commented Nov 8, 2024

Hey @renaynay!

  • The sync_getter was removed as the single flight protection has been moved to the Exchange.
  • The test cases were also adjusted—you're right about the unnecessary number of cases, were reduced. Also added a test case with an untrusted peer and removed the untrusted peer instance that was running.

Lmk if you have other feedback

@renaynay renaynay changed the title Exchange Head single-fligth protection Exchange Head single-flight protection Nov 12, 2024
Comment on lines 174 to 185
{
requestFromTrusted: true,
lastHeader: trustedStore.Headers[trustedStore.HeadHeight-1],
expectedHeight: trustedStore.HeadHeight,
expectedHash: trustedStore.Headers[trustedStore.HeadHeight].Hash(),
},
{
requestFromTrusted: true,
lastHeader: trustedStore.Headers[trustedStore.HeadHeight-1],
expectedHeight: trustedStore.HeadHeight,
expectedHash: trustedStore.Headers[trustedStore.HeadHeight].Hash(),
},
Copy link
Member

Choose a reason for hiding this comment

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

what's the difference between these two test cases?

Copy link
Author

Choose a reason for hiding this comment

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

The duplicate cases serve to double-check that singleflight consistently returns the same response for identical requests from a trusted source. However, if you think a single case is sufficient for validation, we can remove the duplicates to streamline the test

Copy link
Member

Choose a reason for hiding this comment

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

That seems like a good test generally-speaking but I don't think it is relevant to the single-flight protection feature and should rather be implemented in a different way. I appreciate the thought here, however.

Copy link
Author

Choose a reason for hiding this comment

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

Got it, I’ll remove the test as it’s not directly relevant to single-flight. Thanks for the feedback!

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.

3 participants