Skip to content

Commit f486514

Browse files
Follow-up nits from #1199 (phantom node support)
1 parent 03f1c7d commit f486514

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

fuzz/src/full_stack.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
390390
best_block: BestBlock::from_genesis(network),
391391
};
392392
let channelmanager = Arc::new(ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, params));
393+
// Adding new calls to `KeysInterface::get_secure_random_bytes` during startup can change all the
394+
// keys subsequently generated in this test. Rather than regenerating all the messages manually,
395+
// it's easier to just increment the counter here so the keys don't change.
393396
keys_manager.counter.fetch_sub(1, Ordering::AcqRel);
394397
let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret(Recipient::Node).unwrap());
395398
let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash()));

lightning/src/util/scid_utils.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,15 @@ pub(crate) mod fake_scid {
104104
let rand_bytes = keys_manager.get_secure_random_bytes();
105105

106106
let segwit_activation_height = segwit_activation_height(genesis_hash);
107-
let mut valid_block_range = if highest_seen_blockheight > segwit_activation_height {
108-
highest_seen_blockheight - segwit_activation_height
109-
} else {
110-
1
111-
};
107+
let mut blocks_since_segwit_activation = highest_seen_blockheight.saturating_sub(segwit_activation_height);
108+
112109
// We want to ensure that this fake channel won't conflict with any transactions we haven't
113110
// seen yet, in case `highest_seen_blockheight` is updated before we get full information
114111
// about transactions confirmed in the given block.
115-
if valid_block_range > BLOCKS_PER_MONTH { valid_block_range -= BLOCKS_PER_MONTH; }
112+
blocks_since_segwit_activation = blocks_since_segwit_activation.saturating_sub(BLOCKS_PER_MONTH);
116113

117114
let rand_for_height = u32::from_be_bytes(rand_bytes[..4].try_into().unwrap());
118-
let fake_scid_height = segwit_activation_height + rand_for_height % valid_block_range;
115+
let fake_scid_height = segwit_activation_height + rand_for_height % (blocks_since_segwit_activation + 1);
119116

120117
let rand_for_tx_index = u32::from_be_bytes(rand_bytes[4..8].try_into().unwrap());
121118
let fake_scid_tx_index = rand_for_tx_index % MAX_TX_INDEX;

0 commit comments

Comments
 (0)