@@ -289,7 +289,7 @@ type ShutdownResult = (Option<(OutPoint, ChannelMonitorUpdate)>, Vec<(HTLCSource
289
289
290
290
struct MsgHandleErrInternal {
291
291
err : msgs:: LightningError ,
292
- chan_id : Option < ( [ u8 ; 32 ] , u64 ) > , // If Some a channel of ours has been closed
292
+ chan_id : Option < ( [ u8 ; 32 ] , u128 ) > , // If Some a channel of ours has been closed
293
293
shutdown_finish : Option < ( ShutdownResult , Option < msgs:: ChannelUpdate > ) > ,
294
294
}
295
295
impl MsgHandleErrInternal {
@@ -325,7 +325,7 @@ impl MsgHandleErrInternal {
325
325
Self { err, chan_id : None , shutdown_finish : None }
326
326
}
327
327
#[ inline]
328
- fn from_finish_shutdown ( err : String , channel_id : [ u8 ; 32 ] , user_channel_id : u64 , shutdown_res : ShutdownResult , channel_update : Option < msgs:: ChannelUpdate > ) -> Self {
328
+ fn from_finish_shutdown ( err : String , channel_id : [ u8 ; 32 ] , user_channel_id : u128 , shutdown_res : ShutdownResult , channel_update : Option < msgs:: ChannelUpdate > ) -> Self {
329
329
Self {
330
330
err : LightningError {
331
331
err : err. clone ( ) ,
@@ -1083,8 +1083,9 @@ pub struct ChannelDetails {
1083
1083
///
1084
1084
/// [`outbound_capacity_msat`]: ChannelDetails::outbound_capacity_msat
1085
1085
pub unspendable_punishment_reserve : Option < u64 > ,
1086
- /// The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
1087
- pub user_channel_id : u64 ,
1086
+ /// The `user_channel_id` passed in to create_channel, or a random value if the channel was
1087
+ /// inbound.
1088
+ pub user_channel_id : u128 ,
1088
1089
/// Our total balance. This is the amount we would get if we close the channel.
1089
1090
/// This value is not exact. Due to various in-flight changes and feerate changes, exactly this
1090
1091
/// amount is not likely to be recoverable on close.
@@ -1740,7 +1741,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
1740
1741
/// [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
1741
1742
/// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
1742
1743
/// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
1743
- 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 > {
1744
+ pub fn create_channel ( & self , their_network_key : PublicKey , channel_value_satoshis : u64 , push_msat : u64 , user_channel_id : u128 , override_config : Option < UserConfig > ) -> Result < [ u8 ; 32 ] , APIError > {
1744
1745
if channel_value_satoshis < 1000 {
1745
1746
return Err ( APIError :: APIMisuseError { err : format ! ( "Channel value must be at least 1000 satoshis. It was {}" , channel_value_satoshis) } ) ;
1746
1747
}
@@ -4529,7 +4530,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4529
4530
///
4530
4531
/// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
4531
4532
/// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
4532
- pub fn accept_inbound_channel ( & self , temporary_channel_id : & [ u8 ; 32 ] , counterparty_node_id : & PublicKey , user_channel_id : u64 ) -> Result < ( ) , APIError > {
4533
+ pub fn accept_inbound_channel ( & self , temporary_channel_id : & [ u8 ; 32 ] , counterparty_node_id : & PublicKey , user_channel_id : u128 ) -> Result < ( ) , APIError > {
4533
4534
self . do_accept_inbound_channel ( temporary_channel_id, counterparty_node_id, false , user_channel_id)
4534
4535
}
4535
4536
@@ -4551,11 +4552,11 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4551
4552
///
4552
4553
/// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
4553
4554
/// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
4554
- pub fn accept_inbound_channel_from_trusted_peer_0conf ( & self , temporary_channel_id : & [ u8 ; 32 ] , counterparty_node_id : & PublicKey , user_channel_id : u64 ) -> Result < ( ) , APIError > {
4555
+ pub fn accept_inbound_channel_from_trusted_peer_0conf ( & self , temporary_channel_id : & [ u8 ; 32 ] , counterparty_node_id : & PublicKey , user_channel_id : u128 ) -> Result < ( ) , APIError > {
4555
4556
self . do_accept_inbound_channel ( temporary_channel_id, counterparty_node_id, true , user_channel_id)
4556
4557
}
4557
4558
4558
- fn do_accept_inbound_channel ( & self , temporary_channel_id : & [ u8 ; 32 ] , counterparty_node_id : & PublicKey , accept_0conf : bool , user_channel_id : u64 ) -> Result < ( ) , APIError > {
4559
+ fn do_accept_inbound_channel ( & self , temporary_channel_id : & [ u8 ; 32 ] , counterparty_node_id : & PublicKey , accept_0conf : bool , user_channel_id : u128 ) -> Result < ( ) , APIError > {
4559
4560
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
4560
4561
4561
4562
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -4603,9 +4604,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
4603
4604
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "No inbound channels accepted" . to_owned ( ) , msg. temporary_channel_id . clone ( ) ) ) ;
4604
4605
}
4605
4606
4606
- let mut random_bytes = [ 0u8 ; 8 ] ;
4607
- random_bytes. copy_from_slice ( & self . keys_manager . get_secure_random_bytes ( ) [ ..8 ] ) ;
4608
- let user_channel_id = u64 :: from_be_bytes ( random_bytes) ;
4607
+ let mut random_bytes = [ 0u8 ; 16 ] ;
4608
+ random_bytes. copy_from_slice ( & self . keys_manager . get_secure_random_bytes ( ) [ ..16 ] ) ;
4609
+ let user_channel_id = u128 :: from_be_bytes ( random_bytes) ;
4609
4610
4610
4611
let outbound_scid_alias = self . create_and_insert_outbound_scid_alias ( ) ;
4611
4612
let mut channel = match Channel :: new_from_req ( & self . fee_estimator , & self . keys_manager ,
@@ -6407,33 +6408,108 @@ impl_writeable_tlv_based!(ChannelCounterparty, {
6407
6408
( 11 , outbound_htlc_maximum_msat, option) ,
6408
6409
} ) ;
6409
6410
6410
- impl_writeable_tlv_based ! ( ChannelDetails , {
6411
- ( 1 , inbound_scid_alias, option) ,
6412
- ( 2 , channel_id, required) ,
6413
- ( 3 , channel_type, option) ,
6414
- ( 4 , counterparty, required) ,
6415
- ( 5 , outbound_scid_alias, option) ,
6416
- ( 6 , funding_txo, option) ,
6417
- ( 7 , config, option) ,
6418
- ( 8 , short_channel_id, option) ,
6419
- ( 10 , channel_value_satoshis, required) ,
6420
- ( 12 , unspendable_punishment_reserve, option) ,
6421
- ( 14 , user_channel_id, required) ,
6422
- ( 16 , balance_msat, required) ,
6423
- ( 18 , outbound_capacity_msat, required) ,
6424
- // Note that by the time we get past the required read above, outbound_capacity_msat will be
6425
- // filled in, so we can safely unwrap it here.
6426
- ( 19 , next_outbound_htlc_limit_msat, ( default_value, outbound_capacity_msat. 0 . unwrap( ) as u64 ) ) ,
6427
- ( 20 , inbound_capacity_msat, required) ,
6428
- ( 22 , confirmations_required, option) ,
6429
- ( 24 , force_close_spend_delay, option) ,
6430
- ( 26 , is_outbound, required) ,
6431
- ( 28 , is_channel_ready, required) ,
6432
- ( 30 , is_usable, required) ,
6433
- ( 32 , is_public, required) ,
6434
- ( 33 , inbound_htlc_minimum_msat, option) ,
6435
- ( 35 , inbound_htlc_maximum_msat, option) ,
6436
- } ) ;
6411
+ impl Writeable for ChannelDetails {
6412
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
6413
+ // `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
6414
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
6415
+ let user_channel_id_low = self . user_channel_id as u64 ;
6416
+ let user_channel_id_high_opt = Some ( ( self . user_channel_id >> 64 ) as u64 ) ;
6417
+ write_tlv_fields ! ( writer, {
6418
+ ( 1 , self . inbound_scid_alias, option) ,
6419
+ ( 2 , self . channel_id, required) ,
6420
+ ( 3 , self . channel_type, option) ,
6421
+ ( 4 , self . counterparty, required) ,
6422
+ ( 5 , self . outbound_scid_alias, option) ,
6423
+ ( 6 , self . funding_txo, option) ,
6424
+ ( 7 , self . config, option) ,
6425
+ ( 8 , self . short_channel_id, option) ,
6426
+ ( 10 , self . channel_value_satoshis, required) ,
6427
+ ( 12 , self . unspendable_punishment_reserve, option) ,
6428
+ ( 14 , user_channel_id_low, required) ,
6429
+ ( 16 , self . balance_msat, required) ,
6430
+ ( 18 , self . outbound_capacity_msat, required) ,
6431
+ // Note that by the time we get past the required read above, outbound_capacity_msat will be
6432
+ // filled in, so we can safely unwrap it here.
6433
+ ( 19 , self . next_outbound_htlc_limit_msat, ( default_value, outbound_capacity_msat. 0 . unwrap( ) as u64 ) ) ,
6434
+ ( 20 , self . inbound_capacity_msat, required) ,
6435
+ ( 22 , self . confirmations_required, option) ,
6436
+ ( 24 , self . force_close_spend_delay, option) ,
6437
+ ( 26 , self . is_outbound, required) ,
6438
+ ( 28 , self . is_channel_ready, required) ,
6439
+ ( 30 , self . is_usable, required) ,
6440
+ ( 32 , self . is_public, required) ,
6441
+ ( 33 , self . inbound_htlc_minimum_msat, option) ,
6442
+ ( 35 , self . inbound_htlc_maximum_msat, option) ,
6443
+ ( 37 , user_channel_id_high_opt, option) ,
6444
+ } ) ;
6445
+ Ok ( ( ) )
6446
+ }
6447
+ }
6448
+
6449
+ impl Readable for ChannelDetails {
6450
+ fn read < R : Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
6451
+ init_and_read_tlv_fields ! ( reader, {
6452
+ ( 1 , inbound_scid_alias, option) ,
6453
+ ( 2 , channel_id, required) ,
6454
+ ( 3 , channel_type, option) ,
6455
+ ( 4 , counterparty, required) ,
6456
+ ( 5 , outbound_scid_alias, option) ,
6457
+ ( 6 , funding_txo, option) ,
6458
+ ( 7 , config, option) ,
6459
+ ( 8 , short_channel_id, option) ,
6460
+ ( 10 , channel_value_satoshis, required) ,
6461
+ ( 12 , unspendable_punishment_reserve, option) ,
6462
+ ( 14 , user_channel_id_low, required) ,
6463
+ ( 16 , balance_msat, required) ,
6464
+ ( 18 , outbound_capacity_msat, required) ,
6465
+ // Note that by the time we get past the required read above, outbound_capacity_msat will be
6466
+ // filled in, so we can safely unwrap it here.
6467
+ ( 19 , next_outbound_htlc_limit_msat, ( default_value, outbound_capacity_msat. 0 . unwrap( ) as u64 ) ) ,
6468
+ ( 20 , inbound_capacity_msat, required) ,
6469
+ ( 22 , confirmations_required, option) ,
6470
+ ( 24 , force_close_spend_delay, option) ,
6471
+ ( 26 , is_outbound, required) ,
6472
+ ( 28 , is_channel_ready, required) ,
6473
+ ( 30 , is_usable, required) ,
6474
+ ( 32 , is_public, required) ,
6475
+ ( 33 , inbound_htlc_minimum_msat, option) ,
6476
+ ( 35 , inbound_htlc_maximum_msat, option) ,
6477
+ ( 37 , user_channel_id_high_opt, option) ,
6478
+ } ) ;
6479
+
6480
+ // `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
6481
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values.
6482
+ let user_channel_id_low: u64 = user_channel_id_low. 0 . unwrap ( ) ;
6483
+ let user_channel_id = user_channel_id_low as u128 +
6484
+ ( ( user_channel_id_high_opt. unwrap_or ( 0 as u64 ) as u128 ) << 64 ) ;
6485
+
6486
+ Ok ( Self {
6487
+ inbound_scid_alias,
6488
+ channel_id : channel_id. 0 . unwrap ( ) ,
6489
+ channel_type,
6490
+ counterparty : counterparty. 0 . unwrap ( ) ,
6491
+ outbound_scid_alias,
6492
+ funding_txo,
6493
+ config,
6494
+ short_channel_id,
6495
+ channel_value_satoshis : channel_value_satoshis. 0 . unwrap ( ) ,
6496
+ unspendable_punishment_reserve,
6497
+ user_channel_id,
6498
+ balance_msat : balance_msat. 0 . unwrap ( ) ,
6499
+ outbound_capacity_msat : outbound_capacity_msat. 0 . unwrap ( ) ,
6500
+ next_outbound_htlc_limit_msat : next_outbound_htlc_limit_msat. 0 . unwrap ( ) ,
6501
+ inbound_capacity_msat : inbound_capacity_msat. 0 . unwrap ( ) ,
6502
+ confirmations_required,
6503
+ force_close_spend_delay,
6504
+ is_outbound : is_outbound. 0 . unwrap ( ) ,
6505
+ is_channel_ready : is_channel_ready. 0 . unwrap ( ) ,
6506
+ is_usable : is_usable. 0 . unwrap ( ) ,
6507
+ is_public : is_public. 0 . unwrap ( ) ,
6508
+ inbound_htlc_minimum_msat,
6509
+ inbound_htlc_maximum_msat,
6510
+ } )
6511
+ }
6512
+ }
6437
6513
6438
6514
impl_writeable_tlv_based ! ( PhantomRouteHints , {
6439
6515
( 2 , channels, vec_type) ,
0 commit comments