@@ -509,7 +509,7 @@ pub(super) struct Channel<Signer: Sign> {
509
509
510
510
inbound_handshake_limits_override : Option < ChannelHandshakeLimits > ,
511
511
512
- user_id : u64 ,
512
+ user_id : u128 ,
513
513
514
514
channel_id : [ u8 ; 32 ] ,
515
515
channel_state : u32 ,
@@ -899,7 +899,7 @@ impl<Signer: Sign> Channel<Signer> {
899
899
// Constructors:
900
900
pub fn new_outbound < K : Deref , F : Deref > (
901
901
fee_estimator : & LowerBoundedFeeEstimator < F > , keys_provider : & K , counterparty_node_id : PublicKey , their_features : & InitFeatures ,
902
- channel_value_satoshis : u64 , push_msat : u64 , user_id : u64 , config : & UserConfig , current_chain_height : u32 ,
902
+ channel_value_satoshis : u64 , push_msat : u64 , user_id : u128 , config : & UserConfig , current_chain_height : u32 ,
903
903
outbound_scid_alias : u64
904
904
) -> Result < Channel < Signer > , APIError >
905
905
where K :: Target : KeysInterface < Signer = Signer > ,
@@ -1097,7 +1097,7 @@ impl<Signer: Sign> Channel<Signer> {
1097
1097
/// Assumes chain_hash has already been checked and corresponds with what we expect!
1098
1098
pub fn new_from_req < K : Deref , F : Deref , L : Deref > (
1099
1099
fee_estimator : & LowerBoundedFeeEstimator < F > , keys_provider : & K , counterparty_node_id : PublicKey , their_features : & InitFeatures ,
1100
- msg : & msgs:: OpenChannel , user_id : u64 , config : & UserConfig , current_chain_height : u32 , logger : & L ,
1100
+ msg : & msgs:: OpenChannel , user_id : u128 , config : & UserConfig , current_chain_height : u32 , logger : & L ,
1101
1101
outbound_scid_alias : u64
1102
1102
) -> Result < Channel < Signer > , ChannelError >
1103
1103
where K :: Target : KeysInterface < Signer = Signer > ,
@@ -4475,7 +4475,7 @@ impl<Signer: Sign> Channel<Signer> {
4475
4475
4476
4476
/// Gets the "user_id" value passed into the construction of this channel. It has no special
4477
4477
/// meaning and exists only to allow users to have a persistent identifier of a channel.
4478
- pub fn get_user_id ( & self ) -> u64 {
4478
+ pub fn get_user_id ( & self ) -> u128 {
4479
4479
self . user_id
4480
4480
}
4481
4481
@@ -5156,7 +5156,7 @@ impl<Signer: Sign> Channel<Signer> {
5156
5156
/// should be sent back to the counterparty node.
5157
5157
///
5158
5158
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
5159
- pub fn accept_inbound_channel ( & mut self , user_id : u64 ) -> msgs:: AcceptChannel {
5159
+ pub fn accept_inbound_channel ( & mut self , user_id : u128 ) -> msgs:: AcceptChannel {
5160
5160
if self . is_outbound ( ) {
5161
5161
panic ! ( "Tried to send accept_channel for an outbound channel?" ) ;
5162
5162
}
@@ -5985,7 +5985,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
5985
5985
5986
5986
write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
5987
5987
5988
- self . user_id . write ( writer) ?;
5988
+ // `user_id` used to be a single u64 value. In order to remain backwards compatible with
5989
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. We write
5990
+ // the low bytes now and the optional high bytes later.
5991
+ let mut low_bytes = [ 0u8 ; 8 ] ;
5992
+ low_bytes. copy_from_slice ( & self . user_id . to_be_bytes ( ) [ 8 ..16 ] ) ;
5993
+ let user_id_low = u64:: from_be_bytes ( low_bytes) ;
5994
+ user_id_low. write ( writer) ?;
5989
5995
5990
5996
// Version 1 deserializers expected to read parts of the config object here. Version 2
5991
5997
// deserializers (0.0.99) now read config through TLVs, and as we now require them for
@@ -6230,6 +6236,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
6230
6236
if self . holder_max_htlc_value_in_flight_msat != Self :: get_holder_max_htlc_value_in_flight_msat ( self . channel_value_satoshis , & old_max_in_flight_percent_config)
6231
6237
{ Some ( self . holder_max_htlc_value_in_flight_msat ) } else { None } ;
6232
6238
6239
+ // `user_id` used to be a single u64 value. In order to remain backwards compatible with
6240
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
6241
+ // we write the high bytes as an option here.
6242
+ let mut high_bytes = [ 0u8 ; 8 ] ;
6243
+ high_bytes. copy_from_slice ( & self . user_id . to_be_bytes ( ) [ 0 ..8 ] ) ;
6244
+ let user_id_high_opt = Some ( u64:: from_be_bytes ( high_bytes) ) ;
6245
+
6233
6246
write_tlv_fields ! ( writer, {
6234
6247
( 0 , self . announcement_sigs, option) ,
6235
6248
// minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -6252,6 +6265,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
6252
6265
( 17 , self . announcement_sigs_state, required) ,
6253
6266
( 19 , self . latest_inbound_scid_alias, option) ,
6254
6267
( 21 , self . outbound_scid_alias, required) ,
6268
+ ( 23 , user_id_high_opt, option) ,
6255
6269
} ) ;
6256
6270
6257
6271
Ok ( ( ) )
@@ -6265,7 +6279,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6265
6279
let ( keys_source, serialized_height) = args;
6266
6280
let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
6267
6281
6268
- let user_id = Readable :: read ( reader) ?;
6282
+ // `user_id` used to be a single u64 value. In order to remain backwards compatible with
6283
+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. We read
6284
+ // the low bytes now and the high bytes later.
6285
+ let user_id_low: u64 = Readable :: read ( reader) ?;
6269
6286
6270
6287
let mut config = Some ( LegacyChannelConfig :: default ( ) ) ;
6271
6288
if ver == 1 {
@@ -6510,6 +6527,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6510
6527
let mut latest_inbound_scid_alias = None ;
6511
6528
let mut outbound_scid_alias = None ;
6512
6529
6530
+ let mut user_id_high_opt: Option < u64 > = None ;
6531
+
6513
6532
read_tlv_fields ! ( reader, {
6514
6533
( 0 , announcement_sigs, option) ,
6515
6534
( 1 , minimum_depth, option) ,
@@ -6526,6 +6545,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6526
6545
( 17 , announcement_sigs_state, option) ,
6527
6546
( 19 , latest_inbound_scid_alias, option) ,
6528
6547
( 21 , outbound_scid_alias, option) ,
6548
+ ( 23 , user_id_high_opt, option) ,
6529
6549
} ) ;
6530
6550
6531
6551
if let Some ( preimages) = preimages_opt {
@@ -6562,6 +6582,16 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
6562
6582
let mut secp_ctx = Secp256k1 :: new ( ) ;
6563
6583
secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
6564
6584
6585
+ // `user_id` used to be a single u64 value. In order to remain backwards
6586
+ // compatible with versions prior to 0.0.113, the u128 is serialized as two
6587
+ // separate u64 values.
6588
+ let mut user_id_bytes = [ 0u8 ; 16 ] ;
6589
+ user_id_bytes[ 8 ..16 ] . copy_from_slice ( & user_id_low. to_be_bytes ( ) ) ;
6590
+ if let Some ( high_bytes) = user_id_high_opt {
6591
+ user_id_bytes[ 0 ..8 ] . copy_from_slice ( & high_bytes. to_be_bytes ( ) ) ;
6592
+ }
6593
+ let user_id = u128:: from_be_bytes ( user_id_bytes) ;
6594
+
6565
6595
Ok ( Channel {
6566
6596
user_id,
6567
6597
0 commit comments