From 5ca5095d28e2f0f55362b0590786ba23b5f4adf9 Mon Sep 17 00:00:00 2001 From: Bjerg Date: Fri, 3 Nov 2023 14:04:55 +0100 Subject: [PATCH 1/3] chore: add `rpc-types` to bug form --- .github/ISSUE_TEMPLATE/BUG-FORM.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/BUG-FORM.yml b/.github/ISSUE_TEMPLATE/BUG-FORM.yml index 9cc25c35ef8..c6c44a5ab5d 100644 --- a/.github/ISSUE_TEMPLATE/BUG-FORM.yml +++ b/.github/ISSUE_TEMPLATE/BUG-FORM.yml @@ -19,6 +19,7 @@ body: - transports - networks - providers + - rpc-types validations: required: true - type: input From 641d9ab4b44825c4c69d5bf836d353b6404542ae Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 7 Nov 2023 15:51:56 -0400 Subject: [PATCH 2/3] fix(`rpc-types`/`providers`): Use `U64` in block-number related types, make storage keys U256 (#22) * fix: make access list storage keys U256 instead of B256 * fix: Use U64 in block number related types * chore: return slice to avoid clone --- crates/providers/src/provider.rs | 4 +- crates/rpc-types/src/eth/block.rs | 19 +++++---- crates/rpc-types/src/eth/filter.rs | 6 +-- .../src/eth/transaction/access_list.rs | 42 +++++++------------ 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/crates/providers/src/provider.rs b/crates/providers/src/provider.rs index d7e971cd24b..d00304da95f 100644 --- a/crates/providers/src/provider.rs +++ b/crates/providers/src/provider.rs @@ -53,7 +53,7 @@ impl Provider { } /// Gets the last block number available. - pub async fn get_block_number(&self) -> RpcResult, TransportError> + pub async fn get_block_number(&self) -> RpcResult, TransportError> where Self: Sync, { @@ -464,7 +464,7 @@ mod providers_test { let anvil = Anvil::new().spawn(); let provider = Provider::new(&anvil.endpoint()).unwrap(); let num = provider.get_block_number().await.unwrap(); - assert_eq!(U256::ZERO, num) + assert_eq!(U64::ZERO, num) } #[tokio::test] diff --git a/crates/rpc-types/src/eth/block.rs b/crates/rpc-types/src/eth/block.rs index e07a7530d8e..d2b0be0f854 100644 --- a/crates/rpc-types/src/eth/block.rs +++ b/crates/rpc-types/src/eth/block.rs @@ -1,6 +1,8 @@ //! Contains types that represent ethereum types when used in RPC use crate::{Transaction, Withdrawal}; -use alloy_primitives::{Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64}; +use alloy_primitives::{ + ruint::ParseError, Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64, +}; use alloy_rlp::{bytes, Decodable, Encodable, Error as RlpError}; use serde::{ de::{MapAccess, Visitor}, @@ -244,12 +246,12 @@ pub enum BlockNumberOrTag { /// Pending block (not yet part of the blockchain) Pending, /// Block by number from canon chain - Number(u64), + Number(U64), } impl BlockNumberOrTag { /// Returns the numeric block number if explicitly set - pub const fn as_number(&self) -> Option { + pub const fn as_number(&self) -> Option { match *self { BlockNumberOrTag::Number(num) => Some(num), _ => None, @@ -289,13 +291,13 @@ impl BlockNumberOrTag { impl From for BlockNumberOrTag { fn from(num: u64) -> Self { - BlockNumberOrTag::Number(num) + BlockNumberOrTag::Number(U64::from(num)) } } impl From for BlockNumberOrTag { fn from(num: U64) -> Self { - num.into_limbs()[0].into() + BlockNumberOrTag::Number(num) } } @@ -337,7 +339,7 @@ impl FromStr for BlockNumberOrTag { "pending" => Self::Pending, _number => { if let Some(hex_val) = s.strip_prefix("0x") { - let number = u64::from_str_radix(hex_val, 16); + let number = U64::from_str_radix(hex_val, 16); BlockNumberOrTag::Number(number?) } else { return Err(HexStringMissingPrefixError::default().into()); @@ -367,6 +369,9 @@ pub enum ParseBlockNumberError { /// Failed to parse hex value #[error(transparent)] ParseIntErr(#[from] ParseIntError), + /// Failed to parse hex value + #[error(transparent)] + ParseErr(#[from] ParseError), /// Block numbers should be 0x-prefixed #[error(transparent)] MissingPrefix(#[from] HexStringMissingPrefixError), @@ -412,7 +417,7 @@ impl BlockId { impl From for BlockId { fn from(num: u64) -> Self { - BlockNumberOrTag::Number(num).into() + BlockNumberOrTag::Number(U64::from(num)).into() } } diff --git a/crates/rpc-types/src/eth/filter.rs b/crates/rpc-types/src/eth/filter.rs index 5c812d66a38..919cf3b4ee7 100644 --- a/crates/rpc-types/src/eth/filter.rs +++ b/crates/rpc-types/src/eth/filter.rs @@ -480,12 +480,12 @@ impl Filter { } /// Returns the numeric value of the `toBlock` field - pub fn get_to_block(&self) -> Option { + pub fn get_to_block(&self) -> Option { self.block_option.get_to_block().and_then(|b| b.as_number()) } /// Returns the numeric value of the `fromBlock` field - pub fn get_from_block(&self) -> Option { + pub fn get_from_block(&self) -> Option { self.block_option .get_from_block() .and_then(|b| b.as_number()) @@ -798,7 +798,7 @@ impl FilteredParams { } /// Returns true if the filter matches the given block number - pub fn filter_block_range(&self, block_number: u64) -> bool { + pub fn filter_block_range(&self, block_number: U64) -> bool { if self.filter.is_none() { return true; } diff --git a/crates/rpc-types/src/eth/transaction/access_list.rs b/crates/rpc-types/src/eth/transaction/access_list.rs index 3ee3c677ac1..bf2c95e92c6 100644 --- a/crates/rpc-types/src/eth/transaction/access_list.rs +++ b/crates/rpc-types/src/eth/transaction/access_list.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{Address, B256, U256}; +use alloy_primitives::{Address, U256}; use serde::{Deserialize, Serialize}; /// A list of addresses and storage keys that the transaction plans to access. @@ -9,7 +9,7 @@ pub struct AccessListItem { /// Account addresses that would be loaded at the start of execution pub address: Address, /// Keys of storage that would be loaded at the start of execution - pub storage_keys: Vec, + pub storage_keys: Vec, } /// AccessList as defined in EIP-2930 @@ -19,7 +19,9 @@ pub struct AccessList(pub Vec); impl AccessList { /// Converts the list into a vec, expected by revm pub fn flattened(&self) -> Vec<(Address, Vec)> { - self.flatten().collect() + self.flatten() + .map(|(addr, keys)| (addr, keys.to_vec())) + .collect() } /// Consumes the type and converts the list into a vec, expected by revm @@ -29,28 +31,16 @@ impl AccessList { /// Consumes the type and returns an iterator over the list's addresses and storage keys. pub fn into_flatten(self) -> impl Iterator)> { - self.0.into_iter().map(|item| { - ( - item.address, - item.storage_keys - .into_iter() - .map(|slot| U256::from_be_bytes(slot.0)) - .collect(), - ) - }) + self.0 + .into_iter() + .map(|item| (item.address, item.storage_keys)) } /// Returns an iterator over the list's addresses and storage keys. - pub fn flatten(&self) -> impl Iterator)> + '_ { - self.0.iter().map(|item| { - ( - item.address, - item.storage_keys - .iter() - .map(|slot| U256::from_be_bytes(slot.0)) - .collect(), - ) - }) + pub fn flatten(&self) -> impl Iterator + '_ { + self.0 + .iter() + .map(|item| (item.address, item.storage_keys.as_slice())) } } @@ -73,11 +63,11 @@ mod tests { let list = AccessList(vec![ AccessListItem { address: Address::ZERO, - storage_keys: vec![B256::ZERO], + storage_keys: vec![U256::ZERO], }, AccessListItem { address: Address::ZERO, - storage_keys: vec![B256::ZERO], + storage_keys: vec![U256::ZERO], }, ]); let json = serde_json::to_string(&list).unwrap(); @@ -91,11 +81,11 @@ mod tests { access_list: AccessList(vec![ AccessListItem { address: Address::ZERO, - storage_keys: vec![B256::ZERO], + storage_keys: vec![U256::ZERO], }, AccessListItem { address: Address::ZERO, - storage_keys: vec![B256::ZERO], + storage_keys: vec![U256::ZERO], }, ]), gas_used: U256::from(100), From db0c36dfe27ab4190a7474658956a27a484b0c89 Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Tue, 7 Nov 2023 16:29:04 -0400 Subject: [PATCH 3/3] chore: add evalir to codeowners --- .github/CODEOWNERS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index aa54b7a1043..46eca8de2c0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,6 +1,6 @@ -* @danipopes @gakonst @prestwich +* @danipopes @gakonst @prestwich @evalir crates/json-rpc @prestwich -crates/transports @prestwich +crates/transports @prestwich @evalir crates/networks @prestwich -crates/providers @prestwich \ No newline at end of file +crates/providers @prestwich @evalir \ No newline at end of file