Skip to content

Commit 2cf4293

Browse files
committed
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]: rust-lang/cargo#8716.
1 parent a045dc9 commit 2cf4293

File tree

13 files changed

+48
-40
lines changed

13 files changed

+48
-40
lines changed

.cargo/config.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[target.'cfg(feature = "cargo-clippy")']
2+
rustflags = [
3+
"-Wclippy::dbg_macro",
4+
"-Wclippy::print_stderr",
5+
"-Wclippy::print_stdout",
6+
"-Wunused-import-braces",
7+
"-Wunused-qualifications",
8+
]

coordinator/src/logger.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn init_tracing(level: LevelFilter, json_format: bool) -> Result<()> {
3131
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
3232
Some(Ok(env)) => {
3333
for directive in env.split(',') {
34+
#[allow(clippy::print_stdout)]
3435
match directive.parse() {
3536
Ok(d) => filter = filter.add_directive(d),
3637
Err(e) => println!("WARN ignoring log directive: `{directive}`: {e}"),

coordinator/src/routes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use axum::routing::post;
1515
use axum::Json;
1616
use axum::Router;
1717
use bitcoin::secp256k1::PublicKey;
18-
use diesel::r2d2;
1918
use diesel::r2d2::ConnectionManager;
2019
use diesel::r2d2::Pool;
2120
use diesel::PgConnection;
@@ -32,7 +31,7 @@ pub struct AppState {
3231
pub node: Arc<Node>,
3332
// Channel used to send messages to all connected clients.
3433
pub tx_pricefeed: broadcast::Sender<PriceFeedMessage>,
35-
pub pool: r2d2::Pool<ConnectionManager<PgConnection>>,
34+
pub pool: Pool<ConnectionManager<PgConnection>>,
3635
}
3736

3837
pub fn router(node: Arc<Node>, pool: Pool<ConnectionManager<PgConnection>>) -> Router {

crates/bdk-ldk/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ where
405405
{
406406
fn broadcast_transaction(&self, tx: &Transaction) {
407407
if let Err(e) = self.client.broadcast(tx) {
408-
eprintln!("Error broadcasting transaction: {e:#}");
408+
tracing::error!("Error broadcasting transaction: {e:#}");
409409
}
410410
}
411411
}

crates/ln-dlc-node/src/dlc_custom_signer.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl BaseSign for CustomSigner {
5252
fn get_per_commitment_point(
5353
&self,
5454
idx: u64,
55-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
55+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
5656
) -> secp256k1_zkp::PublicKey {
5757
self.in_memory_signer
5858
.lock()
@@ -78,7 +78,7 @@ impl BaseSign for CustomSigner {
7878
.validate_holder_commitment(holder_tx, preimages)
7979
}
8080

81-
fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
81+
fn pubkeys(&self) -> &ChannelPublicKeys {
8282
&self.channel_public_keys
8383
}
8484

@@ -90,7 +90,7 @@ impl BaseSign for CustomSigner {
9090
&self,
9191
commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction,
9292
preimages: Vec<lightning::ln::PaymentPreimage>,
93-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
93+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
9494
) -> Result<
9595
(
9696
secp256k1_zkp::ecdsa::Signature,
@@ -104,11 +104,7 @@ impl BaseSign for CustomSigner {
104104
.sign_counterparty_commitment(commitment_tx, preimages, secp_ctx)
105105
}
106106

107-
fn validate_counterparty_revocation(
108-
&self,
109-
idx: u64,
110-
secret: &secp256k1_zkp::SecretKey,
111-
) -> Result<(), ()> {
107+
fn validate_counterparty_revocation(&self, idx: u64, secret: &SecretKey) -> Result<(), ()> {
112108
self.in_memory_signer
113109
.lock()
114110
.unwrap()
@@ -118,7 +114,7 @@ impl BaseSign for CustomSigner {
118114
fn sign_holder_commitment_and_htlcs(
119115
&self,
120116
commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction,
121-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
117+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
122118
) -> Result<
123119
(
124120
secp256k1_zkp::ecdsa::Signature,
@@ -134,11 +130,11 @@ impl BaseSign for CustomSigner {
134130

135131
fn sign_justice_revoked_output(
136132
&self,
137-
justice_tx: &bitcoin::Transaction,
133+
justice_tx: &Transaction,
138134
input: usize,
139135
amount: u64,
140-
per_commitment_key: &secp256k1_zkp::SecretKey,
141-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
136+
per_commitment_key: &SecretKey,
137+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
142138
) -> Result<secp256k1_zkp::ecdsa::Signature, ()> {
143139
self.in_memory_signer
144140
.lock()
@@ -148,12 +144,12 @@ impl BaseSign for CustomSigner {
148144

149145
fn sign_justice_revoked_htlc(
150146
&self,
151-
justice_tx: &bitcoin::Transaction,
147+
justice_tx: &Transaction,
152148
input: usize,
153149
amount: u64,
154-
per_commitment_key: &secp256k1_zkp::SecretKey,
150+
per_commitment_key: &SecretKey,
155151
htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment,
156-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
152+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
157153
) -> Result<secp256k1_zkp::ecdsa::Signature, ()> {
158154
self.in_memory_signer
159155
.lock()
@@ -170,12 +166,12 @@ impl BaseSign for CustomSigner {
170166

171167
fn sign_counterparty_htlc_transaction(
172168
&self,
173-
htlc_tx: &bitcoin::Transaction,
169+
htlc_tx: &Transaction,
174170
input: usize,
175171
amount: u64,
176172
per_commitment_point: &secp256k1_zkp::PublicKey,
177173
htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment,
178-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
174+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
179175
) -> Result<secp256k1_zkp::ecdsa::Signature, ()> {
180176
self.in_memory_signer
181177
.lock()
@@ -193,7 +189,7 @@ impl BaseSign for CustomSigner {
193189
fn sign_closing_transaction(
194190
&self,
195191
closing_tx: &lightning::ln::chan_utils::ClosingTransaction,
196-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
192+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
197193
) -> Result<secp256k1_zkp::ecdsa::Signature, ()> {
198194
self.in_memory_signer
199195
.lock()
@@ -204,7 +200,7 @@ impl BaseSign for CustomSigner {
204200
fn sign_channel_announcement(
205201
&self,
206202
msg: &lightning::ln::msgs::UnsignedChannelAnnouncement,
207-
secp_ctx: &secp256k1_zkp::Secp256k1<bitcoin::secp256k1::All>,
203+
secp_ctx: &Secp256k1<bitcoin::secp256k1::All>,
208204
) -> Result<
209205
(
210206
secp256k1_zkp::ecdsa::Signature,
@@ -244,7 +240,7 @@ impl BaseSign for CustomSigner {
244240
impl ExtraSign for CustomSigner {
245241
fn sign_with_fund_key_callback<F>(&self, cb: &mut F)
246242
where
247-
F: FnMut(&secp256k1_zkp::SecretKey),
243+
F: FnMut(&SecretKey),
248244
{
249245
self.in_memory_signer
250246
.lock()

crates/ln-dlc-node/src/ln/event_handler.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ impl EventHandler {
208208
Event::PaymentPathSuccessful { .. } => {}
209209
Event::PaymentPathFailed { .. } => {}
210210
Event::PaymentFailed { payment_hash, .. } => {
211-
print!("\nEVENT: Failed to send payment to payment hash {:?}: exhausted payment retry attempts", hex::encode(payment_hash.0));
211+
tracing::warn!(
212+
"Failed to send payment to payment hash {:?}: exhausted payment retry attempts",
213+
hex::encode(payment_hash.0)
214+
);
212215

213216
let mut payments = self.outbound_payments.lock().unwrap();
214217
if payments.contains_key(&payment_hash) {

crates/ln-dlc-node/src/node/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct Node {
9595
dlc_message_handler: Arc<DlcMessageHandler>,
9696
inbound_payments: PaymentInfoStorage,
9797

98-
pub(crate) user_config: lightning::util::config::UserConfig,
98+
pub(crate) user_config: UserConfig,
9999

100100
pending_trades: Arc<Mutex<HashSet<PublicKey>>>,
101101
}

crates/ln-dlc-node/src/tests/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Node {
9898
Ok(node)
9999
}
100100

101-
async fn fund(&self, amount: bitcoin::Amount) -> Result<()> {
101+
async fn fund(&self, amount: Amount) -> Result<()> {
102102
let starting_balance = self.get_confirmed_balance()?;
103103
let expected_balance = starting_balance + amount.to_sat();
104104

maker/src/logger.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn init_tracing(level: LevelFilter, json_format: bool) -> Result<()> {
3131
let filter = match std::env::var_os(RUST_LOG_ENV).map(|s| s.into_string()) {
3232
Some(Ok(env)) => {
3333
for directive in env.split(',') {
34+
#[allow(clippy::print_stdout)]
3435
match directive.parse() {
3536
Ok(d) => filter = filter.add_directive(d),
3637
Err(e) => println!("WARN ignoring log directive: `{directive}`: {e}"),

maker/src/routes.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use axum::Json;
99
use axum::Router;
1010
use bitcoin::hashes::hex::ToHex;
1111
use bitcoin::secp256k1::PublicKey;
12-
use diesel::r2d2;
1312
use diesel::r2d2::ConnectionManager;
1413
use diesel::r2d2::Pool;
1514
use diesel::PgConnection;
@@ -23,7 +22,7 @@ use std::sync::Arc;
2322

2423
pub struct AppState {
2524
pub node: Arc<Node>,
26-
pub pool: r2d2::Pool<ConnectionManager<PgConnection>>,
25+
pub pool: Pool<ConnectionManager<PgConnection>>,
2726
}
2827

2928
pub fn router(node: Arc<Node>, pool: Pool<ConnectionManager<PgConnection>>) -> Router {
@@ -263,7 +262,6 @@ pub async fn pay_invoice(
263262
State(state): State<Arc<AppState>>,
264263
Path(invoice): Path<String>,
265264
) -> Result<Json<String>, AppError> {
266-
dbg!(&invoice);
267265
let invoice = invoice
268266
.parse()
269267
.map_err(|e| AppError::BadRequest(format!("Invalid invoice provided {e:#}")))?;

mobile/native/src/db/custom_types.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use diesel::serialize::IsNull;
99
use diesel::serialize::Output;
1010
use diesel::serialize::ToSql;
1111
use diesel::serialize::{self};
12-
use diesel::sql_types;
1312
use diesel::sql_types::Text;
1413
use diesel::sqlite::Sqlite;
1514

16-
impl ToSql<sql_types::Text, Sqlite> for OrderType {
15+
impl ToSql<Text, Sqlite> for OrderType {
1716
fn to_sql(&self, out: &mut Output<Sqlite>) -> serialize::Result {
1817
let text = match *self {
1918
OrderType::Market => "market".to_string(),
@@ -24,7 +23,7 @@ impl ToSql<sql_types::Text, Sqlite> for OrderType {
2423
}
2524
}
2625

27-
impl FromSql<sql_types::Text, Sqlite> for OrderType {
26+
impl FromSql<Text, Sqlite> for OrderType {
2827
fn from_sql(bytes: backend::RawValue<Sqlite>) -> deserialize::Result<Self> {
2928
let string = <String as FromSql<Text, Sqlite>>::from_sql(bytes)?;
3029

@@ -36,7 +35,7 @@ impl FromSql<sql_types::Text, Sqlite> for OrderType {
3635
}
3736
}
3837

39-
impl ToSql<sql_types::Text, Sqlite> for OrderState {
38+
impl ToSql<Text, Sqlite> for OrderState {
4039
fn to_sql(&self, out: &mut Output<Sqlite>) -> serialize::Result {
4140
let text = match *self {
4241
OrderState::Initial => "initial".to_string(),
@@ -50,7 +49,7 @@ impl ToSql<sql_types::Text, Sqlite> for OrderState {
5049
}
5150
}
5251

53-
impl FromSql<sql_types::Text, Sqlite> for OrderState {
52+
impl FromSql<Text, Sqlite> for OrderState {
5453
fn from_sql(bytes: backend::RawValue<Sqlite>) -> deserialize::Result<Self> {
5554
let string = <String as FromSql<Text, Sqlite>>::from_sql(bytes)?;
5655

@@ -65,7 +64,7 @@ impl FromSql<sql_types::Text, Sqlite> for OrderState {
6564
}
6665
}
6766

68-
impl ToSql<sql_types::Text, Sqlite> for ContractSymbol {
67+
impl ToSql<Text, Sqlite> for ContractSymbol {
6968
fn to_sql(&self, out: &mut Output<Sqlite>) -> serialize::Result {
7069
let text = match *self {
7170
ContractSymbol::BtcUsd => "BtcUsd",
@@ -75,7 +74,7 @@ impl ToSql<sql_types::Text, Sqlite> for ContractSymbol {
7574
}
7675
}
7776

78-
impl FromSql<sql_types::Text, Sqlite> for ContractSymbol {
77+
impl FromSql<Text, Sqlite> for ContractSymbol {
7978
fn from_sql(bytes: backend::RawValue<Sqlite>) -> deserialize::Result<Self> {
8079
let string = <String as FromSql<Text, Sqlite>>::from_sql(bytes)?;
8180

@@ -86,7 +85,7 @@ impl FromSql<sql_types::Text, Sqlite> for ContractSymbol {
8685
}
8786
}
8887

89-
impl ToSql<sql_types::Text, Sqlite> for Direction {
88+
impl ToSql<Text, Sqlite> for Direction {
9089
fn to_sql(&self, out: &mut Output<Sqlite>) -> serialize::Result {
9190
let text = match *self {
9291
Direction::Long => "Long",
@@ -97,7 +96,7 @@ impl ToSql<sql_types::Text, Sqlite> for Direction {
9796
}
9897
}
9998

100-
impl FromSql<sql_types::Text, Sqlite> for Direction {
99+
impl FromSql<Text, Sqlite> for Direction {
101100
fn from_sql(bytes: backend::RawValue<Sqlite>) -> deserialize::Result<Self> {
102101
let string = <String as FromSql<Text, Sqlite>>::from_sql(bytes)?;
103102

@@ -149,7 +148,7 @@ pub mod tests {
149148
connection
150149
.batch_execute(
151150
r#"
152-
create table customstruct (
151+
create table customstruct (
153152
id TEXT PRIMARY KEY NOT NULL,
154153
order_type TEXT NOT NULL,
155154
order_state TEXT NOT NULL,

mobile/native/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ pub mod db;
44
pub mod schema;
55

66
mod api;
7-
mod bridge_generated;
87
pub mod calculations;
98
pub(crate) mod config;
109
pub mod event;
1110
pub mod ln_dlc;
1211
pub mod logger;
1312
pub mod trade;
13+
14+
#[allow(clippy::all, unused_import_braces, unused_qualifications)]
15+
mod bridge_generated;

mobile/native/src/logger.rs

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub fn init_tracing(level: LevelFilter, json_format: bool) -> Result<()> {
141141
Some(Ok(env)) => {
142142
let mut filter = log_base_directives(EnvFilter::new(""), level)?;
143143
for directive in env.split(',') {
144+
#[allow(clippy::print_stdout)]
144145
match directive.parse() {
145146
Ok(d) => filter = filter.add_directive(d),
146147
Err(e) => println!("WARN ignoring log directive: `{directive}`: {e}"),

0 commit comments

Comments
 (0)