Skip to content

Commit 0bc4187

Browse files
committed
Fix clippy issues, enforce in CI
We weren't checking for any clippy issues. This fixes most of them and adds a few exceptions for ones not worth fixing or ones that will be fixed with future changes.
1 parent 0eb5f9d commit 0bc4187

File tree

16 files changed

+113
-197
lines changed

16 files changed

+113
-197
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
run: |
2929
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ matrix.toolchain }}
3030
rustup override set ${{ matrix.toolchain }}
31+
if [ "${{ matrix.msrv }}" = "true" ]; then rustup component add clippy; fi
3132
- name: Check formatting
3233
if: matrix.check-fmt
3334
run: rustup component add rustfmt && cargo fmt --all -- --check
@@ -37,6 +38,9 @@ jobs:
3738
echo "No packages need pinning for MSRV ${{ matrix.toolchain }}"
3839
- name: Build on Rust ${{ matrix.toolchain }}
3940
run: cargo build --verbose --color always
41+
- name: Check clippy if on msrv
42+
if: matrix.msrv
43+
run: cargo clippy --all-features -- -D warnings
4044
- name: Test on Rust ${{ matrix.toolchain }}
4145
run: cargo test
4246
- name: Cargo check release on Rust ${{ matrix.toolchain }}

ldk-server-protos/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ edition = "2021"
55

66
build = "build.rs"
77

8+
# We use a cfg instead of a feature for genproto to prevent it from being
9+
# enabled with --all-features. Proto generation is a developer-only tool that
10+
# requires external dependencies (protoc) and shouldn't be triggered accidentally.
11+
# This lint configuration tells Cargo that genproto is an expected custom cfg.
12+
[lints.rust]
13+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(genproto)'] }
14+
815
[features]
916
default = []
1017
serde = ["dep:serde", "dep:bytes"]

ldk-server/src/api/bolt11_send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::str::FromStr;
99
pub(crate) fn handle_bolt11_send_request(
1010
context: Context, request: Bolt11SendRequest,
1111
) -> Result<Bolt11SendResponse, LdkServerError> {
12-
let invoice = Bolt11Invoice::from_str(&request.invoice.as_str())
12+
let invoice = Bolt11Invoice::from_str(request.invoice.as_str())
1313
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;
1414

1515
let route_parameters = match request.route_parameters {

ldk-server/src/api/bolt12_send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(crate) fn handle_bolt12_send_request(
1010
context: Context, request: Bolt12SendRequest,
1111
) -> Result<Bolt12SendResponse, LdkServerError> {
1212
let offer =
13-
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;
13+
Offer::from_str(request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;
1414

1515
let route_parameters = match request.route_parameters {
1616
Some(params) => {

ldk-server/src/api/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ impl fmt::Display for LdkServerError {
2929
}
3030

3131
#[derive(Clone, Debug, PartialEq, Eq)]
32+
#[allow(clippy::enum_variant_names)]
3233
pub(crate) enum LdkServerErrorCode {
3334
/// Please refer to [`protos::error::ErrorCode::InvalidRequestError`].
3435
InvalidRequestError,
3536

36-
/// Please refer to [`protos::error::ErrorCode::AuthError`].
37-
AuthError,
38-
3937
/// Please refer to [`protos::error::ErrorCode::LightningError`].
4038
LightningError,
4139

@@ -47,7 +45,6 @@ impl fmt::Display for LdkServerErrorCode {
4745
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4846
match self {
4947
LdkServerErrorCode::InvalidRequestError => write!(f, "InvalidRequestError"),
50-
LdkServerErrorCode::AuthError => write!(f, "AuthError"),
5148
LdkServerErrorCode::LightningError => write!(f, "LightningError"),
5249
LdkServerErrorCode::InternalServerError => write!(f, "InternalServerError"),
5350
}

ldk-server/src/api/get_payment_details.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pub(crate) fn handle_get_payment_details_request(
1919

2020
let payment_details = context.node.payment(&PaymentId(payment_id_bytes));
2121

22-
let response = GetPaymentDetailsResponse {
23-
payment: payment_details.map(|payment| payment_to_proto(payment)),
24-
};
22+
let response = GetPaymentDetailsResponse { payment: payment_details.map(payment_to_proto) };
2523

2624
Ok(response)
2725
}

ldk-server/src/api/list_channels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ldk_server_protos::api::{ListChannelsRequest, ListChannelsResponse};
66
pub(crate) fn handle_list_channels_request(
77
context: Context, _request: ListChannelsRequest,
88
) -> Result<ListChannelsResponse, LdkServerError> {
9-
let channels = context.node.list_channels().into_iter().map(|c| channel_to_proto(c)).collect();
9+
let channels = context.node.list_channels().into_iter().map(channel_to_proto).collect();
1010

1111
let response = ListChannelsResponse { channels };
1212
Ok(response)

ldk-server/src/api/onchain_send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) fn handle_onchain_send_request(
1818
)
1919
})?;
2020

21-
let fee_rate = request.fee_rate_sat_per_vb.map(FeeRate::from_sat_per_vb).flatten();
21+
let fee_rate = request.fee_rate_sat_per_vb.and_then(FeeRate::from_sat_per_vb);
2222
let txid = match (request.amount_sats, request.send_all) {
2323
(Some(amount_sats), None) => {
2424
context.node.onchain_payment().send_to_address(&address, amount_sats, fee_rate)?

ldk-server/src/io/events/event_publisher.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ pub trait EventPublisher: Send + Sync {
4141
async fn publish(&self, event: EventEnvelope) -> Result<(), LdkServerError>;
4242
}
4343

44+
/// A no-op implementation of the [`EventPublisher`] trait.
45+
#[cfg(not(feature = "events-rabbitmq"))]
4446
pub(crate) struct NoopEventPublisher;
4547

4648
#[async_trait]
49+
#[cfg(not(feature = "events-rabbitmq"))]
4750
impl EventPublisher for NoopEventPublisher {
4851
/// Publishes an event to a no-op sink, effectively discarding it.
4952
///

ldk-server/src/io/persist/paginated_kv_store.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,6 @@ pub trait PaginatedKVStore: Send + Sync {
4949
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, time: i64, buf: &[u8],
5050
) -> Result<(), io::Error>;
5151

52-
/// Removes any data that had previously been persisted under the given `key`.
53-
///
54-
/// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
55-
/// remove the given `key` at some point in time after the method returns, e.g., as part of an
56-
/// eventual batch deletion of multiple keys. As a consequence, subsequent calls to
57-
/// [`PaginatedKVStore::list`] might include the removed key until the changes are actually persisted.
58-
///
59-
/// Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
60-
/// `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
61-
/// potentially get lost on crash after the method returns. Therefore, this flag should only be
62-
/// set for `remove` operations that can be safely replayed at a later time.
63-
///
64-
/// Returns successfully if no data will be stored for the given `primary_namespace`,
65-
/// `secondary_namespace`, and `key`, independently of whether it was present before its
66-
/// invocation or not.
67-
fn remove(
68-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
69-
) -> Result<(), io::Error>;
70-
7152
/// Returns a paginated list of keys that are stored under the given `secondary_namespace` in
7253
/// `primary_namespace`, ordered in descending order of `time`.
7354
///

0 commit comments

Comments
 (0)