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

Latest payload utils from reth #224

Merged
merged 3 commits into from
Apr 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 79 additions & 80 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ version = "0.3.0"
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "0919f02435e1b64e27c53931cac8e08edaad5f8b" }
beacon-api-client = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "0919f02435e1b64e27c53931cac8e08edaad5f8b" }

reth = { git = "https://github.com/paradigmxyz/reth", rev = "6d7cd53ad25f0b79c89fd60a4db2a0f2fe097efe" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "6d7cd53ad25f0b79c89fd60a4db2a0f2fe097efe" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "6d7cd53ad25f0b79c89fd60a4db2a0f2fe097efe" }
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "6d7cd53ad25f0b79c89fd60a4db2a0f2fe097efe" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "6d7cd53ad25f0b79c89fd60a4db2a0f2fe097efe" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "4e22b9e" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "4e22b9e" }
reth = { git = "https://github.com/paradigmxyz/reth", rev = "8e65cb3" }
reth-db = { git = "https://github.com/paradigmxyz/reth", rev = "8e65cb3" }
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", rev = "8e65cb3" }
reth-basic-payload-builder = { git = "https://github.com/paradigmxyz/reth", rev = "8e65cb3" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "ca54552" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "ca54552" }

eyre = "0.6.8"
futures-util = "0.3.30"
Expand Down
1 change: 0 additions & 1 deletion mev-build-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mev-rs = { path = "../mev-rs" }
reth = { workspace = true }
reth-db = { workspace = true }
reth-node-ethereum = { workspace = true }
reth-evm-ethereum = { workspace = true }
reth-basic-payload-builder = { workspace = true }
alloy-signer = { workspace = true }
alloy-signer-wallet = { workspace = true, features = ["mnemonic"] }
Expand Down
19 changes: 11 additions & 8 deletions mev-build-rs/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use reth::{
ExecutionPayloadV1,
},
};
use reth_evm_ethereum::EthEvmConfig;
use reth_node_ethereum::node::{EthereumNetworkBuilder, EthereumPoolBuilder};
use reth_node_ethereum::node::{
EthereumExecutorBuilder, EthereumNetworkBuilder, EthereumPoolBuilder,
};

#[derive(Debug, Default, Clone, Copy)]
pub struct BuilderNode;
Expand All @@ -29,7 +30,13 @@ impl BuilderNode {
/// Returns a [ComponentsBuilder] configured for a regular Ethereum node.
pub fn components_with<Node>(
payload_service_builder: PayloadServiceBuilder,
) -> ComponentsBuilder<Node, EthereumPoolBuilder, PayloadServiceBuilder, EthereumNetworkBuilder>
) -> ComponentsBuilder<
Node,
EthereumPoolBuilder,
PayloadServiceBuilder,
EthereumNetworkBuilder,
EthereumExecutorBuilder,
>
where
Node: FullNodeTypes<Engine = BuilderEngineTypes>,
{
Expand All @@ -38,17 +45,13 @@ impl BuilderNode {
.pool(EthereumPoolBuilder::default())
.payload(payload_service_builder)
.network(EthereumNetworkBuilder::default())
.executor(EthereumExecutorBuilder::default())
}
}

impl NodeTypes for BuilderNode {
type Primitives = ();
type Engine = BuilderEngineTypes;
type Evm = EthEvmConfig;

fn evm_config(&self) -> Self::Evm {
EthEvmConfig::default()
}
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
Expand Down
17 changes: 7 additions & 10 deletions mev-build-rs/src/payload/job.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::{
payload::{
attributes::BuilderPayloadBuilderAttributes,
builder::PayloadBuilder,
resolve::{PayloadFinalizer, PayloadFinalizerConfig, ResolveBuilderPayload},
},
utils::payload_job::PayloadTaskGuard,
use crate::payload::{
attributes::BuilderPayloadBuilderAttributes,
builder::PayloadBuilder,
resolve::{PayloadFinalizer, PayloadFinalizerConfig, ResolveBuilderPayload},
};
use futures_util::{Future, FutureExt};
use reth::{
Expand All @@ -18,8 +15,8 @@ use reth::{
transaction_pool::TransactionPool,
};
use reth_basic_payload_builder::{
BuildArguments, BuildOutcome, Cancelled, PayloadBuilder as _, PayloadConfig, PendingPayload,
ResolveBestPayload,
BuildArguments, BuildOutcome, Cancelled, PayloadBuilder as _, PayloadConfig, PayloadTaskGuard,
PendingPayload, ResolveBestPayload,
};
use std::{
pin::Pin,
Expand Down Expand Up @@ -173,7 +170,7 @@ where
let builder = this.builder.clone();
this.executor.spawn_blocking(Box::pin(async move {
// acquire the permit for executing the task
let _permit = guard.0.acquire().await;
let _permit = guard.acquire().await;
let args = BuildArguments {
client,
pool,
Expand Down
11 changes: 4 additions & 7 deletions mev-build-rs/src/payload/job_generator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::{
payload::{
builder::{PayloadBuilder, BASE_TX_GAS_LIMIT},
job::PayloadJob,
},
utils::payload_job::PayloadTaskGuard,
use crate::payload::{
builder::{PayloadBuilder, BASE_TX_GAS_LIMIT},
job::PayloadJob,
};
use ethereum_consensus::clock::duration_until;
use mev_rs::compute_preferred_gas_limit;
Expand All @@ -15,7 +12,7 @@ use reth::{
tasks::TaskSpawner,
transaction_pool::TransactionPool,
};
use reth_basic_payload_builder::{PayloadConfig, PrecachedState};
use reth_basic_payload_builder::{PayloadConfig, PayloadTaskGuard, PrecachedState};
use std::{sync::Arc, time::Duration};

fn apply_gas_limit<P>(config: &mut PayloadConfig<P>, gas_limit: u64) {
Expand Down
2 changes: 1 addition & 1 deletion mev-build-rs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub async fn launch(
let payload_builder = PayloadServiceBuilder::try_from(&config.builder)?;

let handle = node_builder
.with_types(BuilderNode)
.with_types::<BuilderNode>()
.with_components(BuilderNode::components_with(payload_builder))
.launch()
.await?;
Expand Down
91 changes: 0 additions & 91 deletions mev-build-rs/src/utils/compat.rs

This file was deleted.

95 changes: 93 additions & 2 deletions mev-build-rs/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,93 @@
pub mod compat;
pub mod payload_job;
pub mod compat {
use ethereum_consensus::{
deneb::{
mainnet as spec,
polynomial_commitments::{KzgCommitment, KzgProof},
Blob,
},
primitives::{Bytes32, ExecutionAddress},
ssz::prelude::{ByteList, ByteVector, List, U256},
};
use mev_rs::types::{BlobsBundle, ExecutionPayload};
use reth::primitives::{Address, BlobTransactionSidecar, Bloom, SealedBlock, B256};

pub fn to_bytes32(value: B256) -> Bytes32 {
Bytes32::try_from(value.as_ref()).unwrap()
}

pub fn to_bytes20(value: Address) -> ExecutionAddress {
ExecutionAddress::try_from(value.as_ref()).unwrap()
}

fn to_byte_vector(value: Bloom) -> ByteVector<256> {
ByteVector::<256>::try_from(value.as_ref()).unwrap()
}

// TODO: support multiple forks
pub fn to_execution_payload(value: &SealedBlock) -> ExecutionPayload {
let hash = value.hash();
let header = &value.header;
let transactions = &value.body;
let withdrawals = &value.withdrawals;
let transactions = transactions
.iter()
.map(|t| spec::Transaction::try_from(t.envelope_encoded().as_ref()).unwrap())
.collect::<Vec<_>>();
let withdrawals = withdrawals
.as_ref()
.unwrap()
.iter()
.map(|w| spec::Withdrawal {
index: w.index as usize,
validator_index: w.validator_index as usize,
address: to_bytes20(w.address),
amount: w.amount,
})
.collect::<Vec<_>>();

let payload = spec::ExecutionPayload {
parent_hash: to_bytes32(header.parent_hash),
fee_recipient: to_bytes20(header.beneficiary),
state_root: to_bytes32(header.state_root),
receipts_root: to_bytes32(header.receipts_root),
logs_bloom: to_byte_vector(header.logs_bloom),
prev_randao: to_bytes32(header.mix_hash),
block_number: header.number,
gas_limit: header.gas_limit,
gas_used: header.gas_used,
timestamp: header.timestamp,
extra_data: ByteList::try_from(header.extra_data.as_ref()).unwrap(),
base_fee_per_gas: U256::from(header.base_fee_per_gas.unwrap_or_default()),
block_hash: to_bytes32(hash),
transactions: TryFrom::try_from(transactions).unwrap(),
withdrawals: TryFrom::try_from(withdrawals).unwrap(),
blob_gas_used: header.blob_gas_used.unwrap(),
excess_blob_gas: header.excess_blob_gas.unwrap(),
};
ExecutionPayload::Deneb(payload)
}

pub fn to_blobs_bundle(sidecars: &[BlobTransactionSidecar]) -> BlobsBundle {
let mut commitments = List::default();
let mut proofs = List::default();
let mut blobs = List::default();

// TODO: perform length checks to avoid panic on `push`
for sidecar in sidecars {
for commitment in &sidecar.commitments {
let commitment = KzgCommitment::try_from(commitment.as_slice()).unwrap();
commitments.push(commitment);
}
for proof in &sidecar.proofs {
let proof = KzgProof::try_from(proof.as_slice()).unwrap();
proofs.push(proof);
}
for blob in &sidecar.blobs {
let blob = Blob::try_from(blob.as_ref()).unwrap();
blobs.push(blob);
}
}

BlobsBundle { commitments, proofs, blobs }
}
}
11 changes: 0 additions & 11 deletions mev-build-rs/src/utils/payload_job.rs

This file was deleted.

Loading