Skip to content

Commit 168b3a5

Browse files
committed
Define a crate-public constant for max fake SCID in blocks offset
1 parent 585493a commit 168b3a5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lightning/src/util/scid_utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ pub(crate) mod fake_scid {
7979
const MAX_NAMESPACES: u8 = 8; // We allocate 3 bits for the namespace identifier.
8080
const NAMESPACE_ID_BITMASK: u8 = 0b111;
8181

82+
const BLOCKS_PER_MONTH: u32 = 144 /* blocks per day */ * 30 /* days per month */;
83+
pub(crate) const MAX_SCID_BLOCKS_FROM_NOW: u32 = BLOCKS_PER_MONTH;
84+
85+
8286
/// Fake scids are divided into namespaces, with each namespace having its own identifier between
8387
/// [0..7]. This allows us to identify what namespace a fake scid corresponds to upon HTLC
8488
/// receipt, and handle the HTLC accordingly. The namespace identifier is encrypted when encoded
@@ -100,7 +104,6 @@ pub(crate) mod fake_scid {
100104
// Ensure we haven't created a namespace that doesn't fit into the 3 bits we've allocated for
101105
// namespaces.
102106
assert!((*self as u8) < MAX_NAMESPACES);
103-
const BLOCKS_PER_MONTH: u32 = 144 /* blocks per day */ * 30 /* days per month */;
104107
let rand_bytes = keys_manager.get_secure_random_bytes();
105108

106109
let segwit_activation_height = segwit_activation_height(genesis_hash);
@@ -109,7 +112,7 @@ pub(crate) mod fake_scid {
109112
// We want to ensure that this fake channel won't conflict with any transactions we haven't
110113
// seen yet, in case `highest_seen_blockheight` is updated before we get full information
111114
// about transactions confirmed in the given block.
112-
blocks_since_segwit_activation = blocks_since_segwit_activation.saturating_sub(BLOCKS_PER_MONTH);
115+
blocks_since_segwit_activation = blocks_since_segwit_activation.saturating_sub(MAX_SCID_BLOCKS_FROM_NOW);
113116

114117
let rand_for_height = u32::from_be_bytes(rand_bytes[..4].try_into().unwrap());
115118
let fake_scid_height = segwit_activation_height + rand_for_height % (blocks_since_segwit_activation + 1);

0 commit comments

Comments
 (0)