Merge pull request #2883 from tnull/2024-02-dyn-kvstore-blanket-impls
authorElias Rohrer <dev@tnull.de>
Wed, 14 Feb 2024 08:01:51 +0000 (09:01 +0100)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2024 08:01:51 +0000 (09:01 +0100)
Add blanket `Persist`/`Persister` impls for `dyn KVStore + Send + Sync`

1  2 
lightning/src/util/test_utils.rs

index 09a8c3a26612725c07fedadc7cbb269814b54f88,63106b9121d5c482639c936776140deedc876282..8fc5a8197a78c38e13740ea663e678582676515f
@@@ -632,6 -632,9 +632,9 @@@ impl KVStore for TestStore 
        }
  }
  
+ unsafe impl Sync for TestStore {}
+ unsafe impl Send for TestStore {}
  pub struct TestBroadcaster {
        pub txn_broadcasted: Mutex<Vec<Transaction>>,
        pub blocks: Arc<Mutex<Vec<(Block, u32)>>>,
@@@ -1164,7 -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 {
@@@ -1223,11 -1225,7 +1226,11 @@@ impl SignerProvider for TestKeysInterfa
        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> {
@@@ -1265,7 -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()),
                }
        }
  
        }
  
        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>> {