From: Matt Corallo Date: Wed, 24 Feb 2021 03:52:12 +0000 (-0500) Subject: Make router fuzz runs deterministic X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=3e1d0dad188bdcb5b2fc293114dd305506736e88;p=rust-lightning Make router fuzz runs deterministic --- diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 51602d5b5..4d06d9e3e 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -26,7 +26,8 @@ use bitcoin::blockdata::constants::genesis_block; use utils::test_logger; -use std::collections::HashSet; +use std::collections::{HashSet, HashMap}; +use std::hash; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -93,6 +94,13 @@ impl chain::Access for FuzzChainSource { } } +// We sometimes walk the HashSet of peer node_ids, which, in order to keep the ordering consistent +// across fuzz runs, we need to use a consistent hasher. +// Tt is deprecated, but the "replacement" doesn't actually accomplish the same goals, so we just +// ignore it. +#[allow(deprecated)] +pub type NonRandomHash = hash::BuildHasherDefault; + #[inline] pub fn do_test(data: &[u8], out: Out) { let input = Arc::new(InputData { @@ -159,7 +167,7 @@ pub fn do_test(data: &[u8], out: Out) { let our_pubkey = get_pubkey!(); let mut net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash()); - let mut node_pks = HashSet::new(); + let mut node_pks: HashSet<_, NonRandomHash> = HashSet::default(); let mut scid = 42; loop {