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

Do not cache on fast blockchains #1297

Merged
merged 2 commits into from
Oct 27, 2021
Merged
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
17 changes: 14 additions & 3 deletions brownie/network/middlewares/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,20 @@ def __init__(self, w3: Web3) -> None:

@classmethod
def get_layer(cls, w3: Web3, network_type: str) -> Optional[int]:
if network_type == "live" and _new_filter(w3) is not None:
return 0
else:
if network_type != "live":
# do not cache on development chains
return None
try:
latest = w3.eth.get_block("latest")
except Exception:
return None
if latest.timestamp - w3.eth.get_block(latest.number - 50).timestamp < 250:
# do not cache on chains with an average block time of less than 5 seconds
return None
if _new_filter(w3) is None:
# do not cache if we cannot create a filter for new blocks
return None
return 0

@property
def time_since(self) -> float:
Expand Down Expand Up @@ -229,5 +239,6 @@ def process_request(self, make_request: Callable, method: str, params: List) ->

def uninstall(self) -> None:
self.is_killed = True
self.block_cache.clear()
if self.w3.isConnected():
self.w3.eth.uninstallFilter(self.block_filter.filter_id)