Update mev-rs and remove patches (#4496)

## Issue Addressed

Fixes occasional compilation errors with mev-rs (see #4456).

## Proposed Changes

- Update `mev-rs` to the latest version, which allows us to remove hacky `[patch]` sections
- Update the `axum` version used in `watch` so LH only uses a single version
This commit is contained in:
Michael Sproul 2023-07-17 00:14:15 +00:00
parent 1a5de8b0f0
commit 03674c7199
6 changed files with 88 additions and 98 deletions

96
Cargo.lock generated
View File

@ -245,6 +245,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "anvil-rpc"
version = "0.1.0"
source = "git+https://github.com/foundry-rs/foundry?rev=b45456717ffae1af65acdc71099f8cb95e6683a0#b45456717ffae1af65acdc71099f8cb95e6683a0"
dependencies = [
"serde",
"serde_json",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.71" version = "1.0.71"
@ -494,9 +503,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.5.17" version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core", "axum-core",
@ -512,22 +521,23 @@ dependencies = [
"mime", "mime",
"percent-encoding", "percent-encoding",
"pin-project-lite 0.2.9", "pin-project-lite 0.2.9",
"rustversion",
"serde", "serde",
"serde_json", "serde_json",
"serde_path_to_error",
"serde_urlencoded", "serde_urlencoded",
"sync_wrapper", "sync_wrapper",
"tokio", "tokio",
"tower", "tower",
"tower-http",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
] ]
[[package]] [[package]]
name = "axum-core" name = "axum-core"
version = "0.2.9" version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bytes", "bytes",
@ -535,6 +545,7 @@ dependencies = [
"http", "http",
"http-body", "http-body",
"mime", "mime",
"rustversion",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
] ]
@ -593,7 +604,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]] [[package]]
name = "beacon-api-client" name = "beacon-api-client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/ralexstokes/beacon-api-client#30679e9e25d61731cde54e14cd8a3688a39d8e5b" source = "git+https://github.com/ralexstokes/beacon-api-client?rev=93d7e8c#93d7e8c38fe9782c4862909663e7b57c44f805a9"
dependencies = [ dependencies = [
"ethereum-consensus", "ethereum-consensus",
"http", "http",
@ -2492,7 +2503,7 @@ dependencies = [
[[package]] [[package]]
name = "ethereum-consensus" name = "ethereum-consensus"
version = "0.1.1" version = "0.1.1"
source = "git+https://github.com/ralexstokes//ethereum-consensus?rev=9b0ee0a8a45b968c8df5e7e64ea1c094e16f053d#9b0ee0a8a45b968c8df5e7e64ea1c094e16f053d" source = "git+https://github.com/ralexstokes/ethereum-consensus?rev=e380108#e380108d15fcc40349927fdf3d11c71f9edb67c2"
dependencies = [ dependencies = [
"async-stream", "async-stream",
"blst", "blst",
@ -2505,8 +2516,9 @@ dependencies = [
"rand 0.8.5", "rand 0.8.5",
"serde", "serde",
"serde_json", "serde_json",
"serde_yaml",
"sha2 0.9.9", "sha2 0.9.9",
"ssz-rs", "ssz_rs",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
@ -2779,7 +2791,7 @@ dependencies = [
"serde_json", "serde_json",
"slog", "slog",
"slot_clock", "slot_clock",
"ssz-rs", "ssz_rs",
"ssz_types", "ssz_types",
"state_processing", "state_processing",
"strum", "strum",
@ -3503,12 +3515,6 @@ dependencies = [
"pin-project-lite 0.2.9", "pin-project-lite 0.2.9",
] ]
[[package]]
name = "http-range-header"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29"
[[package]] [[package]]
name = "http_api" name = "http_api"
version = "0.1.0" version = "0.1.0"
@ -4969,9 +4975,9 @@ checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
[[package]] [[package]]
name = "matchit" name = "matchit"
version = "0.5.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40"
[[package]] [[package]]
name = "md-5" name = "md-5"
@ -5060,16 +5066,20 @@ dependencies = [
[[package]] [[package]]
name = "mev-rs" name = "mev-rs"
version = "0.2.1" version = "0.3.0"
source = "git+https://github.com/ralexstokes//mev-rs?rev=7813d4a4a564e0754e9aaab2d95520ba437c3889#7813d4a4a564e0754e9aaab2d95520ba437c3889" source = "git+https://github.com/ralexstokes/mev-rs?rev=216657016d5c0889b505857c89ae42c7aa2764af#216657016d5c0889b505857c89ae42c7aa2764af"
dependencies = [ dependencies = [
"anvil-rpc",
"async-trait", "async-trait",
"axum", "axum",
"beacon-api-client", "beacon-api-client",
"ethereum-consensus", "ethereum-consensus",
"hyper", "hyper",
"parking_lot 0.12.1",
"reqwest",
"serde", "serde",
"ssz-rs", "serde_json",
"ssz_rs",
"thiserror", "thiserror",
"tokio", "tokio",
"tracing", "tracing",
@ -7368,6 +7378,16 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_path_to_error"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1b6471d7496b051e03f1958802a73f88b947866f5146f329e47e36554f4e55"
dependencies = [
"itoa",
"serde",
]
[[package]] [[package]]
name = "serde_repr" name = "serde_repr"
version = "0.1.12" version = "0.1.12"
@ -7865,23 +7885,24 @@ dependencies = [
] ]
[[package]] [[package]]
name = "ssz-rs" name = "ssz_rs"
version = "0.8.0" version = "0.9.0"
source = "git+https://github.com/ralexstokes//ssz-rs?rev=adf1a0b14cef90b9536f28ef89da1fab316465e1#adf1a0b14cef90b9536f28ef89da1fab316465e1" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "057291e5631f280978fa9c8009390663ca4613359fc1318e36a8c24c392f6d1f"
dependencies = [ dependencies = [
"bitvec 1.0.1", "bitvec 1.0.1",
"hex", "hex",
"num-bigint", "num-bigint",
"serde", "serde",
"sha2 0.9.9", "sha2 0.9.9",
"ssz-rs-derive", "ssz_rs_derive",
"thiserror",
] ]
[[package]] [[package]]
name = "ssz-rs-derive" name = "ssz_rs_derive"
version = "0.8.0" version = "0.9.0"
source = "git+https://github.com/ralexstokes//ssz-rs?rev=adf1a0b14cef90b9536f28ef89da1fab316465e1#adf1a0b14cef90b9536f28ef89da1fab316465e1" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f07d54c4d01a1713eb363b55ba51595da15f6f1211435b71466460da022aa140"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -8640,25 +8661,6 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "tower-http"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858"
dependencies = [
"bitflags",
"bytes",
"futures-core",
"futures-util",
"http",
"http-body",
"http-range-header",
"pin-project-lite 0.2.9",
"tower",
"tower-layer",
"tower-service",
]
[[package]] [[package]]
name = "tower-layer" name = "tower-layer"
version = "0.3.2" version = "0.3.2"

View File

@ -92,13 +92,6 @@ resolver = "2"
warp = { git = "https://github.com/macladson/warp", rev="7e75acc368229a46a236a8c991bf251fe7fe50ef" } warp = { git = "https://github.com/macladson/warp", rev="7e75acc368229a46a236a8c991bf251fe7fe50ef" }
arbitrary = { git = "https://github.com/michaelsproul/arbitrary", rev="f002b99989b561ddce62e4cf2887b0f8860ae991" } arbitrary = { git = "https://github.com/michaelsproul/arbitrary", rev="f002b99989b561ddce62e4cf2887b0f8860ae991" }
[patch."https://github.com/ralexstokes/mev-rs"]
mev-rs = { git = "https://github.com/ralexstokes//mev-rs", rev = "7813d4a4a564e0754e9aaab2d95520ba437c3889" }
[patch."https://github.com/ralexstokes/ethereum-consensus"]
ethereum-consensus = { git = "https://github.com/ralexstokes//ethereum-consensus", rev = "9b0ee0a8a45b968c8df5e7e64ea1c094e16f053d" }
[patch."https://github.com/ralexstokes/ssz-rs"]
ssz-rs = { git = "https://github.com/ralexstokes//ssz-rs", rev = "adf1a0b14cef90b9536f28ef89da1fab316465e1" }
[profile.maxperf] [profile.maxperf]
inherits = "release" inherits = "release"
lto = "fat" lto = "fat"

View File

@ -41,9 +41,9 @@ lazy_static = "1.4.0"
ethers-core = "1.0.2" ethers-core = "1.0.2"
builder_client = { path = "../builder_client" } builder_client = { path = "../builder_client" }
fork_choice = { path = "../../consensus/fork_choice" } fork_choice = { path = "../../consensus/fork_choice" }
mev-rs = { git = "https://github.com/ralexstokes/mev-rs" } mev-rs = { git = "https://github.com/ralexstokes/mev-rs", rev = "216657016d5c0889b505857c89ae42c7aa2764af" }
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus" } ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "e380108" }
ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" } ssz_rs = "0.9.0"
tokio-stream = { version = "0.1.9", features = [ "sync" ] } tokio-stream = { version = "0.1.9", features = [ "sync" ] }
strum = "0.24.0" strum = "0.24.0"
keccak-hash = "0.10.0" keccak-hash = "0.10.0"

View File

@ -11,11 +11,17 @@ use ethereum_consensus::{
}; };
use fork_choice::ForkchoiceUpdateParameters; use fork_choice::ForkchoiceUpdateParameters;
use mev_rs::{ use mev_rs::{
bellatrix::{BuilderBid as BuilderBidBellatrix, SignedBuilderBid as SignedBuilderBidBellatrix}, blinded_block_provider::Server as BlindedBlockProviderServer,
signing::{sign_builder_message, verify_signed_builder_message},
types::{
bellatrix::{
BuilderBid as BuilderBidBellatrix, SignedBuilderBid as SignedBuilderBidBellatrix,
},
capella::{BuilderBid as BuilderBidCapella, SignedBuilderBid as SignedBuilderBidCapella}, capella::{BuilderBid as BuilderBidCapella, SignedBuilderBid as SignedBuilderBidCapella},
sign_builder_message, verify_signed_builder_message, BidRequest, BlindedBlockProviderError, BidRequest, BuilderBid, ExecutionPayload as ServerPayload, SignedBlindedBeaconBlock,
BlindedBlockProviderServer, BuilderBid, ExecutionPayload as ServerPayload, SignedBuilderBid, SignedValidatorRegistration,
SignedBlindedBeaconBlock, SignedBuilderBid, SignedValidatorRegistration, },
Error as MevError,
}; };
use parking_lot::RwLock; use parking_lot::RwLock;
use sensitive_url::SensitiveUrl; use sensitive_url::SensitiveUrl;
@ -47,7 +53,7 @@ pub enum Operation {
} }
impl Operation { impl Operation {
fn apply<B: BidStuff>(self, bid: &mut B) -> Result<(), BlindedBlockProviderError> { fn apply<B: BidStuff>(self, bid: &mut B) -> Result<(), MevError> {
match self { match self {
Operation::FeeRecipient(fee_recipient) => { Operation::FeeRecipient(fee_recipient) => {
*bid.fee_recipient_mut() = to_ssz_rs(&fee_recipient)? *bid.fee_recipient_mut() = to_ssz_rs(&fee_recipient)?
@ -73,7 +79,7 @@ pub trait BidStuff {
fn prev_randao_mut(&mut self) -> &mut Hash32; fn prev_randao_mut(&mut self) -> &mut Hash32;
fn block_number_mut(&mut self) -> &mut u64; fn block_number_mut(&mut self) -> &mut u64;
fn timestamp_mut(&mut self) -> &mut u64; fn timestamp_mut(&mut self) -> &mut u64;
fn withdrawals_root_mut(&mut self) -> Result<&mut Root, BlindedBlockProviderError>; fn withdrawals_root_mut(&mut self) -> Result<&mut Root, MevError>;
fn sign_builder_message( fn sign_builder_message(
&mut self, &mut self,
@ -134,11 +140,9 @@ impl BidStuff for BuilderBid {
} }
} }
fn withdrawals_root_mut(&mut self) -> Result<&mut Root, BlindedBlockProviderError> { fn withdrawals_root_mut(&mut self) -> Result<&mut Root, MevError> {
match self { match self {
Self::Bellatrix(_) => Err(BlindedBlockProviderError::Custom( Self::Bellatrix(_) => Err(MevError::InvalidFork),
"withdrawals_root called on bellatrix bid".to_string(),
)),
Self::Capella(bid) => Ok(&mut bid.header.withdrawals_root), Self::Capella(bid) => Ok(&mut bid.header.withdrawals_root),
} }
} }
@ -274,7 +278,7 @@ impl<E: EthSpec> MockBuilder<E> {
*self.invalidate_signatures.write() = false; *self.invalidate_signatures.write() = false;
} }
fn apply_operations<B: BidStuff>(&self, bid: &mut B) -> Result<(), BlindedBlockProviderError> { fn apply_operations<B: BidStuff>(&self, bid: &mut B) -> Result<(), MevError> {
let mut guard = self.operations.write(); let mut guard = self.operations.write();
while let Some(op) = guard.pop() { while let Some(op) = guard.pop() {
op.apply(bid)?; op.apply(bid)?;
@ -288,7 +292,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
async fn register_validators( async fn register_validators(
&self, &self,
registrations: &mut [SignedValidatorRegistration], registrations: &mut [SignedValidatorRegistration],
) -> Result<(), BlindedBlockProviderError> { ) -> Result<(), MevError> {
for registration in registrations { for registration in registrations {
let pubkey = registration.message.public_key.clone(); let pubkey = registration.message.public_key.clone();
let message = &mut registration.message; let message = &mut registration.message;
@ -307,10 +311,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
Ok(()) Ok(())
} }
async fn fetch_best_bid( async fn fetch_best_bid(&self, bid_request: &BidRequest) -> Result<SignedBuilderBid, MevError> {
&self,
bid_request: &BidRequest,
) -> Result<SignedBuilderBid, BlindedBlockProviderError> {
let slot = Slot::new(bid_request.slot); let slot = Slot::new(bid_request.slot);
let fork = self.spec.fork_name_at_slot::<E>(slot); let fork = self.spec.fork_name_at_slot::<E>(slot);
let signed_cached_data = self let signed_cached_data = self
@ -336,7 +337,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
.map_err(convert_err)? .map_err(convert_err)?
.block_hash(); .block_hash();
if head_execution_hash != from_ssz_rs(&bid_request.parent_hash)? { if head_execution_hash != from_ssz_rs(&bid_request.parent_hash)? {
return Err(BlindedBlockProviderError::Custom(format!( return Err(custom_err(format!(
"head mismatch: {} {}", "head mismatch: {} {}",
head_execution_hash, bid_request.parent_hash head_execution_hash, bid_request.parent_hash
))); )));
@ -396,7 +397,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
.get_debug_beacon_states(StateId::Head) .get_debug_beacon_states(StateId::Head)
.await .await
.map_err(convert_err)? .map_err(convert_err)?
.ok_or_else(|| BlindedBlockProviderError::Custom("missing head state".to_string()))? .ok_or_else(|| custom_err("missing head state".to_string()))?
.data; .data;
let prev_randao = head_state let prev_randao = head_state
.get_randao_mix(head_state.current_epoch()) .get_randao_mix(head_state.current_epoch())
@ -409,10 +410,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
PayloadAttributes::new(timestamp, *prev_randao, fee_recipient, Some(vec![])) PayloadAttributes::new(timestamp, *prev_randao, fee_recipient, Some(vec![]))
} }
ForkName::Base | ForkName::Altair => { ForkName::Base | ForkName::Altair => {
return Err(BlindedBlockProviderError::Custom(format!( return Err(MevError::InvalidFork);
"Unsupported fork: {}",
fork
)));
} }
}; };
@ -452,12 +450,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
value: to_ssz_rs(&Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI))?, value: to_ssz_rs(&Uint256::from(DEFAULT_BUILDER_PAYLOAD_VALUE_WEI))?,
public_key: self.builder_sk.public_key(), public_key: self.builder_sk.public_key(),
}), }),
ForkName::Base | ForkName::Altair => { ForkName::Base | ForkName::Altair => return Err(MevError::InvalidFork),
return Err(BlindedBlockProviderError::Custom(format!(
"Unsupported fork: {}",
fork
)))
}
}; };
*message.gas_limit_mut() = cached_data.gas_limit; *message.gas_limit_mut() = cached_data.gas_limit;
@ -475,7 +468,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
async fn open_bid( async fn open_bid(
&self, &self,
signed_block: &mut SignedBlindedBeaconBlock, signed_block: &mut SignedBlindedBeaconBlock,
) -> Result<ServerPayload, BlindedBlockProviderError> { ) -> Result<ServerPayload, MevError> {
let node = match signed_block { let node = match signed_block {
SignedBlindedBeaconBlock::Bellatrix(block) => { SignedBlindedBeaconBlock::Bellatrix(block) => {
block.message.body.execution_payload_header.hash_tree_root() block.message.body.execution_payload_header.hash_tree_root()
@ -496,9 +489,7 @@ impl<E: EthSpec> mev_rs::BlindedBlockProvider for MockBuilder<E> {
} }
} }
pub fn from_ssz_rs<T: SimpleSerialize, U: Decode>( pub fn from_ssz_rs<T: SimpleSerialize, U: Decode>(ssz_rs_data: &T) -> Result<U, MevError> {
ssz_rs_data: &T,
) -> Result<U, BlindedBlockProviderError> {
U::from_ssz_bytes( U::from_ssz_bytes(
ssz_rs::serialize(ssz_rs_data) ssz_rs::serialize(ssz_rs_data)
.map_err(convert_err)? .map_err(convert_err)?
@ -507,12 +498,17 @@ pub fn from_ssz_rs<T: SimpleSerialize, U: Decode>(
.map_err(convert_err) .map_err(convert_err)
} }
pub fn to_ssz_rs<T: Encode, U: SimpleSerialize>( pub fn to_ssz_rs<T: Encode, U: SimpleSerialize>(ssz_data: &T) -> Result<U, MevError> {
ssz_data: &T,
) -> Result<U, BlindedBlockProviderError> {
ssz_rs::deserialize::<U>(&ssz_data.as_ssz_bytes()).map_err(convert_err) ssz_rs::deserialize::<U>(&ssz_data.as_ssz_bytes()).map_err(convert_err)
} }
fn convert_err<E: Debug>(e: E) -> BlindedBlockProviderError { fn convert_err<E: Debug>(e: E) -> MevError {
BlindedBlockProviderError::Custom(format!("{e:?}")) custom_err(format!("{e:?}"))
}
// This is a bit of a hack since the `Custom` variant was removed from `mev_rs::Error`.
fn custom_err(s: String) -> MevError {
MevError::Consensus(ethereum_consensus::state_transition::Error::Io(
std::io::Error::new(std::io::ErrorKind::Other, s),
))
} }

View File

@ -21,7 +21,7 @@ types = { path = "../consensus/types" }
eth2 = { path = "../common/eth2" } eth2 = { path = "../common/eth2" }
beacon_node = { path = "../beacon_node"} beacon_node = { path = "../beacon_node"}
tokio = { version = "1.14.0", features = ["time"] } tokio = { version = "1.14.0", features = ["time"] }
axum = "0.5.15" axum = "0.6.18"
hyper = "0.14.20" hyper = "0.14.20"
serde = "1.0.116" serde = "1.0.116"
serde_json = "1.0.58" serde_json = "1.0.58"

View File

@ -5,7 +5,6 @@ use crate::config::Config as FullConfig;
use crate::database::{self, PgPool}; use crate::database::{self, PgPool};
use crate::suboptimal_attestations::{attestation_routes, blockprint_attestation_routes}; use crate::suboptimal_attestations::{attestation_routes, blockprint_attestation_routes};
use axum::{ use axum::{
handler::Handler,
http::{StatusCode, Uri}, http::{StatusCode, Uri},
routing::get, routing::get,
Extension, Json, Router, Extension, Json, Router,
@ -104,7 +103,7 @@ pub fn start_server(
} }
let app = routes let app = routes
.fallback(route_not_found.into_service()) .fallback(route_not_found)
.layer(Extension(pool)) .layer(Extension(pool))
.layer(Extension(slots_per_epoch)); .layer(Extension(slots_per_epoch));