Skip to content

Commit

Permalink
Merge pull request #9 from flashbots/bidder-version
Browse files Browse the repository at this point in the history
New bidding service version metric.
  • Loading branch information
ZanCorDX authored Oct 22, 2024
2 parents 4f74e27 + 081734a commit e9a18f2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
19 changes: 16 additions & 3 deletions src/bidding_service_wrapper/bidding_service.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/// Mapping of build_info::Version
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BidderVersionInfo {
#[prost(string, tag = "1")]
pub git_commit: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub git_ref: ::prost::alloc::string::String,
#[prost(string, tag = "3")]
pub build_time_utc: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Empty {}
Expand Down Expand Up @@ -190,10 +201,11 @@ pub mod bidding_service_client {
self
}
/// Call after connection before calling anything. This will really create the BiddingService on the server side.
/// Returns the version info for the server side.
pub async fn initialize(
&mut self,
request: impl tonic::IntoRequest<super::LandedBlocksParams>,
) -> Result<tonic::Response<super::Empty>, tonic::Status> {
) -> Result<tonic::Response<super::BidderVersionInfo>, tonic::Status> {
self.inner
.ready()
.await
Expand Down Expand Up @@ -358,10 +370,11 @@ pub mod bidding_service_server {
#[async_trait]
pub trait BiddingService: Send + Sync + 'static {
/// Call after connection before calling anything. This will really create the BiddingService on the server side.
/// Returns the version info for the server side.
async fn initialize(
&self,
request: tonic::Request<super::LandedBlocksParams>,
) -> Result<tonic::Response<super::Empty>, tonic::Status>;
) -> Result<tonic::Response<super::BidderVersionInfo>, tonic::Status>;
/// Server streaming response type for the CreateSlotBidder method.
type CreateSlotBidderStream: futures_core::Stream<
Item = Result<super::Callback, tonic::Status>,
Expand Down Expand Up @@ -476,7 +489,7 @@ pub mod bidding_service_server {
T: BiddingService,
> tonic::server::UnaryService<super::LandedBlocksParams>
for InitializeSvc<T> {
type Response = super::Empty;
type Response = super::BidderVersionInfo;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloy_primitives::U256;
use rbuilder::live_builder::block_output::bidding::interfaces::{
BiddingServiceWinControl, LandedBlockInfo as RealLandedBlockInfo,
use rbuilder::{
live_builder::block_output::bidding::interfaces::{
BiddingServiceWinControl, LandedBlockInfo as RealLandedBlockInfo,
},
utils::build_info::Version,
};
use std::{
path::PathBuf,
Expand All @@ -19,6 +22,7 @@ use crate::{
MustWinBlockParams, NewBlockParams, UpdateNewBidParams,
},
block_descriptor_bidding::traits::{Bid, BidMaker, BiddingService, BlockId, SlotBidder},
metrics::set_bidding_service_version,
};

use super::slot_bidder_client::SlotBidderClient;
Expand Down Expand Up @@ -102,10 +106,16 @@ impl BiddingServiceClientAdapter {
.map(real2rpc_landed_block_info)
.collect(),
};
client
let bidding_service_version = client
.initialize(init_params)
.await
.map_err(|_| Error::InitFailed)?;
let bidding_service_version = bidding_service_version.into_inner();
set_bidding_service_version(Version {
git_commit: bidding_service_version.git_commit,
git_ref: bidding_service_version.git_ref,
build_time_utc: bidding_service_version.build_time_utc,
});
let (commands_sender, mut rx) = mpsc::unbounded_channel::<BiddingServiceClientCommand>();
// Spawn a task to execute received futures
tokio::spawn(async move {
Expand Down
10 changes: 9 additions & 1 deletion src/bidding_service_wrapper/proto/bidding_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ package bidding_service;
service BiddingService {

// Call after connection before calling anything. This will really create the BiddingService on the server side.
rpc Initialize(LandedBlocksParams) returns (Empty);
// Returns the version info for the server side.
rpc Initialize(LandedBlocksParams) returns (BidderVersionInfo);

// BiddingService
rpc CreateSlotBidder(CreateSlotBidderParams) returns (stream Callback);
Expand All @@ -36,6 +37,13 @@ service BiddingService {
// uint64 block + uint64 slot should be something like BidderId


// Mapping of build_info::Version
message BidderVersionInfo {
string git_commit = 1;
string git_ref = 2;
string build_time_utc = 3;
}

message Empty {
}

Expand Down
19 changes: 17 additions & 2 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use ctor::ctor;
use lazy_static::lazy_static;
use metrics_macros::register_metrics;
use prometheus::{IntCounter, IntCounterVec, Opts};
use rbuilder::telemetry::REGISTRY;
use prometheus::{IntCounter, IntCounterVec, IntGaugeVec, Opts};
use rbuilder::{telemetry::REGISTRY, utils::build_info::Version};

register_metrics! {
pub static BLOCK_API_ERRORS: IntCounterVec = IntCounterVec::new(
Expand All @@ -17,6 +17,11 @@ register_metrics! {
)
.unwrap();

pub static BIDDING_SERVICE_VERSION: IntGaugeVec = IntGaugeVec::new(
Opts::new("bidding_service_version", "Version of the bidding service"),
&["git", "git_ref", "build_time_utc"]
)
.unwrap();
}

pub fn inc_blocks_api_errors() {
Expand All @@ -26,3 +31,13 @@ pub fn inc_blocks_api_errors() {
pub fn inc_non_0_competition_bids() {
NON_0_COMPETITION_BIDS.inc();
}

pub(super) fn set_bidding_service_version(version: Version) {
BIDDING_SERVICE_VERSION
.with_label_values(&[
&version.git_commit,
&version.git_ref,
&version.build_time_utc,
])
.set(1);
}

0 comments on commit e9a18f2

Please sign in to comment.