From: Matt Corallo Date: Mon, 30 Oct 2023 21:11:53 +0000 (+0000) Subject: wip fuzz coverage X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=aaadeecd14ddca55e0749b2b905fa2749b64fa3b;p=rust-lightning wip fuzz coverage --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 837a73a75..c5eb04f53 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -168,10 +168,15 @@ impl chain::Watch for TestChainMonitor { } } +struct SignerState { + enforcement: Arc>, + unavailable: Arc>, +} + struct KeyProvider { node_secret: SecretKey, rand_bytes_id: atomic::AtomicU32, - enforcement_states: Mutex>>>, + enforcement_states: Mutex>, } impl EntropySource for KeyProvider { @@ -253,22 +258,19 @@ impl SignerProvider for KeyProvider { channel_keys_id, channel_keys_id, ); - let revoked_commitment = self.make_enforcement_state_cell(keys.commitment_seed); - TestChannelSigner::new_with_revoked(keys, revoked_commitment, false) + let mut revoked_commitments = self.enforcement_states.lock().unwrap(); + let new_state = revoked_commitments.entry(keys.commitment_seed) + .or_insert(SignerState { + enforcement: Arc::new(Mutex::new(EnforcementState::new())), + unavailable: Arc::new(Mutex::new(0)), + }); + let mut ret = TestChannelSigner::new_with_revoked(keys, Arc::clone(&new_state.enforcement), false); + ret.unavailable = Arc::clone(&new_state.unavailable); + ret } - fn read_chan_signer(&self, buffer: &[u8]) -> Result { - let mut reader = std::io::Cursor::new(buffer); - - let inner: InMemorySigner = ReadableArgs::read(&mut reader, self)?; - let state = self.make_enforcement_state_cell(inner.commitment_seed); - - Ok(TestChannelSigner { - inner, - state, - disable_revocation_policy_check: false, - unavailable: Arc::new(Mutex::new(0)), - }) + fn read_chan_signer(&self, _buffer: &[u8]) -> Result { + unreachable!(); } fn get_destination_script(&self) -> Result { @@ -286,17 +288,6 @@ impl SignerProvider for KeyProvider { } } -impl KeyProvider { - fn make_enforcement_state_cell(&self, commitment_seed: [u8; 32]) -> Arc> { - let mut revoked_commitments = self.enforcement_states.lock().unwrap(); - if !revoked_commitments.contains_key(&commitment_seed) { - revoked_commitments.insert(commitment_seed, Arc::new(Mutex::new(EnforcementState::new()))); - } - let cell = revoked_commitments.get(&commitment_seed).unwrap(); - Arc::clone(cell) - } -} - #[inline] fn check_api_err(api_err: APIError, sendable_bounds_violated: bool) { match api_err { @@ -1259,6 +1250,51 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { }, 0x89 => { fee_est_c.ret_val.store(253, atomic::Ordering::Release); nodes[2].maybe_update_chan_fees(); }, + 0xa0 => { + let signer_states = keys_manager_a.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = u32::max_value(); + } + 0xa1 => { + let signer_states = keys_manager_a.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = 0; + nodes[0].signer_unblocked(None); + } + /*0xa2 => { + let signer_states = keys_manager_a.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = true; + } + 0xa3 => { + let signer_states = keys_manager_a.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = false; + nodes[0].signer_unblocked(None); + } + 0xa4 => { + let signer_states = keys_manager_a.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = true; + } + 0xa5 => { + let signer_states = keys_manager_a.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = false; + nodes[0].signer_unblocked(None); + }*/ + 0xa6 => { + let signer_states = keys_manager_c.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = u32::max_value(); + } + 0xa7 => { + let signer_states = keys_manager_c.enforcement_states.lock().unwrap(); + assert_eq!(signer_states.len(), 1); + *signer_states.values().next().unwrap().unavailable.lock().unwrap() = 0; + nodes[2].signer_unblocked(None); + } + 0xff => { // Test that no channel is in a stuck state where neither party can send funds even // after we resolve all pending events. @@ -1268,6 +1304,19 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { *monitor_b.persister.update_ret.lock().unwrap() = ChannelMonitorUpdateStatus::Completed; *monitor_c.persister.update_ret.lock().unwrap() = ChannelMonitorUpdateStatus::Completed; + for signer_state in keys_manager_a.enforcement_states.lock().unwrap().values() { + *signer_state.unavailable.lock().unwrap() = 0; + } + for signer_state in keys_manager_b.enforcement_states.lock().unwrap().values() { + *signer_state.unavailable.lock().unwrap() = 0; + } + for signer_state in keys_manager_c.enforcement_states.lock().unwrap().values() { + *signer_state.unavailable.lock().unwrap() = 0; + } + nodes[0].signer_unblocked(None); + nodes[1].signer_unblocked(None); + nodes[2].signer_unblocked(None); + if let Some((id, _)) = monitor_a.latest_monitors.lock().unwrap().get(&chan_1_funding) { monitor_a.chain_monitor.force_channel_monitor_updated(chan_1_funding, *id); nodes[0].process_monitor_events(); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index ea5001dd8..e7d58cf58 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -7278,8 +7278,6 @@ where /// attempted in every channel, or in the specifically provided channel. /// /// [`ChannelSigner`]: crate::sign::ChannelSigner - #[cfg(test)] // This is only implemented for one signer method, and should be private until we - // actually finish implementing it fully. pub fn signer_unblocked(&self, channel_opt: Option<(PublicKey, ChannelId)>) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);