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

fix(mev-build-rs): reduce ethers dependency size #195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
703 changes: 8 additions & 695 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions bin/mev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version.workspace = true
edition = "2021"
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["boost", "build", "relay"]
boost = ["mev-boost-rs"]
Expand Down
2 changes: 0 additions & 2 deletions bin/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version.workspace = true
edition = "2021"
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.0", features = ["full"] }
url = { version = "2.2.2", default-features = false }
Expand Down
2 changes: 0 additions & 2 deletions mev-boost-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version.workspace = true
edition = "2021"
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.0", features = ["full"] }
tracing = "0.1"
Expand Down
5 changes: 2 additions & 3 deletions mev-build-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ version.workspace = true
edition = "2021"
license = "MIT OR Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "1.0", features = ["full"] }
tokio-stream = "0.1.14"
Expand All @@ -32,6 +30,7 @@ reth-interfaces = { workspace = true }
reth-revm = { workspace = true }
reth = { workspace = true }

ethers = "2.0"
ethers-core = "2.0"
ethers-signers = "2.0"
eyre = { workspace = true }
clap = { version = "4.1.4", features = ["derive", "env"] }
2 changes: 1 addition & 1 deletion mev-build-rs/src/reth_builder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ethereum_consensus::{
ssz::prelude::*,
state_transition::Context,
};
use ethers::signers::LocalWallet;
use ethers_signers::LocalWallet;
use mev_rs::{
signing::sign_builder_message,
types::{BidTrace, SignedBidSubmission},
Expand Down
4 changes: 2 additions & 2 deletions mev-build-rs/src/reth_builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ethereum_consensus::{
primitives::{BlsPublicKey, Epoch, ExecutionAddress, Slot},
state_transition::Context,
};
use ethers::signers::{LocalWallet, Signer};
use ethers_signers::{LocalWallet, Signer};
use mev_rs::{blinded_block_relayer::BlindedBlockRelayer, compute_preferred_gas_limit, Relay};
use reth_payload_builder::PayloadBuilderAttributes;
use reth_primitives::{Address, BlockNumberOrTag, Bytes, ChainSpec, B256, U256};
Expand Down Expand Up @@ -316,7 +316,7 @@ impl<Pool: TransactionPool, Client: StateProviderFactory + BlockReaderIdExt> Bui
let build_identifier = compute_build_id(slot, parent_hash, &proposer.public_key);

if state.builds.contains_key(&build_identifier) {
return Ok(PayloadAttributesProcessingOutcome::Duplicate(payload_attributes))
return Ok(PayloadAttributesProcessingOutcome::Duplicate(payload_attributes));
}

tracing::info!(slot, ?relays, %build_identifier, "constructing new build");
Expand Down
37 changes: 17 additions & 20 deletions mev-build-rs/src/reth_builder/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use crate::reth_builder::{
cancelled::Cancelled,
error::Error,
};
use ethers::{
signers::Signer,
types::{
transaction::eip2718::TypedTransaction, Eip1559TransactionRequest, H160,
U256 as ethers_U256,
},
use ethers_core::types::transaction::{
eip1559::Eip1559TransactionRequest, eip2718::TypedTransaction, eip2930::AccessList,
};
use ethers_signers::Signer;
use reth_interfaces::RethError;
use reth_primitives::{
constants::{BEACON_NONCE, EMPTY_OMMER_ROOT_HASH},
Expand Down Expand Up @@ -63,14 +60,14 @@ fn assemble_txs_from_pool<Pool: reth_transaction_pool::TransactionPool>(
let effective_gas_limit = block_gas_limit - context.build.gas_reserve;
while let Some(pool_tx) = best_txs.next() {
if context.is_cancelled() {
return Ok(())
return Ok(());
}

// NOTE: we withhold the `gas_reserve` so the "bidder" has some guaranteed room
// to play with the payload after it is built.
if context.cumulative_gas_used + pool_tx.gas_limit() > effective_gas_limit {
best_txs.mark_invalid(&pool_tx);
continue
continue;
}

let tx = pool_tx.to_recovered_transaction();
Expand All @@ -81,7 +78,7 @@ fn assemble_txs_from_pool<Pool: reth_transaction_pool::TransactionPool>(
if !matches!(err, InvalidTransaction::NonceTooLow { .. }) {
best_txs.mark_invalid(&pool_tx);
}
continue
continue;
}
_ => return Err(err),
}
Expand All @@ -106,7 +103,7 @@ fn assemble_payload_with_payments(
)?;

if context.is_cancelled() {
return Ok(BuildOutcome::Cancelled)
return Ok(BuildOutcome::Cancelled);
}

context.db.merge_transitions(BundleRetention::PlainState);
Expand Down Expand Up @@ -169,18 +166,18 @@ fn construct_payment_tx(
let nonce = signer_account.account_info().expect("account exists").nonce;
let chain_id = context.build.chain_spec.chain().id();

let fee_recipient = H160::from_slice(context.build.proposer_fee_recipient.as_ref());
let value = ethers_U256::from_big_endian(&context.total_payment.to_be_bytes::<32>());
let fee_recipient = Address::from_slice(context.build.proposer_fee_recipient.as_ref());
let value = U256::from_be_bytes(context.total_payment.to_be_bytes::<32>());
let tx = Eip1559TransactionRequest::new()
.from(sender)
.to(fee_recipient)
.to(fee_recipient.to_string())
// TODO: support smart contract payments
.gas(21000)
.max_fee_per_gas(context.build.base_fee())
.max_priority_fee_per_gas(0)
.value(value)
.data(ethers::types::Bytes::default())
.access_list(ethers::types::transaction::eip2930::AccessList::default())
.value(value.to_be_bytes())
.data(ethers_core::types::Bytes::default())
.access_list(AccessList::default())
.nonce(nonce)
.chain_id(chain_id);

Expand Down Expand Up @@ -301,27 +298,27 @@ pub fn build_payload<
let mut context = ExecutionContext::try_from(context, cancel, provider)?;

if context.is_cancelled() {
return Ok(BuildOutcome::Cancelled)
return Ok(BuildOutcome::Cancelled);
}
assemble_txs_from_pool(&mut context, pool)?;

if context.total_fees < threshold_value {
return Ok(BuildOutcome::Worse { threshold: threshold_value, provided: context.total_fees })
return Ok(BuildOutcome::Worse { threshold: threshold_value, provided: context.total_fees });
}

context.compute_payment_from_fees();

let payment_tx = construct_payment_tx(&mut context)?;

if context.is_cancelled() {
return Ok(BuildOutcome::Cancelled)
return Ok(BuildOutcome::Cancelled);
}

// NOTE: assume payment transaction always succeeds
context.extend_transaction(payment_tx)?;

if context.is_cancelled() {
return Ok(BuildOutcome::Cancelled)
return Ok(BuildOutcome::Cancelled);
}

assemble_payload_with_payments(context, provider)
Expand Down
17 changes: 8 additions & 9 deletions mev-build-rs/src/reth_builder/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use ethereum_consensus::{
crypto::SecretKey,
state_transition::Context,
};
use ethers::signers::{coins_bip39::English, MnemonicBuilder, Signer};
use ethers_signers::{coins_bip39::English, MnemonicBuilder, Signer};
use futures::StreamExt;
use mev_rs::{relay::parse_relay_endpoints, Error, Relay};
use reth_primitives::{Bytes, ChainSpec};
use serde::Deserialize;
use std::{future::Future, pin::Pin, sync::Arc, task::Poll};
use tokio::task::{JoinError, JoinHandle};
use tracing::{error, info};

const DEFAULT_BID_PERCENT: f64 = 0.9;

Expand Down Expand Up @@ -61,12 +60,12 @@ impl<
.collect::<Vec<_>>();

if relays.is_empty() {
error!("no valid relays provided; please restart with correct configuration");
tracing::error!("no valid relays provided; please restart with correct configuration");
} else {
let count = relays.len();
info!("configured with {count} relay(s)");
tracing::info!("configured with {count} relay(s)");
for relay in &relays {
info!(%relay, "configured with relay");
tracing::info!(%relay, "configured with relay");
}
}

Expand Down Expand Up @@ -134,7 +133,7 @@ impl<
Ok(stream) => stream,
Err(err) => {
tracing::error!(err = ?err, "could not open builds stream");
return
return;
}
};

Expand Down Expand Up @@ -175,7 +174,7 @@ impl<
Ok(stream) => stream,
Err(err) => {
tracing::error!(err = ?err, "could not open payload attributes stream");
return
return;
}
};

Expand Down Expand Up @@ -230,11 +229,11 @@ impl Future for ServiceHandle {

let clock = this.clock.poll(cx);
if clock.is_ready() {
return clock
return clock;
}
let builder = this.payload_builder.poll(cx);
if builder.is_ready() {
return builder
return builder;
}
this.bidder.poll(cx)
}
Expand Down
7 changes: 3 additions & 4 deletions mev-build-rs/src/reth_builder/service_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use reth::{
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use std::{sync::Arc, time::Duration};
use tracing::info;

#[derive(Debug, Args)]
pub struct ServiceExt {
Expand Down Expand Up @@ -46,7 +45,7 @@ impl RethNodeCommandConfig for ServiceExt {

let config = from_toml_file::<_, Config>(config_file)?;
let network = &config.network;
info!("configured for `{network}`");
tracing::info!("configured for `{network}`");

self.config = Some(config);
Ok(())
Expand All @@ -61,7 +60,7 @@ impl RethNodeCommandConfig for ServiceExt {
Conf: PayloadBuilderConfig,
Reth: RethNodeComponents,
{
let config = self.config.as_ref().expect("already loaded config");
let config = self.config.as_ref().ok_or(eyre::eyre!("already loaded config"))?;
let context = Arc::new(Context::try_from(config.network.clone())?);
let clock = context.clock().unwrap_or_else(|| {
let genesis_time = networks::typical_genesis_time(&context);
Expand All @@ -79,7 +78,7 @@ impl RethNodeCommandConfig for ServiceExt {
bidder,
components.chain_spec(),
)
.unwrap();
.map_err(|err| eyre::eyre!(err))?;

let (payload_service, payload_builder) = PayloadBuilderService::new(builder);

Expand Down
Loading