1
0

lnworker: use config lightning fee for estimate

I was unable to do a "Max" amount submarine swap because the
`fee_estimate` method used by `LNWallet.num_sats_can_send()` uses a
hardcoded `fee_proportional_millionths` to estimate the fee for the
lightning payment.
When the actual fee determined later is higher
than the estimated fee the payment fails as the channel is unable to add
the htlc sum including the real fees as the amount exceeds the balance of
the channel.
Using the fees the maximum fees user has configured and estimate the
potential fee as inverse of PaymentFeeBudget is more
reliable/conservative as we definitely aren't going to pay more fees
than this amount.
This commit is contained in:
f321x
2025-11-24 11:01:51 +01:00
parent 3f45c41981
commit af4dc24d87
3 changed files with 77 additions and 17 deletions

View File

@@ -10,7 +10,7 @@ from electrum.lnutil import (
derive_privkey, derive_pubkey, make_htlc_tx, extract_ctn_from_tx, get_compressed_pubkey_from_bech32,
ScriptHtlc, calc_fees_for_commitment_tx, UpdateAddHtlc, LnFeatures, ln_compare_features,
IncompatibleLightningFeatures, ChannelType, offered_htlc_trim_threshold_sat, received_htlc_trim_threshold_sat,
ImportedChannelBackupStorage, list_enabled_ln_feature_bits
ImportedChannelBackupStorage, list_enabled_ln_feature_bits, PaymentFeeBudget,
)
from electrum.util import bfh, MyEncoder
from electrum.transaction import Transaction, PartialTransaction, Sighash
@@ -1121,3 +1121,33 @@ class TestLNUtil(ElectrumTestCase):
),
decoded_cb,
)
async def test_payment_fee_budget(self):
config = SimpleConfig()
# test value above cutoff
invoice_amount_msat = 1_000_000 * 1000
budget = PaymentFeeBudget.from_invoice_amount(
invoice_amount_msat=invoice_amount_msat,
config=config,
)
reversed_fee_msat = PaymentFeeBudget.reverse_from_total_amount(
total_amount_msat=invoice_amount_msat + budget.fee_msat,
config=config,
)
self.assertGreater(budget.fee_msat, config.LIGHTNING_PAYMENT_FEE_CUTOFF_MSAT)
self.assertEqual(reversed_fee_msat, budget.fee_msat)
# test value below cutoff
invoice_amount_msat = 1000
budget = PaymentFeeBudget.from_invoice_amount(
invoice_amount_msat=invoice_amount_msat,
config=config,
)
reversed_fee_msat = PaymentFeeBudget.reverse_from_total_amount(
total_amount_msat=invoice_amount_msat + budget.fee_msat,
config=config,
)
self.assertEqual(budget.fee_msat, config.LIGHTNING_PAYMENT_FEE_CUTOFF_MSAT)
self.assertEqual(reversed_fee_msat, budget.fee_msat)