]> git.bitcoin.ninja Git - rust-lightning/commitdiff
[fuzz] Add fst coverage for `ChannelManager::update_channel_config` 2024-01-fuzz-gossip
authorMatt Corallo <git@bluematt.me>
Wed, 7 Feb 2024 02:27:22 +0000 (02:27 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 7 Feb 2024 02:32:52 +0000 (02:32 +0000)
fuzz/src/full_stack.rs

index a68cef1b9b4c1ad760679efd2328758c426b4c5c..2150bcfb73d26b3a440dea9024299700cff2efbb 100644 (file)
@@ -48,7 +48,7 @@ use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessa
 use lightning::routing::gossip::{P2PGossipSync, NetworkGraph};
 use lightning::routing::utxo::UtxoLookup;
 use lightning::routing::router::{InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router};
-use lightning::util::config::UserConfig;
+use lightning::util::config::{ChannelConfig, UserConfig};
 use lightning::util::errors::APIError;
 use lightning::util::test_channel_signer::{TestChannelSigner, EnforcementState};
 use lightning::util::logger::Logger;
@@ -104,6 +104,16 @@ impl InputData {
                Some(&self.data[old_pos..old_pos + len])
        }
 }
+impl std::io::Read for &InputData {
+       fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
+               if let Some(sl) = self.get_slice(buf.len()) {
+                       buf.copy_from_slice(sl);
+                       Ok(buf.len())
+               } else {
+                       Ok(0)
+               }
+       }
+}
 
 struct FuzzEstimator {
        input: Arc<InputData>,
@@ -758,6 +768,16 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
                                        }
                                }
                        }
+                       35 => {
+                               let config: ChannelConfig =
+                                       if let Ok(c) = Readable::read(&mut &*input) { c } else { return; };
+                               let chans = channelmanager.list_channels();
+                               if let Some(chan) = chans.get(0) {
+                                       let _ = channelmanager.update_channel_config(
+                                               &chan.counterparty.node_id, &[chan.channel_id], &config
+                                       );
+                               }
+                       }
                        _ => return,
                }
                loss_detector.handler.process_events();