From ed23b95abe314665aa9280114019b86b8fe79901 Mon Sep 17 00:00:00 2001 From: 0xriazaka <0xriazaka@gmail.com> Date: Sat, 21 Sep 2024 00:44:14 +0100 Subject: [PATCH 1/3] Split MevApi trait into two #11036 --- crates/rpc/rpc-api/src/mev.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/rpc/rpc-api/src/mev.rs b/crates/rpc/rpc-api/src/mev.rs index ebe6f5ee8708..e3486f3077b9 100644 --- a/crates/rpc/rpc-api/src/mev.rs +++ b/crates/rpc/rpc-api/src/mev.rs @@ -6,7 +6,21 @@ use reth_rpc_types::mev::{ /// Mev rpc interface. #[cfg_attr(not(feature = "client"), rpc(server, namespace = "mev"))] #[cfg_attr(feature = "client", rpc(server, client, namespace = "mev"))] -pub trait MevApi { +pub trait MevSimApi { + /// Similar to `mev_sendBundle` but instead of submitting a bundle to the relay, it returns + /// a simulation result. Only fully matched bundles can be simulated. + #[method(name = "simBundle")] + async fn sim_bundle( + &self, + bundle: SendBundleRequest, + sim_overrides: SimBundleOverrides, + ) -> jsonrpsee::core::RpcResult; +} + +/// Mev rpc interface. +#[cfg_attr(not(feature = "client"), rpc(server, namespace = "mev"))] +#[cfg_attr(feature = "client", rpc(server, client, namespace = "mev"))] +pub trait MevFullApi { /// Submitting bundles to the relay. It takes in a bundle and provides a bundle hash as a /// return value. #[method(name = "sendBundle")] From 0b3fc03b717371562b3912b102b76d8c5e236a23 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sun, 22 Sep 2024 14:27:13 +0200 Subject: [PATCH 2/3] Fix exports --- crates/rpc/rpc-api/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rpc/rpc-api/src/lib.rs b/crates/rpc/rpc-api/src/lib.rs index 89968960fb4b..73775112dcf5 100644 --- a/crates/rpc/rpc-api/src/lib.rs +++ b/crates/rpc/rpc-api/src/lib.rs @@ -39,7 +39,7 @@ pub mod servers { admin::AdminApiServer, debug::DebugApiServer, engine::{EngineApiServer, EngineEthApiServer}, - mev::MevApiServer, + mev::{MevFullApiServer, MevSimApiServer}, net::NetApiServer, otterscan::OtterscanServer, reth::RethApiServer, @@ -69,7 +69,7 @@ pub mod clients { engine::{EngineApiClient, EngineEthApiClient}, ganache::GanacheApiClient, hardhat::HardhatApiClient, - mev::MevApiClient, + mev::{MevFullApiClient, MevSimApiClient}, net::NetApiClient, otterscan::OtterscanClient, reth::RethApiClient, From 7f4d78cf9f4090b47c85495aac9a2bc4fefdc0c0 Mon Sep 17 00:00:00 2001 From: 0xriazaka <0xriazaka@gmail.com> Date: Sat, 28 Sep 2024 03:30:17 +0100 Subject: [PATCH 3/3] Remove unsafe from impl Compact for ClientVersion --- .../storage/db-models/src/client_version.rs | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/crates/storage/db-models/src/client_version.rs b/crates/storage/db-models/src/client_version.rs index de074ac88c6e..5f8708342c09 100644 --- a/crates/storage/db-models/src/client_version.rs +++ b/crates/storage/db-models/src/client_version.rs @@ -3,23 +3,48 @@ use reth_codecs::{add_arbitrary_tests, Compact}; use serde::{Deserialize, Serialize}; +/// Wrapper around `String` +#[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize)] +pub struct CompactString(String); + /// Client version that accessed the database. #[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize)] #[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] #[add_arbitrary_tests(compact)] pub struct ClientVersion { /// Client version - pub version: String, + pub version: CompactString, /// The git commit sha - pub git_sha: String, + pub git_sha: CompactString, /// Build timestamp - pub build_timestamp: String, + pub build_timestamp: CompactString, } impl ClientVersion { /// Returns `true` if no version fields are set. pub fn is_empty(&self) -> bool { - self.version.is_empty() && self.git_sha.is_empty() && self.build_timestamp.is_empty() + self.version.0.is_empty() && self.git_sha.0.is_empty() && self.build_timestamp.0.is_empty() + } +} + +impl From for CompactString { + fn from(s: String) -> Self { + CompactString(s) + } +} + +impl Compact for CompactString { + fn to_compact(&self, buf: &mut B) -> usize + where + B: bytes::BufMut + AsMut<[u8]>, + { + self.0.as_bytes().to_compact(buf) + } + + fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) { + let (vec, buf) = Vec::::from_compact(buf, len); + let string = String::from_utf8(vec).unwrap(); // Safe conversion + (CompactString(string), buf) } } @@ -28,20 +53,16 @@ impl Compact for ClientVersion { where B: bytes::BufMut + AsMut<[u8]>, { - self.version.as_bytes().to_compact(buf); - self.git_sha.as_bytes().to_compact(buf); - self.build_timestamp.as_bytes().to_compact(buf) + self.version.to_compact(buf); + self.git_sha.to_compact(buf); + self.build_timestamp.to_compact(buf) } fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) { - let (version, buf) = Vec::::from_compact(buf, len); - let (git_sha, buf) = Vec::::from_compact(buf, len); - let (build_timestamp, buf) = Vec::::from_compact(buf, len); - let client_version = Self { - version: unsafe { String::from_utf8_unchecked(version) }, - git_sha: unsafe { String::from_utf8_unchecked(git_sha) }, - build_timestamp: unsafe { String::from_utf8_unchecked(build_timestamp) }, - }; + let (version, buf) = CompactString::from_compact(buf, len); + let (git_sha, buf) = CompactString::from_compact(buf, len); + let (build_timestamp, buf) = CompactString::from_compact(buf, len); + let client_version = Self { version, git_sha, build_timestamp }; (client_version, buf) } }