Skip to content

Commit

Permalink
fix: better local default for new block timeout [SBK-210] (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Aug 11, 2023
1 parent ef285db commit f3c2dea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit f3c2dea

Please sign in to comment.