Skip to content

Commit a3411d6

Browse files
committed
Randomize user_channel_id for inbound channels
Previously, all inbound channels defaulted to a `user_channel_id` of 0, which didn't allow for them being discerned on that basis. Here, we simply randomize the identifier to fix this and enable the use of `user_channel_id` as a true identifier for channels (assuming an equally reasonable value is chosen for outbound channels and given upon `create_channel()`).
1 parent 505102d commit a3411d6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lightning/src/ln/channelmanager.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1719,10 +1719,9 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
17191719
///
17201720
/// `user_channel_id` will be provided back as in
17211721
/// [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
1722-
/// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
1723-
/// for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
1724-
/// `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
1725-
/// ignored.
1722+
/// correspond with which `create_channel` call. Note that the `user_channel_id` defaults to a
1723+
/// randomized value for inbound channels. `user_channel_id` has no meaning inside of LDK, it
1724+
/// is simply copied to events and otherwise ignored.
17261725
///
17271726
/// Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
17281727
/// greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
@@ -4604,9 +4603,13 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
46044603
return Err(MsgHandleErrInternal::send_err_msg_no_close("No inbound channels accepted".to_owned(), msg.temporary_channel_id.clone()));
46054604
}
46064605

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);
4609+
46074610
let outbound_scid_alias = self.create_and_insert_outbound_scid_alias();
46084611
let mut channel = match Channel::new_from_req(&self.fee_estimator, &self.keys_manager,
4609-
counterparty_node_id.clone(), &their_features, msg, 0, &self.default_configuration,
4612+
counterparty_node_id.clone(), &their_features, msg, user_channel_id, &self.default_configuration,
46104613
self.best_block.read().unwrap().height(), &self.logger, outbound_scid_alias)
46114614
{
46124615
Err(e) => {

0 commit comments

Comments
 (0)