Browse Source

Add option for support_large_channels.

max_funding_sats is a config variable and defaults to the old value.
master
ThomasV 3 years ago
parent
commit
40f2087ac3
  1. 2
      electrum/gui/qml/qechannelopener.py
  2. 6
      electrum/gui/qt/new_channel_dialog.py
  3. 4
      electrum/gui/qt/utxo_list.py
  4. 3
      electrum/lnpeer.py
  5. 4
      electrum/lnutil.py
  6. 10
      electrum/lnworker.py
  7. 1
      electrum/simple_config.py

2
electrum/gui/qml/qechannelopener.py

@ -141,7 +141,7 @@ class QEChannelOpener(QObject, AuthMixin):
return False
return True
# FIXME "max" button in amount_dialog should enforce LN_MAX_FUNDING_SAT
# FIXME "max" button in amount_dialog should enforce LIGHTNING_MAX_FUNDING_SAT
@pyqtSlot()
@pyqtSlot(bool)
def openChannel(self, confirm_backup_conflict=False):

6
electrum/gui/qt/new_channel_dialog.py

@ -4,7 +4,7 @@ from PyQt5.QtWidgets import QLabel, QVBoxLayout, QGridLayout, QPushButton, QComb
from electrum.i18n import _
from electrum.transaction import PartialTxOutput, PartialTransaction
from electrum.lnutil import LN_MAX_FUNDING_SAT, MIN_FUNDING_SAT
from electrum.lnutil import MIN_FUNDING_SAT
from electrum.lnworker import hardcoded_trampoline_nodes
from electrum import ecc
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates
@ -131,13 +131,13 @@ class NewChannelDialog(WindowModalDialog):
self.window.show_error(str(e))
return
amount = tx.output_value()
amount = min(amount, LN_MAX_FUNDING_SAT)
amount = min(amount, self.config.LIGHTNING_MAX_FUNDING_SAT)
self.amount_e.setAmount(amount)
def run(self):
if not self.exec_():
return
if self.max_button.isChecked() and self.amount_e.get_amount() < LN_MAX_FUNDING_SAT:
if self.max_button.isChecked() and self.amount_e.get_amount() < self.config.LIGHTNING_MAX_FUNDING_SAT:
# if 'max' enabled and amount is strictly less than max allowed,
# that means we have fewer coins than max allowed, and hence we can
# spend all coins

4
electrum/gui/qt/utxo_list.py

@ -34,7 +34,7 @@ from PyQt5.QtWidgets import QAbstractItemView, QMenu, QLabel, QHBoxLayout
from electrum.i18n import _
from electrum.bitcoin import is_address
from electrum.transaction import PartialTxInput, PartialTxOutput
from electrum.lnutil import LN_MAX_FUNDING_SAT, MIN_FUNDING_SAT
from electrum.lnutil import MIN_FUNDING_SAT
from electrum.util import profiler
from .util import ColorScheme, MONOSPACE_FONT, EnterButton
@ -243,7 +243,7 @@ class UTXOList(MyTreeView):
if self.wallet.lnworker is None:
return False
value = sum(x.value_sats() for x in coins)
return value >= MIN_FUNDING_SAT and value <= LN_MAX_FUNDING_SAT
return value >= MIN_FUNDING_SAT and value <= self.config.LIGHTNING_MAX_FUNDING_SAT
def open_channel_with_coins(self, coins):
# todo : use a single dialog in new flow

3
electrum/lnpeer.py

@ -603,6 +603,9 @@ class Peer(Logger):
def is_shutdown_anysegwit(self):
return self.features.supports(LnFeatures.OPTION_SHUTDOWN_ANYSEGWIT_OPT)
def supports_large_channels(self):
return self.features.supports(LnFeatures.OPTION_SUPPORT_LARGE_CHANNELS)
def is_channel_type(self):
return self.features.supports(LnFeatures.OPTION_CHANNEL_TYPE_OPT)

4
electrum/lnutil.py

@ -49,7 +49,6 @@ HTLC_SUCCESS_WEIGHT = 703
COMMITMENT_TX_WEIGHT = 724
HTLC_OUTPUT_WEIGHT = 172
LN_MAX_FUNDING_SAT = pow(2, 24) - 1
DUST_LIMIT_MAX = 1000
# dummy address for fee estimation of funding tx
@ -106,9 +105,6 @@ class ChannelConfig(StoredObject):
raise Exception(f"{conf_name}. invalid pubkey in channel config")
if funding_sat < MIN_FUNDING_SAT:
raise Exception(f"funding_sat too low: {funding_sat} sat < {MIN_FUNDING_SAT}")
# MUST set funding_satoshis to less than 2^24 satoshi
if funding_sat > LN_MAX_FUNDING_SAT:
raise Exception(f"funding_sat too high: {funding_sat} sat > {LN_MAX_FUNDING_SAT}")
# MUST set push_msat to equal or less than 1000 * funding_satoshis
if not (0 <= self.initial_msat <= 1000 * funding_sat):
raise Exception(f"{conf_name}. insane initial_msat={self.initial_msat}. (funding_sat={funding_sat})")

10
electrum/lnworker.py

@ -34,7 +34,6 @@ from .invoices import Invoice, PR_UNPAID, PR_EXPIRED, PR_PAID, PR_INFLIGHT, PR_F
from .invoices import BaseInvoice
from .util import NetworkRetryManager, JsonRPCClient, NotEnoughFunds
from .util import EventListener, event_listener
from .lnutil import LN_MAX_FUNDING_SAT
from .keystore import BIP32_KeyStore
from .bitcoin import COIN
from .bitcoin import opcodes, make_op_return, address_to_scripthash
@ -222,6 +221,7 @@ LNWALLET_FEATURES = (
| LnFeatures.OPTION_SHUTDOWN_ANYSEGWIT_OPT
| LnFeatures.OPTION_CHANNEL_TYPE_OPT
| LnFeatures.OPTION_SCID_ALIAS_OPT
| LnFeatures.OPTION_SUPPORT_LARGE_CHANNEL_OPT
)
LNGOSSIP_FEATURES = (
@ -1156,7 +1156,7 @@ class LNWallet(LNWorker):
assert lightning_needed > 0
min_funding_sat = lightning_needed + (lightning_needed // 20) + 1000 # safety margin
min_funding_sat = max(min_funding_sat, 100_000) # at least 1mBTC
if min_funding_sat > LN_MAX_FUNDING_SAT:
if min_funding_sat > self.config.LIGHTNING_MAX_FUNDING_SAT:
return
fee_est = partial(self.config.estimate_fee, allow_fallback_to_static_rates=True) # to avoid NoDynamicFeeEstimates
try:
@ -1165,7 +1165,7 @@ class LNWallet(LNWorker):
except NotEnoughFunds:
return
# if available, suggest twice that amount:
if 2 * min_funding_sat <= LN_MAX_FUNDING_SAT:
if 2 * min_funding_sat <= self.config.LIGHTNING_MAX_FUNDING_SAT:
try:
self.mktx_for_open_channel(coins=coins, funding_sat=2*min_funding_sat, node_id=bytes(32), fee_est=fee_est)
funding_sat = 2 * min_funding_sat
@ -1175,8 +1175,8 @@ class LNWallet(LNWorker):
def open_channel(self, *, connect_str: str, funding_tx: PartialTransaction,
funding_sat: int, push_amt_sat: int, password: str = None) -> Tuple[Channel, PartialTransaction]:
if funding_sat > LN_MAX_FUNDING_SAT:
raise Exception(_("Requested channel capacity is over protocol allowed maximum."))
if funding_sat > self.config.LIGHTNING_MAX_FUNDING_SAT:
raise Exception(_("Requested channel capacity is over maximum."))
coro = self._open_channel_coroutine(
connect_str=connect_str, funding_tx=funding_tx, funding_sat=funding_sat,
push_sat=push_amt_sat, password=password)

1
electrum/simple_config.py

@ -888,6 +888,7 @@ class SimpleConfig(Logger):
LIGHTNING_USE_RECOVERABLE_CHANNELS = ConfigVar('use_recoverable_channels', default=True, type_=bool)
LIGHTNING_ALLOW_INSTANT_SWAPS = ConfigVar('allow_instant_swaps', default=False, type_=bool)
LIGHTNING_TO_SELF_DELAY_CSV = ConfigVar('lightning_to_self_delay', default=7 * 144, type_=int)
LIGHTNING_MAX_FUNDING_SAT = ConfigVar('lightning_max_funding_sat', default=pow(2, 24) - 1, type_=int)
EXPERIMENTAL_LN_FORWARD_PAYMENTS = ConfigVar('lightning_forward_payments', default=False, type_=bool)
EXPERIMENTAL_LN_FORWARD_TRAMPOLINE_PAYMENTS = ConfigVar('lightning_forward_trampoline_payments', default=False, type_=bool)

Loading…
Cancel
Save