commit 4445cef033b1c60e05e19ff4dae43d0a026105da
parent 259dacd56f8d272738682875f7a88b037981fecd
Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 2 Mar 2021 12:10:17 +0100
lnutil: turn global forwarding fee params into Channel attributes
useful for unit testing, and it is the conceptually correct thing anyway
Diffstat:
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
@@ -503,6 +503,11 @@ class Channel(AbstractChannel):
# they are ambiguous. Use "oldest_unrevoked" or "latest" or "next".
# TODO enforce this ^
+ # our forwarding parameters for forwarding HTLCs through this channel
+ forwarding_cltv_expiry_delta = 144
+ forwarding_fee_base_msat = 1000
+ forwarding_fee_proportional_millionths = 1
+
def __init__(self, state: 'StoredDict', *, sweep_address=None, name=None, lnworker=None, initial_feerate=None):
self.name = name
Logger.__init__(self)
@@ -600,11 +605,11 @@ class Channel(AbstractChannel):
short_channel_id=self.short_channel_id,
channel_flags=channel_flags,
message_flags=b'\x01',
- cltv_expiry_delta=lnutil.NBLOCK_OUR_CLTV_EXPIRY_DELTA,
+ cltv_expiry_delta=self.forwarding_cltv_expiry_delta,
htlc_minimum_msat=self.config[REMOTE].htlc_minimum_msat,
htlc_maximum_msat=htlc_maximum_msat,
- fee_base_msat=lnutil.OUR_FEE_BASE_MSAT,
- fee_proportional_millionths=lnutil.OUR_FEE_PROPORTIONAL_MILLIONTHS,
+ fee_base_msat=self.forwarding_fee_base_msat,
+ fee_proportional_millionths=self.forwarding_fee_proportional_millionths,
chain_hash=constants.net.rev_genesis_bytes(),
timestamp=now,
)
diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
@@ -37,8 +37,7 @@ from .lnutil import (Outpoint, LocalConfig, RECEIVED, UpdateAddHtlc,
LOCAL, REMOTE, HTLCOwner,
ln_compare_features, privkey_to_pubkey, MIN_FINAL_CLTV_EXPIRY_ACCEPTED,
LightningPeerConnectionClosed, HandshakeFailed,
- RemoteMisbehaving,
- NBLOCK_OUR_CLTV_EXPIRY_DELTA, ShortChannelID,
+ RemoteMisbehaving, ShortChannelID,
IncompatibleLightningFeatures, derive_payment_secret_from_payment_preimage,
LN_MAX_FUNDING_SAT, calc_fees_for_commitment_tx,
UpfrontShutdownScriptViolation)
@@ -1363,7 +1362,7 @@ class Peer(Logger):
next_cltv_expiry = processed_onion.hop_data.payload["outgoing_cltv_value"]["outgoing_cltv_value"]
except:
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
- if htlc.cltv_expiry - next_cltv_expiry < NBLOCK_OUR_CLTV_EXPIRY_DELTA:
+ if htlc.cltv_expiry - next_cltv_expiry < next_chan.forwarding_cltv_expiry_delta:
data = htlc.cltv_expiry.to_bytes(4, byteorder="big") + outgoing_chan_upd_len + outgoing_chan_upd
raise OnionRoutingFailure(code=OnionFailureCode.INCORRECT_CLTV_EXPIRY, data=data)
if htlc.cltv_expiry - lnutil.MIN_FINAL_CLTV_EXPIRY_ACCEPTED <= local_height \
@@ -1378,8 +1377,8 @@ class Peer(Logger):
raise OnionRoutingFailure(code=OnionFailureCode.INVALID_ONION_PAYLOAD, data=b'\x00\x00\x00')
forwarding_fees = fee_for_edge_msat(
forwarded_amount_msat=next_amount_msat_htlc,
- fee_base_msat=lnutil.OUR_FEE_BASE_MSAT,
- fee_proportional_millionths=lnutil.OUR_FEE_PROPORTIONAL_MILLIONTHS)
+ fee_base_msat=next_chan.forwarding_fee_base_msat,
+ fee_proportional_millionths=next_chan.forwarding_fee_proportional_millionths)
if htlc.amount_msat - next_amount_msat_htlc < forwarding_fees:
data = next_amount_msat_htlc.to_bytes(8, byteorder="big") + outgoing_chan_upd_len + outgoing_chan_upd
raise OnionRoutingFailure(code=OnionFailureCode.FEE_INSUFFICIENT, data=data)
diff --git a/electrum/lnutil.py b/electrum/lnutil.py
@@ -319,11 +319,6 @@ NBLOCK_DEADLINE_AFTER_EXPIRY_FOR_OFFERED_HTLCS = 1
# the deadline after which the channel has to be failed and the HTLC fulfilled on-chain before its cltv_expiry
NBLOCK_DEADLINE_BEFORE_EXPIRY_FOR_RECEIVED_HTLCS = 72
-# the cltv_expiry_delta for channels when we are forwarding payments
-NBLOCK_OUR_CLTV_EXPIRY_DELTA = 144
-OUR_FEE_BASE_MSAT = 1000
-OUR_FEE_PROPORTIONAL_MILLIONTHS = 1
-
NBLOCK_CLTV_EXPIRY_TOO_FAR_INTO_FUTURE = 28 * 144
MAXIMUM_REMOTE_TO_SELF_DELAY_ACCEPTED = 2016