Follow-up nits from #1199 (phantom node support)
authorValentine Wallace <vwallace@protonmail.com>
Sat, 19 Feb 2022 21:41:38 +0000 (16:41 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 22 Feb 2022 16:54:35 +0000 (11:54 -0500)
fuzz/src/full_stack.rs
lightning/src/util/scid_utils.rs

index 19ec541b942592a00ba93fe1687eba2e95559952..6800a3fe1798a8a328e139cfbde733fbf3c52e5a 100644 (file)
@@ -390,6 +390,9 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                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()));
index f9dfd1b0320cb8308d91489928f3bdc1503504e0..11b8d0c95e098761ad6cfdd86e9ad717a48fcd27 100644 (file)
@@ -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;