@@ -509,7 +509,7 @@ pub(super) struct Channel<Signer: Sign> {
509509
510510 inbound_handshake_limits_override : Option < ChannelHandshakeLimits > ,
511511
512- user_id : u64 ,
512+ user_id : u128 ,
513513
514514 channel_id : [ u8 ; 32 ] ,
515515 channel_state : u32 ,
@@ -902,7 +902,7 @@ impl<Signer: Sign> Channel<Signer> {
902902 // Constructors:
903903 pub fn new_outbound < K : Deref , F : Deref > (
904904 fee_estimator : & LowerBoundedFeeEstimator < F > , keys_provider : & K , counterparty_node_id : PublicKey , their_features : & InitFeatures ,
905- channel_value_satoshis : u64 , push_msat : u64 , user_id : u64 , config : & UserConfig , current_chain_height : u32 ,
905+ channel_value_satoshis : u64 , push_msat : u64 , user_id : u128 , config : & UserConfig , current_chain_height : u32 ,
906906 outbound_scid_alias : u64
907907 ) -> Result < Channel < Signer > , APIError >
908908 where K :: Target : KeysInterface < Signer = Signer > ,
@@ -1102,7 +1102,7 @@ impl<Signer: Sign> Channel<Signer> {
11021102 /// Assumes chain_hash has already been checked and corresponds with what we expect!
11031103 pub fn new_from_req < K : Deref , F : Deref , L : Deref > (
11041104 fee_estimator : & LowerBoundedFeeEstimator < F > , keys_provider : & K , counterparty_node_id : PublicKey , their_features : & InitFeatures ,
1105- msg : & msgs:: OpenChannel , user_id : u64 , config : & UserConfig , current_chain_height : u32 , logger : & L ,
1105+ msg : & msgs:: OpenChannel , user_id : u128 , config : & UserConfig , current_chain_height : u32 , logger : & L ,
11061106 outbound_scid_alias : u64
11071107 ) -> Result < Channel < Signer > , ChannelError >
11081108 where K :: Target : KeysInterface < Signer = Signer > ,
@@ -4482,7 +4482,7 @@ impl<Signer: Sign> Channel<Signer> {
44824482
44834483 /// Gets the "user_id" value passed into the construction of this channel. It has no special
44844484 /// meaning and exists only to allow users to have a persistent identifier of a channel.
4485- pub fn get_user_id ( & self ) -> u64 {
4485+ pub fn get_user_id ( & self ) -> u128 {
44864486 self . user_id
44874487 }
44884488
@@ -5173,7 +5173,7 @@ impl<Signer: Sign> Channel<Signer> {
51735173 /// should be sent back to the counterparty node.
51745174 ///
51755175 /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
5176- pub fn accept_inbound_channel ( & mut self , user_id : u64 ) -> msgs:: AcceptChannel {
5176+ pub fn accept_inbound_channel ( & mut self , user_id : u128 ) -> msgs:: AcceptChannel {
51775177 if self . is_outbound ( ) {
51785178 panic ! ( "Tried to send accept_channel for an outbound channel?" ) ;
51795179 }
@@ -6002,7 +6002,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
60026002
60036003 write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
60046004
6005- self . user_id . write ( writer) ?;
6005+ // `user_id` used to be a single u64 value. In order to remain backwards compatible with
6006+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. We write
6007+ // the low bytes now and the optional high bytes later.
6008+ let mut low_bytes = [ 0u8 ; 8 ] ;
6009+ low_bytes. copy_from_slice ( & self . user_id . to_be_bytes ( ) [ 8 ..16 ] ) ;
6010+ let user_id_low = u64:: from_be_bytes ( low_bytes) ;
6011+ user_id_low. write ( writer) ?;
60066012
60076013 // Version 1 deserializers expected to read parts of the config object here. Version 2
60086014 // deserializers (0.0.99) now read config through TLVs, and as we now require them for
@@ -6249,6 +6255,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
62496255
62506256 let channel_ready_event_emitted = Some ( self . channel_ready_event_emitted ) ;
62516257
6258+ // `user_id` used to be a single u64 value. In order to remain backwards compatible with
6259+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
6260+ // we write the high bytes as an option here.
6261+ let mut high_bytes = [ 0u8 ; 8 ] ;
6262+ high_bytes. copy_from_slice ( & self . user_id . to_be_bytes ( ) [ 0 ..8 ] ) ;
6263+ let user_id_high_opt = Some ( u64:: from_be_bytes ( high_bytes) ) ;
6264+
62526265 write_tlv_fields ! ( writer, {
62536266 ( 0 , self . announcement_sigs, option) ,
62546267 // minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -6272,6 +6285,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
62726285 ( 19 , self . latest_inbound_scid_alias, option) ,
62736286 ( 21 , self . outbound_scid_alias, required) ,
62746287 ( 23 , channel_ready_event_emitted, option) ,
6288+ ( 25 , user_id_high_opt, option) ,
62756289 } ) ;
62766290
62776291 Ok ( ( ) )
@@ -6285,7 +6299,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
62856299 let ( keys_source, serialized_height) = args;
62866300 let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
62876301
6288- let user_id = Readable :: read ( reader) ?;
6302+ // `user_id` used to be a single u64 value. In order to remain backwards compatible with
6303+ // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. We read
6304+ // the low bytes now and the high bytes later.
6305+ let user_id_low: u64 = Readable :: read ( reader) ?;
62896306
62906307 let mut config = Some ( LegacyChannelConfig :: default ( ) ) ;
62916308 if ver == 1 {
@@ -6531,6 +6548,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65316548 let mut outbound_scid_alias = None ;
65326549 let mut channel_ready_event_emitted = None ;
65336550
6551+ let mut user_id_high_opt: Option < u64 > = None ;
6552+
65346553 read_tlv_fields ! ( reader, {
65356554 ( 0 , announcement_sigs, option) ,
65366555 ( 1 , minimum_depth, option) ,
@@ -6548,6 +6567,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65486567 ( 19 , latest_inbound_scid_alias, option) ,
65496568 ( 21 , outbound_scid_alias, option) ,
65506569 ( 23 , channel_ready_event_emitted, option) ,
6570+ ( 25 , user_id_high_opt, option) ,
65516571 } ) ;
65526572
65536573 if let Some ( preimages) = preimages_opt {
@@ -6584,6 +6604,16 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65846604 let mut secp_ctx = Secp256k1 :: new ( ) ;
65856605 secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
65866606
6607+ // `user_id` used to be a single u64 value. In order to remain backwards
6608+ // compatible with versions prior to 0.0.113, the u128 is serialized as two
6609+ // separate u64 values.
6610+ let mut user_id_bytes = [ 0u8 ; 16 ] ;
6611+ user_id_bytes[ 8 ..16 ] . copy_from_slice ( & user_id_low. to_be_bytes ( ) ) ;
6612+ if let Some ( high_bytes) = user_id_high_opt {
6613+ user_id_bytes[ 0 ..8 ] . copy_from_slice ( & high_bytes. to_be_bytes ( ) ) ;
6614+ }
6615+ let user_id = u128:: from_be_bytes ( user_id_bytes) ;
6616+
65876617 Ok ( Channel {
65886618 user_id,
65896619
0 commit comments