@@ -3771,19 +3771,21 @@ where
37713771
37723772 #[cfg(test)]
37733773 pub fn create_and_insert_outbound_scid_alias_for_test(&self) -> u64 {
3774- self.create_and_insert_outbound_scid_alias()
3774+ self.create_and_insert_outbound_scid_alias_with_namespace(
3775+ fake_scid::Namespace::OutboundAlias
3776+ )
37753777 }
37763778
37773779 #[rustfmt::skip]
3778- fn create_and_insert_outbound_scid_alias (&self) -> u64 {
3780+ fn create_and_insert_outbound_scid_alias_with_namespace (&self, namespace: fake_scid::Namespace ) -> u64 {
37793781 let height = self.best_block.read().unwrap().height;
37803782 let mut outbound_scid_alias = 0;
37813783 let mut i = 0;
37823784 loop {
37833785 if cfg!(fuzzing) { // fuzzing chacha20 doesn't use the key at all so we always get the same alias
37843786 outbound_scid_alias += 1;
37853787 } else {
3786- outbound_scid_alias = fake_scid::Namespace::OutboundAlias .get_fake_scid(height, &self.chain_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
3788+ outbound_scid_alias = namespace .get_fake_scid(height, &self.chain_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
37873789 }
37883790 if outbound_scid_alias != 0 && self.outbound_scid_aliases.lock().unwrap().insert(outbound_scid_alias) {
37893791 break;
@@ -3794,6 +3796,15 @@ where
37943796 outbound_scid_alias
37953797 }
37963798
3799+ /// Determines the appropriate outbound SCID namespace based on the intercept_htlcs_on_channel configuration.
3800+ fn get_outbound_scid_namespace(intercept_htlcs_on_channel: bool) -> fake_scid::Namespace {
3801+ if intercept_htlcs_on_channel {
3802+ fake_scid::Namespace::Intercept
3803+ } else {
3804+ fake_scid::Namespace::OutboundAlias
3805+ }
3806+ }
3807+
37973808 /// Creates a new outbound channel to the given remote node and with the given value.
37983809 ///
37993810 /// `user_channel_id` will be provided back as in
@@ -3850,9 +3861,10 @@ where
38503861 }
38513862
38523863 let mut channel = {
3853- let outbound_scid_alias = self.create_and_insert_outbound_scid_alias();
3854- let their_features = &peer_state.latest_features;
38553864 let config = if override_config.is_some() { override_config.as_ref().unwrap() } else { &self.default_configuration };
3865+ let outbound_scid_namespace = Self::get_outbound_scid_namespace(config.channel_handshake_config.intercept_htlcs_on_channel);
3866+ let outbound_scid_alias = self.create_and_insert_outbound_scid_alias_with_namespace(outbound_scid_namespace);
3867+ let their_features = &peer_state.latest_features;
38563868 match OutboundV1Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider, their_network_key,
38573869 their_features, channel_value_satoshis, push_msat, user_channel_id, config,
38583870 self.best_block.read().unwrap().height, outbound_scid_alias, temporary_channel_id, &*self.logger)
@@ -8191,7 +8203,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81918203 }
81928204
81938205 // Now that we know we have a channel, assign an outbound SCID alias.
8194- let outbound_scid_alias = self.create_and_insert_outbound_scid_alias();
8206+ let outbound_scid_namespace = Self::get_outbound_scid_namespace(config.channel_handshake_config.intercept_htlcs_on_channel);
8207+ let outbound_scid_alias = self.create_and_insert_outbound_scid_alias_with_namespace(outbound_scid_namespace);
81958208 channel.context_mut().set_outbound_scid_alias(outbound_scid_alias);
81968209
81978210 if let Some(message_send_event) = message_send_event {
@@ -8407,7 +8420,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
84078420 },
84088421 };
84098422
8410- let outbound_scid_alias = self.create_and_insert_outbound_scid_alias();
8423+ let outbound_scid_namespace = Self::get_outbound_scid_namespace(self.default_configuration.channel_handshake_config.intercept_htlcs_on_channel);
8424+ let outbound_scid_alias = self.create_and_insert_outbound_scid_alias_with_namespace(outbound_scid_namespace);
84118425 channel.context_mut().set_outbound_scid_alias(outbound_scid_alias);
84128426
84138427 if let Some(message_send_event) = message_send_event {
@@ -16303,6 +16317,7 @@ mod tests {
1630316317 to_self_delay: Some(200),
1630416318 max_accepted_htlcs: Some(5),
1630516319 channel_reserve_proportional_millionths: Some(20000),
16320+ intercept_htlcs_on_channel: None,
1630616321 }),
1630716322 update_overrides: None,
1630816323 };
0 commit comments