From 3e1d0dad188bdcb5b2fc293114dd305506736e88 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 23 Feb 2021 22:52:12 -0500 Subject: [PATCH] Make router fuzz runs deterministic --- fuzz/src/router.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 { -- 2.39.5