From: Valentine Wallace Date: Sat, 19 Feb 2022 21:41:38 +0000 (-0500) Subject: Follow-up nits from #1199 (phantom node support) X-Git-Tag: v0.0.105~5^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=1f6700c72d8b23d53b3d2866993e3d39dc1905a3;p=rust-lightning Follow-up nits from #1199 (phantom node support) --- diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 19ec541b9..6800a3fe1 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -390,6 +390,9 @@ pub fn do_test(data: &[u8], logger: &Arc) { best_block: BestBlock::from_genesis(network), }; let channelmanager = Arc::new(ChannelManager::new(fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, params)); + // Adding new calls to `KeysInterface::get_secure_random_bytes` during startup can change all the + // keys subsequently generated in this test. Rather than regenerating all the messages manually, + // it's easier to just increment the counter here so the keys don't change. keys_manager.counter.fetch_sub(1, Ordering::AcqRel); let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret(Recipient::Node).unwrap()); let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash())); diff --git a/lightning/src/util/scid_utils.rs b/lightning/src/util/scid_utils.rs index f9dfd1b03..11b8d0c95 100644 --- a/lightning/src/util/scid_utils.rs +++ b/lightning/src/util/scid_utils.rs @@ -104,18 +104,15 @@ pub(crate) mod fake_scid { let rand_bytes = keys_manager.get_secure_random_bytes(); let segwit_activation_height = segwit_activation_height(genesis_hash); - let mut valid_block_range = if highest_seen_blockheight > segwit_activation_height { - highest_seen_blockheight - segwit_activation_height - } else { - 1 - }; + let mut blocks_since_segwit_activation = highest_seen_blockheight.saturating_sub(segwit_activation_height); + // We want to ensure that this fake channel won't conflict with any transactions we haven't // seen yet, in case `highest_seen_blockheight` is updated before we get full information // about transactions confirmed in the given block. - if valid_block_range > BLOCKS_PER_MONTH { valid_block_range -= BLOCKS_PER_MONTH; } + blocks_since_segwit_activation = blocks_since_segwit_activation.saturating_sub(BLOCKS_PER_MONTH); let rand_for_height = u32::from_be_bytes(rand_bytes[..4].try_into().unwrap()); - let fake_scid_height = segwit_activation_height + rand_for_height % valid_block_range; + let fake_scid_height = segwit_activation_height + rand_for_height % (blocks_since_segwit_activation + 1); let rand_for_tx_index = u32::from_be_bytes(rand_bytes[4..8].try_into().unwrap()); let fake_scid_tx_index = rand_for_tx_index % MAX_TX_INDEX;