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

Added execution client cache middleware #71

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sw-utils"
version = "0.3.30"
version = "0.3.31"
description = "StakeWise Python utils"
authors = ["StakeWise Labs <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
8 changes: 6 additions & 2 deletions sw_utils/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from eth_typing import URI
from web3 import AsyncWeb3
from web3.eth import AsyncEth
from web3.middleware import async_geth_poa_middleware
from web3.middleware import async_geth_poa_middleware, async_simple_cache_middleware
from web3.net import AsyncNet
from web3.providers.async_rpc import AsyncHTTPProvider
from web3.types import AsyncMiddleware, RPCEndpoint, RPCResponse
Expand Down Expand Up @@ -108,7 +108,7 @@ def set_retry_timeout(self, retry_timeout: int):


def get_execution_client(
endpoints: list[str], is_poa=False, timeout=60, retry_timeout=0
endpoints: list[str], is_poa=False, timeout=60, retry_timeout=0, use_cache=True
) -> AsyncWeb3:
provider = ExtendedAsyncHTTPProvider(
endpoint_urls=endpoints, request_kwargs={'timeout': timeout}, retry_timeout=retry_timeout
Expand All @@ -121,4 +121,8 @@ def get_execution_client(
if is_poa:
client.middleware_onion.inject(async_geth_poa_middleware, layer=0)
logger.debug('Injected POA middleware')

if use_cache:
client.middleware_onion.add(async_simple_cache_middleware)

return client
Loading