From a16094c9483e4c6d5e76f3637a6da889d0d7a32e Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Sun, 27 Oct 2024 15:27:10 -0500 Subject: [PATCH] Fix clippy warnings --- src/app.rs | 20 +++++++++---------- src/babylon/proto/mod.rs | 2 ++ src/ethereum/consensus/mod.rs | 32 +++++++++++++++---------------- src/ethereum/consensus/relayer.rs | 12 +++--------- src/ethereum/mod.rs | 14 +++++++------- src/ethereum/proofs.rs | 16 ---------------- src/ethereum/relayer.rs | 10 +--------- 7 files changed, 38 insertions(+), 68 deletions(-) diff --git a/src/app.rs b/src/app.rs index f9833eb8..7a7bcc1e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -487,18 +487,16 @@ impl InnerApp { let amount = coins.amount; if let Err(e) = self.validate_dest(&dest, amount, sender) { log::debug!("Error validating transfer: {}", e); + } else if let Err(e) = self.credit_dest(dest.clone(), coins.take(amount)?, sender) { + log::debug!("Error crediting transfer: {:?}", e); + // TODO: ensure no errors can happen after mutating + // state in credit_dest since state won't be reverted + + // Assume coins passed into credit_dest are burnt, + // replace them in `coins` + coins.give(Coin::mint(amount))?; } else { - if let Err(e) = self.credit_dest(dest.clone(), coins.take(amount)?, sender) { - log::debug!("Error crediting transfer: {:?}", e); - // TODO: ensure no errors can happen after mutating - // state in credit_dest since state won't be reverted - - // Assume coins passed into credit_dest are burnt, - // replace them in `coins` - coins.give(Coin::mint(amount))?; - } else { - succeeded = true; - } + succeeded = true; } // Handle failures diff --git a/src/babylon/proto/mod.rs b/src/babylon/proto/mod.rs index 91e4da6e..ff5e4510 100644 --- a/src/babylon/proto/mod.rs +++ b/src/babylon/proto/mod.rs @@ -1,3 +1,5 @@ +#![allow(clippy::all)] + pub mod btccheckpoint; // @generated diff --git a/src/ethereum/consensus/mod.rs b/src/ethereum/consensus/mod.rs index c5e59f05..29e9be25 100644 --- a/src/ethereum/consensus/mod.rs +++ b/src/ethereum/consensus/mod.rs @@ -4,17 +4,16 @@ use std::{ str::FromStr, }; -use bitcoin::{consensus::encode, network}; use ed::{Decode, Encode, Terminated}; use helios_consensus_core::{ - apply_bootstrap, apply_finality_update, apply_update, expected_current_slot, + apply_bootstrap, apply_finality_update, apply_update, types::{ bls::{PublicKey as HeliosPublicKey, Signature as HeliosSignature}, bytes::{ByteList, ByteVector}, BeaconBlockHeader as HeliosBeaconBlockHeader, Bootstrap as HeliosBootstrap, ExecutionPayloadHeader as HeliosExecutionPayloadHeaderOuter, ExecutionPayloadHeaderDeneb as HeliosExecutionPayloadHeader, - FinalityUpdate as HeliosFinalityUpdate, Forks, GenericUpdate, + FinalityUpdate as HeliosFinalityUpdate, Forks, LightClientHeader as HeliosLightClientHeader, LightClientStore, SyncAggregate as HeliosSyncAggregate, SyncCommittee as HeliosSyncCommittee, Update as HeliosUpdate, @@ -22,8 +21,8 @@ use helios_consensus_core::{ verify_bootstrap, verify_finality_update, verify_update, }; use orga::{ - call::FieldCall, describe::Describe, encoding::LengthVec, migrate::Migrate, orga, - query::FieldQuery, state::State, + call::FieldCall, describe::Describe, encoding::LengthVec, migrate::Migrate, query::FieldQuery, + state::State, }; use serde::{Deserialize, Serialize}; use serde_hex::{SerHex, StrictPfx}; @@ -50,7 +49,7 @@ impl LightClient { forks.deneb.fork_version = (network.deneb_fork_version.to_be_bytes()).into(); verify_bootstrap(&bootstrap, bootstrap.header.beacon.tree_hash_root(), &forks) - .map_err(|e| orga::Error::App(format!("Invalid bootstrap: {}", e.to_string())))?; + .map_err(|e| orga::Error::App(format!("Invalid bootstrap: {}", e)))?; let mut lcs = LightClientStore::default(); apply_bootstrap(&mut lcs, &bootstrap); @@ -68,12 +67,12 @@ impl LightClient { if update.next_sync_committee.is_some() { let update: HeliosUpdate = update.try_into().unwrap(); verify_update(&update, expected_slot, &self.lcs, genesis_root, &forks) - .map_err(|e| orga::Error::App(format!("Invalid update: {}", e.to_string())))?; + .map_err(|e| orga::Error::App(format!("Invalid update: {}", e)))?; apply_update(&mut self.lcs, &update); } else { let update: HeliosFinalityUpdate = update.into(); verify_finality_update(&update, expected_slot, &self.lcs, genesis_root, &forks) - .map_err(|e| orga::Error::App(format!("Invalid update: {}", e.to_string())))?; + .map_err(|e| orga::Error::App(format!("Invalid update: {}", e)))?; apply_finality_update(&mut self.lcs, &update); } @@ -124,7 +123,7 @@ impl State for LightClient { Ok(self.encode_into(out)?) } - fn load(store: orga::prelude::Store, bytes: &mut &[u8]) -> orga::Result { + fn load(_store: orga::prelude::Store, bytes: &mut &[u8]) -> orga::Result { Ok(Self::decode(bytes)?) } } @@ -142,7 +141,7 @@ impl Migrate for LightClient { impl FieldCall for LightClient { type FieldCall = (); - fn field_call(&mut self, call: ()) -> orga::Result<()> { + fn field_call(&mut self, _call: ()) -> orga::Result<()> { Err(orga::Error::App("FieldCall not supported".to_string())) } } @@ -150,7 +149,7 @@ impl FieldCall for LightClient { impl FieldQuery for LightClient { type FieldQuery = (); - fn field_query(&self, query: ()) -> orga::Result<()> { + fn field_query(&self, _query: ()) -> orga::Result<()> { Err(orga::Error::App("FieldQuery not supported".to_string())) } } @@ -732,7 +731,7 @@ pub fn encode_sync_committee( impl Decode for SyncCommittee { fn decode(mut input: R) -> ed::Result { let mut pubkeys = Vec::with_capacity(512); - for i in 0..512 { + for _ in 0..512 { pubkeys.push(PublicKey::decode(&mut input)?.into_inner()); } let aggregate_pubkey = PublicKey::decode(&mut input)?.into_inner(); @@ -796,7 +795,7 @@ impl Decode for SyncAggregate { Ok(SyncAggregate(HeliosSyncAggregate { sync_committee_bits: Bitfield::from_ssz_bytes(&sync_committee_bits) // TODO: pass through error - .map_err(|e| ed::Error::UnexpectedByte(34))?, + .map_err(|_| ed::Error::UnexpectedByte(34))?, sync_committee_signature, })) } @@ -859,7 +858,7 @@ impl Decode for PublicKey { input.read_exact(&mut bytes)?; // TODO: pass through error let value = - HeliosPublicKey::from_ssz_bytes(&bytes).map_err(|e| ed::Error::UnexpectedByte(33))?; + HeliosPublicKey::from_ssz_bytes(&bytes).map_err(|_| ed::Error::UnexpectedByte(33))?; Ok(PublicKey(value)) } } @@ -921,7 +920,8 @@ impl Decode for Signature { input.read_exact(&mut bytes)?; // TODO: pass through error let value = - HeliosSignature::from_ssz_bytes(&bytes).map_err(|e| ed::Error::UnexpectedByte(33))?; + HeliosSignature::from_ssz_bytes(&bytes).map_err(|_| ed::Error::UnexpectedByte(33))?; + Ok(Signature(value)) } } @@ -946,7 +946,7 @@ impl From<[u8; 32]> for Bytes32 { impl Display for Bytes32 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "0x{}", hex::encode(&self.0)) + write!(f, "0x{}", hex::encode(self.0)) } } diff --git a/src/ethereum/consensus/relayer.rs b/src/ethereum/consensus/relayer.rs index 3ea3e302..8b011818 100644 --- a/src/ethereum/consensus/relayer.rs +++ b/src/ethereum/consensus/relayer.rs @@ -1,15 +1,9 @@ -use ed::{Decode, Encode}; -use orga::{client::Client as OrgaClient, encoding::LengthVec}; +use orga::client::Client as OrgaClient; use reqwest::get; use serde::{Deserialize, Serialize}; -use super::{ - encode_sync_aggregate, Bootstrap, Bytes32, LightClient, LightClientHeader, SyncAggregate, - SyncCommittee, Update, -}; -use crate::{app, error::Result}; - -use super::{encode_lc_header, encode_sync_committee}; +use super::{Bootstrap, Bytes32, LightClient, Update}; +use crate::error::Result; pub async fn get_updates>( app_client: &C, diff --git a/src/ethereum/mod.rs b/src/ethereum/mod.rs index 297b5dc2..87e030a7 100644 --- a/src/ethereum/mod.rs +++ b/src/ethereum/mod.rs @@ -9,9 +9,8 @@ use bitcoin::secp256k1::{ use bitcoin::Script; use consensus::LightClient; use orga::{context::GetContext as _, plugins::Time, query::MethodQuery}; -use proofs::{BridgeContractData, ConsensusState, StateProof}; +use proofs::{BridgeContractData, StateProof}; use std::collections::BTreeSet; -use std::u64; use ed::{Decode, Encode}; use orga::{ @@ -26,7 +25,7 @@ use orga::{ store::Store, Error, }; -use serde::{Deserialize, Serialize}; +use serde::Serialize; use serde_hex::{SerHex, StrictPfx}; use crate::app::Identity; @@ -140,7 +139,6 @@ impl Ethereum { state_proof: StateProof, ) -> Result<()> { exempt_from_fee()?; - let now_seconds = self.now()? as u64; let mut net = self .networks @@ -648,7 +646,7 @@ impl Connection { Ok(dest) => self.pending.push_back((dest, coins, sender_id))?, Err(e) => { log::debug!("failed to parse dest: {}, {}", dest.as_str(), e); - self.transfer(sender.into(), coins)?; + self.transfer(sender, coins)?; } } self.return_index += 1; @@ -733,11 +731,12 @@ impl Connection { OutMessageArgs::ContractCall { contract_address, data, - max_gas, - fallback_address, transfer_amount, fee_amount, message_index, + // max_gas, TODO: include in hash + // fallback_address, TODO: include in hash + .. } => call_hash( self.chain_id, self.bridge_contract.into(), @@ -855,6 +854,7 @@ impl Describe for OutMessageArgs { } } +#[allow(clippy::too_many_arguments)] pub fn call_hash( chain_id: u32, bridge_contract: [u8; 20], diff --git a/src/ethereum/proofs.rs b/src/ethereum/proofs.rs index 5a665e49..c07f2fc2 100644 --- a/src/ethereum/proofs.rs +++ b/src/ethereum/proofs.rs @@ -10,15 +10,12 @@ use ethereum_triedb::{ use orga::coins::Amount; use orga::encoding::LengthString; use orga::encoding::{Decode, Encode}; -use orga::orga; use orga::{coins::Address, encoding::LengthVec}; use primitive_types::{H256, U256}; use rlp::{Decodable as _, Rlp}; use rlp_derive::RlpDecodable; use trie_db::{Trie, TrieDBBuilder}; -use super::consensus; - #[derive(RlpDecodable, Debug)] struct Account { _nonce: u64, @@ -282,16 +279,3 @@ impl BridgeContractData { pub fn extra_slots_required(len: usize) -> usize { (len + 31) / 32 } -// updated header -#[derive(Debug, Clone, Encode, Decode)] -pub struct ConsensusProof { - pub updates: LengthVec, -} - -// sync committee / next_sync_committee won't change across updates except when -// no longer in current period -#[orga] -#[derive(Debug, Clone)] -pub struct ConsensusState { - pub state_root: [u8; 32], -} diff --git a/src/ethereum/relayer.rs b/src/ethereum/relayer.rs index cbec84d0..b27de667 100644 --- a/src/ethereum/relayer.rs +++ b/src/ethereum/relayer.rs @@ -1,11 +1,9 @@ -use super::consensus; -use super::proofs::{BridgeContractData, ConsensusProof, StateProof}; +use super::proofs::{BridgeContractData, StateProof}; use crate::error::Result as AppResult; use crate::ethereum::proofs::extra_slots_required; use alloy_core::primitives::Address as EthAddress; use alloy_primitives::Uint; use alloy_provider::Provider; -use alloy_rpc_types::BlockId; use alloy_transport::Transport; pub async fn get_state_proof< @@ -17,12 +15,6 @@ pub async fn get_state_proof< index: u64, block_number: u64, ) -> AppResult { - let block = provider - .get_block_by_number(block_number.into(), true) - .await - .map_err(|e| crate::error::Error::Relayer(e.to_string()))? - .unwrap(); - let contract = super::bridge_contract::new(address, provider.clone()); let contract_index: u64 = contract .state_lastReturnNonce()