Merge pull request #1559 from lnbits/feat-fundingfallback

FEAT: add funding source fallback and VoidWallet warning for frontend
This commit is contained in:
Arc 2023-03-07 11:56:01 +00:00 committed by GitHub
commit 00b3ab94ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 6 deletions

View File

@ -105,20 +105,42 @@ async def check_funding_source() -> None:
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
WALLET = get_wallet_class() WALLET = get_wallet_class()
# fallback to void after 30 seconds of failures
sleep_time = 5
timeout = int(30 / sleep_time)
balance = 0
retry_counter = 0
while True: while True:
try: try:
error_message, balance = await WALLET.status() error_message, balance = await WALLET.status()
if not error_message: if not error_message:
retry_counter = 0
break break
logger.error( logger.error(
f"The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'", f"The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'",
RuntimeWarning, RuntimeWarning,
) )
except: except:
pass pass
logger.info("Retrying connection to backend in 5 seconds...")
await asyncio.sleep(5) if settings.lnbits_admin_ui and retry_counter == timeout:
logger.warning(
f"Fallback to VoidWallet, because the backend for {WALLET.__class__.__name__} isn't working properly"
)
set_wallet_class("VoidWallet")
WALLET = get_wallet_class()
break
else:
logger.warning(f"Retrying connection to backend in {sleep_time} seconds...")
retry_counter += 1
await asyncio.sleep(sleep_time)
signal.signal(signal.SIGINT, original_sigint_handler) signal.signal(signal.SIGINT, original_sigint_handler)
logger.info( logger.info(
f"✔️ Backend {WALLET.__class__.__name__} connected and with a balance of {balance} msat." f"✔️ Backend {WALLET.__class__.__name__} connected and with a balance of {balance} msat."
) )

View File

@ -100,6 +100,7 @@ def template_renderer(additional_folders: List = None) -> Jinja2Templates:
t.env.globals["AD_SPACE"] = settings.lnbits_ad_space.split(",") t.env.globals["AD_SPACE"] = settings.lnbits_ad_space.split(",")
t.env.globals["AD_SPACE_TITLE"] = settings.lnbits_ad_space_title t.env.globals["AD_SPACE_TITLE"] = settings.lnbits_ad_space_title
t.env.globals["VOIDWALLET"] = settings.lnbits_backend_wallet_class == "VoidWallet"
t.env.globals["HIDE_API"] = settings.lnbits_hide_api t.env.globals["HIDE_API"] = settings.lnbits_hide_api
t.env.globals["SITE_TITLE"] = settings.lnbits_site_title t.env.globals["SITE_TITLE"] = settings.lnbits_site_title
t.env.globals["LNBITS_DENOMINATION"] = settings.lnbits_denomination t.env.globals["LNBITS_DENOMINATION"] = settings.lnbits_denomination

View File

@ -317,8 +317,9 @@ def set_cli_settings(**kwargs):
# set wallet class after settings are loaded # set wallet class after settings are loaded
def set_wallet_class(): def set_wallet_class(class_name: Optional[str] = None):
wallet_class = getattr(wallets_module, settings.lnbits_backend_wallet_class) backend_wallet_class = class_name or settings.lnbits_backend_wallet_class
wallet_class = getattr(wallets_module, backend_wallet_class)
global WALLET global WALLET
WALLET = wallet_class() WALLET = wallet_class()

View File

@ -44,7 +44,11 @@
endblock %} endblock %}
</q-btn> </q-btn>
</q-toolbar-title> </q-toolbar-title>
{% block beta %} {% block beta %} {% if VOIDWALLET %}
<q-badge color="red" text-color="black" class="q-mr-md">
<span>VoidWallet is active! Payments disabled</span>
</q-badge>
{%endif%}
<q-badge color="yellow" text-color="black" class="q-mr-md"> <q-badge color="yellow" text-color="black" class="q-mr-md">
<span <span
><span v-show="$q.screen.gt.sm" ><span v-show="$q.screen.gt.sm"

View File

@ -72,12 +72,14 @@ exclude = [
"lnbits/wallets", "lnbits/wallets",
"lnbits/core", "lnbits/core",
"lnbits/*.py", "lnbits/*.py",
"lnbits/extensions",
] ]
[tool.mypy] [tool.mypy]
files = "lnbits" files = "lnbits"
exclude = """(?x)( exclude = """(?x)(
^lnbits/wallets/lnd_grpc_files. ^lnbits/wallets/lnd_grpc_files.
| ^lnbits/extensions.
)""" )"""
[[tool.mypy.overrides]] [[tool.mypy.overrides]]
@ -90,7 +92,6 @@ module = [
"websocket.*", "websocket.*",
"websockets.*", "websockets.*",
"pyqrcode.*", "pyqrcode.*",
"cashu.*",
"shortuuid.*", "shortuuid.*",
"grpc.*", "grpc.*",
"lnurl.*", "lnurl.*",