From f24f803be2fad2b61c379747028b7c862db1dc3a Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Wed, 8 Mar 2023 15:28:56 +1100 Subject: [PATCH] chore: Add Clippy lint workspace configuration We've used a similar pattern in past projects. One thing that has changed is that we use `[target.'cfg(feature = "cargo-clippy")']` instead of `[build]`. This allows us to enforce this lint configuration locally and not just on CI. Using `rustflags` does mean that devs might encounter unexpected full rebuilds when switching between IDE and command line when using `cargo clippy`. This is a known issue[1]. For emacs, I just solved this by setting a different Cargo `target-directory` to the one used by default. A similar approach should work for other IDEs. [1]: https://github.com/rust-lang/cargo/issues/8716. --- .cargo/config.toml | 8 +++++ coordinator/src/logger.rs | 1 + coordinator/src/routes.rs | 3 +- crates/bdk-ldk/src/lib.rs | 2 +- crates/ln-dlc-node/src/dlc_custom_signer.rs | 36 +++++++++------------ crates/ln-dlc-node/src/ln/event_handler.rs | 5 ++- crates/ln-dlc-node/src/node/mod.rs | 2 +- crates/ln-dlc-node/src/tests/mod.rs | 2 +- maker/src/logger.rs | 1 + maker/src/routes.rs | 4 +-- mobile/native/src/db/custom_types.rs | 19 ++++++----- mobile/native/src/lib.rs | 4 ++- mobile/native/src/logger.rs | 1 + 13 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..fc1b37042 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,8 @@ +[target.'cfg(feature = "cargo-clippy")'] +rustflags = [ + "-Wclippy::dbg_macro", + "-Wclippy::print_stderr", + "-Wclippy::print_stdout", + "-Wunused-import-braces", + "-Wunused-qualifications", +] \ No newline at end of file diff --git a/coordinator/src/logger.rs b/coordinator/src/logger.rs index dee1d9d2e..271050f41 100644 --- a/coordinator/src/logger.rs +++ b/coordinator/src/logger.rs @@ -31,6 +31,7 @@ pub fn init_tracing(level: LevelFilter, json_format: bool) -> Result<()> { let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) { Some(Ok(env)) => { for directive in env.split(',') { + #[allow(clippy::print_stdout)] match directive.parse() { Ok(d) => filter = filter.add_directive(d), Err(e) => println!("WARN ignoring log directive: `{directive}`: {e}"), diff --git a/coordinator/src/routes.rs b/coordinator/src/routes.rs index 4fd04133b..ce5e570be 100644 --- a/coordinator/src/routes.rs +++ b/coordinator/src/routes.rs @@ -15,7 +15,6 @@ use axum::routing::post; use axum::Json; use axum::Router; use bitcoin::secp256k1::PublicKey; -use diesel::r2d2; use diesel::r2d2::ConnectionManager; use diesel::r2d2::Pool; use diesel::PgConnection; @@ -32,7 +31,7 @@ pub struct AppState { pub node: Arc, // Channel used to send messages to all connected clients. pub tx_pricefeed: broadcast::Sender, - pub pool: r2d2::Pool>, + pub pool: Pool>, } pub fn router(node: Arc, pool: Pool>) -> Router { diff --git a/crates/bdk-ldk/src/lib.rs b/crates/bdk-ldk/src/lib.rs index f0d04bcae..788fcf595 100644 --- a/crates/bdk-ldk/src/lib.rs +++ b/crates/bdk-ldk/src/lib.rs @@ -405,7 +405,7 @@ where { fn broadcast_transaction(&self, tx: &Transaction) { if let Err(e) = self.client.broadcast(tx) { - eprintln!("Error broadcasting transaction: {e:#}"); + tracing::error!("Error broadcasting transaction: {e:#}"); } } } diff --git a/crates/ln-dlc-node/src/dlc_custom_signer.rs b/crates/ln-dlc-node/src/dlc_custom_signer.rs index 822fefc24..a538c0d3c 100644 --- a/crates/ln-dlc-node/src/dlc_custom_signer.rs +++ b/crates/ln-dlc-node/src/dlc_custom_signer.rs @@ -52,7 +52,7 @@ impl BaseSign for CustomSigner { fn get_per_commitment_point( &self, idx: u64, - secp_ctx: &secp256k1_zkp::Secp256k1, + secp_ctx: &Secp256k1, ) -> secp256k1_zkp::PublicKey { self.in_memory_signer .lock() @@ -78,7 +78,7 @@ impl BaseSign for CustomSigner { .validate_holder_commitment(holder_tx, preimages) } - fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys { + fn pubkeys(&self) -> &ChannelPublicKeys { &self.channel_public_keys } @@ -90,7 +90,7 @@ impl BaseSign for CustomSigner { &self, commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, preimages: Vec, - secp_ctx: &secp256k1_zkp::Secp256k1, + secp_ctx: &Secp256k1, ) -> Result< ( secp256k1_zkp::ecdsa::Signature, @@ -104,11 +104,7 @@ impl BaseSign for CustomSigner { .sign_counterparty_commitment(commitment_tx, preimages, secp_ctx) } - fn validate_counterparty_revocation( - &self, - idx: u64, - secret: &secp256k1_zkp::SecretKey, - ) -> Result<(), ()> { + fn validate_counterparty_revocation(&self, idx: u64, secret: &SecretKey) -> Result<(), ()> { self.in_memory_signer .lock() .unwrap() @@ -118,7 +114,7 @@ impl BaseSign for CustomSigner { fn sign_holder_commitment_and_htlcs( &self, commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, - secp_ctx: &secp256k1_zkp::Secp256k1, + secp_ctx: &Secp256k1, ) -> Result< ( secp256k1_zkp::ecdsa::Signature, @@ -134,11 +130,11 @@ impl BaseSign for CustomSigner { fn sign_justice_revoked_output( &self, - justice_tx: &bitcoin::Transaction, + justice_tx: &Transaction, input: usize, amount: u64, - per_commitment_key: &secp256k1_zkp::SecretKey, - secp_ctx: &secp256k1_zkp::Secp256k1, + per_commitment_key: &SecretKey, + secp_ctx: &Secp256k1, ) -> Result { self.in_memory_signer .lock() @@ -148,12 +144,12 @@ impl BaseSign for CustomSigner { fn sign_justice_revoked_htlc( &self, - justice_tx: &bitcoin::Transaction, + justice_tx: &Transaction, input: usize, amount: u64, - per_commitment_key: &secp256k1_zkp::SecretKey, + per_commitment_key: &SecretKey, htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, - secp_ctx: &secp256k1_zkp::Secp256k1, + secp_ctx: &Secp256k1, ) -> Result { self.in_memory_signer .lock() @@ -170,12 +166,12 @@ impl BaseSign for CustomSigner { fn sign_counterparty_htlc_transaction( &self, - htlc_tx: &bitcoin::Transaction, + htlc_tx: &Transaction, input: usize, amount: u64, per_commitment_point: &secp256k1_zkp::PublicKey, htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, - secp_ctx: &secp256k1_zkp::Secp256k1, + secp_ctx: &Secp256k1, ) -> Result { self.in_memory_signer .lock() @@ -193,7 +189,7 @@ impl BaseSign for CustomSigner { fn sign_closing_transaction( &self, closing_tx: &lightning::ln::chan_utils::ClosingTransaction, - secp_ctx: &secp256k1_zkp::Secp256k1, + secp_ctx: &Secp256k1, ) -> Result { self.in_memory_signer .lock() @@ -204,7 +200,7 @@ impl BaseSign for CustomSigner { fn sign_channel_announcement( &self, msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, - secp_ctx: &secp256k1_zkp::Secp256k1, + secp_ctx: &Secp256k1, ) -> Result< ( secp256k1_zkp::ecdsa::Signature, @@ -244,7 +240,7 @@ impl BaseSign for CustomSigner { impl ExtraSign for CustomSigner { fn sign_with_fund_key_callback(&self, cb: &mut F) where - F: FnMut(&secp256k1_zkp::SecretKey), + F: FnMut(&SecretKey), { self.in_memory_signer .lock() diff --git a/crates/ln-dlc-node/src/ln/event_handler.rs b/crates/ln-dlc-node/src/ln/event_handler.rs index 53f7a6e89..1f8ce9656 100644 --- a/crates/ln-dlc-node/src/ln/event_handler.rs +++ b/crates/ln-dlc-node/src/ln/event_handler.rs @@ -208,7 +208,10 @@ impl EventHandler { Event::PaymentPathSuccessful { .. } => {} Event::PaymentPathFailed { .. } => {} Event::PaymentFailed { payment_hash, .. } => { - print!("\nEVENT: Failed to send payment to payment hash {:?}: exhausted payment retry attempts", hex::encode(payment_hash.0)); + tracing::warn!( + "Failed to send payment to payment hash {:?}: exhausted payment retry attempts", + hex::encode(payment_hash.0) + ); let mut payments = self.outbound_payments.lock().unwrap(); if payments.contains_key(&payment_hash) { diff --git a/crates/ln-dlc-node/src/node/mod.rs b/crates/ln-dlc-node/src/node/mod.rs index c4be28f24..d6fb313fb 100644 --- a/crates/ln-dlc-node/src/node/mod.rs +++ b/crates/ln-dlc-node/src/node/mod.rs @@ -95,7 +95,7 @@ pub struct Node { dlc_message_handler: Arc, inbound_payments: PaymentInfoStorage, - pub(crate) user_config: lightning::util::config::UserConfig, + pub(crate) user_config: UserConfig, pending_trades: Arc>>, } diff --git a/crates/ln-dlc-node/src/tests/mod.rs b/crates/ln-dlc-node/src/tests/mod.rs index 38e98a123..4d625bf15 100644 --- a/crates/ln-dlc-node/src/tests/mod.rs +++ b/crates/ln-dlc-node/src/tests/mod.rs @@ -98,7 +98,7 @@ impl Node { Ok(node) } - async fn fund(&self, amount: bitcoin::Amount) -> Result<()> { + async fn fund(&self, amount: Amount) -> Result<()> { let starting_balance = self.get_confirmed_balance()?; let expected_balance = starting_balance + amount.to_sat(); diff --git a/maker/src/logger.rs b/maker/src/logger.rs index dee1d9d2e..271050f41 100644 --- a/maker/src/logger.rs +++ b/maker/src/logger.rs @@ -31,6 +31,7 @@ pub fn init_tracing(level: LevelFilter, json_format: bool) -> Result<()> { let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) { Some(Ok(env)) => { for directive in env.split(',') { + #[allow(clippy::print_stdout)] match directive.parse() { Ok(d) => filter = filter.add_directive(d), Err(e) => println!("WARN ignoring log directive: `{directive}`: {e}"), diff --git a/maker/src/routes.rs b/maker/src/routes.rs index e03d2883c..1dfd21082 100644 --- a/maker/src/routes.rs +++ b/maker/src/routes.rs @@ -9,7 +9,6 @@ use axum::Json; use axum::Router; use bitcoin::hashes::hex::ToHex; use bitcoin::secp256k1::PublicKey; -use diesel::r2d2; use diesel::r2d2::ConnectionManager; use diesel::r2d2::Pool; use diesel::PgConnection; @@ -23,7 +22,7 @@ use std::sync::Arc; pub struct AppState { pub node: Arc, - pub pool: r2d2::Pool>, + pub pool: Pool>, } pub fn router(node: Arc, pool: Pool>) -> Router { @@ -263,7 +262,6 @@ pub async fn pay_invoice( State(state): State>, Path(invoice): Path, ) -> Result, AppError> { - dbg!(&invoice); let invoice = invoice .parse() .map_err(|e| AppError::BadRequest(format!("Invalid invoice provided {e:#}")))?; diff --git a/mobile/native/src/db/custom_types.rs b/mobile/native/src/db/custom_types.rs index b28af48e8..224f86742 100644 --- a/mobile/native/src/db/custom_types.rs +++ b/mobile/native/src/db/custom_types.rs @@ -9,11 +9,10 @@ use diesel::serialize::IsNull; use diesel::serialize::Output; use diesel::serialize::ToSql; use diesel::serialize::{self}; -use diesel::sql_types; use diesel::sql_types::Text; use diesel::sqlite::Sqlite; -impl ToSql for OrderType { +impl ToSql for OrderType { fn to_sql(&self, out: &mut Output) -> serialize::Result { let text = match *self { OrderType::Market => "market".to_string(), @@ -24,7 +23,7 @@ impl ToSql for OrderType { } } -impl FromSql for OrderType { +impl FromSql for OrderType { fn from_sql(bytes: backend::RawValue) -> deserialize::Result { let string = >::from_sql(bytes)?; @@ -36,7 +35,7 @@ impl FromSql for OrderType { } } -impl ToSql for OrderState { +impl ToSql for OrderState { fn to_sql(&self, out: &mut Output) -> serialize::Result { let text = match *self { OrderState::Initial => "initial".to_string(), @@ -50,7 +49,7 @@ impl ToSql for OrderState { } } -impl FromSql for OrderState { +impl FromSql for OrderState { fn from_sql(bytes: backend::RawValue) -> deserialize::Result { let string = >::from_sql(bytes)?; @@ -65,7 +64,7 @@ impl FromSql for OrderState { } } -impl ToSql for ContractSymbol { +impl ToSql for ContractSymbol { fn to_sql(&self, out: &mut Output) -> serialize::Result { let text = match *self { ContractSymbol::BtcUsd => "BtcUsd", @@ -75,7 +74,7 @@ impl ToSql for ContractSymbol { } } -impl FromSql for ContractSymbol { +impl FromSql for ContractSymbol { fn from_sql(bytes: backend::RawValue) -> deserialize::Result { let string = >::from_sql(bytes)?; @@ -86,7 +85,7 @@ impl FromSql for ContractSymbol { } } -impl ToSql for Direction { +impl ToSql for Direction { fn to_sql(&self, out: &mut Output) -> serialize::Result { let text = match *self { Direction::Long => "Long", @@ -97,7 +96,7 @@ impl ToSql for Direction { } } -impl FromSql for Direction { +impl FromSql for Direction { fn from_sql(bytes: backend::RawValue) -> deserialize::Result { let string = >::from_sql(bytes)?; @@ -149,7 +148,7 @@ pub mod tests { connection .batch_execute( r#" - create table customstruct ( + create table customstruct ( id TEXT PRIMARY KEY NOT NULL, order_type TEXT NOT NULL, order_state TEXT NOT NULL, diff --git a/mobile/native/src/lib.rs b/mobile/native/src/lib.rs index f82ff5cc2..0ec554581 100644 --- a/mobile/native/src/lib.rs +++ b/mobile/native/src/lib.rs @@ -4,10 +4,12 @@ pub mod db; pub mod schema; mod api; -mod bridge_generated; pub mod calculations; pub(crate) mod config; pub mod event; pub mod ln_dlc; pub mod logger; pub mod trade; + +#[allow(clippy::all, unused_import_braces, unused_qualifications)] +mod bridge_generated; diff --git a/mobile/native/src/logger.rs b/mobile/native/src/logger.rs index 8ea8abecd..5a222bd80 100644 --- a/mobile/native/src/logger.rs +++ b/mobile/native/src/logger.rs @@ -141,6 +141,7 @@ pub fn init_tracing(level: LevelFilter, json_format: bool) -> Result<()> { Some(Ok(env)) => { let mut filter = log_base_directives(EnvFilter::new(""), level)?; for directive in env.split(',') { + #[allow(clippy::print_stdout)] match directive.parse() { Ok(d) => filter = filter.add_directive(d), Err(e) => println!("WARN ignoring log directive: `{directive}`: {e}"),