From 6100ca15cd54752cf1b3b9f52d20e11e5fccacdb Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Thu, 1 Jun 2023 22:00:34 -0600 Subject: [PATCH 1/2] add 'group_imports' to rustfmt config --- mev-boost-rs/tests/integration.rs | 2 -- mev-rs/src/blinded_block_provider/mod.rs | 5 ++--- mev-rs/src/lib.rs | 1 - rustfmt.toml | 1 + 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mev-boost-rs/tests/integration.rs b/mev-boost-rs/tests/integration.rs index 8d013cb7..b7692aa8 100644 --- a/mev-boost-rs/tests/integration.rs +++ b/mev-boost-rs/tests/integration.rs @@ -17,13 +17,11 @@ use mev_rs::{ signing::sign_builder_message, types::{BidRequest, ExecutionPayload, SignedBlindedBeaconBlock, SignedBuilderBid}, }; - use rand::seq::SliceRandom; use std::{ collections::HashMap, time::{SystemTime, UNIX_EPOCH}, }; - use url::Url; fn setup_logging() { diff --git a/mev-rs/src/blinded_block_provider/mod.rs b/mev-rs/src/blinded_block_provider/mod.rs index 6a0b1e76..d9f6bec0 100644 --- a/mev-rs/src/blinded_block_provider/mod.rs +++ b/mev-rs/src/blinded_block_provider/mod.rs @@ -1,9 +1,6 @@ #[cfg(feature = "api")] mod api; -#[cfg(feature = "api")] -pub use {api::client::Client, api::server::Server}; - use crate::{ error::Error, types::{ @@ -12,6 +9,8 @@ use crate::{ }, }; use async_trait::async_trait; +#[cfg(feature = "api")] +pub use {api::client::Client, api::server::Server}; #[async_trait] pub trait BlindedBlockProvider { diff --git a/mev-rs/src/lib.rs b/mev-rs/src/lib.rs index 5e1e2bd5..af7bf9e8 100644 --- a/mev-rs/src/lib.rs +++ b/mev-rs/src/lib.rs @@ -11,7 +11,6 @@ pub mod types; mod validator_registry; pub use blinded_block_provider::BlindedBlockProvider; - pub use error::Error; pub use network::*; pub use proposer_scheduler::ProposerScheduler; diff --git a/rustfmt.toml b/rustfmt.toml index e70aee8c..f4a93ad0 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,6 @@ reorder_imports = true imports_granularity = "Crate" +group_imports = "One" use_small_heuristics = "Max" comment_width = 100 wrap_comments = true From 60595c61604f373bb6498658422d36c0c92f328f Mon Sep 17 00:00:00 2001 From: jacobkaufmann Date: Mon, 5 Jun 2023 08:59:35 -0600 Subject: [PATCH 2/2] change rustfmt 'group_imports' to 'StdExternalCrate' --- bin/mev/src/cmd/boost.rs | 3 ++- bin/mev/src/cmd/build.rs | 3 ++- bin/mev/src/cmd/config.rs | 3 ++- bin/mev/src/cmd/relay.rs | 3 ++- bin/mev/src/main.rs | 3 ++- mev-boost-rs/src/relay_mux.rs | 3 ++- mev-boost-rs/src/service.rs | 6 ++++-- mev-boost-rs/tests/integration.rs | 9 +++++---- mev-build-rs/src/mempool_builder.rs | 3 ++- mev-build-rs/src/service.rs | 6 ++++-- mev-relay-rs/src/relay.rs | 3 ++- mev-relay-rs/src/service.rs | 6 ++++-- .../src/blinded_block_provider/api/client.rs | 9 +++++---- .../src/blinded_block_provider/api/server.rs | 20 ++++++++++--------- mev-rs/src/blinded_block_provider/mod.rs | 7 ++++--- mev-rs/src/engine_api_proxy/client.rs | 14 +++++++------ mev-rs/src/engine_api_proxy/server.rs | 16 ++++++++------- mev-rs/src/error.rs | 3 ++- mev-rs/src/proposer_scheduler.rs | 3 ++- mev-rs/src/types/mod.rs | 7 ++++--- mev-rs/src/validator_registry.rs | 6 ++++-- rustfmt.toml | 2 +- 22 files changed, 83 insertions(+), 55 deletions(-) diff --git a/bin/mev/src/cmd/boost.rs b/bin/mev/src/cmd/boost.rs index 6aeb4e21..1cfd5500 100644 --- a/bin/mev/src/cmd/boost.rs +++ b/bin/mev/src/cmd/boost.rs @@ -1,9 +1,10 @@ -use crate::cmd::config::Config; use anyhow::{anyhow, Result}; use clap::Args; use mev_boost_rs::Service; use mev_rs::Network; +use crate::cmd::config::Config; + #[derive(Debug, Args)] #[clap(about = "🚀 connecting proposers to the external builder network")] pub struct Command { diff --git a/bin/mev/src/cmd/build.rs b/bin/mev/src/cmd/build.rs index 66c8f726..a65ffb28 100644 --- a/bin/mev/src/cmd/build.rs +++ b/bin/mev/src/cmd/build.rs @@ -1,9 +1,10 @@ -use crate::cmd::config::Config; use anyhow::{anyhow, Result}; use clap::{Args, Subcommand}; use mev_build_rs::Service; use mev_rs::Network; +use crate::cmd::config::Config; + #[derive(Debug, Args)] #[clap(about = "🛠️ building blocks since 2023", subcommand_negates_reqs = true)] pub struct Command { diff --git a/bin/mev/src/cmd/config.rs b/bin/mev/src/cmd/config.rs index 080db9a0..23c83999 100644 --- a/bin/mev/src/cmd/config.rs +++ b/bin/mev/src/cmd/config.rs @@ -1,3 +1,5 @@ +use std::{fmt, path::Path}; + use anyhow::{Context, Result}; use clap::Args; use mev_boost_rs::Config as BoostConfig; @@ -5,7 +7,6 @@ use mev_build_rs::Config as BuildConfig; use mev_relay_rs::Config as RelayConfig; use mev_rs::Network; use serde::Deserialize; -use std::{fmt, path::Path}; #[derive(Debug, Deserialize)] pub struct Config { diff --git a/bin/mev/src/cmd/relay.rs b/bin/mev/src/cmd/relay.rs index 1f05e669..44e25ba2 100644 --- a/bin/mev/src/cmd/relay.rs +++ b/bin/mev/src/cmd/relay.rs @@ -1,9 +1,10 @@ -use crate::cmd::config::Config; use anyhow::{anyhow, Result}; use clap::{Args, Subcommand}; use mev_relay_rs::Service; use mev_rs::Network; +use crate::cmd::config::Config; + #[derive(Debug, Args)] #[clap(about = "🏗 connecting builders to proposers", subcommand_negates_reqs = true)] pub struct Command { diff --git a/bin/mev/src/main.rs b/bin/mev/src/main.rs index d39ef9ed..97461729 100644 --- a/bin/mev/src/main.rs +++ b/bin/mev/src/main.rs @@ -1,9 +1,10 @@ mod cmd; +use std::future::Future; + use anyhow::Result; use clap::{ArgGroup, Parser, Subcommand}; use mev_rs::Network; -use std::future::Future; use tokio::signal; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; diff --git a/mev-boost-rs/src/relay_mux.rs b/mev-boost-rs/src/relay_mux.rs index 69c1cce7..561246cb 100644 --- a/mev-boost-rs/src/relay_mux.rs +++ b/mev-boost-rs/src/relay_mux.rs @@ -1,3 +1,5 @@ +use std::{collections::HashMap, ops::Deref, sync::Arc, time::Duration}; + use async_trait::async_trait; use ethereum_consensus::{ primitives::{BlsPublicKey, Slot, U256}, @@ -14,7 +16,6 @@ use mev_rs::{ }; use parking_lot::Mutex; use rand::prelude::*; -use std::{collections::HashMap, ops::Deref, sync::Arc, time::Duration}; // See note in the `mev-relay-rs::Relay` about this constant. // TODO likely drop this feature... diff --git a/mev-boost-rs/src/service.rs b/mev-boost-rs/src/service.rs index 2197ceb5..96f66e6b 100644 --- a/mev-boost-rs/src/service.rs +++ b/mev-boost-rs/src/service.rs @@ -1,4 +1,5 @@ -use crate::relay_mux::RelayMux; +use std::{future::Future, net::Ipv4Addr, pin::Pin, task::Poll}; + use beacon_api_client::Client; use ethereum_consensus::state_transition::Context; use futures::StreamExt; @@ -7,10 +8,11 @@ use mev_rs::{ Error, Network, }; use serde::Deserialize; -use std::{future::Future, net::Ipv4Addr, pin::Pin, task::Poll}; use tokio::task::{JoinError, JoinHandle}; use url::Url; +use crate::relay_mux::RelayMux; + #[derive(Debug, Deserialize)] pub struct Config { pub host: Ipv4Addr, diff --git a/mev-boost-rs/tests/integration.rs b/mev-boost-rs/tests/integration.rs index b7692aa8..3107d658 100644 --- a/mev-boost-rs/tests/integration.rs +++ b/mev-boost-rs/tests/integration.rs @@ -1,3 +1,8 @@ +use std::{ + collections::HashMap, + time::{SystemTime, UNIX_EPOCH}, +}; + use beacon_api_client::{Client as ApiClient, ValidatorStatus, ValidatorSummary, Value}; use ethereum_consensus::{ bellatrix::mainnet as bellatrix, @@ -18,10 +23,6 @@ use mev_rs::{ types::{BidRequest, ExecutionPayload, SignedBlindedBeaconBlock, SignedBuilderBid}, }; use rand::seq::SliceRandom; -use std::{ - collections::HashMap, - time::{SystemTime, UNIX_EPOCH}, -}; use url::Url; fn setup_logging() { diff --git a/mev-build-rs/src/mempool_builder.rs b/mev-build-rs/src/mempool_builder.rs index d20e7b90..a56116f6 100644 --- a/mev-build-rs/src/mempool_builder.rs +++ b/mev-build-rs/src/mempool_builder.rs @@ -1,3 +1,5 @@ +use std::{collections::HashMap, ops::Deref, sync::Arc}; + use async_trait::async_trait; use beacon_api_client::{BeaconProposerRegistration, Client, ProposerDuty}; use ethereum_consensus::{ @@ -15,7 +17,6 @@ use mev_rs::{ BlindedBlockProvider, Error, ProposerScheduler, ValidatorRegistry, }; use parking_lot::Mutex; -use std::{collections::HashMap, ops::Deref, sync::Arc}; use tokio::{sync::mpsc, task::JoinHandle}; #[derive(Clone)] diff --git a/mev-build-rs/src/service.rs b/mev-build-rs/src/service.rs index 41646908..0fee11ce 100644 --- a/mev-build-rs/src/service.rs +++ b/mev-build-rs/src/service.rs @@ -1,4 +1,5 @@ -use crate::mempool_builder::Builder; +use std::{fmt, future::Future, net::Ipv4Addr, pin::Pin, sync::Arc, task::Poll}; + use beacon_api_client::Client; use ethereum_consensus::{crypto::SecretKey, state_transition::Context}; use futures::StreamExt; @@ -13,13 +14,14 @@ use mev_rs::{ Error, Network, }; use serde::Deserialize; -use std::{fmt, future::Future, net::Ipv4Addr, pin::Pin, sync::Arc, task::Poll}; use tokio::{ sync::mpsc, task::{JoinError, JoinHandle}, }; use url::Url; +use crate::mempool_builder::Builder; + const BUILD_JOB_BUFFER_SIZE: usize = 1; #[derive(Deserialize)] diff --git a/mev-relay-rs/src/relay.rs b/mev-relay-rs/src/relay.rs index 738261da..2dd06b01 100644 --- a/mev-relay-rs/src/relay.rs +++ b/mev-relay-rs/src/relay.rs @@ -1,3 +1,5 @@ +use std::{collections::HashMap, ops::Deref, sync::Arc}; + use async_trait::async_trait; use beacon_api_client::Client; use ethereum_consensus::{ @@ -17,7 +19,6 @@ use mev_rs::{ BlindedBlockProvider, Error, ValidatorRegistry, }; use parking_lot::Mutex; -use std::{collections::HashMap, ops::Deref, sync::Arc}; // `PROPOSAL_TOLERANCE_DELAY` controls how aggresively the relay drops "old" execution payloads // once they have been fetched from builders -- currently in response to an incoming request from a diff --git a/mev-relay-rs/src/service.rs b/mev-relay-rs/src/service.rs index 59ca668a..d4a772b5 100644 --- a/mev-relay-rs/src/service.rs +++ b/mev-relay-rs/src/service.rs @@ -1,13 +1,15 @@ -use crate::relay::Relay; +use std::{future::Future, net::Ipv4Addr, pin::Pin, sync::Arc, task::Poll}; + use beacon_api_client::Client; use ethereum_consensus::state_transition::Context; use futures::StreamExt; use mev_rs::{blinded_block_provider::Server as BlindedBlockProviderServer, Error, Network}; use serde::Deserialize; -use std::{future::Future, net::Ipv4Addr, pin::Pin, sync::Arc, task::Poll}; use tokio::task::{JoinError, JoinHandle}; use url::Url; +use crate::relay::Relay; + #[derive(Debug, Deserialize)] pub struct Config { pub host: Ipv4Addr, diff --git a/mev-rs/src/blinded_block_provider/api/client.rs b/mev-rs/src/blinded_block_provider/api/client.rs index 1c22d807..3b8706d0 100644 --- a/mev-rs/src/blinded_block_provider/api/client.rs +++ b/mev-rs/src/blinded_block_provider/api/client.rs @@ -1,3 +1,8 @@ +use axum::http::StatusCode; +use beacon_api_client::{ + api_error_or_ok, ApiResult, Client as BeaconApiClient, Error as ApiError, VersionedValue, +}; + use crate::{ blinded_block_provider::Error, types::{ @@ -5,10 +10,6 @@ use crate::{ SignedValidatorRegistration, }, }; -use axum::http::StatusCode; -use beacon_api_client::{ - api_error_or_ok, ApiResult, Client as BeaconApiClient, Error as ApiError, VersionedValue, -}; /// A `Client` for a service implementing the Builder APIs. /// Note that `Client` does not implement the `Builder` trait so that diff --git a/mev-rs/src/blinded_block_provider/api/server.rs b/mev-rs/src/blinded_block_provider/api/server.rs index 8e7af891..3c39a064 100644 --- a/mev-rs/src/blinded_block_provider/api/server.rs +++ b/mev-rs/src/blinded_block_provider/api/server.rs @@ -1,11 +1,5 @@ -use crate::{ - blinded_block_provider::BlindedBlockProvider, - error::Error, - types::{ - bellatrix, capella, BidRequest, ExecutionPayload, SignedBlindedBeaconBlock, - SignedBuilderBid, SignedValidatorRegistration, - }, -}; +use std::net::{Ipv4Addr, SocketAddr}; + use axum::{ extract::{Json, Path, State}, http::StatusCode, @@ -16,9 +10,17 @@ use axum::{ use beacon_api_client::{ApiError, Error as ApiClientError, VersionedValue}; use hyper::server::conn::AddrIncoming; use serde::Deserialize; -use std::net::{Ipv4Addr, SocketAddr}; use tokio::task::JoinHandle; +use crate::{ + blinded_block_provider::BlindedBlockProvider, + error::Error, + types::{ + bellatrix, capella, BidRequest, ExecutionPayload, SignedBlindedBeaconBlock, + SignedBuilderBid, SignedValidatorRegistration, + }, +}; + /// Type alias for the configured axum server pub type BlockProviderServer = axum::Server>; diff --git a/mev-rs/src/blinded_block_provider/mod.rs b/mev-rs/src/blinded_block_provider/mod.rs index d9f6bec0..1fe59537 100644 --- a/mev-rs/src/blinded_block_provider/mod.rs +++ b/mev-rs/src/blinded_block_provider/mod.rs @@ -1,6 +1,10 @@ #[cfg(feature = "api")] mod api; +use async_trait::async_trait; +#[cfg(feature = "api")] +pub use {api::client::Client, api::server::Server}; + use crate::{ error::Error, types::{ @@ -8,9 +12,6 @@ use crate::{ SignedValidatorRegistration, }, }; -use async_trait::async_trait; -#[cfg(feature = "api")] -pub use {api::client::Client, api::server::Server}; #[async_trait] pub trait BlindedBlockProvider { diff --git a/mev-rs/src/engine_api_proxy/client.rs b/mev-rs/src/engine_api_proxy/client.rs index ff93e281..77fd9754 100644 --- a/mev-rs/src/engine_api_proxy/client.rs +++ b/mev-rs/src/engine_api_proxy/client.rs @@ -1,3 +1,11 @@ +use std::sync::Arc; + +use anvil_rpc::request::{Id, RequestParams, RpcMethodCall, Version}; +use ethereum_consensus::{capella::Withdrawal, primitives::ValidatorIndex}; +use parking_lot::Mutex; +use serde::Deserialize; +use ssz_rs::prelude::U256; + use crate::{ engine_api_proxy::{ types::{self, BuildVersion, ExecutionPayloadWithValue, PayloadId}, @@ -5,12 +13,6 @@ use crate::{ }, types::{bellatrix, capella, ExecutionPayload}, }; -use anvil_rpc::request::{Id, RequestParams, RpcMethodCall, Version}; -use ethereum_consensus::{capella::Withdrawal, primitives::ValidatorIndex}; -use parking_lot::Mutex; -use serde::Deserialize; -use ssz_rs::prelude::U256; -use std::sync::Arc; const ENGINE_GET_PAYLOADV1_METHOD: &str = "engine_getPayloadV1"; const ENGINE_GET_PAYLOADV2_METHOD: &str = "engine_getPayloadV2"; diff --git a/mev-rs/src/engine_api_proxy/server.rs b/mev-rs/src/engine_api_proxy/server.rs index b351d624..2f38f5a8 100644 --- a/mev-rs/src/engine_api_proxy/server.rs +++ b/mev-rs/src/engine_api_proxy/server.rs @@ -1,7 +1,8 @@ -use crate::engine_api_proxy::types::{ - BuildJob, BuildVersion, ForkchoiceUpdatedV1Params, ForkchoiceUpdatedV1Response, - ForkchoiceUpdatedV2Params, PayloadAttributes, +use std::{ + net::{Ipv4Addr, SocketAddr}, + sync::Arc, }; + use axum::{ extract::State, http::{uri::Uri, Request, Response}, @@ -11,12 +12,13 @@ use axum::{ use hyper::{body, client::HttpConnector, server::conn::AddrIncoming, Body}; use parking_lot::Mutex; use serde::{Deserialize, Serialize}; -use std::{ - net::{Ipv4Addr, SocketAddr}, - sync::Arc, -}; use tokio::{sync::mpsc, task::JoinHandle}; +use crate::engine_api_proxy::types::{ + BuildJob, BuildVersion, ForkchoiceUpdatedV1Params, ForkchoiceUpdatedV1Response, + ForkchoiceUpdatedV2Params, PayloadAttributes, +}; + pub type EngineApiProxyServer = axum::Server>; pub type Client = hyper::client::Client; diff --git a/mev-rs/src/error.rs b/mev-rs/src/error.rs index e65c9097..c0d19ca2 100644 --- a/mev-rs/src/error.rs +++ b/mev-rs/src/error.rs @@ -1,4 +1,3 @@ -use crate::types::BidRequest; use beacon_api_client::Error as ApiError; use ethereum_consensus::{ primitives::{BlsPublicKey, ExecutionAddress, Hash32}, @@ -6,6 +5,8 @@ use ethereum_consensus::{ }; use thiserror::Error; +use crate::types::BidRequest; + #[derive(Debug, Error)] pub enum Error { #[error("no bid prepared for request {0:?}")] diff --git a/mev-rs/src/proposer_scheduler.rs b/mev-rs/src/proposer_scheduler.rs index a0284d48..62aa3513 100644 --- a/mev-rs/src/proposer_scheduler.rs +++ b/mev-rs/src/proposer_scheduler.rs @@ -1,7 +1,8 @@ +use std::collections::HashMap; + use beacon_api_client::{BeaconProposerRegistration, Client, Error as ApiError, ProposerDuty}; use ethereum_consensus::primitives::{BlsPublicKey, Epoch, Slot}; use parking_lot::Mutex; -use std::collections::HashMap; use thiserror::Error; #[derive(Debug, Error)] diff --git a/mev-rs/src/types/mod.rs b/mev-rs/src/types/mod.rs index 382764ad..915c047e 100644 --- a/mev-rs/src/types/mod.rs +++ b/mev-rs/src/types/mod.rs @@ -1,9 +1,6 @@ pub mod bellatrix; pub mod capella; -use crate::signing::{ - sign_builder_message, verify_signed_builder_message, verify_signed_consensus_message, -}; pub use ethereum_consensus::builder::SignedValidatorRegistration; use ethereum_consensus::{ crypto::SecretKey, @@ -12,6 +9,10 @@ use ethereum_consensus::{ }; use ssz_rs::prelude::*; +use crate::signing::{ + sign_builder_message, verify_signed_builder_message, verify_signed_consensus_message, +}; + #[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct BidRequest { diff --git a/mev-rs/src/validator_registry.rs b/mev-rs/src/validator_registry.rs index 414f8f1b..92e58b84 100644 --- a/mev-rs/src/validator_registry.rs +++ b/mev-rs/src/validator_registry.rs @@ -1,4 +1,5 @@ -use crate::{signing::verify_signed_builder_message, types::SignedValidatorRegistration}; +use std::{cmp::Ordering, collections::HashMap}; + use beacon_api_client::{Client, Error as ApiError, StateId, ValidatorStatus, ValidatorSummary}; use ethereum_consensus::{ builder::ValidatorRegistration, @@ -6,9 +7,10 @@ use ethereum_consensus::{ state_transition::{Context, Error as ConsensusError}, }; use parking_lot::Mutex; -use std::{cmp::Ordering, collections::HashMap}; use thiserror::Error; +use crate::{signing::verify_signed_builder_message, types::SignedValidatorRegistration}; + #[derive(Debug, Error)] pub enum Error { #[error("invalid timestamp")] diff --git a/rustfmt.toml b/rustfmt.toml index f4a93ad0..e1d3fe07 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,6 +1,6 @@ reorder_imports = true imports_granularity = "Crate" -group_imports = "One" +group_imports = "StdExternalCrate" use_small_heuristics = "Max" comment_width = 100 wrap_comments = true