Merge pull request #2883 from tnull/2024-02-dyn-kvstore-blanket-impls
[rust-lightning] / lightning / src / util / test_utils.rs
index 63106b9121d5c482639c936776140deedc876282..8fc5a8197a78c38e13740ea663e678582676515f 100644 (file)
@@ -1167,6 +1167,7 @@ pub struct TestKeysInterface {
        pub disable_revocation_policy_check: bool,
        enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
        expectations: Mutex<Option<VecDeque<OnGetShutdownScriptpubkey>>>,
+       pub unavailable_signers: Mutex<HashSet<[u8; 32]>>,
 }
 
 impl EntropySource for TestKeysInterface {
@@ -1225,7 +1226,11 @@ impl SignerProvider for TestKeysInterface {
        fn derive_channel_signer(&self, channel_value_satoshis: u64, channel_keys_id: [u8; 32]) -> TestChannelSigner {
                let keys = self.backing.derive_channel_signer(channel_value_satoshis, channel_keys_id);
                let state = self.make_enforcement_state_cell(keys.commitment_seed);
-               TestChannelSigner::new_with_revoked(keys, state, self.disable_revocation_policy_check)
+               let signer = TestChannelSigner::new_with_revoked(keys, state, self.disable_revocation_policy_check);
+               if self.unavailable_signers.lock().unwrap().contains(&channel_keys_id) {
+                       signer.set_available(false);
+               }
+               signer
        }
 
        fn read_chan_signer(&self, buffer: &[u8]) -> Result<Self::EcdsaSigner, msgs::DecodeError> {
@@ -1263,6 +1268,7 @@ impl TestKeysInterface {
                        disable_revocation_policy_check: false,
                        enforcement_states: Mutex::new(new_hash_map()),
                        expectations: Mutex::new(None),
+                       unavailable_signers: Mutex::new(new_hash_set()),
                }
        }
 
@@ -1276,9 +1282,7 @@ impl TestKeysInterface {
        }
 
        pub fn derive_channel_keys(&self, channel_value_satoshis: u64, id: &[u8; 32]) -> TestChannelSigner {
-               let keys = self.backing.derive_channel_keys(channel_value_satoshis, id);
-               let state = self.make_enforcement_state_cell(keys.commitment_seed);
-               TestChannelSigner::new_with_revoked(keys, state, self.disable_revocation_policy_check)
+               self.derive_channel_signer(channel_value_satoshis, *id)
        }
 
        fn make_enforcement_state_cell(&self, commitment_seed: [u8; 32]) -> Arc<Mutex<EnforcementState>> {