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 clippy errors and warnings #302

Draft
wants to merge 32 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
24c1363
fix: Clippy errors (mostly redundant locals)
adonagy Mar 26, 2024
07e8dc5
fix clippy warnings: redundant_static_lifetimes
adonagy Mar 26, 2024
5fd0e0e
fix clippy warnings: useless_conversion
adonagy Mar 26, 2024
ec59528
fix clippy warnings: thread_local_initializer_can_be_made_const
adonagy Mar 26, 2024
c0067a4
fix clippy warnings: filter_map_identity
adonagy Mar 26, 2024
8bc8160
fix clippy warnings: needless_borrow, needless_borrows_for_generic_args
adonagy Mar 26, 2024
8a7898c
fix clippy warnings: needless_return
adonagy Mar 26, 2024
eba2e7a
fix clippy warnings: needless_lifetimes
adonagy Mar 26, 2024
8e9678a
fix clippy warnings: redundant_closure, other needless_ lints
adonagy Mar 26, 2024
a54c53c
fix clippy warnings: non_canonical_clone_impl, clone_on_copy
adonagy Mar 26, 2024
f60a769
fix clippy warnings: borrow_deref_ref
adonagy Mar 26, 2024
d830945
fix clippy warnings: unnecessary_cast, unnecessary_fallible_conversio…
adonagy Mar 26, 2024
815f767
fix clippy warnings: into_iter_on_ref
adonagy Mar 26, 2024
f6c82c5
fix clippy warnings: redundant_field_names
adonagy Mar 26, 2024
8aa76d1
fix clippy warnings: let_unit_value
adonagy Mar 26, 2024
3b40628
fix clippy warnings: map_flatten
adonagy Mar 26, 2024
1ec99c0
fix clippy warnings: to_string_in_format_args, useless_format, inhere…
adonagy Mar 26, 2024
73e77a2
fix clippy warnings: extra_unused_lifetimes, manual_is_ascii_check, i…
adonagy Mar 26, 2024
6b8b1f2
fix clippy warnings: match_like_matches_macro
adonagy Mar 26, 2024
66ed26b
fix clippy warnings: collapsible_else_if, single_char_pattern, option…
adonagy Mar 26, 2024
fbb8900
fix clippy warnings: redundant_pattern_matching, redundant_guards, st…
adonagy Mar 26, 2024
6a3abbe
fix clippy warnings: let_and_return, unit_arg, search_is_some, items_…
adonagy Mar 26, 2024
48a5d8b
fix clippy warnings: new_without_default
adonagy Mar 26, 2024
09fff44
fix clippy warnings: collapsible_match, single_match
adonagy Mar 26, 2024
70b21cb
fix clippy warnings: enum_variant_names, large_enum_variant
adonagy Mar 26, 2024
0a54751
fix clippy warnings: type_complexity, too_many_arguments, upper_case_…
adonagy Mar 26, 2024
5ca67f2
fix clippy warnings: op_ref
adonagy Mar 26, 2024
79fba42
fix clippy warnings: option_map_unit_Fn
adonagy Mar 26, 2024
876bae3
fix clippy warnings: derivable_impls, unwrap_or_defualt, suspicious_a…
adonagy Mar 26, 2024
7aded41
fix clippy warnings: explicit_auto_deref, if_same_then_else, unused_v…
adonagy Mar 26, 2024
8f9c6cc
fix clippy warnings: other
adonagy Mar 26, 2024
fbbc929
chore: run cargo fmt
adonagy Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/commands/node/mod.rs
Expand Up @@ -35,7 +35,7 @@ use openmina_node_native::{http_server, tracing, NodeService, P2pTaskSpawner, Rp

// old:
// 3c41383994b87449625df91769dff7b507825c064287d30fada9286f3f1cb15e
const CHAIN_ID: &'static str = openmina_core::CHAIN_ID;
const CHAIN_ID: &str = openmina_core::CHAIN_ID;

/// Openmina node
#[derive(Debug, clap::Args)]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/replay/replay_state_with_input_actions.rs
Expand Up @@ -47,7 +47,7 @@ impl ReplayStateWithInputActions {
// index/srs doesn't match deserialized one.
state.snark.block_verify.verifier_index =
node::snark::get_verifier_index(VerifierKind::Blockchain).into();
state.snark.block_verify.verifier_srs = node::snark::get_srs().into();
state.snark.block_verify.verifier_srs = node::snark::get_srs();
state
};

Expand Down Expand Up @@ -203,7 +203,7 @@ fn dyn_effects(store: &mut Store<NodeService>, action: &ActionWithMeta) {
}

thread_local! {
static DYN_EFFECTS_LIB: RefCell<Option<DynEffectsLib>> = RefCell::new(None);
static DYN_EFFECTS_LIB: RefCell<Option<DynEffectsLib>> = const { RefCell::new(None) };
}

struct DynEffectsLib {
Expand Down
18 changes: 8 additions & 10 deletions core/src/block/block_with_hash.rs
Expand Up @@ -156,16 +156,14 @@ impl<T: AsRef<Block>> BlockWithHash<T> {
}
}
}
match diff.1.as_ref() {
Some(v) => match &v.coinbase {
StagedLedgerDiffDiffPreDiffWithAtMostOneCoinbaseStableV2Coinbase::Zero => {}
StagedLedgerDiffDiffPreDiffWithAtMostOneCoinbaseStableV2Coinbase::One(v) => {
coinbases.push(v.as_ref());
}
},
_ => {}
if let Some(v) = diff.1.as_ref() {
if let StagedLedgerDiffDiffPreDiffWithAtMostOneCoinbaseStableV2Coinbase::One(coinbase) =
&v.coinbase
{
coinbases.push(coinbase.as_ref());
}
}
coinbases.into_iter().filter_map(|v| v)
coinbases.into_iter().flatten()
}

pub fn completed_works_iter<'a>(
Expand Down Expand Up @@ -198,7 +196,7 @@ impl<T: AsRef<BlockHeader>> BlockHeaderWithHash<T> {
}

pub fn header(&self) -> &BlockHeader {
&self.header.as_ref()
self.header.as_ref()
}

pub fn consensus_state(&self) -> &ConsensusProofOfStakeDataConsensusStateValueStableV2 {
Expand Down
17 changes: 10 additions & 7 deletions core/src/consensus.rs
Expand Up @@ -53,7 +53,7 @@ pub fn is_short_range_fork(a: &MinaConsensusState, b: &MinaConsensusState) -> bo
a_prev_lock_checkpoint == b_prev_lock_checkpoint
} else {
// Check for previous epoch case using both orientations
check(&a, &b) || check(&b, &a)
check(a, b) || check(b, a)
}
}

Expand Down Expand Up @@ -85,6 +85,9 @@ pub fn relative_min_window_density(b1: &MinaConsensusState, b2: &MinaConsensusSt

// Ring-shift
let mut i = relative_sub_window_from_global_slot(global_slot(b1));
// TODO(binier): is this correct?
// lint: this loops only once with `_` being `0..=shift_count`
#[allow(clippy::single_element_loop)]
for _ in [0..=shift_count] {
i = (i + 1) % SUB_WINDOWS_PER_WINDOW;
projected_window[i as usize] = 0;
Expand Down Expand Up @@ -121,7 +124,7 @@ pub fn short_range_fork_take(

let tip_height = &tip_cs.blockchain_length;
let candidate_height = &candidate_cs.blockchain_length;
match candidate_height.cmp(&tip_height) {
match candidate_height.cmp(tip_height) {
Greater => return (true, ChainLength),
Less => return (false, ChainLength),
Equal => {}
Expand All @@ -136,9 +139,9 @@ pub fn short_range_fork_take(
}

if candidate_hash > tip_hash {
return (true, StateHash);
(true, StateHash)
} else {
return (false, StateHash);
(false, StateHash)
}
}

Expand All @@ -161,7 +164,7 @@ pub fn long_range_fork_take(

let tip_height = &tip_cs.blockchain_length;
let candidate_height = &candidate_cs.blockchain_length;
match candidate_height.cmp(&tip_height) {
match candidate_height.cmp(tip_height) {
Greater => return (true, ChainLength),
Less => return (false, ChainLength),
Equal => {}
Expand All @@ -176,9 +179,9 @@ pub fn long_range_fork_take(
}

if candidate_hash > tip_hash {
return (true, StateHash);
(true, StateHash)
} else {
return (false, StateHash);
(false, StateHash)
}
}

Expand Down
3 changes: 1 addition & 2 deletions core/src/constants.rs
Expand Up @@ -2,8 +2,7 @@ use binprot_derive::BinProtWrite;
use mina_hasher::Fp;
use mina_p2p_messages::{bigint, number, v2};

pub const GENESIS_PRODUCER_SK: &'static str =
"EKFKgDtU3rcuFTVSEpmpXSkukjmX4cKefYREi6Sdsk7E7wsT7KRw";
pub const GENESIS_PRODUCER_SK: &str = "EKFKgDtU3rcuFTVSEpmpXSkukjmX4cKefYREi6Sdsk7E7wsT7KRw";

pub const PROTOCOL_VERSION: v2::ProtocolVersionStableV2 = v2::ProtocolVersionStableV2 {
transaction: number::Number(2),
Expand Down
4 changes: 2 additions & 2 deletions core/src/invariants.rs
Expand Up @@ -8,13 +8,13 @@ pub trait InvariantService: redux::Service {
pub struct InvariantsState(Vec<Box<dyn 'static + Send + Any>>);

impl InvariantsState {
pub fn get<'a, T: 'static + Send + Default>(&'a mut self, i: usize) -> &'a mut T {
pub fn get<T: 'static + Send + Default>(&mut self, i: usize) -> &mut T {
self.0.resize_with(i + 1, || Box::new(()));
let v = self.0.get_mut(i).unwrap();
if v.is::<T>() {
v.downcast_mut().unwrap()
} else {
*v = Box::new(T::default());
*v = Box::<T>::default();
v.downcast_mut().unwrap()
}
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/lib.rs
@@ -1,3 +1,5 @@
#![allow(clippy::too_many_arguments)]

pub mod invariants;
pub mod log;
pub mod requests;
Expand All @@ -13,8 +15,7 @@ pub mod snark;
pub mod consensus;

/// Default chain id, as used by [berkeleynet](https://berkeley.minaexplorer.com/status).
pub const CHAIN_ID: &'static str =
"fd7d111973bf5a9e3e87384f560fdead2f272589ca00b6d9e357fca9839631da";
pub const CHAIN_ID: &str = "fd7d111973bf5a9e3e87384f560fdead2f272589ca00b6d9e357fca9839631da";

pub fn preshared_key(chain_id: &str) -> [u8; 32] {
use multihash::{Blake2b256, Hasher};
Expand Down
2 changes: 1 addition & 1 deletion core/src/requests/mod.rs
Expand Up @@ -144,7 +144,7 @@ where
use serde::de::{self, MapAccess, SeqAccess, Visitor};
struct RequestsVisitor<IdType, Request>(std::marker::PhantomData<(IdType, Request)>);

const FIELDS: &'static [&'static str] = &["list", "counter", "last_added_req_id"];
const FIELDS: &[&str] = &["list", "counter", "last_added_req_id"];

impl<'de, IdType, Request> Visitor<'de> for RequestsVisitor<IdType, Request>
where
Expand Down
6 changes: 1 addition & 5 deletions core/src/requests/request_id.rs
Expand Up @@ -138,11 +138,7 @@ impl<T: RequestIdType> fmt::Debug for RequestId<T> {

impl<T> Clone for RequestId<T> {
fn clone(&self) -> Self {
Self {
locator: self.locator,
counter: self.counter,
_phantom_request_type: self._phantom_request_type.clone(),
}
*self
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/snark/snark_cmp.rs
Expand Up @@ -71,7 +71,7 @@ where
for<'a> &'a T: Into<SnarkCmp<'a>>,
{
fn eq(&self, other: &T) -> bool {
Into::<SnarkCmp<'_>>::into(&*self) == Into::<SnarkCmp<'_>>::into(other)
Into::<SnarkCmp<'_>>::into(self) == Into::<SnarkCmp<'_>>::into(other)
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/snark/snark_job_id.rs
Expand Up @@ -36,7 +36,7 @@ impl std::str::FromStr for LedgerHashTransition {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
let (source, target) = s.split_once("-").ok_or(())?;
let (source, target) = s.split_once('-').ok_or(())?;
Ok(Self {
source: source.parse()?,
target: target.parse()?,
Expand All @@ -58,7 +58,7 @@ impl FromStr for LedgerHashTransitionPasses {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
let (first_pass, second_pass) = s.split_once("_").ok_or(())?;
let (first_pass, second_pass) = s.split_once('_').ok_or(())?;
Ok(Self {
first_pass_ledger: first_pass.parse().or(Err(()))?,
second_pass_ledger: second_pass.parse().or(Err(()))?,
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/account/common.rs
Expand Up @@ -278,7 +278,7 @@ impl AuthRequired {

match self {
Impossible | Proof => Signature,
x => x.clone(),
x => *x,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ledger/src/account/conv.rs
Expand Up @@ -123,7 +123,7 @@ where
T: 'a,
F: Fn(&T) -> U,
{
value.each_ref().map(|value| fun(value))
value.each_ref().map(fun)
}

impl From<&MinaBaseVerificationKeyWireStableV1> for VerificationKey {
Expand Down Expand Up @@ -501,8 +501,8 @@ impl From<&MinaBaseAccountBinableArgStableV2> for Account {
let s: String = (&acc.token_symbol).try_into().unwrap();
TokenSymbol::from(s)
},
balance: Balance::from_u64(acc.balance.0 .0 .0 .0 as u64),
nonce: Nonce::from_u32(acc.nonce.0 .0 as u32),
balance: Balance::from_u64(acc.balance.0 .0 .0 .0),
nonce: Nonce::from_u32(acc.nonce.0 .0),
receipt_chain_hash: ReceiptChainHash((&acc.receipt_chain_hash.0).into()),
delegate: acc.delegate.as_ref().map(|d| d.inner().into()),
voting_for: VotingFor(acc.voting_for.0.to_field()),
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/address/raw.rs
Expand Up @@ -330,7 +330,7 @@ impl<const NBYTES: usize> Address<NBYTES> {
.rev()
.enumerate()
.find_map(|(index, byte)| match byte.trailing_ones() as usize {
x if x == 8 => None,
8 => None,
x => Some((nused_bytes - index) * 8 - x - 1),
})?;

Expand Down Expand Up @@ -361,7 +361,7 @@ impl<const NBYTES: usize> Address<NBYTES> {
.rev()
.enumerate()
.find_map(|(index, byte)| match byte.trailing_zeros() as usize {
x if x == 8 => None,
8 => None,
x => Some((nused_bytes - index) * 8 - x - 1),
})?;

Expand Down
2 changes: 1 addition & 1 deletion ledger/src/database/database.rs
Expand Up @@ -1003,7 +1003,7 @@ mod tests_ocaml {
let index = rand::thread_rng().gen_range(0..NACCOUNTS);
let index = AccountIndex(index as u64);

db.set_at_index(index.clone(), account.clone()).unwrap();
db.set_at_index(index, account.clone()).unwrap();
let at_index = db.get_at_index(index).unwrap();
assert_eq!(account, at_index);
}
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/database/database_impl.rs
Expand Up @@ -667,7 +667,7 @@ impl BaseLedger for DatabaseImpl<V2> {
fn set(&mut self, addr: Address, account: Box<Account>) {
let index = addr.to_index();

self.hashes_matrix.invalidate_hashes(index.clone());
self.hashes_matrix.invalidate_hashes(index);

let index: usize = index.0 as usize;

Expand Down
27 changes: 13 additions & 14 deletions ledger/src/mask/mask_impl.rs
Expand Up @@ -392,7 +392,7 @@ impl MaskImpl {
};

for (index, account) in accounts {
let addr = Address::from_index(index.clone(), depth);
let addr = Address::from_index(index, depth);
parent.set_impl(addr, Box::new(account), Some(self_uuid.clone()));
}

Expand Down Expand Up @@ -439,7 +439,7 @@ impl MaskImpl {
assert!(self.is_attached());

for child in self.childs().values() {
child.parent_set_notify(account_index.clone(), account)
child.parent_set_notify(account_index, account)
}

match self {
Expand All @@ -455,12 +455,11 @@ impl MaskImpl {

hashes.invalidate_hashes(account_index);

let own_account = match {
id_to_addr
.get(&account_id)
.and_then(|addr| owning_account.get(&addr.to_index()))
.cloned()
} {
let own_account = match id_to_addr
.get(&account_id)
.and_then(|addr| owning_account.get(&addr.to_index()))
.cloned()
{
Some(own) => own,
None => return,
};
Expand Down Expand Up @@ -812,7 +811,7 @@ impl MaskImpl {

for addr in addrs.iter().rev() {
let account_index = addr.to_index();
hashes.invalidate_hashes(account_index.clone());
hashes.invalidate_hashes(account_index);

let account = owning_account.remove(&account_index).unwrap();
token_to_account.remove(&account.token_id).unwrap();
Expand Down Expand Up @@ -845,7 +844,7 @@ impl MaskImpl {
if Some(uuid) == child_to_ignore.as_ref() {
continue;
}
child.parent_set_notify(account_index.clone(), &account)
child.parent_set_notify(account_index, &account)
}

match self {
Expand All @@ -867,7 +866,7 @@ impl MaskImpl {
let account_id = account.id();
let token_id = account.token_id.clone();

owning_account.insert(account_index.clone(), *account);
owning_account.insert(account_index, *account);
id_to_addr.insert(account_id.clone(), addr.clone());
token_to_account.insert(token_id, account_id);

Expand Down Expand Up @@ -937,7 +936,7 @@ impl MaskImpl {
for index in 0..(2u64.pow(tree_depth as u32)) {
let index = AccountIndex(index);
match self
.get_account_hash(index.clone())
.get_account_hash(index)
.filter(|hash| hash != &empty_account_hash)
{
None => break,
Expand Down Expand Up @@ -1200,7 +1199,7 @@ impl BaseLedger for MaskImpl {
id_to_addr.insert(account_id.clone(), location.clone());
*last_location = Some(location.clone());
token_to_account.insert(token_id, account_id);
owning_account.insert(account_index.clone(), account);
owning_account.insert(account_index, account);

self.invalidate_hashes(account_index);

Expand Down Expand Up @@ -1434,7 +1433,7 @@ impl BaseLedger for MaskImpl {

self.recurse_on_childs(&mut |child| {
for index in &indexes {
child.invalidate_hashes(index.clone());
child.invalidate_hashes(*index);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions ledger/src/ondisk/mod.rs
Expand Up @@ -55,9 +55,9 @@
//! ```

pub mod batch;
pub(self) mod compression;
mod compression;
mod database;
pub(self) mod lock;
mod lock;

pub use batch::Batch;
pub use database::*;