Skip to content

Commit

Permalink
fix lint warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 30, 2024
1 parent 44d9eb4 commit 34b0b8e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
- uses: datachainlab/rust-cache@allow_registry_src_caching
- run: cargo test
- run: make fmt
- run: make lint

e2e-test:
needs: test
Expand Down Expand Up @@ -44,4 +46,4 @@ jobs:
- run: cd ./e2e && npm install
- run: |
sed -i "s/#user:/user: \"$(id -u):$(id -g)\"/g" ./e2e/compose.yml
- run: source /opt/sgxsdk/environment && echo "$(id -u):$(id -g)" && make -C e2e e2e-test
- run: source /opt/sgxsdk/environment && make -C e2e e2e-test
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
######## Lint ########

.PHONY: lint-tools
lint-tools:
rustup component add rustfmt clippy
cargo install cargo-machete

.PHONY: fmt
fmt:
@cargo fmt --all $(CARGO_FMT_OPT)

.PHONY: lint
lint:
@$(MAKE) CARGO_FMT_OPT=--check fmt
@cargo clippy --locked --tests $(CARGO_TARGET) -- -D warnings
@cargo machete
3 changes: 3 additions & 0 deletions elc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ parity-scale-codec-derive = { version = "=3.6.4", default-features = false }

[dev-dependencies]
hex-literal = "0.4.1"

[package.metadata.cargo-machete]
ignored = ["parity-scale-codec", "parity-scale-codec-derive"]
19 changes: 8 additions & 11 deletions elc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl LightClient for BesuQBFTLightClient {

let height = client_state.latest_height;

let timestamp = consensus_state.timestamp.clone();
let timestamp = consensus_state.timestamp;
let state_id = gen_state_id(client_state, consensus_state)?;
Ok(CreateClientResult {
height,
Expand Down Expand Up @@ -127,7 +127,7 @@ impl LightClient for BesuQBFTLightClient {
// TODO make this configurable
Duration::from_secs(30),
new_consensus_state.timestamp,
trusted_consensus_state.timestamp.into(),
trusted_consensus_state.timestamp,
))
};
validation_context
Expand All @@ -140,12 +140,9 @@ impl LightClient for BesuQBFTLightClient {
height,
message: UpdateStateProxyMessage {
prev_height: Some(header.trusted_height),
prev_state_id: Some(gen_state_id(
client_state.clone(),
trusted_consensus_state.clone(),
)?),
prev_state_id: Some(gen_state_id(client_state, trusted_consensus_state)?),
post_height: height,
post_state_id: gen_state_id(new_client_state.clone(), new_consensus_state.clone())?,
post_state_id: gen_state_id(new_client_state, new_consensus_state.clone())?,
emitted_states: Default::default(),
timestamp: new_consensus_state.timestamp,
context: validation_context,
Expand All @@ -172,7 +169,7 @@ impl LightClient for BesuQBFTLightClient {
Ok(VerifyMembershipResult {
message: VerifyMembershipProxyMessage::new(
prefix,
path.to_string(),
path,
Some(keccak256(&value)),
proof_height,
gen_state_id(client_state, consensus_state)?,
Expand All @@ -196,7 +193,7 @@ impl LightClient for BesuQBFTLightClient {
Ok(VerifyNonMembershipResult {
message: VerifyMembershipProxyMessage::new(
prefix,
path.to_string(),
path,
None,
proof_height,
gen_state_id(client_state, consensus_state)?,
Expand Down Expand Up @@ -228,7 +225,7 @@ impl BesuQBFTLightClient {
let mut marked = vec![false; trusted_validators.len()];
let mut success = 0;
for seal in committed_seals {
if seal.len() == 0 {
if seal.is_empty() {
continue;
}

Expand Down Expand Up @@ -259,7 +256,7 @@ impl BesuQBFTLightClient {

let mut success = 0;
for (validator, seal) in untrusted_validators.iter().zip(committed_seals.iter()) {
if seal.len() == 0 {
if seal.is_empty() {
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions elc/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use besu_qbft_proto::ibc::{
use core::time::Duration;
use ethereum_light_client_verifier::execution::ExecutionVerifier;
use light_client::types::proto::google::protobuf::Any as ProtoAny;
use light_client::types::{Any, Height, Time};
use light_client::types::{Any, Height};
use prost::Message;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -39,7 +39,7 @@ impl From<ClientState> for RawClientState {
revision_height: value.latest_height.revision_height(),
})
},
trusting_period: value.trusting_period.as_secs() as u64,
trusting_period: value.trusting_period.as_secs(),
}
}
}
Expand Down Expand Up @@ -95,13 +95,13 @@ impl ClientState {
root.to_be_bytes().into(),
// unwrap is safe because the address is 20 bytes
&(path.as_slice().try_into().unwrap()),
proof.clone(),
proof,
)? {
Some(account) => Ok(H256::try_from_be_slice(account.storage_root.as_bytes())
.ok_or_else(|| {
Error::InvalidAccountStorageRoot(account.storage_root.0.to_vec())
})?),
None => Err(Error::AccountNotFound(root, path.clone())),
None => Err(Error::AccountNotFound(root, *path)),
}
}

Expand All @@ -119,7 +119,7 @@ impl ClientState {
root.to_be_bytes().into(),
key.to_be_bytes_vec().as_slice(),
rlp::encode(&trim_left_zero(keccak256(&value).as_slice())).as_ref(),
proof.clone(),
proof,
)?;

Ok(())
Expand All @@ -137,7 +137,7 @@ impl ClientState {
self.execution_verifier.verify_non_membership(
root.to_be_bytes().into(),
key.to_be_bytes_vec().as_slice(),
proof.clone(),
proof,
)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion elc/src/consensus_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct ConsensusState {
impl From<ConsensusState> for RawConsensusState {
fn from(value: ConsensusState) -> Self {
RawConsensusState {
timestamp: value.timestamp.as_unix_timestamp_secs() as u64,
timestamp: value.timestamp.as_unix_timestamp_secs(),
root: value.root.to_be_bytes_vec(),
validators: value.validators.iter().map(|v| v.to_vec()).collect(),
}
Expand Down
6 changes: 3 additions & 3 deletions elc/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TryFrom<RawHeader> for Header {
fn try_from(value: RawHeader) -> Result<Self, Self::Error> {
let trusted_height = value
.trusted_height
.ok_or_else(|| Error::InvalidHeaderZeroTrustedHeight)?;
.ok_or(Error::InvalidHeaderZeroTrustedHeight)?;
Ok(Header {
besu_header_rlp: value.besu_header_rlp,
seals: value.seals,
Expand All @@ -75,7 +75,7 @@ impl TryFrom<Any> for Header {
let raw_header = RawHeader::decode(value).map_err(Error::Decode)?;
Header::try_from(raw_header)
}
_ => Err(Error::UnexpectedClientType(type_url.to_string()).into()),
_ => Err(Error::UnexpectedClientType(type_url.to_string())),
}
}
}
Expand All @@ -101,7 +101,7 @@ impl TryFrom<Any> for ClientMessage {
let header = Header::try_from(raw_header)?;
Ok(ClientMessage::Header(header))
}
_ => Err(Error::UnexpectedClientType(type_url.to_string()).into()),
_ => Err(Error::UnexpectedClientType(type_url.to_string())),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion proto/src/google.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub mod protobuf {
impl Eq for Timestamp {}

#[cfg(feature = "std")]
#[allow(clippy::derived_hash_with_manual_eq)] // Derived logic is correct: comparing the 2 fields for equality
#[allow(clippy::derive_hash_xor_eq)] // Derived logic is correct: comparing the 2 fields for equality
impl std::hash::Hash for Timestamp {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.seconds.hash(state);
Expand Down

0 comments on commit 34b0b8e

Please sign in to comment.