diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ddf899de..caee3168 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -46,6 +46,7 @@ services: - WEBADMIN_ALLOW_CORS - NETWORK - LOG_LEVEL + - SQUEAKNODE_SYNC_INTERVAL_S volumes: - shared:/rpc - ~/.lnd:/root/.lnd diff --git a/squeaknode/config/config.py b/squeaknode/config/config.py index fdfd2460..7cec82f0 100644 --- a/squeaknode/config/config.py +++ b/squeaknode/config/config.py @@ -78,7 +78,7 @@ class Config: self._configs['squeaknode_max_squeaks_per_address_per_hour'] = self._get_squeaknode_max_squeaks_per_address_per_hour() self._configs['squeaknode_database'] = self._get_squeaknode_database() self._configs['squeaknode_sqk_dir'] = self._get_squeaknode_sqk_dir() - self._configs['squeaknode_enable_sync'] = self._get_squeaknode_enable_sync() + self._configs['squeaknode_sync_interval_s'] = self._get_squeaknode_sync_interval_s() self._configs['squeaknode_log_level'] = self._get_squeaknode_log_level() # db @@ -191,9 +191,9 @@ class Config: def _get_squeaknode_sqk_dir(self): return self.parser.get("squeaknode", "sqk_dir", fallback=DEFAULT_SQK_DIR_PATH) - def _get_squeaknode_enable_sync(self): - return environ.get('SQUEAKNODE_ENABLE_SYNC') \ - or self.parser.getboolean("squeaknode", "enable_sync", fallback=False) + def _get_squeaknode_sync_interval_s(self): + return int(environ.get('SQUEAKNODE_SYNC_INTERVAL_S')) \ + or self.parser.getint("squeaknode", "sync_interval_s", fallback=None) def _get_squeaknode_log_level(self): return environ.get('LOG_LEVEL') \ diff --git a/squeaknode/main.py b/squeaknode/main.py index 3a07cccb..06fe356c 100644 --- a/squeaknode/main.py +++ b/squeaknode/main.py @@ -87,8 +87,8 @@ def load_max_squeaks_per_address_per_hour(config): return config.squeaknode_max_squeaks_per_address_per_hour -def load_enable_sync(config): - return config.squeaknode_enable_sync +def load_sync_interval_s(config): + return config.squeaknode_sync_interval_s def load_handler(squeak_node): @@ -222,7 +222,7 @@ def run_server(config): blockchain_client = load_blockchain_client(config) # load enable sync config - enable_sync = load_enable_sync(config) + sync_interval_s = load_sync_interval_s(config) # Create and start the squeak node squeak_node = SqueakNode( @@ -232,7 +232,7 @@ def run_server(config): lightning_host_port, price, max_squeaks_per_address_per_hour, - enable_sync, + sync_interval_s, ) squeak_node.start_running() diff --git a/squeaknode/node/squeak_node.py b/squeaknode/node/squeak_node.py index 9a2aa4b9..a88ca911 100644 --- a/squeaknode/node/squeak_node.py +++ b/squeaknode/node/squeak_node.py @@ -39,14 +39,14 @@ class SqueakNode: lightning_host_port, price, max_squeaks_per_address_per_hour, - enable_sync=False, + sync_interval_s, ): self.postgres_db = postgres_db self.blockchain_client = blockchain_client self.lightning_client = lightning_client self.lightning_host_port = lightning_host_port self.price = price - self.enable_sync = enable_sync + self.sync_interval_s = sync_interval_s self.squeak_block_verifier = SqueakBlockVerifier(postgres_db, blockchain_client) self.squeak_block_periodic_worker = SqueakBlockPeriodicWorker( self.squeak_block_verifier @@ -77,6 +77,7 @@ class SqueakNode: ) self.squeak_peer_sync_worker = SqueakPeerSyncWorker( self.squeak_sync_controller, + self.sync_interval_s, ) self.squeak_expired_offer_cleaner = SqueakExpiredOfferCleaner( self.postgres_db, @@ -88,8 +89,7 @@ class SqueakNode: def start_running(self): self.squeak_block_periodic_worker.start_running() self.squeak_block_queue_worker.start_running() - if self.enable_sync: - self.squeak_peer_sync_worker.start_running() + self.squeak_peer_sync_worker.start_running() self.squeak_offer_expiry_worker.start_running() def save_uploaded_squeak(self, squeak): diff --git a/squeaknode/node/squeak_peer_sync_worker.py b/squeaknode/node/squeak_peer_sync_worker.py index eda26e4a..ea913fa0 100644 --- a/squeaknode/node/squeak_peer_sync_worker.py +++ b/squeaknode/node/squeak_peer_sync_worker.py @@ -4,22 +4,20 @@ import threading logger = logging.getLogger(__name__) -SUBSCRIBE_UPDATE_INTERVAL_S = 10.0 - - class SqueakPeerSyncWorker: def __init__( self, squeak_sync_controller, - update_interval_s=SUBSCRIBE_UPDATE_INTERVAL_S, + sync_interval_s, ): self.squeak_sync_controller = squeak_sync_controller - self.update_interval_s = update_interval_s + self.sync_interval_s = sync_interval_s def sync_timeline(self): logger.info("Syncing timeline with peers...") self.squeak_sync_controller.sync_timeline() def start_running(self): - threading.Timer(self.update_interval_s, self.start_running).start() - self.sync_timeline() + if self.sync_interval_s: + threading.Timer(self.sync_interval_s, self.start_running).start() + self.sync_timeline()