Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
16 changes: 16 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,20 @@ rustflags = [
"-Aclippy::while_immutable_condition", # false positives
"-Aclippy::needless_option_as_deref", # false positives
"-Aclippy::derivable_impls", # false positives

# opt into specific uncontravercial style category lints:
# (These lists have no downside)
"-Dclippy::field_reassign_with_default",
"-Dclippy::into_iter_on_ref",
"-Dclippy::iter_cloned_collect",
"-Dclippy::manual_saturating_arithmetic",
"-Dclippy::map_collect_result_unit",
"-Dclippy::match_ref_pats",
"-Dclippy::mem_replace_option_with_none",
"-Dclippy::mem_replace_with_default",
"-Dclippy::needless_borrow",
"-Dclippy::redundant_static_lifetimes",
"-Dclippy::single_match",
"-Dclippy::unwrap_or_else_default",
"-Dclippy::redundant_closure", # may alter side-effect timing.
]
2 changes: 1 addition & 1 deletion bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn block_production(c: &mut Criterion) {
block_builder.push(extrinsic_set_time(1)).unwrap();
import_block(client, block_builder.build().unwrap());

let (max_transfer_count, extrinsics) = prepare_benchmark(&client);
let (max_transfer_count, extrinsics) = prepare_benchmark(client);
log::info!("Maximum transfer count: {}", max_transfer_count);

let mut group = c.benchmark_group("Block production");
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/tests/export_import_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> ExportImportRevertExecutor<'a> {
// Setting base_path to be a temporary folder if we are importing blocks.
// This allows us to make sure we are importing from scratch.
let base_path = match sub_command {
SubCommand::ExportBlocks => &self.base_path.path(),
SubCommand::ExportBlocks => self.base_path.path(),
SubCommand::ImportBlocks => {
tmp = tempdir().unwrap();
tmp.path()
Expand Down
19 changes: 8 additions & 11 deletions client/api/src/leaves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,14 @@ where
pub fn read_from_db(db: &dyn Database<DbHash>, column: u32, prefix: &[u8]) -> Result<Self> {
let mut storage = BTreeMap::new();

match db.get(column, prefix) {
Some(leaves) => {
let vals: Vec<_> = match Decode::decode(&mut leaves.as_ref()) {
Ok(vals) => vals,
Err(_) => return Err(Error::Backend("Error decoding leaves".into())),
};
for (number, hashes) in vals.into_iter() {
storage.insert(Reverse(number), hashes);
}
},
None => {},
if let Some(leaves) = db.get(column, prefix) {
let vals: Vec<_> = match Decode::decode(&mut leaves.as_ref()) {
Ok(vals) => vals,
Err(_) => return Err(Error::Backend("Error decoding leaves".into())),
};
for (number, hashes) in vals.into_iter() {
storage.insert(Reverse(number), hashes);
}
}
Ok(Self { storage })
}
Expand Down
2 changes: 1 addition & 1 deletion client/authority-discovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn cryptos_are_compatible() {
libp2p::identity::Keypair::Ed25519(x) => x,
_ => panic!("generate_ed25519 should have generated an Ed25519 key ¯\\_(ツ)_/¯"),
};
sp_core::ed25519::Pair::from_seed_slice(&libp2p_ed_secret.secret().as_ref()).unwrap()
sp_core::ed25519::Pair::from_seed_slice(libp2p_ed_secret.secret().as_ref()).unwrap()
};
let sp_core_public = sp_core_secret.public();

Expand Down
8 changes: 4 additions & 4 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ mod tests {

let proposer = proposer_factory.init_with_now(
&client.header(&block_id).unwrap().unwrap(),
Box::new(move || time::Instant::now()),
Box::new(time::Instant::now),
);

let deadline = time::Duration::from_secs(9);
Expand Down Expand Up @@ -792,7 +792,7 @@ mod tests {
expected_pool_transactions| {
let proposer = proposer_factory.init_with_now(
&client.header(&BlockId::number(number)).unwrap().unwrap(),
Box::new(move || time::Instant::now()),
Box::new(time::Instant::now),
);

// when
Expand Down Expand Up @@ -946,7 +946,7 @@ mod tests {
// add 2 * MAX_SKIPPED_TRANSACTIONS that exhaust resources
(0..MAX_SKIPPED_TRANSACTIONS * 2)
.into_iter()
.map(|i| exhausts_resources_extrinsic_from(i))
.map(exhausts_resources_extrinsic_from)
// and some transactions that are okay.
.chain((0..MAX_SKIPPED_TRANSACTIONS).into_iter().map(|i| extrinsic(i as _)))
.collect(),
Expand Down Expand Up @@ -1009,7 +1009,7 @@ mod tests {
SOURCE,
(0..MAX_SKIPPED_TRANSACTIONS + 2)
.into_iter()
.map(|i| exhausts_resources_extrinsic_from(i))
.map(exhausts_resources_extrinsic_from)
// and some transactions that are okay.
.chain((0..MAX_SKIPPED_TRANSACTIONS).into_iter().map(|i| extrinsic(i as _)))
.collect(),
Expand Down
2 changes: 1 addition & 1 deletion client/beefy/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod tests {
let (rpc, _) = setup_io_handler();
let request = r#"{"jsonrpc":"2.0","method":"beefy_getFinalizedHead","params":[],"id":1}"#;
let expected_response = r#"{"jsonrpc":"2.0","error":{"code":1,"message":"BEEFY RPC endpoint not ready"},"id":1}"#.to_string();
let (response, _) = rpc.raw_json_request(&request).await.unwrap();
let (response, _) = rpc.raw_json_request(request).await.unwrap();

assert_eq!(expected_response, response.result);
}
Expand Down
41 changes: 19 additions & 22 deletions client/beefy/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,25 @@ where
// Run inner block import.
let inner_import_result = self.inner.import_block(block, new_cache).await?;

match (beefy_proof, &inner_import_result) {
(Some(proof), ImportResult::Imported(_)) => {
let status = self.backend.blockchain().info();
if number <= status.finalized_number &&
Some(hash) ==
self.backend
.blockchain()
.hash(number)
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?
{
// The proof is valid and the block is imported and final, we can import.
self.import_beefy_justification_unchecked(number, proof);
} else {
error!(
target: "beefy",
"🥩 Cannot import justification: {:?} for, not yet final, block number {:?}",
proof,
number,
);
}
},
_ => (),
if let (Some(proof), ImportResult::Imported(_)) = (beefy_proof, &inner_import_result) {
let status = self.backend.blockchain().info();
if number <= status.finalized_number &&
Some(hash) ==
self.backend
.blockchain()
.hash(number)
.map_err(|e| ConsensusError::ClientImport(e.to_string()))?
{
// The proof is valid and the block is imported and final, we can import.
self.import_beefy_justification_unchecked(number, proof);
} else {
error!(
target: "beefy",
"🥩 Cannot import justification: {:?} for, not yet final, block number {:?}",
proof,
number,
);
}
}

Ok(inner_import_result)
Expand Down
2 changes: 1 addition & 1 deletion client/beefy/src/justification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn verify_with_validator_set<Block: BlockT>(
let message = signed_commitment.commitment.encode();
let valid_signatures = validator_set
.validators()
.into_iter()
.iter()
.zip(signed_commitment.signatures.iter())
.filter(|(id, signature)| {
signature
Expand Down
10 changes: 5 additions & 5 deletions client/beefy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use crate::{
keystore::tests::Keyring as BeefyKeyring, BeefyRPCLinks, BeefyVoterLinks,
};

pub(crate) const BEEFY_PROTOCOL_NAME: &'static str = "/beefy/1";
pub(crate) const BEEFY_PROTOCOL_NAME: &str = "/beefy/1";
const GOOD_MMR_ROOT: MmrRootHash = MmrRootHash::repeat_byte(0xbf);
const BAD_MMR_ROOT: MmrRootHash = MmrRootHash::repeat_byte(0x42);

Expand Down Expand Up @@ -502,12 +502,12 @@ fn finalize_block_and_wait_for_beefy(
if expected_beefy.is_empty() {
// run for quarter second then verify no new best beefy block available
let timeout = Some(Duration::from_millis(250));
streams_empty_after_timeout(best_blocks, &net, runtime, timeout);
streams_empty_after_timeout(versioned_finality_proof, &net, runtime, None);
streams_empty_after_timeout(best_blocks, net, runtime, timeout);
streams_empty_after_timeout(versioned_finality_proof, net, runtime, None);
} else {
// run until expected beefy blocks are received
wait_for_best_beefy_blocks(best_blocks, &net, runtime, expected_beefy);
wait_for_beefy_signed_commitments(versioned_finality_proof, &net, runtime, expected_beefy);
wait_for_best_beefy_blocks(best_blocks, net, runtime, expected_beefy);
wait_for_beefy_signed_commitments(versioned_finality_proof, net, runtime, expected_beefy);
}
}

Expand Down
8 changes: 4 additions & 4 deletions client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ pub(crate) mod tests {
let keys = &[Keyring::Alice];
let validator_set = ValidatorSet::new(make_beefy_ids(keys), 0).unwrap();
let mut net = BeefyTestNet::new(1, 0);
let mut worker = create_beefy_worker(&net.peer(0), &keys[0], 1);
let mut worker = create_beefy_worker(net.peer(0), &keys[0], 1);

// keystore doesn't contain other keys than validators'
assert_eq!(worker.verify_validator_set(&1, &validator_set), Ok(()));
Expand All @@ -1170,7 +1170,7 @@ pub(crate) mod tests {
let keys = &[Keyring::Alice];
let validator_set = ValidatorSet::new(make_beefy_ids(keys), 0).unwrap();
let mut net = BeefyTestNet::new(1, 0);
let mut worker = create_beefy_worker(&net.peer(0), &keys[0], 1);
let mut worker = create_beefy_worker(net.peer(0), &keys[0], 1);

let (mut best_block_streams, mut finality_proofs) = get_beefy_streams(&mut net, keys);
let mut best_block_stream = best_block_streams.drain(..).next().unwrap();
Expand Down Expand Up @@ -1236,7 +1236,7 @@ pub(crate) mod tests {
let keys = &[Keyring::Alice];
let validator_set = ValidatorSet::new(make_beefy_ids(keys), 0).unwrap();
let mut net = BeefyTestNet::new(1, 0);
let mut worker = create_beefy_worker(&net.peer(0), &keys[0], 1);
let mut worker = create_beefy_worker(net.peer(0), &keys[0], 1);

assert!(worker.voting_oracle.sessions.is_empty());

Expand Down Expand Up @@ -1270,7 +1270,7 @@ pub(crate) mod tests {
let keys = &[Keyring::Alice, Keyring::Bob];
let validator_set = ValidatorSet::new(make_beefy_ids(keys), 0).unwrap();
let mut net = BeefyTestNet::new(1, 0);
let mut worker = create_beefy_worker(&net.peer(0), &keys[0], 1);
let mut worker = create_beefy_worker(net.peer(0), &keys[0], 1);

fn new_vote(
block_number: NumberFor<Block>,
Expand Down
2 changes: 1 addition & 1 deletion client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ mod tests {
.unwrap();

assert!(backend
.storage(&sp_core::storage::well_known_keys::CODE)
.storage(sp_core::storage::well_known_keys::CODE)
.unwrap_err()
.contains("Database missing expected key"),);
}
Expand Down
19 changes: 8 additions & 11 deletions client/consensus/common/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,14 @@ impl ImportResult {
) where
B: BlockT,
{
match self {
ImportResult::Imported(aux) => {
if aux.clear_justification_requests {
justification_sync_link.clear_justification_requests();
}

if aux.needs_justification {
justification_sync_link.request_justification(hash, number);
}
},
_ => {},
if let ImportResult::Imported(aux) = self {
if aux.clear_justification_requests {
justification_sync_link.clear_justification_requests();
}

if aux.needs_justification {
justification_sync_link.request_justification(hash, number);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/manual-seal/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<Hash: Send + 'static> ManualSealApiServer<Hash> for ManualSeal<Hash> {
let (sender, receiver) = oneshot::channel();
let command = EngineCommand::FinalizeBlock { hash, sender: Some(sender), justification };
sink.send(command).await?;
receiver.await.map(|_| true).map_err(|e| JsonRpseeError::to_call_error(e))
receiver.await.map(|_| true).map_err(JsonRpseeError::to_call_error)
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/consensus/slots/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ where

// Get headers of this slot.
let mut headers_with_sig =
load_decode::<_, Vec<(H, P)>>(backend, &curr_slot_key[..])?.unwrap_or_else(Vec::new);
load_decode::<_, Vec<(H, P)>>(backend, &curr_slot_key[..])?.unwrap_or_default();

// Get first slot saved.
let slot_header_start = SLOT_HEADER_START.to_vec();
Expand Down
7 changes: 5 additions & 2 deletions client/executor/src/native_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,11 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeElseWasmExecut
);

used_native = true;
let res = with_externalities_safe(&mut **ext, move || (call)())
.and_then(|r| r.map(NativeOrEncoded::Native).map_err(Error::ApiError));
let res =
with_externalities_safe(&mut **ext, call) // TODO: can I remove the move here???
.and_then(|r| {
r.map(NativeOrEncoded::Native).map_err(Error::ApiError)
});

Ok(res)
},
Expand Down
2 changes: 1 addition & 1 deletion client/executor/wasmtime/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl RuntimeBuilder {
},
};

RuntimeBlob::uncompress_if_needed(&wasm)
RuntimeBlob::uncompress_if_needed(wasm)
.expect("failed to create a runtime blob out of test runtime")
};

Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ mod tests {
let (rpc, _) = setup_io_handler(EmptyVoterState);
let expected_response = r#"{"jsonrpc":"2.0","error":{"code":1,"message":"GRANDPA RPC endpoint not ready"},"id":0}"#.to_string();
let request = r#"{"jsonrpc":"2.0","method":"grandpa_roundState","params":[],"id":0}"#;
let (response, _) = rpc.raw_json_request(&request).await.unwrap();
let (response, _) = rpc.raw_json_request(request).await.unwrap();

assert_eq!(expected_response, response.result);
}
Expand All @@ -306,7 +306,7 @@ mod tests {
},\"id\":0}".to_string();

let request = r#"{"jsonrpc":"2.0","method":"grandpa_roundState","params":[],"id":0}"#;
let (response, _) = rpc.raw_json_request(&request).await.unwrap();
let (response, _) = rpc.raw_json_request(request).await.unwrap();
assert_eq!(expected_response, response.result);
}

Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/communication/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2262,10 +2262,10 @@ mod tests {

// add 60 peers, 30 authorities and 30 full nodes
let mut authorities = Vec::new();
authorities.resize_with(30, || PeerId::random());
authorities.resize_with(30, PeerId::random);

let mut full_nodes = Vec::new();
full_nodes.resize_with(30, || PeerId::random());
full_nodes.resize_with(30, PeerId::random);

for i in 0..30 {
val.inner.write().peers.new_peer(authorities[i], ObservedRole::Authority);
Expand Down
4 changes: 2 additions & 2 deletions client/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,8 +1509,8 @@ fn grandpa_environment_never_overwrites_round_voter_state() {
let environment = test_environment(&link, Some(keystore), network_service.clone(), ());

let round_state = || finality_grandpa::round::State::genesis(Default::default());
let base = || Default::default();
let historical_votes = || finality_grandpa::HistoricalVotes::new();
let base = Default::default;
let historical_votes = finality_grandpa::HistoricalVotes::new;

let get_current_round = |n| {
let current_rounds = environment
Expand Down
9 changes: 4 additions & 5 deletions client/network-gossip/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ mod tests {

spawn(gossip_engine);

let mut subscribers =
subscribers.into_iter().map(|s| block_on_stream(s)).collect::<Vec<_>>();
let mut subscribers = subscribers.into_iter().map(block_on_stream).collect::<Vec<_>>();

// Expect each subscriber to receive both events.
for message in messages {
Expand Down Expand Up @@ -690,7 +689,7 @@ mod tests {
// Send messages into the network event stream.
for (i_notification, messages) in notifications.iter().enumerate() {
let messages = messages
.into_iter()
.iter()
.enumerate()
.map(|(i_message, Message { topic })| {
// Embed the topic in the first 256 bytes of the message to be extracted by
Expand Down Expand Up @@ -751,13 +750,13 @@ mod tests {
// Compare amount of expected messages with amount of received messages.
for (expected_topic, expected_num) in expected_msgs_per_topic_all_chan.iter() {
assert_eq!(
received_msgs_per_topic_all_chan.get(&expected_topic).unwrap_or(&0),
received_msgs_per_topic_all_chan.get(expected_topic).unwrap_or(&0),
expected_num,
);
}
for (received_topic, received_num) in expected_msgs_per_topic_all_chan.iter() {
assert_eq!(
expected_msgs_per_topic_all_chan.get(&received_topic).unwrap_or(&0),
expected_msgs_per_topic_all_chan.get(received_topic).unwrap_or(&0),
received_num,
);
}
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ mod tests {

fn secret_bytes(kp: &Keypair) -> Vec<u8> {
match kp {
Keypair::Ed25519(p) => p.secret().as_ref().iter().cloned().collect(),
Keypair::Ed25519(p) => p.secret().as_ref().to_vec(),
Keypair::Secp256k1(p) => p.secret().to_bytes().to_vec(),
_ => panic!("Unexpected keypair."),
}
Expand Down
Loading