From 3885142de0882eb88bfaf58a0c924b55d9c2918f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 7 May 2024 19:27:11 -0600 Subject: [PATCH] add very minimal landing page to visualize relay data --- mev-relay-rs/src/relay.rs | 8 ++ .../src/blinded_block_relayer/api/server.rs | 75 +++++++++++++++++++ mev-rs/src/blinded_block_relayer/mod.rs | 4 + mev-rs/src/validator_registry.rs | 5 ++ 4 files changed, 92 insertions(+) diff --git a/mev-relay-rs/src/relay.rs b/mev-relay-rs/src/relay.rs index 8ed50c7c..38a32605 100644 --- a/mev-relay-rs/src/relay.rs +++ b/mev-relay-rs/src/relay.rs @@ -723,6 +723,14 @@ fn submission_trace_from_auction(auction_context: &AuctionContext) -> Submission #[async_trait] impl BlindedBlockDataProvider for Relay { + fn public_key(&self) -> &BlsPublicKey { + &self.public_key + } + + fn registered_validators_count(&self) -> usize { + self.validator_registry.registration_count() + } + async fn get_delivered_payloads( &self, _filters: &DeliveredPayloadFilter, diff --git a/mev-rs/src/blinded_block_relayer/api/server.rs b/mev-rs/src/blinded_block_relayer/api/server.rs index 7ca7578a..7ecd704f 100644 --- a/mev-rs/src/blinded_block_relayer/api/server.rs +++ b/mev-rs/src/blinded_block_relayer/api/server.rs @@ -17,6 +17,7 @@ use crate::{ }; use axum::{ extract::{Json, Query, State}, + response::Html, routing::{get, post, IntoMakeService}, Router, }; @@ -28,6 +29,79 @@ use tracing::{error, info, trace}; /// Type alias for the configured axum server pub type BlockRelayServer = axum::Server>; +// cribbed from: https://github.com/tbjgolden/simple-json-viewer +const ROOT_HTML_TRAILER: &str = r#" + + +
+ + + + + + +"#; + +async fn handle_get_root( + State(relay): State, +) -> Result, Error> { + trace!("serving root"); + let mut response = format!( + r#" + + + + + +
+

mev-relay-rs

+
+
+
+

relay public key: {0:?}

+

registered validators: {1}

+
+
+ "#, + relay.public_key(), + relay.registered_validators_count(), + ); + response.push_str(ROOT_HTML_TRAILER); + Ok(Html(response)) +} + async fn handle_get_proposal_schedule( State(relay): State, ) -> Result>, Error> { @@ -90,6 +164,7 @@ impl< /// Configures and returns the axum server pub fn serve(&self) -> BlockRelayServer { let router = Router::new() + .route("/", get(handle_get_root::)) .route("/eth/v1/builder/status", get(handle_status_check)) .route("/eth/v1/builder/validators", post(handle_validator_registration::)) .route( diff --git a/mev-rs/src/blinded_block_relayer/mod.rs b/mev-rs/src/blinded_block_relayer/mod.rs index 72562140..4c1a2ffc 100644 --- a/mev-rs/src/blinded_block_relayer/mod.rs +++ b/mev-rs/src/blinded_block_relayer/mod.rs @@ -52,6 +52,10 @@ pub struct ValidatorRegistrationQuery { #[async_trait] pub trait BlindedBlockDataProvider { + fn public_key(&self) -> &BlsPublicKey; + + fn registered_validators_count(&self) -> usize; + async fn get_delivered_payloads( &self, filters: &DeliveredPayloadFilter, diff --git a/mev-rs/src/validator_registry.rs b/mev-rs/src/validator_registry.rs index d630dc05..d36d55bd 100644 --- a/mev-rs/src/validator_registry.rs +++ b/mev-rs/src/validator_registry.rs @@ -120,6 +120,11 @@ impl ValidatorRegistry { state.pubkeys_by_index.get(&index).cloned() } + pub fn registration_count(&self) -> usize { + let state = self.state.read(); + state.validator_preferences.len() + } + // pub fn get_validator_index(&self, public_key: &BlsPublicKey) -> Option { // let state = self.state.read(); // state.validators.get(public_key).map(|v| v.index)