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

Issue with latest_block_based_cache_middleware #2185

Closed
Meemaw opened this issue Oct 18, 2021 · 3 comments
Closed

Issue with latest_block_based_cache_middleware #2185

Meemaw opened this issue Oct 18, 2021 · 3 comments

Comments

@Meemaw
Copy link

Meemaw commented Oct 18, 2021

  • Version: 5.24.0
  • Python: 3.9.5
  • OS: osx

What was wrong?

Please include any of the following that are applicable:

There seems to be an issue with the latest_block_based_cache_middleware implementation. Given the following config:

w3 = Web3(HTTPProvider(settings.ETHEREUM_NODE_URL, request_kwargs={"timeout": 8}))

# Set the gas price strategy
# https://web3py.readthedocs.io/en/stable/gas_price.html#selecting-the-gas-price-strategy
# NOTE - It's recommended to add a cache solution because of how inneficient this gas strategy is
w3.eth.setGasPriceStrategy(fast_gas_price_strategy)

w3.middleware_onion.add(middleware.time_based_cache_middleware)
w3.middleware_onion.add(middleware.latest_block_based_cache_middleware)
w3.middleware_onion.add(middleware.simple_cache_middleware)

I'm observing w3.eth.get_block('latest') to always be cached even though it should never be cached.

Digging into the code a bit more, I suspect the issue in in _is_latest_block_number_request fn,

def _is_latest_block_number_request(method: RPCEndpoint, params: Any) -> bool:
, specifically the part where params are compared:
elif params[:1] == ['latest']:

I've printed params locally, and it seems that params[:1] evaluates to ('latest',) (tuple) and thus the comparison with list fails.

How can it be fixed?

Convert params slice to list before comparing?

@kclowes
Copy link
Collaborator

kclowes commented Oct 18, 2021

Thanks for raising this! This does look like a bug, will fix!

@B3nac
Copy link
Contributor

B3nac commented Apr 1, 2022

Dibs! If nobody is working on this already. 😄

@pacrob
Copy link
Contributor

pacrob commented May 13, 2022

Fixed in #2346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants