diff --git a/.env.example b/.env.example index 496bb905b..d911096db 100644 --- a/.env.example +++ b/.env.example @@ -34,6 +34,9 @@ LNBITS_BACKEND_WALLET_CLASS=VoidWallet # VoidWallet is just a fallback that works without any actual Lightning capabilities, # just so you can see the UI before dealing with this file. +# How many times to retry connectiong to the Funding Source before defaulting to the VoidWallet +# FUNDING_SOURCE_MAX_RETRIES=4 + # Invoice expiry for LND, CLN, Eclair, LNbits funding sources LIGHTNING_INVOICE_EXPIRY=3600 diff --git a/lnbits/app.py b/lnbits/app.py index da82cfe84..5062b8612 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -180,8 +180,7 @@ async def check_funding_source() -> None: WALLET = get_wallet_class() - sleep_time = 5 - max_retries = 5 + max_retries = settings.funding_source_max_retries retry_counter = 0 while True: @@ -203,12 +202,13 @@ async def check_funding_source() -> None: except Exception as e: logger.error(f"Error connecting to {WALLET.__class__.__name__}: {e}") - if retry_counter == max_retries: + if retry_counter >= max_retries: set_void_wallet_class() WALLET = get_wallet_class() break retry_counter += 1 + sleep_time = 0.25 * (2**retry_counter) logger.warning( f"Retrying connection to backend in {sleep_time} seconds... " f"({retry_counter}/{max_retries})" diff --git a/lnbits/settings.py b/lnbits/settings.py index 2e7459fa9..2388f3132 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -377,6 +377,7 @@ class EnvSettings(LNbitsSettings): log_retention: str = Field(default="3 months") server_startup_time: int = Field(default=time()) cleanup_wallets_days: int = Field(default=90) + funding_source_max_retries: int = Field(default=4) @property def has_default_extension_path(self) -> bool: