@@ -393,7 +393,9 @@ def on_init(self, payload):
393
393
if their_networks :
394
394
their_chains = list (chunks (their_networks ["chains" ], 32 ))
395
395
if constants .net .rev_genesis_bytes () not in their_chains :
396
- raise GracefulDisconnect (f"no common chain found with remote. (they sent: { their_chains } )" )
396
+ raise GracefulDisconnect (f"no common chain found with remote. "
397
+ f"(they sent: { [chain .hex () for chain in their_chains ]} ),"
398
+ f" our chain: { constants .net .rev_genesis_bytes ().hex ()} " )
397
399
# all checks passed
398
400
self .lnworker .on_peer_successfully_established (self )
399
401
self ._received_init = True
@@ -967,7 +969,7 @@ async def channel_establishment_flow(
967
969
public : bool ,
968
970
zeroconf : bool = False ,
969
971
temp_channel_id : bytes ,
970
- opening_fee : int = None ,
972
+ opening_fee_msat : int = None ,
971
973
) -> Tuple [Channel , 'PartialTransaction' ]:
972
974
"""Implements the channel opening flow.
973
975
@@ -1033,10 +1035,10 @@ async def channel_establishment_flow(
1033
1035
open_channel_tlvs ['upfront_shutdown_script' ] = {
1034
1036
'shutdown_scriptpubkey' : local_config .upfront_shutdown_script
1035
1037
}
1036
- if opening_fee :
1038
+ if opening_fee_msat :
1037
1039
# todo: maybe add payment hash
1038
1040
open_channel_tlvs ['channel_opening_fee' ] = {
1039
- 'channel_opening_fee' : opening_fee
1041
+ 'channel_opening_fee' : opening_fee_msat
1040
1042
}
1041
1043
# for the first commitment transaction
1042
1044
per_commitment_secret_first = get_per_commitment_secret_from_seed (
@@ -1269,10 +1271,13 @@ async def on_open_channel(self, payload):
1269
1271
# store the temp id now, so that it is recognized for e.g. 'error' messages
1270
1272
# TODO: this is never cleaned up; the dict grows unbounded until disconnect
1271
1273
self .temp_id_to_id [temp_chan_id ] = None
1272
- channel_opening_fee = open_channel_tlvs .get ('channel_opening_fee' ) if open_channel_tlvs else None
1273
- if channel_opening_fee :
1274
- # todo check that the fee is reasonable
1275
- pass
1274
+ channel_opening_fee_tlv = open_channel_tlvs .get ('channel_opening_fee' ) if open_channel_tlvs else None # type: Optional[dict]
1275
+ if channel_opening_fee_tlv :
1276
+ channel_opening_fee_msat = channel_opening_fee_tlv ['channel_opening_fee' ]
1277
+ # reject channel if fee is > 10% of funding amount (e.g. >40k sat on 400k incoming channel)
1278
+ # the opening fee depends on the LSP and mempool situation
1279
+ if channel_opening_fee_msat // 1000 > funding_sat * 0.1 :
1280
+ raise Exception (f"Channel opening fee is too expensive, rejecting channel" )
1276
1281
1277
1282
if self .use_anchors ():
1278
1283
multisig_funding_keypair = lnutil .derive_multisig_funding_key_if_they_opened (
@@ -1386,7 +1391,7 @@ async def on_open_channel(self, payload):
1386
1391
chan_dict ,
1387
1392
lnworker = self .lnworker ,
1388
1393
initial_feerate = feerate ,
1389
- opening_fee = channel_opening_fee ,
1394
+ opening_fee_tlv = channel_opening_fee_tlv ,
1390
1395
)
1391
1396
chan .storage ['init_timestamp' ] = int (time .time ())
1392
1397
if isinstance (self .transport , LNTransport ):
@@ -2244,7 +2249,7 @@ async def maybe_forward_trampoline(
2244
2249
2245
2250
# do we have a connection to the node?
2246
2251
next_peer = self .lnworker .peers .get (outgoing_node_id )
2247
- if next_peer and next_peer .accepts_zeroconf ():
2252
+ if next_peer and next_peer .accepts_zeroconf () and self . lnworker . features . supports ( LnFeatures . OPTION_ZEROCONF_OPT ) :
2248
2253
self .logger .info (f'JIT: found next_peer' )
2249
2254
for next_chan in next_peer .channels .values ():
2250
2255
if next_chan .can_pay (amt_to_forward ):
@@ -2356,8 +2361,8 @@ def check_accepted_htlc(
2356
2361
log_fail_reason (f"'total_msat' missing from onion" )
2357
2362
raise exc_incorrect_or_unknown_pd
2358
2363
2359
- if chan .opening_fee :
2360
- channel_opening_fee = chan .opening_fee ['channel_opening_fee' ]
2364
+ if chan .opening_fee_tlv :
2365
+ channel_opening_fee = chan .opening_fee_tlv ['channel_opening_fee' ]
2361
2366
total_msat -= channel_opening_fee
2362
2367
amt_to_forward -= channel_opening_fee
2363
2368
else :
@@ -2411,7 +2416,7 @@ def maybe_fulfill_htlc(
2411
2416
Return (preimage, (payment_key, callback)) with at most a single element not None.
2412
2417
"""
2413
2418
if not processed_onion .are_we_final :
2414
- if not self .lnworker .enable_htlc_forwarding :
2419
+ if not self .lnworker .enable_htlc_forwarding or already_forwarded :
2415
2420
return None , None
2416
2421
# use the htlc key if we are forwarding
2417
2422
payment_key = serialize_htlc_key (chan .get_scid_or_local_alias (), htlc .htlc_id )
@@ -2498,7 +2503,7 @@ def log_fail_reason(reason: str):
2498
2503
log_fail_reason (f"no payment_info found for RHASH { htlc .payment_hash .hex ()} " )
2499
2504
raise exc_incorrect_or_unknown_pd
2500
2505
2501
- preimage = self .lnworker .get_preimage (payment_hash )
2506
+ preimage = self .lnworker .get_preimage (payment_hash , only_settleable = True )
2502
2507
expected_payment_secrets = [self .lnworker .get_payment_secret (htlc .payment_hash )]
2503
2508
if preimage :
2504
2509
expected_payment_secrets .append (derive_payment_secret_from_payment_preimage (preimage )) # legacy secret for old invoices
@@ -2525,10 +2530,7 @@ def log_fail_reason(reason: str):
2525
2530
else :
2526
2531
return None , None
2527
2532
2528
- if payment_hash .hex () in self .lnworker .dont_settle_htlcs :
2529
- return None , None
2530
-
2531
- chan .opening_fee = None
2533
+ chan .opening_fee_tlv = None
2532
2534
self .logger .info (f"maybe_fulfill_htlc. will FULFILL HTLC: chan { chan .short_channel_id } . htlc={ str (htlc )} " )
2533
2535
return preimage , None
2534
2536
@@ -3120,7 +3122,7 @@ async def wrapped_callback():
3120
3122
# HTLC we are supposed to forward, and have already forwarded
3121
3123
# for final trampoline onions, forwarding failures are stored with forwarding_key (which is the inner key)
3122
3124
payment_key = forwarding_key
3123
- preimage = self .lnworker .get_preimage (payment_hash )
3125
+ preimage = self .lnworker .get_preimage (payment_hash , only_settleable = True )
3124
3126
error_bytes , error_reason = self .lnworker .get_forwarding_failure (payment_key )
3125
3127
if error_bytes :
3126
3128
return None , None , error_bytes
0 commit comments