feat: Lints, Clippy, and Cleaning (#115)

*  cargo fmt smells

* ♻️ cargo cleaning
This commit is contained in:
asnared 2022-11-29 17:31:25 -08:00 committed by GitHub
parent 5e29149297
commit 21c73c1649
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 85 additions and 141 deletions

11
Cargo.lock generated
View File

@ -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",

View File

@ -1,6 +1,6 @@
[package]
name = "helios"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
[workspace]

View File

@ -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(),
};

View File

@ -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" }

View File

@ -31,23 +31,16 @@ impl Client<FileDB> {
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<Network>,
consensus_rpc: Option<String>,
@ -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<DB: Database> Client<DB> {
self.node.read().await.get_storage_at(address, slot).await
}
pub async fn send_raw_transaction(&self, bytes: &Vec<u8>) -> Result<H256> {
pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result<H256> {
self.node.read().await.send_raw_transaction(bytes).await
}

View File

@ -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<u8>) -> Result<H256> {
pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result<H256> {
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)))
}
}
}

View File

@ -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)

View File

@ -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"] }

View File

@ -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"] }

View File

@ -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,
}
}
}

View File

@ -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"

View File

@ -44,7 +44,7 @@ struct LightClientStore {
impl<R: ConsensusRpc> ConsensusClient<R> {
pub fn new(
rpc: &str,
checkpoint_block_root: &Vec<u8>,
checkpoint_block_root: &[u8],
config: Arc<Config>,
) -> Result<ConsensusClient<R>> {
let rpc = R::new(rpc);
@ -54,13 +54,13 @@ impl<R: ConsensusRpc> ConsensusClient<R> {
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<u64>) -> Result<ExecutionPayload> {
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<R: ConsensusRpc> ConsensusClient<R> {
.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<R: ConsensusRpc> ConsensusClient<R> {
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<R: ConsensusRpc> ConsensusClient<R> {
fn verify_sync_committee_signture(
&self,
pks: &Vec<PublicKey>,
pks: &[PublicKey],
attested_header: &Header,
signature: &SignatureBytes,
signature_slot: u64,
) -> bool {
let res: Result<bool> = (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<Bytes32>,
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<Bytes32>,
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<Bytes32>,
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()

View File

@ -18,7 +18,7 @@ impl ConsensusRpc for MockRpc {
}
}
async fn get_bootstrap(&self, _block_root: &Vec<u8>) -> Result<Bootstrap> {
async fn get_bootstrap(&self, _block_root: &'_ [u8]) -> Result<Bootstrap> {
let bootstrap = read_to_string(self.testdata.join("bootstrap.json"))?;
Ok(serde_json::from_str(&bootstrap)?)
}

View File

@ -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<u8>) -> Result<Bootstrap>;
async fn get_bootstrap(&self, block_root: &'_ [u8]) -> Result<Bootstrap>;
async fn get_updates(&self, period: u64, count: u8) -> Result<Vec<Update>>;
async fn get_finality_update(&self) -> Result<FinalityUpdate>;
async fn get_optimistic_update(&self) -> Result<OptimisticUpdate>;

View File

@ -31,7 +31,7 @@ impl ConsensusRpc for NimbusRpc {
}
}
async fn get_bootstrap(&self, block_root: &Vec<u8>) -> Result<Bootstrap> {
async fn get_bootstrap(&self, block_root: &'_ [u8]) -> Result<Bootstrap> {
let root_hex = hex::encode(block_root);
let req = format!(
"{}/eth/v1/beacon/light_client/bootstrap/0x{}",

View File

@ -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<String> = 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::<Result<Vector<BLSPubKey, 512>>>()
.map_err(D::Error::custom)?)
.map_err(D::Error::custom)
}
fn bytes_vector_deserialize<'de, D>(deserializer: D) -> Result<Vector<Bytes32, 33>, D::Error>
@ -337,14 +336,14 @@ where
D: serde::Deserializer<'de>,
{
let elems: Vec<String> = 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::<Result<Vector<Bytes32, 33>>>()
.map_err(D::Error::custom)?)
.map_err(D::Error::custom)
}
fn signature_deserialize<'de, D>(deserializer: D) -> Result<SignatureBytes, D::Error>
@ -361,14 +360,14 @@ where
D: serde::Deserializer<'de>,
{
let branch: Vec<String> = 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::<Result<_>>()
.map_err(D::Error::custom)?)
.map_err(D::Error::custom)
}
fn u64_deserialize<'de, D>(deserializer: D) -> Result<u64, D::Error>

View File

@ -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<L: Merkleized>(
attested_header: &Header,
leaf_object: &mut L,
branch: &Vec<Bytes32>,
branch: &[Bytes32],
depth: usize,
index: usize,
) -> bool {
@ -81,7 +81,6 @@ fn compute_fork_data_root(
current_version: Vector<u8, 4>,
genesis_validator_root: Bytes32,
) -> Result<Node> {
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<Bytes32>) -> Result<Vec<Node>> {
branch
.iter()
.map(|elem| bytes32_to_node(elem))
.map(bytes32_to_node)
.collect::<Result<Vec<Node>>>()
}

View File

@ -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"

View File

@ -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<Account> {
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(),
})
}

View File

@ -46,7 +46,7 @@ impl<R: ExecutionRpc> ExecutionClient<R> {
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<R: ExecutionRpc> ExecutionClient<R> {
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<R: ExecutionRpc> ExecutionClient<R> {
})
}
pub async fn send_raw_transaction(&self, bytes: &Vec<u8>) -> Result<H256> {
pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result<H256> {
self.rpc.send_raw_transaction(bytes).await
}
@ -130,7 +130,7 @@ impl<R: ExecutionRpc> ExecutionClient<R> {
let tx_hashes = payload
.transactions
.iter()
.map(|tx| H256::from_slice(&keccak256(tx.to_vec())))
.map(|tx| H256::from_slice(&keccak256(tx)))
.collect::<Vec<H256>>();
let txs = if full_tx {
@ -212,10 +212,7 @@ impl<R: ExecutionRpc> ExecutionClient<R> {
let receipts = join_all(receipts_fut).await;
let receipts = receipts.into_iter().collect::<Result<Vec<_>>>()?;
let receipts_encoded: Vec<Vec<u8>> = receipts
.iter()
.map(|receipt| encode_receipt(&receipt))
.collect();
let receipts_encoded: Vec<Vec<u8>> = 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<R: ExecutionRpc> ExecutionClient<R> {
.into());
}
}
return Ok(logs);
Ok(logs)
}
}

View File

@ -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<Bytes>, root: &Vec<u8>, path: &Vec<u8>, value: &Vec<u8>) -> bool {
let mut expected_hash = root.clone();
pub fn verify_proof(proof: &Vec<Bytes>, root: &[u8], path: &Vec<u8>, value: &Vec<u8>) -> 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<Bytes>, root: &Vec<u8>, path: &Vec<u8>, 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<Bytes>, root: &Vec<u8>, path: &Vec<u8>, 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<Bytes>, root: &Vec<u8>, path: &Vec<u8>, 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<u8>, path_offset: usize, node_path: &Vec<u8>)
}
fn skip_length(node: &Vec<u8>) -> usize {
if node.len() == 0 {
if node.is_empty() {
return 0;
}
@ -153,7 +149,7 @@ fn skip_length(node: &Vec<u8>) -> usize {
}
}
fn get_nibble(path: &Vec<u8>, offset: usize) -> u8 {
fn get_nibble(path: &[u8], offset: usize) -> u8 {
let byte = path[offset / 2];
if offset % 2 == 0 {
byte >> 4

View File

@ -92,8 +92,8 @@ impl ExecutionRpc for HttpRpc {
Ok(code.to_vec())
}
async fn send_raw_transaction(&self, bytes: &Vec<u8>) -> Result<H256> {
let bytes = Bytes::from(bytes.as_slice().to_owned());
async fn send_raw_transaction(&self, bytes: &[u8]) -> Result<H256> {
let bytes = Bytes::from(bytes.to_owned());
let tx = self
.provider
.send_raw_transaction(bytes)

View File

@ -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<u8>) -> Result<H256> {
async fn send_raw_transaction(&self, _bytes: &[u8]) -> Result<H256> {
Err(eyre!("not implemented"))
}

View File

@ -25,7 +25,7 @@ pub trait ExecutionRpc: Send + Clone + Sync + 'static {
async fn create_access_list(&self, opts: &CallOpts, block: u64) -> Result<AccessList>;
async fn get_code(&self, address: &Address, block: u64) -> Result<Vec<u8>>;
async fn send_raw_transaction(&self, bytes: &Vec<u8>) -> Result<H256>;
async fn send_raw_transaction(&self, bytes: &[u8]) -> Result<H256>;
async fn get_transaction_receipt(&self, tx_hash: &H256) -> Result<Option<TransactionReceipt>>;
async fn get_transaction(&self, tx_hash: &H256) -> Result<Option<Transaction>>;
async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>>;

View File

@ -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()
}
}

View File

@ -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"