Skip to content

Commit 9e6f14f

Browse files
add intercept fake_scid namespace
1 parent e254912 commit 9e6f14f

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lightning/src/util/scid_utils.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub(crate) mod fake_scid {
9191
pub(crate) enum Namespace {
9292
Phantom,
9393
OutboundAlias,
94+
Intercept
9495
}
9596

9697
impl Namespace {
@@ -151,14 +152,25 @@ pub(crate) mod fake_scid {
151152
}
152153

153154
/// Returns whether the given fake scid falls into the given namespace.
154-
pub fn is_valid_phantom(fake_scid_rand_bytes: &[u8; 32], scid: u64) -> bool {
155+
pub fn is_in_namespace(namespace: Namespace, fake_scid_rand_bytes: &[u8; 32], scid: u64) -> bool {
155156
let block_height = scid_utils::block_from_scid(&scid);
156157
let tx_index = scid_utils::tx_index_from_scid(&scid);
157-
let namespace = Namespace::Phantom;
158158
let valid_vout = namespace.get_encrypted_vout(block_height, tx_index, fake_scid_rand_bytes);
159159
valid_vout == scid_utils::vout_from_scid(&scid) as u8
160160
}
161161

162+
/// Returns whether the given fake scid falls into the phantom namespace.
163+
pub fn is_valid_phantom(fake_scid_rand_bytes: &[u8; 32], scid: u64) -> bool {
164+
is_in_namespace(Namespace::Phantom, fake_scid_rand_bytes, scid)
165+
}
166+
167+
/// Returns whether the given fake scid falls into the intercept namespace.
168+
pub fn is_valid_intercept(fake_scid_rand_bytes: &[u8; 32], scid: u64) -> bool {
169+
is_in_namespace(Namespace::Intercept, fake_scid_rand_bytes, scid)
170+
}
171+
172+
173+
162174
#[cfg(test)]
163175
mod tests {
164176
use bitcoin::blockdata::constants::genesis_block;
@@ -168,6 +180,8 @@ pub(crate) mod fake_scid {
168180
use util::test_utils;
169181
use sync::Arc;
170182

183+
use crate::util::scid_utils::fake_scid::is_valid_intercept;
184+
171185
#[test]
172186
fn namespace_identifier_is_within_range() {
173187
let phantom_namespace = Namespace::Phantom;
@@ -201,6 +215,16 @@ pub(crate) mod fake_scid {
201215
assert!(!is_valid_phantom(&fake_scid_rand_bytes, invalid_fake_scid));
202216
}
203217

218+
fn test_is_valid_intercept() {
219+
let namespace = Namespace::Intercept;
220+
let fake_scid_rand_bytes = [0; 32];
221+
let valid_encrypted_vout = namespace.get_encrypted_vout(0, 0, &fake_scid_rand_bytes);
222+
let valid_fake_scid = scid_utils::scid_from_parts(0, 0, valid_encrypted_vout as u64).unwrap();
223+
assert!(is_valid_intercept(&fake_scid_rand_bytes, valid_fake_scid));
224+
let invalid_fake_scid = scid_utils::scid_from_parts(0, 0, 12).unwrap();
225+
assert!(!is_valid_intercept(&fake_scid_rand_bytes, invalid_fake_scid));
226+
}
227+
204228
#[test]
205229
fn test_get_fake_scid() {
206230
let mainnet_genesis = genesis_block(Network::Bitcoin).header.block_hash();

0 commit comments

Comments
 (0)