@@ -1316,9 +1316,12 @@ async def on_open_channel(self, payload):
13161316 # store the temp id now, so that it is recognized for e.g. 'error' messages
13171317 self .temp_id_to_id [temp_chan_id ] = None
13181318 self ._cleanup_temp_channelids ()
1319- channel_opening_fee = open_channel_tlvs .get ('channel_opening_fee' ) if open_channel_tlvs else None
1319+ channel_opening_fee_tlv = open_channel_tlvs .get ('channel_opening_fee' , {})
1320+ channel_opening_fee = channel_opening_fee_tlv .get ('channel_opening_fee' )
13201321 if channel_opening_fee :
13211322 # todo check that the fee is reasonable
1323+ assert is_zeroconf
1324+ self .logger .info (f"just-in-time opening fee: { channel_opening_fee } msat" )
13221325 pass
13231326
13241327 if self .use_anchors ():
@@ -1433,7 +1436,7 @@ async def on_open_channel(self, payload):
14331436 chan_dict ,
14341437 lnworker = self .lnworker ,
14351438 initial_feerate = feerate ,
1436- opening_fee = channel_opening_fee ,
1439+ jit_opening_fee = channel_opening_fee ,
14371440 )
14381441 chan .storage ['init_timestamp' ] = int (time .time ())
14391442 if isinstance (self .transport , LNTransport ):
@@ -2115,8 +2118,8 @@ def _check_accepted_final_htlc(
21152118 log_fail_reason (f"'total_msat' missing from onion" )
21162119 raise exc_incorrect_or_unknown_pd
21172120
2118- if chan .opening_fee :
2119- channel_opening_fee = chan .opening_fee [ 'channel_opening_fee' ] # type: int
2121+ if chan .jit_opening_fee :
2122+ channel_opening_fee = chan .jit_opening_fee
21202123 total_msat -= channel_opening_fee
21212124 amt_to_forward -= channel_opening_fee
21222125 else :
@@ -2281,7 +2284,7 @@ def _fulfill_htlc_set(self, payment_key: str, preimage: bytes):
22812284 self ._fulfill_htlc (chan , htlc_id , preimage )
22822285 htlc_set .htlcs .remove (mpp_htlc )
22832286 # reset just-in-time opening fee of channel
2284- chan .opening_fee = None
2287+ chan .jit_opening_fee = None
22852288
22862289 def _fulfill_htlc (self , chan : Channel , htlc_id : int , preimage : bytes ):
22872290 assert chan .hm .is_htlc_irrevocably_added_yet (htlc_proposer = REMOTE , htlc_id = htlc_id )
@@ -3070,6 +3073,10 @@ def _check_unfulfilled_htlc_set(
30703073 return OnionFailureCode .MPP_TIMEOUT , None , None
30713074
30723075 if mpp_set .resolution == RecvMPPResolution .WAITING :
3076+ # calculate the sum of just in time channel opening fees
3077+ htlc_channels = [self .lnworker .get_channel_by_short_id (scid ) for scid in set (h .scid for h in mpp_set .htlcs )]
3078+ jit_opening_fees_msat = sum ((c .jit_opening_fee or 0 ) for c in htlc_channels )
3079+
30733080 # check if set is first stage multi-trampoline payment to us
30743081 # first stage trampoline payment:
30753082 # is a trampoline payment + we_are_final + payment key is derived from outer onion's payment secret
@@ -3088,14 +3095,14 @@ def _check_unfulfilled_htlc_set(
30883095
30893096 if trampoline_payment_key and trampoline_payment_key != payment_key :
30903097 # first stage of trampoline payment, the first stage must never get set COMPLETE
3091- if amount_msat >= any_trampoline_onion .amt_to_forward :
3098+ if amount_msat >= ( any_trampoline_onion .amt_to_forward - jit_opening_fees_msat ) :
30923099 # setting the parent key will mark the htlcs to be moved to the parent set
30933100 self .logger .debug (f"trampoline part complete. { len (mpp_set .htlcs )= } , "
30943101 f"{ amount_msat = } . setting parent key: { trampoline_payment_key } " )
30953102 self .lnworker .received_mpp_htlcs [payment_key ] = mpp_set ._replace (
30963103 parent_set_key = trampoline_payment_key ,
30973104 )
3098- elif amount_msat >= total_msat :
3105+ elif amount_msat >= ( total_msat - jit_opening_fees_msat ) :
30993106 # set mpp_set as completed as we have received the full total_msat
31003107 mpp_set = self .lnworker .set_mpp_resolution (
31013108 payment_key = payment_key ,
0 commit comments