ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.97k stars 1.69k forks source link

Request Caching can't be configured via providers classes constructors #3394

Closed clover-es closed 4 months ago

clover-es commented 4 months ago

What happened?

Following v7 docs, request caching should be enabled using cache_allowed_requests and RPC cacheable methods using cacheable_requests, but as of today the params are not available in the init of the RPC providers classes.

Code that produced the error

from web3 import Web3, HTTPProvider

w3 = Web3(HTTPProvider(
    endpoint_uri="...",

    # optional flag to turn on cached requests, defaults to False
    cache_allowed_requests=True,

    # optional, defaults to an internal list of deemed-safe-to-cache endpoints
    cacheable_requests={"eth_chainId", "eth_getBlockByNumber"},
))

Full error output

Traceback (most recent call last):
  File "/mnt/c/Users/guill/AppData/Roaming/JetBrains/PyCharm2024.1/scratches/scratch_7.py", line 3, in <module>
    w3 = Web3(HTTPProvider(
              ^^^^^^^^^^^^^
TypeError: HTTPProvider.__init__() got an unexpected keyword argument 'cache_allowed_requests'

Fill this section in if you know how this could or should be fixed

Add cache_allowed_requests and cacheable_requests arguments to __init__() of BaseProvider. The properties of the class already exist but it's not configurable via parameters.

web3 Version

7.0.0-b2f5574

Python Version

3.12

Operating System

linux

Output from pip freeze

No response