]> git.bitcoin.ninja Git - rust-lightning/commitdiff
`rustfmt`: `fuzz/src/offer_deser.rs`
authorElias Rohrer <dev@tnull.de>
Fri, 7 Jun 2024 18:41:50 +0000 (20:41 +0200)
committerElias Rohrer <dev@tnull.de>
Fri, 7 Jun 2024 18:41:50 +0000 (20:41 +0200)
fuzz/src/onion_hop_data.rs
fuzz/src/onion_message.rs
rustfmt_excluded_files

index e7f51b9916775244cb73a87b3b2de57fbe585efa..36aebb4e194e6181cff4b6310e1c481f51148dbd 100644 (file)
@@ -15,19 +15,25 @@ use lightning::util::test_utils;
 
 #[inline]
 pub fn onion_hop_data_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
-       use lightning::util::ser::ReadableArgs;
        use bitcoin::secp256k1::PublicKey;
+       use lightning::util::ser::ReadableArgs;
        let mut r = ::std::io::Cursor::new(data);
        let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
-       let _ =  <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(Option<PublicKey>, &&test_utils::TestNodeSigner)>>::read(&mut r, (None, &&node_signer));
+       let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
+               Option<PublicKey>,
+               &&test_utils::TestNodeSigner,
+       )>>::read(&mut r, (None, &&node_signer));
 }
 
 #[no_mangle]
 pub extern "C" fn onion_hop_data_run(data: *const u8, datalen: usize) {
-       use lightning::util::ser::ReadableArgs;
        use bitcoin::secp256k1::PublicKey;
+       use lightning::util::ser::ReadableArgs;
        let data = unsafe { std::slice::from_raw_parts(data, datalen) };
        let mut r = ::std::io::Cursor::new(data);
        let node_signer = test_utils::TestNodeSigner::new(test_utils::privkey(42));
-       let _ =  <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(Option<PublicKey>, &&test_utils::TestNodeSigner)>>::read(&mut r, (None, &&node_signer));
+       let _ = <lightning::ln::msgs::InboundOnionPayload as ReadableArgs<(
+               Option<PublicKey>,
+               &&test_utils::TestNodeSigner,
+       )>>::read(&mut r, (None, &&node_signer));
 }
index 371a9421fc7fea7d3348eb4304136ca49a357aa6..a8a290fefb3379a176ff781e8b80c8df1036804f 100644 (file)
@@ -1,10 +1,10 @@
 // Imports that need to be added manually
 use bech32::u5;
 use bitcoin::blockdata::script::ScriptBuf;
-use bitcoin::secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey, self};
 use bitcoin::secp256k1::ecdh::SharedSecret;
 use bitcoin::secp256k1::ecdsa::RecoverableSignature;
 use bitcoin::secp256k1::schnorr;
+use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
 
 use lightning::blinded_path::{BlindedPath, EmptyNodeIdLookUp};
 use lightning::ln::features::InitFeatures;
@@ -12,13 +12,16 @@ use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
 use lightning::ln::script::ShutdownScript;
 use lightning::offers::invoice::UnsignedBolt12Invoice;
 use lightning::offers::invoice_request::UnsignedInvoiceRequest;
-use lightning::sign::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
-use lightning::util::test_channel_signer::TestChannelSigner;
-use lightning::util::logger::Logger;
-use lightning::util::ser::{Readable, Writeable, Writer};
-use lightning::onion_message::messenger::{CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger, PendingOnionMessage, Responder, ResponseInstruction};
+use lightning::onion_message::messenger::{
+       CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger,
+       PendingOnionMessage, Responder, ResponseInstruction,
+};
 use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler};
 use lightning::onion_message::packet::OnionMessageContents;
+use lightning::sign::{EntropySource, KeyMaterial, NodeSigner, Recipient, SignerProvider};
+use lightning::util::logger::Logger;
+use lightning::util::ser::{Readable, Writeable, Writer};
+use lightning::util::test_channel_signer::TestChannelSigner;
 
 use crate::utils::test_logger;
 
@@ -32,17 +35,19 @@ pub fn do_test<L: Logger>(data: &[u8], logger: &L) {
                let mut secret_bytes = [1; 32];
                secret_bytes[31] = 2;
                let secret = SecretKey::from_slice(&secret_bytes).unwrap();
-               let keys_manager = KeyProvider {
-                       node_secret: secret,
-                       counter: AtomicU64::new(0),
-               };
+               let keys_manager = KeyProvider { node_secret: secret, counter: AtomicU64::new(0) };
                let node_id_lookup = EmptyNodeIdLookUp {};
                let message_router = TestMessageRouter {};
                let offers_msg_handler = TestOffersMessageHandler {};
                let custom_msg_handler = TestCustomMessageHandler {};
                let onion_messenger = OnionMessenger::new(
-                       &keys_manager, &keys_manager, logger, &node_id_lookup, &message_router,
-                       &offers_msg_handler, &custom_msg_handler
+                       &keys_manager,
+                       &keys_manager,
+                       logger,
+                       &node_id_lookup,
+                       &message_router,
+                       &offers_msg_handler,
+                       &custom_msg_handler,
                );
 
                let peer_node_id = {
@@ -78,13 +83,9 @@ struct TestMessageRouter {}
 
 impl MessageRouter for TestMessageRouter {
        fn find_path(
-               &self, _sender: PublicKey, _peers: Vec<PublicKey>, destination: Destination
+               &self, _sender: PublicKey, _peers: Vec<PublicKey>, destination: Destination,
        ) -> Result<OnionMessagePath, ()> {
-               Ok(OnionMessagePath {
-                       intermediate_nodes: vec![],
-                       destination,
-                       first_node_addresses: None,
-               })
+               Ok(OnionMessagePath { intermediate_nodes: vec![], destination, first_node_addresses: None })
        }
 
        fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
@@ -97,7 +98,9 @@ impl MessageRouter for TestMessageRouter {
 struct TestOffersMessageHandler {}
 
 impl OffersMessageHandler for TestOffersMessageHandler {
-       fn handle_message(&self, _message: OffersMessage, _responder: Option<Responder>) -> ResponseInstruction<OffersMessage> {
+       fn handle_message(
+               &self, _message: OffersMessage, _responder: Option<Responder>,
+       ) -> ResponseInstruction<OffersMessage> {
                ResponseInstruction::NoResponse
        }
 }
@@ -127,16 +130,20 @@ struct TestCustomMessageHandler {}
 
 impl CustomOnionMessageHandler for TestCustomMessageHandler {
        type CustomMessage = TestCustomMessage;
-       fn handle_custom_message(&self, message: Self::CustomMessage, responder: Option<Responder>) -> ResponseInstruction<Self::CustomMessage> {
+       fn handle_custom_message(
+               &self, message: Self::CustomMessage, responder: Option<Responder>,
+       ) -> ResponseInstruction<Self::CustomMessage> {
                match responder {
                        Some(responder) => responder.respond(message),
-                       None => ResponseInstruction::NoResponse
+                       None => ResponseInstruction::NoResponse,
                }
        }
-       fn read_custom_message<R: io::Read>(&self, _message_type: u64, buffer: &mut R) -> Result<Option<Self::CustomMessage>, msgs::DecodeError> {
+       fn read_custom_message<R: io::Read>(
+               &self, _message_type: u64, buffer: &mut R,
+       ) -> Result<Option<Self::CustomMessage>, msgs::DecodeError> {
                let mut buf = Vec::new();
                buffer.read_to_end(&mut buf)?;
-               return Ok(Some(TestCustomMessage {}))
+               return Ok(Some(TestCustomMessage {}));
        }
        fn release_pending_custom_messages(&self) -> Vec<PendingOnionMessage<Self::CustomMessage>> {
                vec![]
@@ -158,8 +165,11 @@ struct KeyProvider {
 impl EntropySource for KeyProvider {
        fn get_secure_random_bytes(&self) -> [u8; 32] {
                let ctr = self.counter.fetch_add(1, Ordering::Relaxed);
-               [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-                       (ctr >> 8*7) as u8, (ctr >> 8*6) as u8, (ctr >> 8*5) as u8, (ctr >> 8*4) as u8, (ctr >> 8*3) as u8, (ctr >> 8*2) as u8, (ctr >> 8*1) as u8, 14, (ctr >> 8*0) as u8]
+               #[rustfmt::skip]
+               let random_bytes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       (ctr >> 8*7) as u8, (ctr >> 8*6) as u8, (ctr >> 8*5) as u8, (ctr >> 8*4) as u8,
+                       (ctr >> 8*3) as u8, (ctr >> 8*2) as u8, (ctr >> 8*1) as u8, 14, (ctr >> 8*0) as u8];
+               random_bytes
        }
 }
 
@@ -167,15 +177,17 @@ impl NodeSigner for KeyProvider {
        fn get_node_id(&self, recipient: Recipient) -> Result<PublicKey, ()> {
                let node_secret = match recipient {
                        Recipient::Node => Ok(&self.node_secret),
-                       Recipient::PhantomNode => Err(())
+                       Recipient::PhantomNode => Err(()),
                }?;
                Ok(PublicKey::from_secret_key(&Secp256k1::signing_only(), node_secret))
        }
 
-       fn ecdh(&self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>) -> Result<SharedSecret, ()> {
+       fn ecdh(
+               &self, recipient: Recipient, other_key: &PublicKey, tweak: Option<&Scalar>,
+       ) -> Result<SharedSecret, ()> {
                let mut node_secret = match recipient {
                        Recipient::Node => Ok(self.node_secret.clone()),
-                       Recipient::PhantomNode => Err(())
+                       Recipient::PhantomNode => Err(()),
                }?;
                if let Some(tweak) = tweak {
                        node_secret = node_secret.mul_tweak(tweak).map_err(|_| ())?;
@@ -183,14 +195,18 @@ impl NodeSigner for KeyProvider {
                Ok(SharedSecret::new(other_key, &node_secret))
        }
 
-       fn get_inbound_payment_key_material(&self) -> KeyMaterial { unreachable!() }
+       fn get_inbound_payment_key_material(&self) -> KeyMaterial {
+               unreachable!()
+       }
 
-       fn sign_invoice(&self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient) -> Result<RecoverableSignature, ()> {
+       fn sign_invoice(
+               &self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient,
+       ) -> Result<RecoverableSignature, ()> {
                unreachable!()
        }
 
        fn sign_bolt12_invoice_request(
-               &self, _invoice_request: &UnsignedInvoiceRequest
+               &self, _invoice_request: &UnsignedInvoiceRequest,
        ) -> Result<schnorr::Signature, ()> {
                unreachable!()
        }
@@ -201,7 +217,9 @@ impl NodeSigner for KeyProvider {
                unreachable!()
        }
 
-       fn sign_gossip_message(&self, _msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
+       fn sign_gossip_message(
+               &self, _msg: lightning::ln::msgs::UnsignedGossipMessage,
+       ) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
                unreachable!()
        }
 }
@@ -211,17 +229,29 @@ impl SignerProvider for KeyProvider {
        #[cfg(taproot)]
        type TaprootSigner = TestChannelSigner;
 
-       fn generate_channel_keys_id(&self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128) -> [u8; 32] { unreachable!() }
+       fn generate_channel_keys_id(
+               &self, _inbound: bool, _channel_value_satoshis: u64, _user_channel_id: u128,
+       ) -> [u8; 32] {
+               unreachable!()
+       }
 
-       fn derive_channel_signer(&self, _channel_value_satoshis: u64, _channel_keys_id: [u8; 32]) -> Self::EcdsaSigner {
+       fn derive_channel_signer(
+               &self, _channel_value_satoshis: u64, _channel_keys_id: [u8; 32],
+       ) -> Self::EcdsaSigner {
                unreachable!()
        }
 
-       fn read_chan_signer(&self, _data: &[u8]) -> Result<TestChannelSigner, DecodeError> { unreachable!() }
+       fn read_chan_signer(&self, _data: &[u8]) -> Result<TestChannelSigner, DecodeError> {
+               unreachable!()
+       }
 
-       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> { unreachable!() }
+       fn get_destination_script(&self, _channel_keys_id: [u8; 32]) -> Result<ScriptBuf, ()> {
+               unreachable!()
+       }
 
-       fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> { unreachable!() }
+       fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
+               unreachable!()
+       }
 }
 
 #[cfg(test)]
@@ -237,8 +267,17 @@ mod tests {
        }
        impl Logger for TrackingLogger {
                fn log(&self, record: Record) {
-                       *self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
-                       println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
+                       let mut lines_lock = self.lines.lock().unwrap();
+                       let key = (record.module_path.to_string(), format!("{}", record.args));
+                       *lines_lock.entry(key).or_insert(0) += 1;
+                       println!(
+                               "{:<5} [{} : {}, {}] {}",
+                               record.level.to_string(),
+                               record.module_path,
+                               record.file,
+                               record.line,
+                               record.args
+                       );
                }
        }
 
index c94d48bfe00d2d8ed94e8de46d2f5d1140088eb2..8ed44546f70c1f805cf5b4b8b3f766e07be39341 100644 (file)
@@ -2,8 +2,6 @@
 ./fuzz/src/chanmon_consistency.rs
 ./fuzz/src/full_stack.rs
 ./fuzz/src/offer_deser.rs
-./fuzz/src/onion_hop_data.rs
-./fuzz/src/onion_message.rs
 ./fuzz/src/peer_crypt.rs
 ./fuzz/src/process_network_graph.rs
 ./fuzz/src/refund_deser.rs