feat: add funding_source_max_retries env setting (#2404)

* feat: add `funding_source_max_retries` env setting

* feat: default to zero retries

* feat: exponential retry time increase

* chore: Let's use the same value as the default

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>

* feat: using 0.25 leads to less awkward numbers

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>

---------

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
Vlad Stan 2024-04-11 19:29:25 +03:00 committed by GitHub
parent e9e69d9d17
commit adb8f9bdec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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})"

View File

@ -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: