From 197ff7d054f7f1780cd2354748154fa483e18cef Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Sat, 13 Aug 2022 19:19:08 +0100 Subject: [PATCH] Core: reserve fee as an .env variable (#631) * reserve fee as an .env variable * fixed bad import * Update .env.example Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> * Update lnbits/core/services.py Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> * Update lnbits/core/services.py Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> * Update lnbits/settings.py Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> * variable consistent names * fix services.py variable names * percent default fix * Update lnbits/settings.py int to float * Update lnbits/settings.py int to float * Update .env.example int to float * make format * fixed failing bleskomat test, expecting 2000 msats fee * Update tests/extensions/bleskomat/test_lnurl_api.py revert to 2 sat * Update .env.example * Update lnbits/settings.py Co-authored-by: calle <93376500+callebtc@users.noreply.github.com> --- .env.example | 2 ++ lnbits/core/services.py | 6 +++--- lnbits/settings.py | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index ec980775f..97105bc3f 100644 --- a/.env.example +++ b/.env.example @@ -25,6 +25,8 @@ LNBITS_DATA_FOLDER="./data" LNBITS_FORCE_HTTPS=true LNBITS_SERVICE_FEE="0.0" +LNBITS_RESERVE_FEE_MIN=2000 # value in millisats +LNBITS_RESERVE_FEE_PERCENT=1.0 # value in percent # Change theme LNBITS_SITE_TITLE="LNbits" diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 6cfad7b4e..90f621862 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -21,7 +21,7 @@ from lnbits.decorators import ( ) from lnbits.helpers import url_for, urlsafe_short_hash from lnbits.requestvars import g -from lnbits.settings import FAKE_WALLET, WALLET +from lnbits.settings import FAKE_WALLET, RESERVE_FEE_MIN, RESERVE_FEE_PERCENT, WALLET from lnbits.wallets.base import PaymentResponse, PaymentStatus from . import db @@ -160,7 +160,7 @@ async def pay_invoice( logger.debug("balance is too low, deleting temporary payment") if not internal_checking_id and wallet.balance_msat > -fee_reserve_msat: raise PaymentFailure( - f"You must reserve at least 1% ({round(fee_reserve_msat/1000)} sat) to cover potential routing fees." + f"You must reserve at least ({round(fee_reserve_msat/1000)} sat) to cover potential routing fees." ) raise PermissionError("Insufficient balance.") @@ -366,4 +366,4 @@ async def check_transaction_status( # WARN: this same value must be used for balance check and passed to WALLET.pay_invoice(), it may cause a vulnerability if the values differ def fee_reserve(amount_msat: int) -> int: - return max(2000, int(amount_msat * 0.01)) + return max(int(RESERVE_FEE_MIN), int(amount_msat * RESERVE_FEE_PERCENT / 100.0)) diff --git a/lnbits/settings.py b/lnbits/settings.py index 5778b9e23..79c74fb45 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -55,6 +55,8 @@ FAKE_WALLET = getattr(wallets_module, "FakeWallet")() DEFAULT_WALLET_NAME = env.str("LNBITS_DEFAULT_WALLET_NAME", default="LNbits wallet") PREFER_SECURE_URLS = env.bool("LNBITS_FORCE_HTTPS", default=True) +RESERVE_FEE_MIN = env.int("LNBITS_RESERVE_FEE_MIN", default=2000) +RESERVE_FEE_PERCENT = env.float("LNBITS_RESERVE_FEE_PERCENT", default=1.0) SERVICE_FEE = env.float("LNBITS_SERVICE_FEE", default=0.0) try: