@@ -242,7 +242,7 @@ type ShutdownResult = (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource
242
242
243
243
struct MsgHandleErrInternal {
244
244
err : msgs:: LightningError ,
245
- chan_id : Option < [ u8 ; 32 ] > , // If Some a channel of ours has been closed
245
+ chan_id : Option < ( [ u8 ; 32 ] , u64 ) > , // If Some a channel of ours has been closed
246
246
shutdown_finish : Option < ( ShutdownResult , Option < msgs:: ChannelUpdate > ) > ,
247
247
}
248
248
impl MsgHandleErrInternal {
@@ -278,7 +278,7 @@ impl MsgHandleErrInternal {
278
278
Self { err, chan_id : None , shutdown_finish : None }
279
279
}
280
280
#[ inline]
281
- fn from_finish_shutdown ( err : String , channel_id : [ u8 ; 32 ] , shutdown_res : ShutdownResult , channel_update : Option < msgs:: ChannelUpdate > ) -> Self {
281
+ fn from_finish_shutdown ( err : String , channel_id : [ u8 ; 32 ] , user_channel_id : u64 , shutdown_res : ShutdownResult , channel_update : Option < msgs:: ChannelUpdate > ) -> Self {
282
282
Self {
283
283
err : LightningError {
284
284
err : err. clone ( ) ,
@@ -289,7 +289,7 @@ impl MsgHandleErrInternal {
289
289
} ,
290
290
} ,
291
291
} ,
292
- chan_id : Some ( channel_id) ,
292
+ chan_id : Some ( ( channel_id, user_channel_id ) ) ,
293
293
shutdown_finish : Some ( ( shutdown_res, channel_update) ) ,
294
294
}
295
295
}
@@ -776,8 +776,8 @@ pub struct ChannelDetails {
776
776
///
777
777
/// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
778
778
pub unspendable_punishment_reserve : Option < u64 > ,
779
- /// The user_id passed in to create_channel, or 0 if the channel was inbound.
780
- pub user_id : u64 ,
779
+ /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
780
+ pub user_channel_id : u64 ,
781
781
/// The available outbound capacity for sending HTLCs to the remote peer. This does not include
782
782
/// any pending HTLCs which are not yet fully resolved (and, thus, who's balance is not
783
783
/// available for inclusion in new outbound HTLCs). This further does not include any pending
@@ -894,8 +894,11 @@ macro_rules! handle_error {
894
894
msg: update
895
895
} ) ;
896
896
}
897
- if let Some ( channel_id) = chan_id {
898
- $self. pending_events. lock( ) . unwrap( ) . push( events:: Event :: ChannelClosed { channel_id, reason: ClosureReason :: ProcessingError { err: err. err. clone( ) } } ) ;
897
+ if let Some ( ( channel_id, user_channel_id) ) = chan_id {
898
+ $self. pending_events. lock( ) . unwrap( ) . push( events:: Event :: ChannelClosed {
899
+ channel_id, user_channel_id,
900
+ reason: ClosureReason :: ProcessingError { err: err. err. clone( ) }
901
+ } ) ;
899
902
}
900
903
}
901
904
@@ -937,15 +940,17 @@ macro_rules! convert_chan_err {
937
940
$short_to_id. remove( & short_id) ;
938
941
}
939
942
let shutdown_res = $channel. force_shutdown( true ) ;
940
- ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update_for_broadcast( & $channel) . ok( ) ) )
943
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, $channel. get_user_id( ) ,
944
+ shutdown_res, $self. get_channel_update_for_broadcast( & $channel) . ok( ) ) )
941
945
} ,
942
946
ChannelError :: CloseDelayBroadcast ( msg) => {
943
947
log_error!( $self. logger, "Channel {} need to be shutdown but closing transactions not broadcast due to {}" , log_bytes!( $channel_id[ ..] ) , msg) ;
944
948
if let Some ( short_id) = $channel. get_short_channel_id( ) {
945
949
$short_to_id. remove( & short_id) ;
946
950
}
947
951
let shutdown_res = $channel. force_shutdown( false ) ;
948
- ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, shutdown_res, $self. get_channel_update_for_broadcast( & $channel) . ok( ) ) )
952
+ ( true , MsgHandleErrInternal :: from_finish_shutdown( msg, * $channel_id, $channel. get_user_id( ) ,
953
+ shutdown_res, $self. get_channel_update_for_broadcast( & $channel) . ok( ) ) )
949
954
}
950
955
}
951
956
}
@@ -1013,7 +1018,7 @@ macro_rules! handle_monitor_err {
1013
1018
// splitting hairs we'd prefer to claim payments that were to us, but we haven't
1014
1019
// given up the preimage yet, so might as well just wait until the payment is
1015
1020
// retried, avoiding the on-chain fees.
1016
- let res: Result <( ) , _> = Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" . to_owned( ) , * $chan_id,
1021
+ let res: Result <( ) , _> = Err ( MsgHandleErrInternal :: from_finish_shutdown( "ChannelMonitor storage failure" . to_owned( ) , * $chan_id, $chan . get_user_id ( ) ,
1017
1022
$chan. force_shutdown( true ) , $self. get_channel_update_for_broadcast( & $chan) . ok( ) ) ) ;
1018
1023
( res, true )
1019
1024
} ,
@@ -1267,22 +1272,31 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1267
1272
1268
1273
/// Creates a new outbound channel to the given remote node and with the given value.
1269
1274
///
1270
- /// user_id will be provided back as user_channel_id in FundingGenerationReady events to allow
1271
- /// tracking of which events correspond with which create_channel call. Note that the
1272
- /// user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for
1273
- /// user_id here. user_id has no meaning inside of LDK, it is simply copied to events and
1274
- /// otherwise ignored.
1275
- ///
1276
- /// If successful, will generate a SendOpenChannel message event, so you should probably poll
1277
- /// PeerManager::process_events afterwards.
1275
+ /// `user_channel_id` will be provided back as in
1276
+ /// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1277
+ /// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1278
+ /// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1279
+ /// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1280
+ /// ignored.
1278
1281
///
1279
- /// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
1280
- /// greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
1282
+ /// Raises [` APIError::APIMisuseError`] when ` channel_value_satoshis` > 2**24 or ` push_msat` is
1283
+ /// greater than ` channel_value_satoshis * 1k` or ` channel_value_satoshis < 1000` .
1281
1284
///
1282
1285
/// Note that we do not check if you are currently connected to the given peer. If no
1283
1286
/// connection is available, the outbound `open_channel` message may fail to send, resulting in
1284
- /// the channel eventually being silently forgotten.
1285
- pub fn create_channel ( & self , their_network_key : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , user_id : u64 , override_config : Option < UserConfig > ) -> Result < ( ) , APIError > {
1287
+ /// the channel eventually being silently forgotten (dropped on reload).
1288
+ ///
1289
+ /// Returns the new Channel's temporary `channel_id`. This ID will appear as
1290
+ /// [`Event::FundingGenerationReady::temporary_channel_id`] and in
1291
+ /// [`ChannelDetails::channel_id`] until after
1292
+ /// [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
1293
+ /// one derived from the funding transaction's TXID. If the counterparty rejects the channel
1294
+ /// immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
1295
+ ///
1296
+ /// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1297
+ /// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1298
+ /// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1299
+ pub fn create_channel ( & self , their_network_key : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , user_channel_id : u64 , override_config : Option < UserConfig > ) -> Result < [ u8 ; 32 ] , APIError > {
1286
1300
if channel_value_satoshis < 1000 {
1287
1301
return Err ( APIError :: APIMisuseError { err : format ! ( "Channel value must be at least 1000 satoshis. It was {}" , channel_value_satoshis) } ) ;
1288
1302
}
@@ -1294,7 +1308,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1294
1308
let peer_state = peer_state. lock ( ) . unwrap ( ) ;
1295
1309
let their_features = & peer_state. latest_features ;
1296
1310
let config = if override_config. is_some ( ) { override_config. as_ref ( ) . unwrap ( ) } else { & self . default_configuration } ;
1297
- Channel :: new_outbound ( & self . fee_estimator , & self . keys_manager , their_network_key, their_features, channel_value_satoshis, push_msat, user_id , config) ?
1311
+ Channel :: new_outbound ( & self . fee_estimator , & self . keys_manager , their_network_key, their_features, channel_value_satoshis, push_msat, user_channel_id , config) ?
1298
1312
} ,
1299
1313
None => return Err ( APIError :: ChannelUnavailable { err : format ! ( "Not connected to node: {}" , their_network_key) } ) ,
1300
1314
}
@@ -1305,8 +1319,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1305
1319
// We want to make sure the lock is actually acquired by PersistenceNotifierGuard.
1306
1320
debug_assert ! ( & self . total_consistency_lock. try_write( ) . is_err( ) ) ;
1307
1321
1322
+ let temporary_channel_id = channel. channel_id ( ) ;
1308
1323
let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1309
- match channel_state. by_id . entry ( channel . channel_id ( ) ) {
1324
+ match channel_state. by_id . entry ( temporary_channel_id ) {
1310
1325
hash_map:: Entry :: Occupied ( _) => {
1311
1326
if cfg ! ( feature = "fuzztarget" ) {
1312
1327
return Err ( APIError :: APIMisuseError { err : "Fuzzy bad RNG" . to_owned ( ) } ) ;
@@ -1320,7 +1335,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1320
1335
node_id : their_network_key,
1321
1336
msg : res,
1322
1337
} ) ;
1323
- Ok ( ( ) )
1338
+ Ok ( temporary_channel_id )
1324
1339
}
1325
1340
1326
1341
fn list_channels_with_filter < Fn : FnMut ( & ( & [ u8 ; 32 ] , & Channel < Signer > ) ) -> bool > ( & self , f : Fn ) -> Vec < ChannelDetails > {
@@ -1346,7 +1361,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1346
1361
unspendable_punishment_reserve : to_self_reserve_satoshis,
1347
1362
inbound_capacity_msat,
1348
1363
outbound_capacity_msat,
1349
- user_id : channel. get_user_id ( ) ,
1364
+ user_channel_id : channel. get_user_id ( ) ,
1350
1365
confirmations_required : channel. minimum_depth ( ) ,
1351
1366
force_close_spend_delay : channel. get_counterparty_selected_contest_delay ( ) ,
1352
1367
is_outbound : channel. is_outbound ( ) ,
@@ -1393,7 +1408,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1393
1408
} ,
1394
1409
None => { } ,
1395
1410
}
1396
- pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : closure_reason } ) ;
1411
+ pending_events_lock. push ( events:: Event :: ChannelClosed {
1412
+ channel_id : channel. channel_id ( ) ,
1413
+ user_channel_id : channel. get_user_id ( ) ,
1414
+ reason : closure_reason
1415
+ } ) ;
1397
1416
}
1398
1417
1399
1418
fn close_channel_internal ( & self , channel_id : & [ u8 ; 32 ] , target_feerate_sats_per_1000_weight : Option < u32 > ) -> Result < ( ) , APIError > {
@@ -2228,7 +2247,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2228
2247
2229
2248
( chan. get_outbound_funding_created ( funding_transaction, funding_txo, & self . logger )
2230
2249
. map_err ( |e| if let ChannelError :: Close ( msg) = e {
2231
- MsgHandleErrInternal :: from_finish_shutdown ( msg, chan. channel_id ( ) , chan. force_shutdown ( true ) , None )
2250
+ MsgHandleErrInternal :: from_finish_shutdown ( msg, chan. channel_id ( ) , chan. get_user_id ( ) , chan . force_shutdown ( true ) , None )
2232
2251
} else { unreachable ! ( ) ; } )
2233
2252
, chan)
2234
2253
} ,
@@ -2570,7 +2589,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2570
2589
channel_state. short_to_id . remove ( & short_id) ;
2571
2590
}
2572
2591
// ChannelClosed event is generated by handle_error for us.
2573
- Err ( MsgHandleErrInternal :: from_finish_shutdown ( msg, channel_id, channel. force_shutdown ( true ) , self . get_channel_update_for_broadcast ( & channel) . ok ( ) ) )
2592
+ Err ( MsgHandleErrInternal :: from_finish_shutdown ( msg, channel_id, channel. get_user_id ( ) , channel . force_shutdown ( true ) , self . get_channel_update_for_broadcast ( & channel) . ok ( ) ) )
2574
2593
} ,
2575
2594
ChannelError :: CloseDelayBroadcast ( _) => { panic ! ( "Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here" ) ; }
2576
2595
} ;
@@ -5609,6 +5628,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
5609
5628
monitor. broadcast_latest_holder_commitment_txn ( & args. tx_broadcaster , & args. logger ) ;
5610
5629
channel_closures. push ( events:: Event :: ChannelClosed {
5611
5630
channel_id : channel. channel_id ( ) ,
5631
+ user_channel_id : channel. get_user_id ( ) ,
5612
5632
reason : ClosureReason :: OutdatedChannelManager
5613
5633
} ) ;
5614
5634
} else {
0 commit comments