Skip to content

Commit 6522b64

Browse files
committed
public scid utils
1 parent d2242f6 commit 6522b64

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lightning/src/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod ser;
2020
pub mod message_signing;
2121
pub mod invoice;
2222
pub mod persist;
23+
pub mod scid_utils;
2324
pub mod string;
2425
pub mod wakers;
2526
#[cfg(fuzzing)]
@@ -34,7 +35,6 @@ pub(crate) mod chacha20;
3435
pub(crate) mod poly1305;
3536
pub(crate) mod chacha20poly1305rfc;
3637
pub(crate) mod transaction_utils;
37-
pub(crate) mod scid_utils;
3838
pub(crate) mod time;
3939

4040
pub mod indexed_map;

lightning/src/util/scid_utils.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10+
//! Utilities for creating and parsing short channel ids.
11+
1012
/// Maximum block height that can be used in a `short_channel_id`. This
1113
/// value is based on the 3-bytes available for block height.
1214
pub const MAX_SCID_BLOCK: u64 = 0x00ffffff;
@@ -22,8 +24,11 @@ pub const MAX_SCID_VOUT_INDEX: u64 = 0xffff;
2224
/// A `short_channel_id` construction error
2325
#[derive(Debug, PartialEq, Eq)]
2426
pub enum ShortChannelIdError {
27+
/// Block height too high
2528
BlockOverflow,
29+
/// Tx index too high
2630
TxIndexOverflow,
31+
/// Vout index too high
2732
VoutIndexOverflow,
2833
}
2934

@@ -65,7 +70,7 @@ pub fn scid_from_parts(block: u64, tx_index: u64, vout_index: u64) -> Result<u64
6570
/// 2) phantom node payments, to get an scid for the phantom node's phantom channel
6671
/// 3) payments intended to be intercepted will route using a fake scid (this is typically used so
6772
/// the forwarding node can open a JIT channel to the next hop)
68-
pub(crate) mod fake_scid {
73+
pub mod fake_scid {
6974
use bitcoin::blockdata::constants::ChainHash;
7075
use bitcoin::network::constants::Network;
7176
use crate::sign::EntropySource;
@@ -90,9 +95,12 @@ pub(crate) mod fake_scid {
9095
/// receipt, and handle the HTLC accordingly. The namespace identifier is encrypted when encoded
9196
/// into the fake scid.
9297
#[derive(Copy, Clone)]
93-
pub(crate) enum Namespace {
98+
pub enum Namespace {
99+
/// Phantom nodes namespace
94100
Phantom,
101+
/// SCID aliases for outbound private channels
95102
OutboundAlias,
103+
/// Payment interception namespace
96104
Intercept
97105
}
98106

@@ -101,7 +109,7 @@ pub(crate) mod fake_scid {
101109
/// between segwit activation and the current best known height, and the tx index and output
102110
/// index are also selected from a "reasonable" range. We add this logic because it makes it
103111
/// non-obvious at a glance that the scid is fake, e.g. if it appears in invoice route hints.
104-
pub(crate) fn get_fake_scid<ES: Deref>(&self, highest_seen_blockheight: u32, chain_hash: &ChainHash, fake_scid_rand_bytes: &[u8; 32], entropy_source: &ES) -> u64
112+
pub fn get_fake_scid<ES: Deref>(&self, highest_seen_blockheight: u32, chain_hash: &ChainHash, fake_scid_rand_bytes: &[u8; 32], entropy_source: &ES) -> u64
105113
where ES::Target: EntropySource,
106114
{
107115
// Ensure we haven't created a namespace that doesn't fit into the 3 bits we've allocated for

0 commit comments

Comments
 (0)