Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rust 1.83 clippy warnings #2148

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ As a minor extension, we have adopted a slightly different versioning convention

- Add a one line shell installation script for the Mithril nodes.

- Update to Rust `1.83`.

- **UNSTABLE** Cardano database incremental certification:

- Implement the new signed entity type `CardanoDatabase`.
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/mithril-metric/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-metric"
version = "0.1.2"
version = "0.1.3"
description = "Common tools to expose metrics."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion internal/mithril-metric/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ macro_rules! build_metrics_service {
}

#[cfg(test)]
pub mod test_tools {
pub(crate) mod test_tools {
use std::{io, sync::Arc};

use slog::{Drain, Logger};
use slog_async::Async;
use slog_term::{CompactFormat, PlainDecorator};

pub struct TestLogger;

impl TestLogger {
Expand Down
3 changes: 0 additions & 3 deletions internal/mithril-metric/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ mod server;
pub use metric::*;
pub use server::MetricsServer;
pub use server::MetricsServiceExporter;

#[cfg(test)]
pub use helper::test_tools::TestLogger;
2 changes: 1 addition & 1 deletion internal/mithril-persistence/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-persistence"
version = "0.2.37"
version = "0.2.38"
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion internal/mithril-persistence/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use version_checker::{DatabaseVersionChecker, SqlMigration};
pub type DbVersion = i64;

#[cfg(test)]
pub mod test_helper {
pub(crate) mod test_helper {
use sqlite::ConnectionThreadSafe;

use mithril_common::StdResult;
Expand Down
5 changes: 3 additions & 2 deletions internal/mithril-persistence/src/sqlite/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,10 @@ mod tests {

#[test]
fn expression_get_all_default() {
impl GetAllCondition for String {}
struct Expression;
impl GetAllCondition for Expression {}

let expression = String::get_all_condition();
let expression = Expression::get_all_condition();
let (sql, params) = expression.expand();

assert_eq!("true".to_string(), sql);
Expand Down
2 changes: 1 addition & 1 deletion internal/mithril-persistence/src/sqlite/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a, T> EntityCursor<'a, T> {
}
}

impl<'a, T> Iterator for EntityCursor<'a, T>
impl<T> Iterator for EntityCursor<'_, T>
where
T: SqLiteEntity,
{
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.5.115"
version = "0.5.116"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
15 changes: 3 additions & 12 deletions mithril-aggregator/src/database/record/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ pub struct CertificateRecord {

#[cfg(test)]
impl CertificateRecord {
pub fn dummy_genesis(id: &str, epoch: Epoch) -> Self {
pub(crate) fn dummy_genesis(id: &str, epoch: Epoch) -> Self {
Self {
parent_certificate_id: None,
signature: fake_keys::genesis_signature()[0].to_owned(),
..Self::dummy(id, "", epoch, SignedEntityType::genesis(epoch))
}
}

pub fn dummy_db_snapshot(
pub(crate) fn dummy_db_snapshot(
id: &str,
parent_id: &str,
epoch: Epoch,
Expand All @@ -94,16 +94,7 @@ impl CertificateRecord {
)
}

pub fn dummy_msd(id: &str, parent_id: &str, epoch: Epoch) -> Self {
Self::dummy(
id,
parent_id,
epoch,
SignedEntityType::MithrilStakeDistribution(epoch),
)
}

pub fn dummy(
pub(crate) fn dummy(
id: &str,
parent_id: &str,
epoch: Epoch,
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/dependency_injection/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl DependencyContainer {
}

#[cfg(test)]
pub mod tests {
pub(crate) mod tests {
use crate::{dependency_injection::DependenciesBuilder, Configuration, DependencyContainer};

pub async fn initialize_dependencies() -> DependencyContainer {
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub use tools::{
};

#[cfg(test)]
pub use dependency_injection::tests::initialize_dependencies;
pub(crate) use dependency_injection::tests::initialize_dependencies;

// Memory allocator (to handle properly memory fragmentation)
#[cfg(all(not(target_env = "msvc"), feature = "jemallocator"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod tests {
}

impl CardanoTransactionsImporter {
pub fn new_for_test(
pub(crate) fn new_for_test(
scanner: Arc<dyn BlockScanner>,
transaction_store: Arc<dyn TransactionStore>,
) -> Self {
Expand Down
5 changes: 3 additions & 2 deletions mithril-aggregator/src/services/epoch_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl EpochService for MithrilEpochService {
}

#[cfg(test)]
pub struct FakeEpochService {
pub(crate) struct FakeEpochService {
epoch_data: Option<EpochData>,
computed_epoch_data: Option<ComputedEpochData>,
inform_epoch_error: bool,
Expand All @@ -525,7 +525,7 @@ pub struct FakeEpochService {
}

#[cfg(test)]
pub struct FakeEpochServiceBuilder {
pub(crate) struct FakeEpochServiceBuilder {
pub cardano_era: CardanoEra,
pub mithril_era: SupportedEra,
pub epoch: Epoch,
Expand Down Expand Up @@ -662,6 +662,7 @@ impl FakeEpochService {
}
}

#[allow(dead_code)]
pub fn toggle_errors(
&mut self,
inform_epoch: bool,
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/signer_registerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct SignerRegistrationRound {

#[cfg(test)]
impl SignerRegistrationRound {
pub fn dummy(epoch: Epoch, stake_distribution: StakeDistribution) -> Self {
pub(crate) fn dummy(epoch: Epoch, stake_distribution: StakeDistribution) -> Self {
Self {
epoch,
stake_distribution,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl MithrilSignerRegisterer {
}

#[cfg(test)]
pub async fn get_current_round(&self) -> Option<SignerRegistrationRound> {
pub(crate) async fn get_current_round(&self) -> Option<SignerRegistrationRound> {
self.current_round.read().await.as_ref().cloned()
}
}
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.4.89"
version = "0.4.90"
description = "Common types, interfaces, and utilities for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions mithril-common/src/chain_observer/cli_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl CardanoCliRunner {
command
}

fn post_config_command<'a>(&'a self, command: &'a mut Command) -> &mut Command {
fn post_config_command<'a>(&'a self, command: &'a mut Command) -> &'a mut Command {
match self.network {
CardanoNetwork::MainNet => command.arg("--mainnet"),
CardanoNetwork::DevNet(magic) => command.args(vec![
Expand Down Expand Up @@ -331,7 +331,7 @@ impl CardanoCliChainObserver {

// This is the only way I found to tell the compiler the correct types
// and lifetimes for the function `double`.
fn parse_string<'a>(&'a self, string: &'a str) -> IResult<&str, f64> {
fn parse_string<'a>(&'a self, string: &'a str) -> IResult<&'a str, f64> {
nom::number::complete::double(string)
}

Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/crypto_helper/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn encode_bech32(human_readable_part: &str, data: &[u8]) -> StdResult<String
}

#[cfg(test)]
pub mod tests {
mod tests {
use hex::FromHex;
use serde::{Deserialize, Serialize};

Expand Down
4 changes: 2 additions & 2 deletions mithril-common/src/crypto_helper/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@ impl<S: MKTreeStorer> MKTree<S> {
.map(|(leaf_position, _leaf)| *leaf_position)
.collect(),
)?;
return Ok(MKProof {
Ok(MKProof {
inner_root: Arc::new(self.compute_root()?),
inner_leaves,
inner_proof_size: proof.mmr_size(),
inner_proof_items: proof.proof_items().to_vec(),
});
})
}
}

Expand Down
23 changes: 15 additions & 8 deletions mithril-common/src/test_utils/apispec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,28 @@ impl<'a> APISpec<'a> {
}

/// Sets the path to specify/check.
pub fn path(&'a mut self, path: &'a str) -> &mut APISpec {
pub fn path(&'a mut self, path: &'a str) -> &'a mut APISpec<'a> {
self.path = Some(path);
self
}

/// Sets the method to specify/check.
pub fn method(&'a mut self, method: &'a str) -> &mut APISpec {
pub fn method(&'a mut self, method: &'a str) -> &'a mut APISpec<'a> {
self.method = Some(method);
self
}

/// Sets the content type to specify/check, note that it defaults to "application/json".
pub fn content_type(&'a mut self, content_type: &'a str) -> &mut APISpec {
pub fn content_type(&'a mut self, content_type: &'a str) -> &'a mut APISpec<'a> {
self.content_type = Some(content_type);
self
}

/// Validates if a request is valid
fn validate_request(&'a self, request_body: &impl Serialize) -> Result<&APISpec, String> {
fn validate_request(
&'a self,
request_body: &impl Serialize,
) -> Result<&'a APISpec<'a>, String> {
let path = self.path.unwrap();
let method = self.method.unwrap().to_lowercase();
let content_type = self.content_type.unwrap();
Expand All @@ -104,7 +107,7 @@ impl<'a> APISpec<'a> {
&'a self,
path: &str,
operation_object: &Value,
) -> Result<&APISpec, String> {
) -> Result<&'a APISpec<'a>, String> {
let fake_base_url = "http://0.0.0.1";
let url = Url::parse(&format!("{}{}", fake_base_url, path)).unwrap();

Expand All @@ -130,7 +133,7 @@ impl<'a> APISpec<'a> {
&'a self,
response: &Response<Bytes>,
expected_status_code: &StatusCode,
) -> Result<&APISpec, String> {
) -> Result<&'a APISpec<'a>, String> {
if expected_status_code.as_u16() != response.status().as_u16() {
return Err(format!(
"expected status code {} but was {}",
Expand All @@ -143,7 +146,7 @@ impl<'a> APISpec<'a> {
}

/// Validates if a response is valid
fn validate_response(&'a self, response: &Response<Bytes>) -> Result<&APISpec, String> {
fn validate_response(&'a self, response: &Response<Bytes>) -> Result<&'a APISpec<'a>, String> {
let body = response.body();
let status = response.status();

Expand Down Expand Up @@ -207,7 +210,11 @@ impl<'a> APISpec<'a> {
}

/// Validates conformity of a value against a schema
fn validate_conformity(&'a self, value: &Value, schema: &Value) -> Result<&APISpec, String> {
fn validate_conformity(
&'a self,
value: &Value,
schema: &Value,
) -> Result<&'a APISpec<'a>, String> {
match schema {
Null => match value {
Null => Ok(self),
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/test_utils/certificate_chain_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl<'a> CertificateChainBuilder<'a> {
}
}

impl<'a> Default for CertificateChainBuilder<'a> {
impl Default for CertificateChainBuilder<'_> {
fn default() -> Self {
Self::new()
}
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use fixture_builder::{MithrilFixtureBuilder, StakeDistributionGenerationMeth
pub use mithril_fixture::{MithrilFixture, SignerFixture};
pub use temp_dir::*;
#[cfg(test)]
pub use utils::*;
pub(crate) use utils::*;

/// Compare two json strings ignoring keys order
#[macro_export]
Expand Down
Loading