X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Ftest_utils.rs;h=4b2c3c2e3742b747e56430451f37d2ea706f29dc;hb=3ccf06416091e107f443ee92027501105c48054b;hp=f6616a8e5d2449391c2beb68d08e93c295127cee;hpb=1d0c6c60c6802126b3b29d6a2aa026c1aa33db02;p=rust-lightning diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index f6616a8e..4b2c3c2e 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -79,6 +79,8 @@ use std::time::{SystemTime, UNIX_EPOCH}; use bitcoin::psbt::Psbt; use bitcoin::Sequence; +use super::test_channel_signer::SignerOp; + pub fn pubkey(byte: u8) -> PublicKey { let secp_ctx = Secp256k1::new(); PublicKey::from_secret_key(&secp_ctx, &privkey(byte)) @@ -545,12 +547,16 @@ pub struct TestPersister { /// /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor pub offchain_monitor_updates: Mutex>>, + /// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the + /// monitor's funding outpoint here. + pub chain_sync_monitor_persistences: Mutex> } impl TestPersister { pub fn new() -> Self { Self { update_rets: Mutex::new(VecDeque::new()), offchain_monitor_updates: Mutex::new(new_hash_map()), + chain_sync_monitor_persistences: Mutex::new(VecDeque::new()) } } @@ -573,15 +579,18 @@ impl chainmonitor::Persist for ret = update_ret; } - if let Some(update) = update { + if let Some(update) = update { self.offchain_monitor_updates.lock().unwrap().entry(funding_txo).or_insert(new_hash_set()).insert(update.update_id); + } else { + self.chain_sync_monitor_persistences.lock().unwrap().push_back(funding_txo); } ret } fn archive_persisted_channel(&self, funding_txo: OutPoint) { - // remove the channel from the offchain_monitor_updates map + // remove the channel from the offchain_monitor_updates and chain_sync_monitor_persistences. self.offchain_monitor_updates.lock().unwrap().remove(&funding_txo); + self.chain_sync_monitor_persistences.lock().unwrap().retain(|x| x != &funding_txo); } } @@ -800,8 +809,8 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { self.received_msg(wire::Message::Stfu(msg.clone())); } #[cfg(splicing)] - fn handle_splice(&self, _their_node_id: &PublicKey, msg: &msgs::Splice) { - self.received_msg(wire::Message::Splice(msg.clone())); + fn handle_splice_init(&self, _their_node_id: &PublicKey, msg: &msgs::SpliceInit) { + self.received_msg(wire::Message::SpliceInit(msg.clone())); } #[cfg(splicing)] fn handle_splice_ack(&self, _their_node_id: &PublicKey, msg: &msgs::SpliceAck) { @@ -1215,6 +1224,7 @@ pub struct TestKeysInterface { enforcement_states: Mutex>>>, expectations: Mutex>>, pub unavailable_signers: Mutex>, + pub unavailable_signers_ops: Mutex>>, } impl EntropySource for TestKeysInterface { @@ -1273,9 +1283,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); - 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); + let mut signer = TestChannelSigner::new_with_revoked(keys, state, self.disable_revocation_policy_check); + if let Some(ops) = self.unavailable_signers_ops.lock().unwrap().get(&channel_keys_id) { + for &op in ops { + signer.disable_op(op); + } } signer } @@ -1316,6 +1328,7 @@ impl TestKeysInterface { enforcement_states: Mutex::new(new_hash_map()), expectations: Mutex::new(None), unavailable_signers: Mutex::new(new_hash_set()), + unavailable_signers_ops: Mutex::new(new_hash_map()), } }