]> git.bitcoin.ninja Git - rust-lightning/commitdiff
wip fuzz coverage 2023-10-2653-fuzz-test
authorMatt Corallo <git@bluematt.me>
Mon, 30 Oct 2023 21:11:53 +0000 (21:11 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 30 Oct 2023 21:19:37 +0000 (21:19 +0000)
fuzz/src/chanmon_consistency.rs
lightning/src/ln/channelmanager.rs

index 837a73a758c1bb241df601a0ca75667bdcfa5e66..c5eb04f53aec91b32ff9874f0701e4551a54c2d8 100644 (file)
@@ -168,10 +168,15 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
        }
 }
 
+struct SignerState {
+       enforcement: Arc<Mutex<EnforcementState>>,
+       unavailable: Arc<Mutex<u32>>,
+}
+
 struct KeyProvider {
        node_secret: SecretKey,
        rand_bytes_id: atomic::AtomicU32,
-       enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
+       enforcement_states: Mutex<HashMap<[u8;32], SignerState>>,
 }
 
 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<Self::Signer, DecodeError> {
-               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<Self::Signer, DecodeError> {
+               unreachable!();
        }
 
        fn get_destination_script(&self) -> Result<Script, ()> {
@@ -286,17 +288,6 @@ impl SignerProvider for KeyProvider {
        }
 }
 
-impl KeyProvider {
-       fn make_enforcement_state_cell(&self, commitment_seed: [u8; 32]) -> Arc<Mutex<EnforcementState>> {
-               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<Out: Output>(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<Out: Output>(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();
index ea5001dd847c84d4498dc66cca77372bc10590bf..e7d58cf5863f31ef0f17576f2c9322d06e46b14c 100644 (file)
@@ -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);