Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum committed Oct 27, 2024
1 parent 9e6d473 commit a16094c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 68 deletions.
20 changes: 9 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/babylon/proto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::all)]

pub mod btccheckpoint;

// @generated
Expand Down
32 changes: 16 additions & 16 deletions src/ethereum/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ 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,
},
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};
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -124,7 +123,7 @@ impl State for LightClient {
Ok(self.encode_into(out)?)
}

fn load(store: orga::prelude::Store, bytes: &mut &[u8]) -> orga::Result<Self> {
fn load(_store: orga::prelude::Store, bytes: &mut &[u8]) -> orga::Result<Self> {
Ok(Self::decode(bytes)?)
}
}
Expand All @@ -142,15 +141,15 @@ 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()))
}
}

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()))
}
}
Expand Down Expand Up @@ -732,7 +731,7 @@ pub fn encode_sync_committee<W: std::io::Write>(
impl Decode for SyncCommittee {
fn decode<R: std::io::Read>(mut input: R) -> ed::Result<Self> {
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();
Expand Down Expand Up @@ -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,
}))
}
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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))
}
}
Expand All @@ -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))
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/ethereum/consensus/relayer.rs
Original file line number Diff line number Diff line change
@@ -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<C: OrgaClient<LightClient>>(
app_client: &C,
Expand Down
14 changes: 7 additions & 7 deletions src/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -855,6 +854,7 @@ impl Describe for OutMessageArgs {
}
}

#[allow(clippy::too_many_arguments)]
pub fn call_hash(
chain_id: u32,
bridge_contract: [u8; 20],
Expand Down
16 changes: 0 additions & 16 deletions src/ethereum/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<u16, consensus::Update>,
}

// 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],
}
10 changes: 1 addition & 9 deletions src/ethereum/relayer.rs
Original file line number Diff line number Diff line change
@@ -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<
Expand All @@ -17,12 +15,6 @@ pub async fn get_state_proof<
index: u64,
block_number: u64,
) -> AppResult<StateProof> {
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()
Expand Down

0 comments on commit a16094c

Please sign in to comment.