Skip to content

Commit

Permalink
lnchannel: rm HTLC value upper limit of ~42 mBTC
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed Jun 10, 2021
1 parent dab25e3 commit f52c0fd
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 33 deletions.
5 changes: 1 addition & 4 deletions electrum/lnchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
funding_output_script, SENT, RECEIVED, LOCAL, REMOTE, HTLCOwner, make_commitment_outputs,
ScriptHtlc, PaymentFailure, calc_fees_for_commitment_tx, RemoteMisbehaving, make_htlc_output_witness_script,
ShortChannelID, map_htlcs_to_ctx_output_idxs, LNPeerAddr,
LN_MAX_HTLC_VALUE_MSAT, fee_for_htlc_output, offered_htlc_trim_threshold_sat,
fee_for_htlc_output, offered_htlc_trim_threshold_sat,
received_htlc_trim_threshold_sat, make_commitment_output_to_remote_address)
from .lnsweep import create_sweeptxs_for_our_ctx, create_sweeptxs_for_their_ctx
from .lnsweep import create_sweeptx_for_their_revoked_htlc, SweepInfo
Expand Down Expand Up @@ -564,7 +564,6 @@ def __init__(self, state: 'StoredDict', *, sweep_address=None, name=None, lnwork
self.revocation_store = RevocationStore(state["revocation_store"])
self._can_send_ctx_updates = True # type: bool
self._receive_fail_reasons = {} # type: Dict[int, (bytes, OnionRoutingFailure)]
self._ignore_max_htlc_value = False # used in tests
self.should_request_force_close = False
self.unconfirmed_closing_txid = None # not a state, only for GUI

Expand Down Expand Up @@ -815,8 +814,6 @@ def _assert_can_add_htlc(self, *, htlc_proposer: HTLCOwner, amount_msat: int,
raise PaymentFailure("HTLC value must be positive")
if amount_msat < chan_config.htlc_minimum_msat:
raise PaymentFailure(f'HTLC value too small: {amount_msat} msat')
if amount_msat > LN_MAX_HTLC_VALUE_MSAT and not self._ignore_max_htlc_value:
raise PaymentFailure(f"HTLC value over protocol maximum: {amount_msat} > {LN_MAX_HTLC_VALUE_MSAT} msat")

# check proposer can afford htlc
max_can_send_msat = self.available_to_spend(htlc_proposer, strict=strict)
Expand Down
1 change: 0 additions & 1 deletion electrum/lnutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
HTLC_OUTPUT_WEIGHT = 172

LN_MAX_FUNDING_SAT = pow(2, 24) - 1
LN_MAX_HTLC_VALUE_MSAT = pow(2, 32) - 1

# dummy address for fee estimation of funding tx
def ln_dummy_address():
Expand Down
4 changes: 2 additions & 2 deletions electrum/submarine_swaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .transaction import PartialTxInput, PartialTxOutput, PartialTransaction
from .transaction import script_GetOp, match_script_against_template, OPPushDataGeneric, OPPushDataPubkey
from .util import log_exceptions
from .lnutil import REDEEM_AFTER_DOUBLE_SPENT_DELAY, ln_dummy_address, LN_MAX_HTLC_VALUE_MSAT
from .lnutil import REDEEM_AFTER_DOUBLE_SPENT_DELAY, ln_dummy_address
from .bitcoin import dust_threshold
from .logging import Logger
from .lnutil import hex_to_bytes
Expand Down Expand Up @@ -450,7 +450,7 @@ async def get_pairs(self) -> None:
self._max_amount = limits['maximal']

def get_max_amount(self):
return min(self._max_amount, LN_MAX_HTLC_VALUE_MSAT // 1000)
return self._max_amount

def check_invoice_amount(self, x):
return x >= self.min_amount and x <= self._max_amount
Expand Down
26 changes: 0 additions & 26 deletions electrum/tests/test_lnchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ def create_test_channels(*, feerate=6000, local_msat=None, remote_msat=None,
alice._fallback_sweep_address = bitcoin.pubkey_to_address('p2wpkh', alice.config[LOCAL].payment_basepoint.pubkey.hex())
bob._fallback_sweep_address = bitcoin.pubkey_to_address('p2wpkh', bob.config[LOCAL].payment_basepoint.pubkey.hex())

alice._ignore_max_htlc_value = True
bob._ignore_max_htlc_value = True

return alice, bob

class TestFee(ElectrumTestCase):
Expand Down Expand Up @@ -683,29 +680,6 @@ def test_DesyncHTLCs(self):
self.assertEqual(500000000000, bob_channel.available_to_spend(LOCAL))
alice_channel.add_htlc(htlc_dict)

def test_max_htlc_value(self):
alice_channel, bob_channel = create_test_channels()
paymentPreimage = b"\x01" * 32
paymentHash = bitcoin.sha256(paymentPreimage)
htlc_dict = {
'payment_hash' : paymentHash,
'amount_msat' : one_bitcoin_in_msat * 41 // 10,
'cltv_expiry' : 5,
'timestamp' : 0,
}

alice_channel._ignore_max_htlc_value = False
bob_channel._ignore_max_htlc_value = False
with self.assertRaises(lnutil.PaymentFailure):
alice_channel.add_htlc(htlc_dict)
with self.assertRaises(lnutil.RemoteMisbehaving):
bob_channel.receive_htlc(htlc_dict)

alice_channel._ignore_max_htlc_value = True
bob_channel._ignore_max_htlc_value = True
alice_channel.add_htlc(htlc_dict)
bob_channel.receive_htlc(htlc_dict)


class TestChanReserve(ElectrumTestCase):
def setUp(self):
Expand Down

0 comments on commit f52c0fd

Please sign in to comment.