From: Matt Corallo Date: Fri, 4 Mar 2022 21:31:55 +0000 (+0000) Subject: Clean up `TestKeysInterface` random bytes override interface X-Git-Tag: v0.0.106~32^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2022-02-fix-bunk-test;p=rust-lightning Clean up `TestKeysInterface` random bytes override interface Its very confusing to have multiple fields that do the same thing, one of which isn't even used for its stated purpose anymore after the previous few commits. --- diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 7816db2b1..00db1f5ca 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -6001,7 +6001,7 @@ fn bolt2_open_channel_sending_node_checks_part1() { //This test needs to be on i let nodes = create_network(2, &node_cfgs, &node_chanmgrs); //Force duplicate channel ids for node in nodes.iter() { - *node.keys_manager.override_channel_id_priv.lock().unwrap() = Some([0; 32]); + *node.keys_manager.override_random_bytes.lock().unwrap() = Some([0; 32]); } // BOLT #2 spec: Sending node must ensure temporary_channel_id is unique from any other channel ID with the same peer. diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index 414c98d4e..d67abeefd 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -320,7 +320,7 @@ fn test_onion_failure() { let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(config), Some(config), Some(node_2_cfg)]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); for node in nodes.iter() { - *node.keys_manager.override_session_priv.lock().unwrap() = Some([3; 32]); + *node.keys_manager.override_random_bytes.lock().unwrap() = Some([3; 32]); } let channels = [create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()), create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known())]; let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 40000); @@ -693,7 +693,7 @@ fn test_phantom_invalid_onion_payload() { // We'll use the session priv later when constructing an invalid onion packet. let session_priv = [3; 32]; - *nodes[0].keys_manager.override_session_priv.lock().unwrap() = Some(session_priv); + *nodes[0].keys_manager.override_random_bytes.lock().unwrap() = Some(session_priv); nodes[0].node.send_payment(&route, payment_hash.clone(), &Some(payment_secret)).unwrap(); check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 9cd2f9ec1..afdc10dda 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -471,8 +471,7 @@ impl Logger for TestLogger { pub struct TestKeysInterface { pub backing: keysinterface::PhantomKeysManager, - pub override_session_priv: Mutex>, - pub override_channel_id_priv: Mutex>, + pub override_random_bytes: Mutex>, pub disable_revocation_policy_check: bool, enforcement_states: Mutex>>>, expectations: Mutex>>, @@ -506,16 +505,9 @@ impl keysinterface::KeysInterface for TestKeysInterface { } fn get_secure_random_bytes(&self) -> [u8; 32] { - let override_channel_id = self.override_channel_id_priv.lock().unwrap(); - let override_session_key = self.override_session_priv.lock().unwrap(); - if override_channel_id.is_some() && override_session_key.is_some() { - panic!("We don't know which override key to use!"); - } - if let Some(key) = &*override_channel_id { - return *key; - } - if let Some(key) = &*override_session_key { - return *key; + let override_random_bytes = self.override_random_bytes.lock().unwrap(); + if let Some(bytes) = &*override_random_bytes { + return *bytes; } self.backing.get_secure_random_bytes() } @@ -543,8 +535,7 @@ impl TestKeysInterface { let now = Duration::from_secs(genesis_block(network).header.time as u64); Self { backing: keysinterface::PhantomKeysManager::new(seed, now.as_secs(), now.subsec_nanos(), seed), - override_session_priv: Mutex::new(None), - override_channel_id_priv: Mutex::new(None), + override_random_bytes: Mutex::new(None), disable_revocation_policy_check: false, enforcement_states: Mutex::new(HashMap::new()), expectations: Mutex::new(None),