@@ -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 ,
@@ -899,7 +899,7 @@ impl<Signer: Sign> Channel<Signer> {
899899 // Constructors:
900900 pub fn new_outbound < K : Deref , F : Deref > (
901901 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 ,
903903 outbound_scid_alias : u64
904904 ) -> Result < Channel < Signer > , APIError >
905905 where K :: Target : KeysInterface < Signer = Signer > ,
@@ -1097,7 +1097,7 @@ impl<Signer: Sign> Channel<Signer> {
10971097 /// Assumes chain_hash has already been checked and corresponds with what we expect!
10981098 pub fn new_from_req < K : Deref , F : Deref , L : Deref > (
10991099 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 ,
11011101 outbound_scid_alias : u64
11021102 ) -> Result < Channel < Signer > , ChannelError >
11031103 where K :: Target : KeysInterface < Signer = Signer > ,
@@ -4475,7 +4475,7 @@ impl<Signer: Sign> Channel<Signer> {
44754475
44764476 /// Gets the "user_id" value passed into the construction of this channel. It has no special
44774477 /// 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 {
44794479 self . user_id
44804480 }
44814481
@@ -5156,7 +5156,7 @@ impl<Signer: Sign> Channel<Signer> {
51565156 /// should be sent back to the counterparty node.
51575157 ///
51585158 /// [`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 {
51605160 if self . is_outbound ( ) {
51615161 panic ! ( "Tried to send accept_channel for an outbound channel?" ) ;
51625162 }
@@ -5985,7 +5985,13 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
59855985
59865986 write_ver_prefix ! ( writer, SERIALIZATION_VERSION , MIN_SERIALIZATION_VERSION ) ;
59875987
5988- self . user_id . write ( writer) ?;
5988+ // `user_id` used to be a single u64 value. In order to remain backwards compatibility 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) ?;
59895995
59905996 // Version 1 deserializers expected to read parts of the config object here. Version 2
59915997 // 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> {
62306236 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)
62316237 { Some ( self . holder_max_htlc_value_in_flight_msat ) } else { None } ;
62326238
6239+ // `user_id` used to be a single u64 value. In order to remain backwards
6240+ // compatibility with versions prior to 0.0.113, the u128 is serialized as two
6241+ // separate u64 values. Therefore, 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+
62336246 write_tlv_fields ! ( writer, {
62346247 ( 0 , self . announcement_sigs, option) ,
62356248 // minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -6252,6 +6265,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
62526265 ( 17 , self . announcement_sigs_state, required) ,
62536266 ( 19 , self . latest_inbound_scid_alias, option) ,
62546267 ( 21 , self . outbound_scid_alias, required) ,
6268+ ( 23 , user_id_high_opt, option) ,
62556269 } ) ;
62566270
62576271 Ok ( ( ) )
@@ -6265,7 +6279,10 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
62656279 let ( keys_source, serialized_height) = args;
62666280 let ver = read_ver_prefix ! ( reader, SERIALIZATION_VERSION ) ;
62676281
6268- let user_id = Readable :: read ( reader) ?;
6282+ // `user_id` used to be a single u64 value. In order to remain backwards
6283+ // compatibility with versions prior to 0.0.113, the u128 is serialized as two
6284+ // separate u64 values. We read the low bytes now and the high bytes later.
6285+ let user_id_low: u64 = Readable :: read ( reader) ?;
62696286
62706287 let mut config = Some ( LegacyChannelConfig :: default ( ) ) ;
62716288 if ver == 1 {
@@ -6510,6 +6527,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65106527 let mut latest_inbound_scid_alias = None ;
65116528 let mut outbound_scid_alias = None ;
65126529
6530+ let mut user_id_high_opt: Option < u64 > = None ;
6531+
65136532 read_tlv_fields ! ( reader, {
65146533 ( 0 , announcement_sigs, option) ,
65156534 ( 1 , minimum_depth, option) ,
@@ -6526,6 +6545,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65266545 ( 17 , announcement_sigs_state, option) ,
65276546 ( 19 , latest_inbound_scid_alias, option) ,
65286547 ( 21 , outbound_scid_alias, option) ,
6548+ ( 23 , user_id_high_opt, option) ,
65296549 } ) ;
65306550
65316551 if let Some ( preimages) = preimages_opt {
@@ -6562,6 +6582,16 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<(&'a K, u32)> for Channel<Signer>
65626582 let mut secp_ctx = Secp256k1 :: new ( ) ;
65636583 secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
65646584
6585+ // `user_id` used to be a single u64 value. In order to remain backwards
6586+ // compatibility 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+
65656595 Ok ( Channel {
65666596 user_id,
65676597
0 commit comments