@@ -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
@@ -1026,10 +1028,10 @@ async def channel_establishment_flow(
1026
1028
open_channel_tlvs ['upfront_shutdown_script' ] = {
1027
1029
'shutdown_scriptpubkey' : local_config .upfront_shutdown_script
1028
1030
}
1029
- if opening_fee :
1031
+ if opening_fee_msat :
1030
1032
# todo: maybe add payment hash
1031
1033
open_channel_tlvs ['channel_opening_fee' ] = {
1032
- 'channel_opening_fee' : opening_fee
1034
+ 'channel_opening_fee' : opening_fee_msat
1033
1035
}
1034
1036
# for the first commitment transaction
1035
1037
per_commitment_secret_first = get_per_commitment_secret_from_seed (
@@ -1258,10 +1260,13 @@ async def on_open_channel(self, payload):
1258
1260
# store the temp id now, so that it is recognized for e.g. 'error' messages
1259
1261
# TODO: this is never cleaned up; the dict grows unbounded until disconnect
1260
1262
self .temp_id_to_id [temp_chan_id ] = None
1261
- channel_opening_fee = open_channel_tlvs .get ('channel_opening_fee' ) if open_channel_tlvs else None
1262
- if channel_opening_fee :
1263
- # todo check that the fee is reasonable
1264
- pass
1263
+ channel_opening_fee_tlv = open_channel_tlvs .get ('channel_opening_fee' ) if open_channel_tlvs else None # type: Optional[dict]
1264
+ if channel_opening_fee_tlv :
1265
+ channel_opening_fee_msat = channel_opening_fee_tlv ['channel_opening_fee' ]
1266
+ # reject channel if fee is > 10% of funding amount (e.g. >40k sat on 400k incoming channel)
1267
+ # the opening fee depends on the LSP and mempool situation
1268
+ if channel_opening_fee_msat // 1000 > funding_sat * 0.1 :
1269
+ raise Exception (f"Channel opening fee is too expensive, rejecting channel" )
1265
1270
1266
1271
if self .use_anchors ():
1267
1272
multisig_funding_keypair = lnutil .derive_multisig_funding_key_if_they_opened (
@@ -1375,7 +1380,7 @@ async def on_open_channel(self, payload):
1375
1380
chan_dict ,
1376
1381
lnworker = self .lnworker ,
1377
1382
initial_feerate = feerate ,
1378
- opening_fee = channel_opening_fee ,
1383
+ opening_fee_tlv = channel_opening_fee_tlv ,
1379
1384
)
1380
1385
chan .storage ['init_timestamp' ] = int (time .time ())
1381
1386
if isinstance (self .transport , LNTransport ):
@@ -2221,7 +2226,7 @@ async def maybe_forward_trampoline(
2221
2226
2222
2227
# do we have a connection to the node?
2223
2228
next_peer = self .lnworker .peers .get (outgoing_node_id )
2224
- if next_peer and next_peer .accepts_zeroconf ():
2229
+ if next_peer and next_peer .accepts_zeroconf () and self . lnworker . features . supports ( LnFeatures . OPTION_ZEROCONF_OPT ) :
2225
2230
self .logger .info (f'JIT: found next_peer' )
2226
2231
for next_chan in next_peer .channels .values ():
2227
2232
if next_chan .can_pay (amt_to_forward ):
@@ -2333,8 +2338,8 @@ def check_accepted_htlc(
2333
2338
log_fail_reason (f"'total_msat' missing from onion" )
2334
2339
raise exc_incorrect_or_unknown_pd
2335
2340
2336
- if chan .opening_fee :
2337
- channel_opening_fee = chan .opening_fee ['channel_opening_fee' ]
2341
+ if chan .opening_fee_tlv :
2342
+ channel_opening_fee = chan .opening_fee_tlv ['channel_opening_fee' ]
2338
2343
total_msat -= channel_opening_fee
2339
2344
amt_to_forward -= channel_opening_fee
2340
2345
else :
@@ -2388,7 +2393,7 @@ def maybe_fulfill_htlc(
2388
2393
Return (preimage, (payment_key, callback)) with at most a single element not None.
2389
2394
"""
2390
2395
if not processed_onion .are_we_final :
2391
- if not self .lnworker .enable_htlc_forwarding :
2396
+ if not self .lnworker .enable_htlc_forwarding or already_forwarded :
2392
2397
return None , None
2393
2398
# use the htlc key if we are forwarding
2394
2399
payment_key = serialize_htlc_key (chan .get_scid_or_local_alias (), htlc .htlc_id )
@@ -2475,7 +2480,7 @@ def log_fail_reason(reason: str):
2475
2480
log_fail_reason (f"no payment_info found for RHASH { htlc .payment_hash .hex ()} " )
2476
2481
raise exc_incorrect_or_unknown_pd
2477
2482
2478
- preimage = self .lnworker .get_preimage (payment_hash )
2483
+ preimage = self .lnworker .get_preimage (payment_hash , only_settleable = True )
2479
2484
expected_payment_secrets = [self .lnworker .get_payment_secret (htlc .payment_hash )]
2480
2485
if preimage :
2481
2486
expected_payment_secrets .append (derive_payment_secret_from_payment_preimage (preimage )) # legacy secret for old invoices
@@ -2502,10 +2507,7 @@ def log_fail_reason(reason: str):
2502
2507
else :
2503
2508
return None , None
2504
2509
2505
- if payment_hash .hex () in self .lnworker .dont_settle_htlcs :
2506
- return None , None
2507
-
2508
- chan .opening_fee = None
2510
+ chan .opening_fee_tlv = None
2509
2511
self .logger .info (f"maybe_fulfill_htlc. will FULFILL HTLC: chan { chan .short_channel_id } . htlc={ str (htlc )} " )
2510
2512
return preimage , None
2511
2513
@@ -3093,7 +3095,7 @@ async def wrapped_callback():
3093
3095
# HTLC we are supposed to forward, and have already forwarded
3094
3096
# for final trampoline onions, forwarding failures are stored with forwarding_key (which is the inner key)
3095
3097
payment_key = forwarding_key
3096
- preimage = self .lnworker .get_preimage (payment_hash )
3098
+ preimage = self .lnworker .get_preimage (payment_hash , only_settleable = True )
3097
3099
error_bytes , error_reason = self .lnworker .get_forwarding_failure (payment_key )
3098
3100
if error_bytes :
3099
3101
return None , None , error_bytes
0 commit comments