diff --git a/Cargo.lock b/Cargo.lock index e308d8a..84bf8be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -492,10 +492,8 @@ dependencies = [ [[package]] name = "client" -version = "0.1.0" +version = "0.1.1" dependencies = [ - "blst", - "bytes", "common", "config", "consensus", @@ -506,14 +504,10 @@ dependencies = [ "hex", "jsonrpsee", "log", - "openssl", - "reqwest", - "revm", "serde", "ssz-rs", "thiserror", "tokio", - "toml", ] [[package]] @@ -1213,7 +1207,6 @@ name = "execution" version = "0.1.0" dependencies = [ "async-trait", - "blst", "bytes", "common", "consensus", @@ -1646,7 +1639,7 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "helios" -version = "0.1.0" +version = "0.1.1" dependencies = [ "client", "common", diff --git a/Cargo.toml b/Cargo.toml index f301446..42bfb31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "helios" -version = "0.1.0" +version = "0.1.1" edition = "2021" [workspace] diff --git a/cli/src/main.rs b/cli/src/main.rs index b8bc870..1ac8603 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -90,7 +90,7 @@ struct Cli { impl Cli { fn as_cli_config(&self) -> CliConfig { let checkpoint = match &self.checkpoint { - Some(checkpoint) => Some(hex_str_to_bytes(&checkpoint).expect("invalid checkpoint")), + Some(checkpoint) => Some(hex_str_to_bytes(checkpoint).expect("invalid checkpoint")), None => self.get_cached_checkpoint(), }; diff --git a/client/Cargo.toml b/client/Cargo.toml index efe0d91..cbaa020 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,26 +1,18 @@ [package] name = "client" -version = "0.1.0" +version = "0.1.1" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -reqwest = { version = "0.11", features = ["json"] } tokio = { version = "1", features = ["full"] } eyre = "0.6.8" serde = { version = "1.0.143", features = ["derive"] } hex = "0.4.3" ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "cb08f18ca919cc1b685b861d0fa9e2daabe89737" } -blst = "0.3.10" ethers = "1.0.0" jsonrpsee = { version = "0.15.1", features = ["full"] } -revm = "2.1.0" -bytes = "1.2.1" futures = "0.3.23" -toml = "0.5.9" log = "0.4.17" -openssl = { version = "0.10", features = ["vendored"] } thiserror = "1.0.37" common = { path = "../common" } diff --git a/client/src/client.rs b/client/src/client.rs index e2c6f8c..e482420 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -31,23 +31,16 @@ impl Client { let node = Node::new(config.clone())?; let node = Arc::new(RwLock::new(node)); - let rpc = if let Some(port) = config.rpc_port { - Some(Rpc::new(node.clone(), port)) - } else { - None - }; + let rpc = config.rpc_port.map(|port| Rpc::new(node.clone(), port)); let data_dir = config.data_dir.clone(); - let db = if let Some(dir) = data_dir { - Some(FileDB::new(dir)) - } else { - None - }; + let db = data_dir.map(FileDB::new); Ok(Client { node, rpc, db }) } } +#[derive(Default)] pub struct ClientBuilder { network: Option, consensus_rpc: Option, @@ -60,15 +53,7 @@ pub struct ClientBuilder { impl ClientBuilder { pub fn new() -> Self { - Self { - network: None, - consensus_rpc: None, - execution_rpc: None, - checkpoint: None, - rpc_port: None, - data_dir: None, - config: None, - } + Self::default() } pub fn network(mut self, network: Network) -> Self { @@ -249,7 +234,7 @@ impl Client { self.node.read().await.get_storage_at(address, slot).await } - pub async fn send_raw_transaction(&self, bytes: &Vec) -> Result { + pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result { self.node.read().await.send_raw_transaction(bytes).await } diff --git a/client/src/node.rs b/client/src/node.rs index 8b2209e..4bd623e 100644 --- a/client/src/node.rs +++ b/client/src/node.rs @@ -117,7 +117,7 @@ impl Node { let payload = self.get_payload(block)?; let mut evm = Evm::new( self.execution.clone(), - &payload, + payload, &self.payloads, self.chain_id(), ); @@ -130,7 +130,7 @@ impl Node { let payload = self.get_payload(BlockTag::Latest)?; let mut evm = Evm::new( self.execution.clone(), - &payload, + payload, &self.payloads, self.chain_id(), ); @@ -143,7 +143,7 @@ impl Node { self.check_blocktag_age(&block)?; let payload = self.get_payload(block)?; - let account = self.execution.get_account(&address, None, payload).await?; + let account = self.execution.get_account(address, None, payload).await?; Ok(account.balance) } @@ -151,7 +151,7 @@ impl Node { self.check_blocktag_age(&block)?; let payload = self.get_payload(block)?; - let account = self.execution.get_account(&address, None, payload).await?; + let account = self.execution.get_account(address, None, payload).await?; Ok(account.nonce) } @@ -159,7 +159,7 @@ impl Node { self.check_blocktag_age(&block)?; let payload = self.get_payload(block)?; - let account = self.execution.get_account(&address, None, payload).await?; + let account = self.execution.get_account(address, None, payload).await?; Ok(account.code) } @@ -179,7 +179,7 @@ impl Node { } } - pub async fn send_raw_transaction(&self, bytes: &Vec) -> Result { + pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result { self.execution.send_raw_transaction(bytes).await } @@ -233,11 +233,7 @@ impl Node { self.check_blocktag_age(&block)?; match self.get_payload(block) { - Ok(payload) => self - .execution - .get_block(payload, full_tx) - .await - .map(|b| Some(b)), + Ok(payload) => self.execution.get_block(payload, full_tx).await.map(Some), Err(_) => Ok(None), } } @@ -257,7 +253,7 @@ impl Node { self.execution .get_block(payload_entry.1, full_tx) .await - .map(|b| Some(b)) + .map(Some) } else { Ok(None) } @@ -290,7 +286,7 @@ impl Node { } BlockTag::Number(num) => { let payload = self.payloads.get(&num); - payload.ok_or(BlockNotFoundError::new(BlockTag::Number(num)).into()) + payload.ok_or(BlockNotFoundError::new(BlockTag::Number(num))) } } } diff --git a/client/src/rpc.rs b/client/src/rpc.rs index e39a9b6..12dc87a 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -264,7 +264,7 @@ fn format_hex(num: &U256) -> String { .encode_hex() .strip_prefix("0x") .unwrap() - .trim_start_matches("0") + .trim_start_matches('0') .to_string(); format!("0x{}", stripped) diff --git a/common/Cargo.toml b/common/Cargo.toml index d4b7413..9ae1181 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -3,8 +3,6 @@ name = "common" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] eyre = "0.6.8" serde = { version = "1.0.143", features = ["derive"] } diff --git a/config/Cargo.toml b/config/Cargo.toml index dfc3676..2a76f39 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -4,8 +4,6 @@ name = "config" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] eyre = "0.6.8" serde = { version = "1.0.143", features = ["derive"] } diff --git a/config/src/lib.rs b/config/src/lib.rs index 0eed18b..750481d 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -53,7 +53,7 @@ impl Config { Err(err) => { match err.kind { figment::error::Kind::MissingField(field) => { - let field = field.replace("_", "-"); + let field = field.replace('_', "-"); println!( "\x1b[91merror\x1b[0m: missing configuration field: {}", @@ -94,7 +94,7 @@ impl Config { checkpoint: self.checkpoint.clone(), chain: self.chain.clone(), forks: self.forks.clone(), - max_checkpoint_age: self.max_checkpoint_age.clone(), + max_checkpoint_age: self.max_checkpoint_age, } } } diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index 65813cd..bf96ac2 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -3,8 +3,6 @@ name = "consensus" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tokio = { version = "1", features = ["full"] } eyre = "0.6.8" diff --git a/consensus/src/consensus.rs b/consensus/src/consensus.rs index 2a77b9f..10052e9 100644 --- a/consensus/src/consensus.rs +++ b/consensus/src/consensus.rs @@ -44,7 +44,7 @@ struct LightClientStore { impl ConsensusClient { pub fn new( rpc: &str, - checkpoint_block_root: &Vec, + checkpoint_block_root: &[u8], config: Arc, ) -> Result> { let rpc = R::new(rpc); @@ -54,13 +54,13 @@ impl ConsensusClient { store: LightClientStore::default(), last_checkpoint: None, config, - initial_checkpoint: checkpoint_block_root.clone(), + initial_checkpoint: checkpoint_block_root.to_vec(), }) } pub async fn get_execution_payload(&self, slot: &Option) -> Result { let slot = slot.unwrap_or(self.store.optimistic_header.slot); - let mut block = self.rpc.get_block(slot).await?.clone(); + let mut block = self.rpc.get_block(slot).await?; let block_hash = block.hash_tree_root()?; let latest_slot = self.store.optimistic_header.slot; @@ -102,8 +102,8 @@ impl ConsensusClient { .get_updates(current_period, MAX_REQUEST_LIGHT_CLIENT_UPDATES) .await?; - for mut update in updates { - self.verify_update(&mut update)?; + for update in updates { + self.verify_update(&update)?; self.apply_update(&update); } @@ -133,12 +133,12 @@ impl ConsensusClient { let mut updates = self.rpc.get_updates(current_period, 1).await?; if updates.len() == 1 { - let mut update = updates.get_mut(0).unwrap(); - let res = self.verify_update(&mut update); + let update = updates.get_mut(0).unwrap(); + let res = self.verify_update(update); if res.is_ok() { info!("updating sync committee"); - self.apply_update(&update); + self.apply_update(update); } } } @@ -427,13 +427,13 @@ impl ConsensusClient { fn verify_sync_committee_signture( &self, - pks: &Vec, + pks: &[PublicKey], attested_header: &Header, signature: &SignatureBytes, signature_slot: u64, ) -> bool { let res: Result = (move || { - let pks: Vec<&PublicKey> = pks.iter().map(|pk| pk).collect(); + let pks: Vec<&PublicKey> = pks.iter().collect(); let header_root = bytes_to_bytes32(attested_header.clone().hash_tree_root()?.as_bytes()); let signing_root = self.compute_committee_sign_root(header_root, signature_slot)?; @@ -519,7 +519,7 @@ fn get_participating_keys( bitfield.iter().enumerate().for_each(|(i, bit)| { if bit == true { let pk = &committee.pubkeys[i]; - let pk = PublicKey::from_bytes(&pk).unwrap(); + let pk = PublicKey::from_bytes(pk).unwrap(); pks.push(pk); } }); @@ -541,7 +541,7 @@ fn get_bits(bitfield: &Bitvector<512>) -> u64 { fn is_finality_proof_valid( attested_header: &Header, finality_header: &mut Header, - finality_branch: &Vec, + finality_branch: &[Bytes32], ) -> bool { is_proof_valid(attested_header, finality_header, finality_branch, 6, 41) } @@ -549,7 +549,7 @@ fn is_finality_proof_valid( fn is_next_committee_proof_valid( attested_header: &Header, next_committee: &mut SyncCommittee, - next_committee_branch: &Vec, + next_committee_branch: &[Bytes32], ) -> bool { is_proof_valid( attested_header, @@ -563,7 +563,7 @@ fn is_next_committee_proof_valid( fn is_current_committee_proof_valid( attested_header: &Header, current_committee: &mut SyncCommittee, - current_committee_branch: &Vec, + current_committee_branch: &[Bytes32], ) -> bool { is_proof_valid( attested_header, @@ -620,8 +620,8 @@ mod tests { .await .unwrap(); - let mut update = updates[0].clone(); - client.verify_update(&mut update).unwrap(); + let update = updates[0].clone(); + client.verify_update(&update).unwrap(); } #[tokio::test] @@ -637,7 +637,7 @@ mod tests { let mut update = updates[0].clone(); update.next_sync_committee.pubkeys[0] = Vector::default(); - let err = client.verify_update(&mut update).err().unwrap(); + let err = client.verify_update(&update).err().unwrap(); assert_eq!( err.to_string(), ConsensusError::InvalidNextSyncCommitteeProof.to_string() diff --git a/consensus/src/rpc/mock_rpc.rs b/consensus/src/rpc/mock_rpc.rs index 8f87ba2..97a4b90 100644 --- a/consensus/src/rpc/mock_rpc.rs +++ b/consensus/src/rpc/mock_rpc.rs @@ -18,7 +18,7 @@ impl ConsensusRpc for MockRpc { } } - async fn get_bootstrap(&self, _block_root: &Vec) -> Result { + async fn get_bootstrap(&self, _block_root: &'_ [u8]) -> Result { let bootstrap = read_to_string(self.testdata.join("bootstrap.json"))?; Ok(serde_json::from_str(&bootstrap)?) } diff --git a/consensus/src/rpc/mod.rs b/consensus/src/rpc/mod.rs index b3d9229..cba8bf1 100644 --- a/consensus/src/rpc/mod.rs +++ b/consensus/src/rpc/mod.rs @@ -10,7 +10,7 @@ use crate::types::{BeaconBlock, Bootstrap, FinalityUpdate, OptimisticUpdate, Upd #[async_trait] pub trait ConsensusRpc { fn new(path: &str) -> Self; - async fn get_bootstrap(&self, block_root: &Vec) -> Result; + async fn get_bootstrap(&self, block_root: &'_ [u8]) -> Result; async fn get_updates(&self, period: u64, count: u8) -> Result>; async fn get_finality_update(&self) -> Result; async fn get_optimistic_update(&self) -> Result; diff --git a/consensus/src/rpc/nimbus_rpc.rs b/consensus/src/rpc/nimbus_rpc.rs index 2f1e180..ca6c478 100644 --- a/consensus/src/rpc/nimbus_rpc.rs +++ b/consensus/src/rpc/nimbus_rpc.rs @@ -31,7 +31,7 @@ impl ConsensusRpc for NimbusRpc { } } - async fn get_bootstrap(&self, block_root: &Vec) -> Result { + async fn get_bootstrap(&self, block_root: &'_ [u8]) -> Result { let root_hex = hex::encode(block_root); let req = format!( "{}/eth/v1/beacon/light_client/bootstrap/0x{}", diff --git a/consensus/src/types.rs b/consensus/src/types.rs index a4e534f..2fb7d37 100644 --- a/consensus/src/types.rs +++ b/consensus/src/types.rs @@ -271,7 +271,7 @@ impl From<&Update> for GenericUpdate { Self { attested_header: update.attested_header.clone(), sync_aggregate: update.sync_aggregate.clone(), - signature_slot: update.signature_slot.clone(), + signature_slot: update.signature_slot, next_sync_committee: Some(update.next_sync_committee.clone()), next_sync_committee_branch: Some(update.next_sync_committee_branch.clone()), finalized_header: Some(update.finalized_header.clone()), @@ -285,7 +285,7 @@ impl From<&FinalityUpdate> for GenericUpdate { Self { attested_header: update.attested_header.clone(), sync_aggregate: update.sync_aggregate.clone(), - signature_slot: update.signature_slot.clone(), + signature_slot: update.signature_slot, next_sync_committee: None, next_sync_committee_branch: None, finalized_header: Some(update.finalized_header.clone()), @@ -299,7 +299,7 @@ impl From<&OptimisticUpdate> for GenericUpdate { Self { attested_header: update.attested_header.clone(), sync_aggregate: update.sync_aggregate.clone(), - signature_slot: update.signature_slot.clone(), + signature_slot: update.signature_slot, next_sync_committee: None, next_sync_committee_branch: None, finalized_header: None, @@ -322,14 +322,13 @@ where D: serde::Deserializer<'de>, { let keys: Vec = serde::Deserialize::deserialize(deserializer)?; - Ok(keys - .iter() + keys.iter() .map(|key| { let key_bytes = hex_str_to_bytes(key)?; Ok(Vector::from_iter(key_bytes)) }) .collect::>>() - .map_err(D::Error::custom)?) + .map_err(D::Error::custom) } fn bytes_vector_deserialize<'de, D>(deserializer: D) -> Result, D::Error> @@ -337,14 +336,14 @@ where D: serde::Deserializer<'de>, { let elems: Vec = serde::Deserialize::deserialize(deserializer)?; - Ok(elems + elems .iter() .map(|elem| { let elem_bytes = hex_str_to_bytes(elem)?; Ok(Vector::from_iter(elem_bytes)) }) .collect::>>() - .map_err(D::Error::custom)?) + .map_err(D::Error::custom) } fn signature_deserialize<'de, D>(deserializer: D) -> Result @@ -361,14 +360,14 @@ where D: serde::Deserializer<'de>, { let branch: Vec = serde::Deserialize::deserialize(deserializer)?; - Ok(branch + branch .iter() .map(|elem| { let elem_bytes = hex_str_to_bytes(elem)?; Ok(Vector::from_iter(elem_bytes)) }) .collect::>() - .map_err(D::Error::custom)?) + .map_err(D::Error::custom) } fn u64_deserialize<'de, D>(deserializer: D) -> Result diff --git a/consensus/src/utils.rs b/consensus/src/utils.rs index b43f744..92dffed 100644 --- a/consensus/src/utils.rs +++ b/consensus/src/utils.rs @@ -15,9 +15,9 @@ pub fn calc_sync_period(slot: u64) -> u64 { pub fn is_aggregate_valid(sig_bytes: &SignatureBytes, msg: &[u8], pks: &[&PublicKey]) -> bool { let dst: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; - let sig_res = Signature::from_bytes(&sig_bytes); + let sig_res = Signature::from_bytes(sig_bytes); match sig_res { - Ok(sig) => sig.fast_aggregate_verify(true, msg, dst, &pks) == BLST_ERROR::BLST_SUCCESS, + Ok(sig) => sig.fast_aggregate_verify(true, msg, dst, pks) == BLST_ERROR::BLST_SUCCESS, Err(_) => false, } } @@ -25,7 +25,7 @@ pub fn is_aggregate_valid(sig_bytes: &SignatureBytes, msg: &[u8], pks: &[&Public pub fn is_proof_valid( attested_header: &Header, leaf_object: &mut L, - branch: &Vec, + branch: &[Bytes32], depth: usize, index: usize, ) -> bool { @@ -81,7 +81,6 @@ fn compute_fork_data_root( current_version: Vector, genesis_validator_root: Bytes32, ) -> Result { - let current_version = current_version.try_into()?; let mut fork_data = ForkData { current_version, genesis_validator_root, @@ -92,6 +91,6 @@ fn compute_fork_data_root( pub fn branch_to_nodes(branch: Vec) -> Result> { branch .iter() - .map(|elem| bytes32_to_node(elem)) + .map(bytes32_to_node) .collect::>>() } diff --git a/execution/Cargo.toml b/execution/Cargo.toml index 9d65098..ee819f5 100644 --- a/execution/Cargo.toml +++ b/execution/Cargo.toml @@ -3,8 +3,6 @@ name = "execution" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] reqwest = { version = "0.11", features = ["json"] } tokio = { version = "1", features = ["full"] } @@ -13,7 +11,6 @@ serde = { version = "1.0.143", features = ["derive"] } serde_json = "1.0.85" hex = "0.4.3" ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "cb08f18ca919cc1b685b861d0fa9e2daabe89737" } -blst = "0.3.10" ethers = "1.0.0" revm = "2.1.0" bytes = "1.2.1" diff --git a/execution/src/evm.rs b/execution/src/evm.rs index ac49298..9113042 100644 --- a/execution/src/evm.rs +++ b/execution/src/evm.rs @@ -120,9 +120,8 @@ impl<'a, R: ExecutionRpc> Evm<'a, R> { gas_price: opts.gas_price, }; - let block_moved = block.clone(); let mut list = rpc - .create_access_list(&opts_moved, block_moved) + .create_access_list(&opts_moved, block) .await .map_err(EvmError::RpcError)? .0; @@ -148,7 +147,7 @@ impl<'a, R: ExecutionRpc> Evm<'a, R> { let mut account_map = HashMap::new(); for chunk in list.chunks(PARALLEL_QUERY_BATCH_SIZE) { - let account_chunk_futs = chunk.into_iter().map(|account| { + let account_chunk_futs = chunk.iter().map(|account| { let account_fut = execution.get_account( &account.address, Some(account.storage_keys.as_slice()), @@ -221,12 +220,11 @@ impl<'a, R: ExecutionRpc> ProofDB<'a, R> { fn get_account(&mut self, address: Address, slots: &[H256]) -> Result { let execution = self.execution.clone(); - let addr = address.clone(); let payload = self.current_payload.clone(); let slots = slots.to_owned(); let handle = thread::spawn(move || { - let account_fut = execution.get_account(&addr, Some(&slots), &payload); + let account_fut = execution.get_account(&address, Some(&slots), &payload); let runtime = Runtime::new()?; runtime.block_on(account_fut) }); @@ -281,20 +279,18 @@ impl<'a, R: ExecutionRpc> Database for ProofDB<'a, R> { Ok(match self.accounts.get(&address) { Some(account) => match account.slots.get(&slot) { - Some(slot) => slot.clone(), - None => self + Some(slot) => *slot, + None => *self .get_account(address, &[slot])? .slots .get(&slot) - .unwrap() - .clone(), + .unwrap(), }, - None => self + None => *self .get_account(address, &[slot])? .slots .get(&slot) - .unwrap() - .clone(), + .unwrap(), }) } diff --git a/execution/src/execution.rs b/execution/src/execution.rs index 27cdfa8..400d027 100644 --- a/execution/src/execution.rs +++ b/execution/src/execution.rs @@ -46,7 +46,7 @@ impl ExecutionClient { let proof = self .rpc - .get_proof(&address, slots, payload.block_number) + .get_proof(address, slots, payload.block_number) .await?; let account_path = keccak256(address.as_bytes()).to_vec(); @@ -73,7 +73,7 @@ impl ExecutionClient { let is_valid = verify_proof( &storage_proof.proof, - &proof.storage_hash.as_bytes().to_vec(), + proof.storage_hash.as_bytes(), &key_hash.to_vec(), &value, ); @@ -115,7 +115,7 @@ impl ExecutionClient { }) } - pub async fn send_raw_transaction(&self, bytes: &Vec) -> Result { + pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result { self.rpc.send_raw_transaction(bytes).await } @@ -130,7 +130,7 @@ impl ExecutionClient { let tx_hashes = payload .transactions .iter() - .map(|tx| H256::from_slice(&keccak256(tx.to_vec()))) + .map(|tx| H256::from_slice(&keccak256(tx))) .collect::>(); let txs = if full_tx { @@ -212,10 +212,7 @@ impl ExecutionClient { let receipts = join_all(receipts_fut).await; let receipts = receipts.into_iter().collect::>>()?; - let receipts_encoded: Vec> = receipts - .iter() - .map(|receipt| encode_receipt(&receipt)) - .collect(); + let receipts_encoded: Vec> = receipts.iter().map(encode_receipt).collect(); let expected_receipt_root = ordered_trie_root(receipts_encoded); let expected_receipt_root = H256::from_slice(&expected_receipt_root.to_fixed_bytes()); @@ -309,7 +306,7 @@ impl ExecutionClient { .into()); } } - return Ok(logs); + Ok(logs) } } diff --git a/execution/src/proof.rs b/execution/src/proof.rs index fea6792..72b5e9a 100644 --- a/execution/src/proof.rs +++ b/execution/src/proof.rs @@ -2,8 +2,8 @@ use ethers::types::{Bytes, EIP1186ProofResponse}; use ethers::utils::keccak256; use ethers::utils::rlp::{decode_list, RlpStream}; -pub fn verify_proof(proof: &Vec, root: &Vec, path: &Vec, value: &Vec) -> bool { - let mut expected_hash = root.clone(); +pub fn verify_proof(proof: &Vec, root: &[u8], path: &Vec, value: &Vec) -> bool { + let mut expected_hash = root.to_vec(); let mut path_offset = 0; for (i, node) in proof.iter().enumerate() { @@ -16,14 +16,14 @@ pub fn verify_proof(proof: &Vec, root: &Vec, path: &Vec, value: & if node_list.len() == 17 { if i == proof.len() - 1 { // exclusion proof - let nibble = get_nibble(&path, path_offset); + let nibble = get_nibble(path, path_offset); let node = &node_list[nibble as usize]; - if node.len() == 0 && is_empty_value(value) { + if node.is_empty() && is_empty_value(value) { return true; } } else { - let nibble = get_nibble(&path, path_offset); + let nibble = get_nibble(path, path_offset); expected_hash = node_list[nibble as usize].clone(); path_offset += 1; @@ -31,12 +31,8 @@ pub fn verify_proof(proof: &Vec, root: &Vec, path: &Vec, value: & } else if node_list.len() == 2 { if i == proof.len() - 1 { // exclusion proof - if !paths_match( - &node_list[0], - skip_length(&node_list[0]), - &path, - path_offset, - ) && is_empty_value(value) + if !paths_match(&node_list[0], skip_length(&node_list[0]), path, path_offset) + && is_empty_value(value) { return true; } @@ -46,7 +42,7 @@ pub fn verify_proof(proof: &Vec, root: &Vec, path: &Vec, value: & return paths_match( &node_list[0], skip_length(&node_list[0]), - &path, + path, path_offset, ); } @@ -139,7 +135,7 @@ fn shared_prefix_length(path: &Vec, path_offset: usize, node_path: &Vec) } fn skip_length(node: &Vec) -> usize { - if node.len() == 0 { + if node.is_empty() { return 0; } @@ -153,7 +149,7 @@ fn skip_length(node: &Vec) -> usize { } } -fn get_nibble(path: &Vec, offset: usize) -> u8 { +fn get_nibble(path: &[u8], offset: usize) -> u8 { let byte = path[offset / 2]; if offset % 2 == 0 { byte >> 4 diff --git a/execution/src/rpc/http_rpc.rs b/execution/src/rpc/http_rpc.rs index b2af06e..4b02ee4 100644 --- a/execution/src/rpc/http_rpc.rs +++ b/execution/src/rpc/http_rpc.rs @@ -92,8 +92,8 @@ impl ExecutionRpc for HttpRpc { Ok(code.to_vec()) } - async fn send_raw_transaction(&self, bytes: &Vec) -> Result { - let bytes = Bytes::from(bytes.as_slice().to_owned()); + async fn send_raw_transaction(&self, bytes: &[u8]) -> Result { + let bytes = Bytes::from(bytes.to_owned()); let tx = self .provider .send_raw_transaction(bytes) diff --git a/execution/src/rpc/mock_rpc.rs b/execution/src/rpc/mock_rpc.rs index 70d76cb..4527c68 100644 --- a/execution/src/rpc/mock_rpc.rs +++ b/execution/src/rpc/mock_rpc.rs @@ -43,7 +43,7 @@ impl ExecutionRpc for MockRpc { hex_str_to_bytes(&code[0..code.len() - 1]) } - async fn send_raw_transaction(&self, _bytes: &Vec) -> Result { + async fn send_raw_transaction(&self, _bytes: &[u8]) -> Result { Err(eyre!("not implemented")) } diff --git a/execution/src/rpc/mod.rs b/execution/src/rpc/mod.rs index 45eb33b..1a47c16 100644 --- a/execution/src/rpc/mod.rs +++ b/execution/src/rpc/mod.rs @@ -25,7 +25,7 @@ pub trait ExecutionRpc: Send + Clone + Sync + 'static { async fn create_access_list(&self, opts: &CallOpts, block: u64) -> Result; async fn get_code(&self, address: &Address, block: u64) -> Result>; - async fn send_raw_transaction(&self, bytes: &Vec) -> Result; + async fn send_raw_transaction(&self, bytes: &[u8]) -> Result; async fn get_transaction_receipt(&self, tx_hash: &H256) -> Result>; async fn get_transaction(&self, tx_hash: &H256) -> Result>; async fn get_logs(&self, filter: &Filter) -> Result>; diff --git a/execution/src/types.rs b/execution/src/types.rs index 38c574d..49c3cf7 100644 --- a/execution/src/types.rs +++ b/execution/src/types.rs @@ -78,7 +78,7 @@ impl fmt::Debug for CallOpts { .field("from", &self.from) .field("to", &self.to) .field("value", &self.value) - .field("data", &hex::encode(&self.data.clone().unwrap_or_default())) + .field("data", &hex::encode(self.data.clone().unwrap_or_default())) .finish() } } diff --git a/heliosup/heliosup b/heliosup/heliosup index 8b1364e..c1b2c31 100644 --- a/heliosup/heliosup +++ b/heliosup/heliosup @@ -44,4 +44,4 @@ fi TARBALL_URL="https://github.com/$REPO/releases/download/${TAG}/${NAME}_${PLATFORM}_${ARCHITECTURE}.tar.gz" curl -L $TARBALL_URL | tar -xzC $BIN_DIR -echo "Installed $NAME" +echo "Installed $NAME"