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

fix: better local default for new block timeout [SBK-210] #25

Merged
merged 4 commits into from
Aug 11, 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
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@
url="https://github.com/SilverBackLtd/sdk",
include_package_data=True,
install_requires=[
"eth-ape>=0.6.11,<1.0",
"eth-ape>=0.6.15,<1.0",
"taskiq[metrics]>=0.6.0,<0.7.0",
# Can loosen constraint once https://github.com/pallets/click/issues/2558 resolved
"click==8.1.3",
"click", # Use same version as eth-ape
],
entry_points={
"console_scripts": ["silverback=silverback._cli:cli"],
Expand Down
18 changes: 17 additions & 1 deletion silverback/application.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import atexit
from datetime import timedelta
from typing import Callable, Dict, Optional, Union

from ape.api.networks import LOCAL_NETWORK_NAME
from ape.contracts import ContractEvent, ContractInstance
from ape.logging import logger
from ape.managers.chain import BlockContainer
Expand All @@ -20,6 +22,13 @@ def __init__(self, settings: Optional[Settings] = None):
if not settings:
settings = Settings()

# Adjust defaults from connection
if settings.NEW_BLOCK_TIMEOUT is None and (
self.chain_manager.provider.network.name.endswith("-fork")
or self.chain_manager.provider.network.name == LOCAL_NETWORK_NAME
):
settings.NEW_BLOCK_TIMEOUT = int(timedelta(days=1).total_seconds())

settings_str = "\n ".join(f'{key}="{val}"' for key, val in settings.dict().items() if val)
logger.info(f"Loading Silverback App with settings:\n {settings_str}")

Expand All @@ -39,7 +48,14 @@ def __init__(self, settings: Optional[Settings] = None):

network_str = f'\n NETWORK="{provider.network.ecosystem.name}:{provider.network.name}"'
signer_str = f"\n SIGNER={repr(self.signer)}"
logger.info(f"Loaded Silverback App:{network_str}{signer_str}")
start_block_str = f"\n START_BLOCK={self.start_block}" if self.start_block else ""
new_bock_timeout_str = (
f"\n NEW_BLOCK_TIMEOUT={self.new_block_timeout}" if self.new_block_timeout else ""
)
logger.info(
f"Loaded Silverback App:{network_str}"
f"{signer_str}{start_block_str}{new_bock_timeout_str}"
)

def on_startup(self) -> Callable:
"""
Expand Down