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

The return of simple_cache_middleware #3436

Merged
merged 2 commits into from
Feb 8, 2024
Merged

Conversation

cygnusv
Copy link
Member

@cygnusv cygnusv commented Feb 8, 2024

Type of PR:

  • Bugfix
  • Feature
  • Documentation
  • Other

Required reviews:

  • 1
  • 2
  • 3

What this does:

  • Cache certain RPC calls using web3.py's simple_cache_middleware

Issues fixed/closed:

Why it's needed:
Currently, TACo nodes exhibit a relatively high RPC requests consumption (see #3370). This is just a small improvement, mainly reducing repeated calls to eth_chainId. For some reason, with v7.1.0 I've seen ~5,000 of these per day.

Notes for reviewers:
We had to temporarily remove simple_cache_middleware when @KPrasch and I detected that it shared state between multiple Web3 instances (see ethereum/web3.py#2977 ). This was fixed by ethereum/web3.py#2979, and released in v6.5.0 (https://web3py.readthedocs.io/en/stable/releases.html#web3-py-v6-5-0-2023-06-15). We currently pin v6.14.0.

@cygnusv cygnusv marked this pull request as ready for review February 8, 2024 14:41
@KPrasch KPrasch added Optimization use less, go faster Network HTTP related, not strictly P2P labels Feb 8, 2024
Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

🎸 .

Not sure if there is a test we can add, but looks good nonetheless.

@derekpierre derekpierre mentioned this pull request Feb 8, 2024
@@ -259,6 +259,9 @@ def attach_middleware(self):
self.log.debug('Injecting POA middleware at layer 0')
self.client.inject_middleware(geth_poa_middleware, layer=0)

self.log.debug("Adding simple_cache_middleware")
self.client.add_middleware(simple_cache_middleware)
Copy link
Member

Choose a reason for hiding this comment

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

Welcome back old friend.

@cygnusv
Copy link
Member Author

cygnusv commented Feb 8, 2024

Not sure if there is a test we can add

Yeah, I thought about that too, but we'd be testing web3py. There's also no middlewares at the current TesterBlockchain level.

@KPrasch KPrasch merged commit 276061c into nucypher:v7.2.x Feb 8, 2024
3 of 6 checks passed
derekpierre pushed a commit that referenced this pull request Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Network HTTP related, not strictly P2P Optimization use less, go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants