@@ -142,6 +142,7 @@ pub(super) struct PendingAddHTLCInfo {
142
142
prev_short_channel_id : u64 ,
143
143
prev_htlc_id : u64 ,
144
144
prev_funding_outpoint : OutPoint ,
145
+ prev_user_channel_id : u128 ,
145
146
}
146
147
147
148
pub ( super ) enum HTLCForwardInfo {
@@ -1145,6 +1146,10 @@ pub struct ChannelDetails {
1145
1146
/// [`ChannelHandshakeConfig::minimum_depth`]: crate::util::config::ChannelHandshakeConfig::minimum_depth
1146
1147
/// [`ChannelHandshakeLimits::max_minimum_depth`]: crate::util::config::ChannelHandshakeLimits::max_minimum_depth
1147
1148
pub confirmations_required : Option < u32 > ,
1149
+ /// The current number of confirmations on the funding transaction.
1150
+ ///
1151
+ /// This value will be `None` for objects serialized with LDK versions prior to 0.0.113.
1152
+ pub confirmations : Option < u32 > ,
1148
1153
/// The number of blocks (after our commitment transaction confirms) that we will need to wait
1149
1154
/// until we can claim our funds after we force-close the channel. During this time our
1150
1155
/// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty
@@ -1693,6 +1698,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1693
1698
let mut res = Vec :: new ( ) ;
1694
1699
{
1695
1700
let channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1701
+ let best_block_height = self . best_block . read ( ) . unwrap ( ) . height ( ) ;
1696
1702
res. reserve ( channel_state. by_id . len ( ) ) ;
1697
1703
for ( channel_id, channel) in channel_state. by_id . iter ( ) . filter ( f) {
1698
1704
let balance = channel. get_available_balances ( ) ;
@@ -1729,6 +1735,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1729
1735
next_outbound_htlc_limit_msat : balance. next_outbound_htlc_limit_msat ,
1730
1736
user_channel_id : channel. get_user_id ( ) ,
1731
1737
confirmations_required : channel. minimum_depth ( ) ,
1738
+ confirmations : Some ( channel. get_funding_tx_confirmations ( best_block_height) ) ,
1732
1739
force_close_spend_delay : channel. get_counterparty_selected_contest_delay ( ) ,
1733
1740
is_outbound : channel. is_outbound ( ) ,
1734
1741
is_channel_ready : channel. is_usable ( ) ,
@@ -3025,7 +3032,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3025
3032
3026
3033
let mut new_events = Vec :: new ( ) ;
3027
3034
let mut failed_forwards = Vec :: new ( ) ;
3028
- let mut phantom_receives: Vec < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) > = Vec :: new ( ) ;
3035
+ let mut phantom_receives: Vec < ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) > = Vec :: new ( ) ;
3029
3036
let mut handle_errors = Vec :: new ( ) ;
3030
3037
{
3031
3038
let mut forward_htlcs = HashMap :: new ( ) ;
@@ -3038,7 +3045,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3038
3045
for forward_info in pending_forwards. drain( ..) {
3039
3046
match forward_info {
3040
3047
HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3041
- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint,
3048
+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id ,
3042
3049
forward_info: PendingHTLCInfo {
3043
3050
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat,
3044
3051
outgoing_cltv_value, incoming_amt_msat: _
@@ -3104,7 +3111,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3104
3111
match next_hop {
3105
3112
onion_utils:: Hop :: Receive ( hop_data) => {
3106
3113
match self . construct_recv_pending_htlc_info( hop_data, incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value, Some ( phantom_shared_secret) ) {
3107
- Ok ( info) => phantom_receives. push( ( prev_short_channel_id, prev_funding_outpoint, vec![ ( info, prev_htlc_id) ] ) ) ,
3114
+ Ok ( info) => phantom_receives. push( ( prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id , vec![ ( info, prev_htlc_id) ] ) ) ,
3108
3115
Err ( ReceiveError { err_code, err_data, msg } ) => failed_payment!( msg, err_code, err_data, Some ( phantom_shared_secret) )
3109
3116
}
3110
3117
} ,
@@ -3147,7 +3154,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3147
3154
for forward_info in pending_forwards. drain ( ..) {
3148
3155
match forward_info {
3149
3156
HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3150
- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint ,
3157
+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id : _ ,
3151
3158
forward_info : PendingHTLCInfo {
3152
3159
incoming_shared_secret, payment_hash, outgoing_amt_msat, outgoing_cltv_value,
3153
3160
routing : PendingHTLCRouting :: Forward { onion_packet, .. } , incoming_amt_msat : _,
@@ -3274,7 +3281,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3274
3281
for forward_info in pending_forwards. drain ( ..) {
3275
3282
match forward_info {
3276
3283
HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
3277
- prev_short_channel_id, prev_htlc_id, prev_funding_outpoint,
3284
+ prev_short_channel_id, prev_htlc_id, prev_funding_outpoint, prev_user_channel_id ,
3278
3285
forward_info : PendingHTLCInfo {
3279
3286
routing, incoming_shared_secret, payment_hash, outgoing_amt_msat, ..
3280
3287
}
@@ -3369,12 +3376,15 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3369
3376
log_bytes!( payment_hash. 0 ) , total_value, $payment_data. total_msat) ;
3370
3377
fail_htlc!( claimable_htlc, payment_hash) ;
3371
3378
} else if total_value == $payment_data. total_msat {
3379
+ let prev_channel_id = prev_funding_outpoint. to_channel_id( ) ;
3372
3380
htlcs. push( claimable_htlc) ;
3373
3381
new_events. push( events:: Event :: PaymentReceived {
3374
3382
receiver_node_id: Some ( receiver_node_id) ,
3375
3383
payment_hash,
3376
3384
purpose: purpose( ) ,
3377
3385
amount_msat: total_value,
3386
+ via_channel_id: Some ( prev_channel_id) ,
3387
+ via_user_channel_id: Some ( prev_user_channel_id) ,
3378
3388
} ) ;
3379
3389
payment_received_generated = true ;
3380
3390
} else {
@@ -3413,11 +3423,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
3413
3423
hash_map:: Entry :: Vacant ( e) => {
3414
3424
let purpose = events:: PaymentPurpose :: SpontaneousPayment ( preimage) ;
3415
3425
e. insert ( ( purpose. clone ( ) , vec ! [ claimable_htlc] ) ) ;
3426
+ let prev_channel_id = prev_funding_outpoint. to_channel_id ( ) ;
3416
3427
new_events. push ( events:: Event :: PaymentReceived {
3417
3428
receiver_node_id : Some ( receiver_node_id) ,
3418
3429
payment_hash,
3419
3430
amount_msat : outgoing_amt_msat,
3420
3431
purpose,
3432
+ via_channel_id : Some ( prev_channel_id) ,
3433
+ via_user_channel_id : Some ( prev_user_channel_id) ,
3421
3434
} ) ;
3422
3435
} ,
3423
3436
hash_map:: Entry :: Occupied ( _) => {
@@ -4389,13 +4402,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4389
4402
commitment_update : Option < msgs:: CommitmentUpdate > , order : RAACommitmentOrder ,
4390
4403
pending_forwards : Vec < ( PendingHTLCInfo , u64 ) > , funding_broadcastable : Option < Transaction > ,
4391
4404
channel_ready : Option < msgs:: ChannelReady > , announcement_sigs : Option < msgs:: AnnouncementSignatures > )
4392
- -> Option < ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) > {
4405
+ -> Option < ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) > {
4393
4406
let mut htlc_forwards = None ;
4394
4407
4395
4408
let counterparty_node_id = channel. get_counterparty_node_id ( ) ;
4396
4409
if !pending_forwards. is_empty ( ) {
4397
4410
htlc_forwards = Some ( ( channel. get_short_channel_id ( ) . unwrap_or ( channel. outbound_scid_alias ( ) ) ,
4398
- channel. get_funding_txo ( ) . unwrap ( ) , pending_forwards) ) ;
4411
+ channel. get_funding_txo ( ) . unwrap ( ) , channel . get_user_id ( ) , pending_forwards) ) ;
4399
4412
}
4400
4413
4401
4414
if let Some ( msg) = channel_ready {
@@ -5056,8 +5069,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5056
5069
}
5057
5070
5058
5071
#[ inline]
5059
- fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
5060
- for & mut ( prev_short_channel_id, prev_funding_outpoint, ref mut pending_forwards) in per_source_pending_forwards {
5072
+ fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
5073
+ for & mut ( prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id , ref mut pending_forwards) in per_source_pending_forwards {
5061
5074
let mut forward_event = None ;
5062
5075
if !pending_forwards. is_empty ( ) {
5063
5076
let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
@@ -5072,11 +5085,11 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5072
5085
} ) {
5073
5086
hash_map:: Entry :: Occupied ( mut entry) => {
5074
5087
entry. get_mut ( ) . push ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
5075
- prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, forward_info } ) ) ;
5088
+ prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id , forward_info } ) ) ;
5076
5089
} ,
5077
5090
hash_map:: Entry :: Vacant ( entry) => {
5078
5091
entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
5079
- prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, forward_info } ) ) ) ;
5092
+ prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id , forward_info } ) ) ) ;
5080
5093
}
5081
5094
}
5082
5095
}
@@ -5135,21 +5148,22 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
5135
5148
raa_updates. finalized_claimed_htlcs ,
5136
5149
chan. get ( ) . get_short_channel_id ( )
5137
5150
. unwrap_or ( chan. get ( ) . outbound_scid_alias ( ) ) ,
5138
- chan. get ( ) . get_funding_txo ( ) . unwrap ( ) ) )
5151
+ chan. get ( ) . get_funding_txo ( ) . unwrap ( ) ,
5152
+ chan. get ( ) . get_user_id ( ) ) )
5139
5153
} ,
5140
5154
hash_map:: Entry :: Vacant ( _) => break Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
5141
5155
}
5142
5156
} ;
5143
5157
self . fail_holding_cell_htlcs ( htlcs_to_fail, msg. channel_id , counterparty_node_id) ;
5144
5158
match res {
5145
5159
Ok ( ( pending_forwards, mut pending_failures, finalized_claim_htlcs,
5146
- short_channel_id, channel_outpoint) ) =>
5160
+ short_channel_id, channel_outpoint, user_channel_id ) ) =>
5147
5161
{
5148
5162
for failure in pending_failures. drain ( ..) {
5149
5163
let receiver = HTLCDestination :: NextHopChannel { node_id : Some ( * counterparty_node_id) , channel_id : channel_outpoint. to_channel_id ( ) } ;
5150
5164
self . fail_htlc_backwards_internal ( failure. 0 , & failure. 1 , failure. 2 , receiver) ;
5151
5165
}
5152
- self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, pending_forwards) ] ) ;
5166
+ self . forward_htlcs ( & mut [ ( short_channel_id, channel_outpoint, user_channel_id , pending_forwards) ] ) ;
5153
5167
self . finalize_claims ( finalized_claim_htlcs) ;
5154
5168
Ok ( ( ) )
5155
5169
} ,
@@ -6127,7 +6141,7 @@ where
6127
6141
}
6128
6142
}
6129
6143
6130
- impl < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
6144
+ impl < M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
6131
6145
ChannelMessageHandler for ChannelManager < M , T , K , F , L >
6132
6146
where M :: Target : chain:: Watch < <K :: Target as KeysInterface >:: Signer > ,
6133
6147
T :: Target : BroadcasterInterface ,
@@ -6459,6 +6473,7 @@ impl Writeable for ChannelDetails {
6459
6473
( 6 , self . funding_txo, option) ,
6460
6474
( 7 , self . config, option) ,
6461
6475
( 8 , self . short_channel_id, option) ,
6476
+ ( 9 , self . confirmations, option) ,
6462
6477
( 10 , self . channel_value_satoshis, required) ,
6463
6478
( 12 , self . unspendable_punishment_reserve, option) ,
6464
6479
( 14 , user_channel_id_low, required) ,
@@ -6493,6 +6508,7 @@ impl Readable for ChannelDetails {
6493
6508
( 6 , funding_txo, option) ,
6494
6509
( 7 , config, option) ,
6495
6510
( 8 , short_channel_id, option) ,
6511
+ ( 9 , confirmations, option) ,
6496
6512
( 10 , channel_value_satoshis, required) ,
6497
6513
( 12 , unspendable_punishment_reserve, option) ,
6498
6514
( 14 , user_channel_id_low, required) ,
@@ -6536,6 +6552,7 @@ impl Readable for ChannelDetails {
6536
6552
next_outbound_htlc_limit_msat : next_outbound_htlc_limit_msat. 0 . unwrap ( ) ,
6537
6553
inbound_capacity_msat : inbound_capacity_msat. 0 . unwrap ( ) ,
6538
6554
confirmations_required,
6555
+ confirmations,
6539
6556
force_close_spend_delay,
6540
6557
is_outbound : is_outbound. 0 . unwrap ( ) ,
6541
6558
is_channel_ready : is_channel_ready. 0 . unwrap ( ) ,
@@ -6799,6 +6816,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReason,
6799
6816
6800
6817
impl_writeable_tlv_based ! ( PendingAddHTLCInfo , {
6801
6818
( 0 , forward_info, required) ,
6819
+ ( 1 , prev_user_channel_id, ( default_value, 0 ) ) ,
6802
6820
( 2 , prev_short_channel_id, required) ,
6803
6821
( 4 , prev_htlc_id, required) ,
6804
6822
( 6 , prev_funding_outpoint, required) ,
0 commit comments