]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Clean up `TestKeysInterface` random bytes override interface 2022-02-fix-bunk-test
authorMatt Corallo <git@bluematt.me>
Fri, 4 Mar 2022 21:31:55 +0000 (21:31 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 4 Mar 2022 21:54:32 +0000 (21:54 +0000)
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.

lightning/src/ln/functional_tests.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/util/test_utils.rs

index 7816db2b1785be982c0f630507b43033cd37269e..00db1f5ca552bd1942807a9b0f03c5ab53d173dc 100644 (file)
@@ -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.
index 414c98d4e85da80ee3f0ada988d5835f36ea8e13..d67abeefdada29b6d38962737ea5282ee89e1d80 100644 (file)
@@ -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());
index 9cd2f9ec13e8bd49de15be2fc0f283fe34660eee..afdc10dda3c473443e369b11b38bbfad9ff68c66 100644 (file)
@@ -471,8 +471,7 @@ impl Logger for TestLogger {
 
 pub struct TestKeysInterface {
        pub backing: keysinterface::PhantomKeysManager,
-       pub override_session_priv: Mutex<Option<[u8; 32]>>,
-       pub override_channel_id_priv: Mutex<Option<[u8; 32]>>,
+       pub override_random_bytes: Mutex<Option<[u8; 32]>>,
        pub disable_revocation_policy_check: bool,
        enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
        expectations: Mutex<Option<VecDeque<OnGetShutdownScriptpubkey>>>,
@@ -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),