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

Suavex builder endpoints #2

Merged
merged 7 commits into from
Apr 8, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ alloy-pubsub = { git = "https://github.com/alloy-rs/alloy" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy" }
alloy-rpc-trace-types = { git = "https://github.com/alloy-rs/alloy" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy" }
alloy-rpc-engine-types = { git = "https://github.com/alloy-rs/alloy" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy" }
alloy-transport = { git = "https://github.com/alloy-rs/alloy" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy" }
Expand Down
2 changes: 2 additions & 0 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ hash-db = "0.15"
memory-db = "0.29"
alloy-primitives = { workspace = true, features = ["serde"] }
alloy-consensus.workspace = true
alloy-eips.workspace = true
alloy-network.workspace = true
alloy-rlp.workspace = true
alloy-signer = { workspace = true, features = ["eip712", "mnemonic"] }
alloy-sol-types = { workspace = true, features = ["std"] }
alloy-dyn-abi = { workspace = true, features = ["std", "eip712"] }
alloy-rpc-engine-types.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-trace-types.workspace = true
alloy-providers.workspace = true
Expand Down
1 change: 1 addition & 0 deletions crates/anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ revm = { workspace = true, default-features = false, features = ["std", "serde",

alloy-primitives = { workspace = true, features = ["serde"] }
alloy-rpc-types = { workspace = true }
alloy-rpc-engine-types = { workspace = true }
alloy-rpc-trace-types.workspace = true
alloy-rlp.workspace = true
alloy-eips.workspace = true
Expand Down
73 changes: 73 additions & 0 deletions crates/anvil/core/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ use super::{
trie,
};
use alloy_consensus::Header;
use alloy_network::Sealable;
use alloy_primitives::{Address, Bloom, Bytes, B256, U256};
use alloy_rlp::{RlpDecodable, RlpEncodable};
use alloy_rpc_engine_types::{
BlobsBundleV1, ExecutionPayloadEnvelopeV3, ExecutionPayloadV1, ExecutionPayloadV2,
ExecutionPayloadV3,
};
use alloy_rpc_types::Withdrawal;

// Type alias to optionally support impersonated transactions
#[cfg(not(feature = "impersonated-tx"))]
Expand All @@ -20,6 +26,55 @@ pub struct BlockInfo {
pub receipts: Vec<TypedReceipt>,
}

impl BlockInfo {
pub fn execution_envelope(
&self,
raw_transactions: &[Bytes],
args: BuildBlockArgs,
fees: U256,
) -> ExecutionPayloadEnvelopeV3 {
let block_hash = self.block.header.hash();
ExecutionPayloadEnvelopeV3 {
execution_payload: ExecutionPayloadV3 {
payload_inner: ExecutionPayloadV2 {
payload_inner: ExecutionPayloadV1 {
parent_hash: self.block.header.parent_hash,
fee_recipient: self.block.header.beneficiary,
state_root: self.block.header.state_root,
receipts_root: self.block.header.receipts_root,
logs_bloom: self.block.header.logs_bloom,
prev_randao: self.block.header.mix_hash,
block_number: self.block.header.number,
gas_limit: self.block.header.gas_limit,
gas_used: self.block.header.gas_used,
timestamp: self.block.header.timestamp,
extra_data: self.block.header.extra_data.to_owned(),
base_fee_per_gas: self
.block
.header
.base_fee_per_gas
.map(|f| U256::from(f))
.unwrap_or("1000000000".parse::<U256>().unwrap()),
block_hash,
transactions: raw_transactions.to_vec(),
},
withdrawals: args
.withdrawals
.into_iter()
.map(|w| w.into())
.collect::<Vec<Withdrawal>>(),
},
blob_gas_used: self.block.header.blob_gas_used.unwrap_or_default(),
excess_blob_gas: self.block.header.excess_blob_gas.unwrap_or_default(),
},
block_value: fees,
blobs_bundle: BlobsBundleV1 { commitments: vec![], blobs: vec![], proofs: vec![] },
should_override_builder: false,
parent_beacon_block_root: None,
}
}
}

/// An Ethereum Block
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable)]
pub struct Block {
Expand Down Expand Up @@ -118,6 +173,24 @@ impl From<Header> for PartialHeader {
}
}

#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct BuildBlockArgs {
pub slot: u64,
// #[serde(deserialize_with = "base64_to_bytes")] // TODO: use serde macro so we can use Bytes instead of String
pub proposer_pubkey: String,
pub parent: B256,
pub timestamp: u64,
pub fee_recipient: Address,
pub gas_limit: u64,
pub random: B256,
pub withdrawals: Vec<Withdrawal>,
pub parent_beacon_block_root: Option<B256>,
pub extra: Bytes,
pub beacon_root: B256,
pub fill_pending: bool,
}

#[cfg(test)]
mod tests {
use alloy_network::Sealable;
Expand Down
12 changes: 12 additions & 0 deletions crates/anvil/core/src/eth/bundle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use alloy_primitives::{Bytes, B256, U256};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct SBundle {
pub block_number: Option<U256>, // // if BlockNumber is set it must match DecryptionCondition
pub max_block: Option<U256>,
#[serde(rename = "txs")]
pub transactions: Vec<Bytes>,
pub reverting_hashes: Option<Vec<B256>>,
}
8 changes: 8 additions & 0 deletions crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use alloy_rpc_types::{
};

pub mod block;
pub mod bundle;
pub mod proof;
pub mod subscription;
pub mod transaction;
Expand All @@ -23,6 +24,7 @@ pub mod serde_helpers;

#[cfg(feature = "serde")]
use self::serde_helpers::*;
use self::{block::BuildBlockArgs, bundle::SBundle};

#[cfg(feature = "serde")]
use foundry_common::serde_helpers::{
Expand Down Expand Up @@ -173,6 +175,12 @@ pub enum EthRequest {
#[cfg_attr(feature = "serde", serde(rename = "suavex_call"))]
SuavexCall(Address, String),

#[cfg_attr(feature = "serde", serde(rename = "suavex_buildEthBlock"))]
SuavexBuildEthBlock(Option<BuildBlockArgs>, Vec<TransactionRequest>),

#[cfg_attr(feature = "serde", serde(rename = "suavex_buildEthBlockFromBundles"))]
SuavexBuildEthBlockFromBundles(BuildBlockArgs, Vec<SBundle>),

#[cfg_attr(feature = "serde", serde(rename = "eth_createAccessList"))]
EthCreateAccessList(
TransactionRequest,
Expand Down