Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add call_many #1085

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/consensus/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ impl From<WithdrawalRequest> for Request {
}
}

impl From<ConsolidationRequest> for Request {
fn from(v: ConsolidationRequest) -> Self {
Self::ConsolidationRequest(v)
}
}

impl Request {
/// Whether this is a [`DepositRequest`].
pub const fn is_deposit_request(&self) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions crates/eips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ arbitrary = { workspace = true, features = ["derive"], optional = true }

# for signed authorization list arbitrary
k256 = { workspace = true, optional = true }
rand = { workspace = true, optional = true }

[dev-dependencies]
alloy-primitives = { workspace = true, features = [
Expand Down Expand Up @@ -80,6 +81,7 @@ arbitrary = [
"std",
"kzg-sidecar",
"dep:arbitrary",
"dep:rand",
"alloy-primitives/arbitrary",
"alloy-serde?/arbitrary",
]
21 changes: 15 additions & 6 deletions crates/eips/src/eip7702/auth_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,15 @@ impl Deref for SignedAuthorization {
#[cfg(all(any(test, feature = "arbitrary"), feature = "k256"))]
impl<'a> arbitrary::Arbitrary<'a> for SignedAuthorization {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
use k256::ecdsa::{signature::hazmat::PrehashSigner, SigningKey};
let key_bytes = u.arbitrary::<[u8; 32]>()?;
let signing_key = SigningKey::from_bytes(&key_bytes.into())
.map_err(|_| arbitrary::Error::IncorrectFormat)?;
use k256::{
ecdsa::{signature::hazmat::PrehashSigner, SigningKey},
NonZeroScalar,
};
use rand::{rngs::StdRng, SeedableRng};

let rng_seed = u.arbitrary::<[u8; 32]>()?;
let mut rand_gen = StdRng::from_seed(rng_seed);
let signing_key: SigningKey = NonZeroScalar::random(&mut rand_gen).into();

let inner = u.arbitrary::<Authorization>()?;
let signature_hash = inner.signature_hash();
Expand Down Expand Up @@ -307,7 +312,6 @@ impl Deref for OptionalNonce {
mod tests {
use super::*;
use alloy_primitives::{hex, Signature};
use arbitrary::Arbitrary;
use core::str::FromStr;

fn test_encode_decode_roundtrip(auth: Authorization) {
Expand Down Expand Up @@ -367,10 +371,15 @@ mod tests {
assert_eq!(decoded, auth);
}

#[cfg(feature = "k256")]
#[cfg(all(feature = "arbitrary", feature = "k256"))]
#[test]
fn test_arbitrary_auth() {
use arbitrary::Arbitrary;
let mut unstructured = arbitrary::Unstructured::new(b"unstructured auth");
// try this multiple times
let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap();
let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap();
let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap();
let _auth = SignedAuthorization::arbitrary(&mut unstructured).unwrap();
}
}
5 changes: 5 additions & 0 deletions crates/eips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
#[macro_use]
extern crate alloc;

// To ensure no unused imports, since signed auth list requires arbitrary _and_ k256 features, but
// is only enabled using the `arbitrary` feature.
#[cfg(all(not(feature = "k256"), feature = "arbitrary"))]
use rand as _;

pub mod eip1559;
pub use eip1559::calc_next_block_base_fee;

Expand Down
2 changes: 1 addition & 1 deletion crates/node-bindings/src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl Anvil {

let mut child = cmd.spawn().map_err(AnvilError::SpawnError)?;

let stdout = child.stdout.as_mut().ok_or(AnvilError::NoStderr)?;
let stdout = child.stdout.take().ok_or(AnvilError::NoStderr)?;

let start = Instant::now();
let mut reader = BufReader::new(stdout);
Expand Down
22 changes: 21 additions & 1 deletion crates/provider/src/ext/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
use crate::Provider;
use alloy_network::Network;
use alloy_primitives::{hex, Bytes, TxHash, B256};
use alloy_rpc_types_eth::{Block, BlockNumberOrTag, TransactionRequest};
use alloy_rpc_types_eth::{
state::StateOverride, Block, BlockNumberOrTag, Bundle, EthCallResponse, StateContext,
TransactionRequest,
};
use alloy_rpc_types_trace::geth::{
BlockTraceResult, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace, TraceResult,
};
Expand Down Expand Up @@ -126,6 +129,15 @@ pub trait DebugApi<N, T>: Send + Sync {
block: BlockNumberOrTag,
trace_options: GethDebugTracingCallOptions,
) -> TransportResult<Vec<GethTrace>>;

/// Simulate arbitrary number of transactions at an arbitrary blockchain index, with the
/// optionality of state overrides
async fn call_many(
&self,
tx: Bundle,
state_context: Option<StateContext>,
state_override: Option<StateOverride>,
) -> TransportResult<Vec<EthCallResponse>>;
}

#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
Expand All @@ -136,6 +148,14 @@ where
T: Transport + Clone,
P: Provider<T, N>,
{
async fn call_many(
&self,
tx: Bundle,
state_context: Option<StateContext>,
state_override: Option<StateOverride>,
) -> TransportResult<Vec<EthCallResponse>> {
self.client().request("callMany", (tx, state_context, state_override)).await
}
async fn debug_get_raw_header(&self, block: BlockNumberOrTag) -> TransportResult<Bytes> {
self.client().request("debug_getRawHeader", (block,)).await
}
Expand Down
5 changes: 1 addition & 4 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:

/// Retrieves account information ([Account](alloy_consensus::Account)) for the given [Address]
/// at the particular [BlockId].
async fn get_account(
&self,
address: Address,
) -> RpcWithBlock<T, Address, alloy_consensus::Account> {
fn get_account(&self, address: Address) -> RpcWithBlock<T, Address, alloy_consensus::Account> {
RpcWithBlock::new(self.weak_client(), "eth_getAccount", address)
}

Expand Down
4 changes: 4 additions & 0 deletions crates/rpc-types-eth/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use alloy_primitives::{Address, Bytes, B256, B512, U256};
use alloy_serde::storage::JsonStorageKey;
use serde::{Deserialize, Serialize};

// re-export account type for `eth_getAccount`
pub use alloy_consensus::Account;

/// Account information.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct AccountInfo {
Expand Down
24 changes: 20 additions & 4 deletions crates/rpc-types-eth/src/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::BTreeMap;

/// Syncing info
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncInfo {
/// Starting block
Expand All @@ -16,6 +16,22 @@ pub struct SyncInfo {
pub warp_chunks_amount: Option<U256>,
/// Warp sync snapshot chunks processed.
pub warp_chunks_processed: Option<U256>,
/// The details of the sync stages as an hashmap
/// where the key is the name of the stage and the value is the block number.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub stages: Option<Vec<Stage>>,
}

/// The detail of the sync stages.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Stage {
/// The name of the sync stage.
#[serde(alias = "stage_name")]
pub name: String,
/// Indicates the progress of the sync stage.
#[serde(alias = "block_number", with = "alloy_serde::quantity")]
pub block: u64,
}

/// Peers info
Expand Down Expand Up @@ -99,10 +115,10 @@ pub struct PipProtocolInfo {
}

/// Sync status
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SyncStatus {
/// Info when syncing
Info(SyncInfo),
Info(Box<SyncInfo>),
/// Not syncing
None,
}
Expand All @@ -117,7 +133,7 @@ impl<'de> Deserialize<'de> for SyncStatus {
enum Syncing {
/// When client is synced to the highest block, eth_syncing with return "false"
None(bool),
IsSyncing(SyncInfo),
IsSyncing(Box<SyncInfo>),
}

match Syncing::deserialize(deserializer)? {
Expand Down