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 warnings from Rust v1.59.0 #1097

Merged
merged 4 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Upgrade to contracts v0.6.2 and fix clippy errors
Signed-off-by: Thane Thomson <[email protected]>
  • Loading branch information
thanethomson committed Mar 11, 2022
commit 58b0c7b671bcf126a2f2f26167af6b2da42077bf
2 changes: 1 addition & 1 deletion light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tendermint = { version = "0.24.0-pre.1", path = "../tendermint", default-feature
tendermint-rpc = { version = "0.24.0-pre.1", path = "../rpc", default-features = false }
tendermint-light-client-verifier = { version = "0.24.0-pre.1", path = "../light-client-verifier", default-features = false }

contracts = { version = "0.4.0", default-features = false }
contracts = { version = "0.6.2", default-features = false }
crossbeam-channel = { version = "0.4.2", default-features = false }
derive_more = { version = "0.99.5", default-features = false, features = ["display"] }
futures = { version = "0.3.4", default-features = false }
Expand Down
12 changes: 6 additions & 6 deletions light-client/src/components/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub trait Scheduler: Send + Sync {
///
/// ## Postcondition
/// - The resulting height must be valid according to `valid_schedule`. [LCV-SCHEDULE-POST.1]
#[pre(light_store.highest_trusted_or_verified().is_some())]
#[post(valid_schedule(ret, target_height, current_height, light_store))]
#[requires(light_store.highest_trusted_or_verified().is_some())]
#[ensures(valid_schedule(ret, target_height, current_height, light_store))]
fn schedule(
&self,
light_store: &dyn LightStore,
Expand Down Expand Up @@ -53,8 +53,8 @@ where
///
/// ## Postcondition
/// - The resulting height must be valid according to `valid_schedule`. [LCV-SCHEDULE-POST.1]
#[pre(light_store.highest_trusted_or_verified().is_some())]
#[post(valid_schedule(ret, target_height, current_height, light_store))]
#[requires(light_store.highest_trusted_or_verified().is_some())]
#[ensures(valid_schedule(ret, target_height, current_height, light_store))]
pub fn basic_bisecting_schedule(
light_store: &dyn LightStore,
current_height: Height,
Expand Down Expand Up @@ -120,8 +120,8 @@ pub fn valid_schedule(
}
}

#[pre(low <= high)]
#[post(low <= ret && ret <= high)]
#[requires(low <= high)]
#[ensures(low <= ret && ret <= high)]
fn midpoint(low: Height, high: Height) -> Height {
(low.value() + (high.value() + 1 - low.value()) / 2)
.try_into()
Expand Down
6 changes: 3 additions & 3 deletions light-client/src/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod prod {
use super::*;
use crate::utils::block_on;

use contracts::pre;
use contracts::requires;
use std::{collections::HashMap, time::Duration};

use tendermint_rpc as rpc;
Expand All @@ -40,7 +40,7 @@ mod prod {

#[contract_trait]
impl EvidenceReporter for ProdEvidenceReporter {
#[pre(self.peer_map.contains_key(&peer))]
#[requires(self.peer_map.contains_key(&peer))]
fn report(&self, e: Evidence, peer: PeerId) -> Result<Hash, IoError> {
let client = self.rpc_client_for(peer)?;

Expand All @@ -65,7 +65,7 @@ mod prod {
Self { peer_map, timeout }
}

#[pre(self.peer_map.contains_key(&peer))]
#[requires(self.peer_map.contains_key(&peer))]
fn rpc_client_for(&self, peer: PeerId) -> Result<rpc::HttpClient, IoError> {
let peer_addr = self.peer_map.get(&peer).unwrap().to_owned();
rpc::HttpClient::new(peer_addr).map_err(IoError::rpc)
Expand Down
7 changes: 4 additions & 3 deletions light-client/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ impl LightClient {
/// - If the core verification loop invariant is violated [LCV-INV-TP.1]
/// - If verification of a light block fails
/// - If the fetching a light block from the primary node fails
#[post(
ret.is_ok() ==> trusted_store_contains_block_at_target_height(
#[allow(clippy::nonminimal_bool)]
#[ensures(
ret.is_ok() -> trusted_store_contains_block_at_target_height(
state.light_store.as_ref(),
target_height,
)
Expand Down Expand Up @@ -365,7 +366,7 @@ impl LightClient {
///
/// ## Postcondition
/// - The provider of block that is returned matches the given peer.
#[post(ret.as_ref().map(|(lb, _)| lb.provider == self.peer).unwrap_or(true))]
#[ensures(ret.as_ref().map(|(lb, _)| lb.provider == self.peer).unwrap_or(true))]
pub fn get_or_fetch_block(
&self,
height: Height,
Expand Down
19 changes: 10 additions & 9 deletions light-client/src/peer_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Provides a peer list for use within the `Supervisor`

use contracts::{post, pre};
use contracts::*;
use std::collections::{BTreeSet, HashMap};

use crate::errors::Error;
Expand Down Expand Up @@ -111,8 +111,8 @@ impl<T> PeerList<T> {
/// ## Precondition
/// - The given peer id must not be the primary peer id.
/// - The given peer must be in the witness list
#[pre(faulty_witness != self.primary && self.witnesses.contains(&faulty_witness))]
#[post(Self::invariant(self))]
#[requires(faulty_witness != self.primary && self.witnesses.contains(&faulty_witness))]
#[ensures(Self::invariant(self))]
pub fn replace_faulty_witness(&mut self, faulty_witness: PeerId) -> Option<PeerId> {
let mut result = None;

Expand All @@ -134,7 +134,8 @@ impl<T> PeerList<T> {
///
/// ## Errors
/// - If there are no witness left, returns `ErrorKind::NoWitnessLeft`.
#[post(ret.is_ok() ==> Self::invariant(self))]
#[allow(clippy::nonminimal_bool)]
#[ensures(ret.is_ok() -> Self::invariant(self))]
pub fn replace_faulty_primary(
&mut self,
primary_error: Option<Error>,
Expand Down Expand Up @@ -196,21 +197,21 @@ impl<T> PeerListBuilder<T> {
}

/// Register the given peer id and value as a witness.
#[pre(self.primary != Some(peer_id))]
#[requires(self.primary != Some(peer_id))]
pub fn witness(&mut self, peer_id: PeerId, value: T) {
self.values.insert(peer_id, value);
self.witnesses.insert(peer_id);
}

/// Register the given peer id and value as a full node.
#[pre(self.primary != Some(peer_id))]
#[requires(self.primary != Some(peer_id))]
pub fn full_node(&mut self, peer_id: PeerId, value: T) {
self.values.insert(peer_id, value);
self.full_nodes.insert(peer_id);
}

/// Register the given peer id and value as a faulty node.
#[pre(self.primary != Some(peer_id))]
#[requires(self.primary != Some(peer_id))]
pub fn faulty_node(&mut self, peer_id: PeerId, value: T) {
self.values.insert(peer_id, value);
self.faulty_nodes.insert(peer_id);
Expand All @@ -220,8 +221,8 @@ impl<T> PeerListBuilder<T> {
///
/// ## Precondition
/// - A primary has been set with a call to `PeerListBuilder::primary`.
#[pre(self.primary.is_some())]
#[post(PeerList::invariant(&ret))]
#[requires(self.primary.is_some())]
#[ensures(PeerList::invariant(&ret))]
pub fn build(self) -> PeerList<T> {
PeerList {
values: self.values,
Expand Down
2 changes: 1 addition & 1 deletion light-client/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl State {
///
/// ## Preconditions
/// - `height` <= `target_height`
#[pre(height <= target_height)]
#[requires(height <= target_height)]
pub fn trace_block(&mut self, target_height: Height, height: Height) {
self.verification_trace
.entry(target_height)
Expand Down