Skip to content

Commit 6b574bd

Browse files
authored
New fields on clickhouse (#819)
## 📝 Summary New fields on buidlernet.blocks: builder_name: name of the node that submitted the block rbuilder_commit: git commit of the rbuilder running builder_name comes from a new cfg parameter BuiltBlocksClickhouseConfig::builder_name. As a bonus changed BuiltBlocksClickhouseConfig::password from String to EnvOrValue<String>. ## ✅ I have completed the following steps: * [X] Run `make lint` * [X] Run `make test` * [ ] Added tests (if applicable)
1 parent a6ebe67 commit 6b574bd

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

crates/rbuilder-operator/src/clickhouse.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ use crate::{flashbots_config::BuiltBlocksClickhouseConfig, metrics::ClickhouseMe
3131
#[derive(Debug, Clone, Serialize, Deserialize, Row)]
3232
pub struct BlockRow {
3333
pub block_number: u64,
34+
/// name of the node that submitted the block
35+
pub builder_name: String,
36+
/// git commit of the rbuilder running
37+
pub rbuilder_commit: String,
3438
pub profit: String,
3539
pub slot: u64,
3640
pub hash: String,
@@ -45,6 +49,7 @@ pub struct BlockRow {
4549
pub timestamp_datetime: i64,
4650
pub orders_closed_at: i64,
4751
pub sealed_at: i64,
52+
/// name of the algorithm that created the block
4853
pub algorithm: String,
4954

5055
#[serde(with = "option_u256")]
@@ -106,15 +111,21 @@ const DEFAULT_MAX_MEMORY_SIZE_MB: u64 = KILO;
106111
#[derive(Debug)]
107112
pub struct BuiltBlocksWriter {
108113
blocks_tx: mpsc::Sender<BlockRow>,
114+
rbuilder_commit: String,
115+
builder_name: String,
109116
}
110117

111118
impl BuiltBlocksWriter {
112-
pub fn new(config: BuiltBlocksClickhouseConfig, cancellation_token: CancellationToken) -> Self {
119+
pub fn new(
120+
config: BuiltBlocksClickhouseConfig,
121+
rbuilder_commit: String,
122+
cancellation_token: CancellationToken,
123+
) -> eyre::Result<Self> {
113124
let client = Client::default()
114125
.with_url(config.host)
115126
.with_database(config.database)
116127
.with_user(config.username)
117-
.with_password(config.password)
128+
.with_password(config.password.value()?)
118129
.with_validation(false); // CRITICAL for U256 serialization.
119130

120131
let task_manager = rbuilder_utils::tasks::TaskManager::current();
@@ -142,9 +153,11 @@ impl BuiltBlocksWriter {
142153
tokio::time::sleep(RUN_SUBMIT_TO_RELAYS_JOB_CANCEL_TIME).await;
143154
task_manager.graceful_shutdown_with_timeout(Duration::from_secs(5));
144155
});
145-
Self {
156+
Ok(Self {
146157
blocks_tx: block_tx,
147-
}
158+
rbuilder_commit,
159+
builder_name: config.builder_name,
160+
})
148161
}
149162
}
150163

@@ -217,14 +230,16 @@ impl BidObserver for BuiltBlocksWriter {
217230
slot_data: &MevBoostSlotData,
218231
submit_block_request: Arc<AlloySubmitBlockRequest>,
219232
built_block_trace: Arc<BuiltBlockTrace>,
220-
builder_name: String,
233+
builder_algorithm_name: String,
221234
best_bid_value: U256,
222235
_relays: &RelaySet,
223236
sent_to_relay_at: OffsetDateTime,
224237
) {
225238
let slot = slot_data.slot();
226239
let block_number = slot_data.block();
227240
let blocks_tx = self.blocks_tx.clone();
241+
let rbuilder_commit = self.rbuilder_commit.clone();
242+
let builder_name = self.builder_name.clone();
228243
tokio::spawn(async move {
229244
let submit_trace = submit_block_request.bid_trace();
230245
let execution_payload_v1 = match submit_block_request.as_ref() {
@@ -264,6 +279,8 @@ impl BidObserver for BuiltBlocksWriter {
264279
.collect();
265280
let block_row = BlockRow {
266281
block_number,
282+
builder_name,
283+
rbuilder_commit,
267284
profit: format_ether(submit_trace.value),
268285
slot,
269286
hash: execution_payload_v1.block_hash.to_string(),
@@ -283,7 +300,7 @@ impl BidObserver for BuiltBlocksWriter {
283300
built_block_trace.orders_closed_at,
284301
),
285302
sealed_at: offset_date_to_clickhouse_timestamp(built_block_trace.orders_sealed_at),
286-
algorithm: builder_name,
303+
algorithm: builder_algorithm_name,
287304
true_value: Some(built_block_trace.true_bid_value),
288305
best_relay_value: Some(best_bid_value),
289306
block_value: Some(submit_trace.value),

crates/rbuilder-operator/src/flashbots_config.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ struct TBVPushRedisConfig {
7272

7373
/// Config used to record built blocks to clickhouse using a local
7474
/// storage on errors.
75-
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Default)]
75+
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
7676
pub struct BuiltBlocksClickhouseConfig {
7777
/// clickhouse host url (starts with http/https)
7878
pub host: String,
7979
pub database: String,
8080
pub username: String,
81-
pub password: String,
81+
/// Unique id for this server.
82+
/// Since this is only used in clickhouse to identify the builder blocks we put it here but we could have it in the base_config.
83+
pub builder_name: String,
84+
pub password: EnvOrValue<String>,
8285
pub disk_database_path: PathBuf,
8386
pub disk_max_size_mb: Option<u64>,
8487
pub memory_max_size_mb: Option<u64>,
@@ -312,10 +315,12 @@ impl FlashbotsConfig {
312315
block_processor_key: Option<PrivateKeySigner>,
313316
) -> eyre::Result<Option<Box<dyn BidObserver + Send + Sync>>> {
314317
if let Some(built_blocks_clickhouse_config) = &self.built_blocks_clickhouse_config {
318+
let rbuilder_version = rbuilder_version();
315319
let writer = BuiltBlocksWriter::new(
316320
built_blocks_clickhouse_config.clone(),
321+
rbuilder_version.git_commit,
317322
cancellation_token.clone(),
318-
);
323+
)?;
319324
Ok(Some(Box::new(writer)))
320325
} else {
321326
if block_processor_key.is_some() {
@@ -452,7 +457,7 @@ impl BidObserver for RbuilderOperatorBidObserver {
452457
slot_data: &MevBoostSlotData,
453458
submit_block_request: Arc<AlloySubmitBlockRequest>,
454459
built_block_trace: Arc<BuiltBlockTrace>,
455-
builder_name: String,
460+
builder_algorithm_name: String,
456461
best_bid_value: U256,
457462
relays: &RelaySet,
458463
sent_to_relay_at: OffsetDateTime,
@@ -462,7 +467,7 @@ impl BidObserver for RbuilderOperatorBidObserver {
462467
slot_data,
463468
submit_block_request.clone(),
464469
built_block_trace.clone(),
465-
builder_name.clone(),
470+
builder_algorithm_name.clone(),
466471
best_bid_value,
467472
relays,
468473
sent_to_relay_at,
@@ -473,7 +478,7 @@ impl BidObserver for RbuilderOperatorBidObserver {
473478
slot_data,
474479
submit_block_request,
475480
built_block_trace,
476-
builder_name,
481+
builder_algorithm_name,
477482
best_bid_value,
478483
relays,
479484
sent_to_relay_at,

crates/rbuilder-operator/src/true_block_value_push/best_true_value_observer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl BidObserver for BestTrueValueObserver {
7878
slot_data: &MevBoostSlotData,
7979
_submit_block_request: Arc<AlloySubmitBlockRequest>,
8080
built_block_trace: Arc<BuiltBlockTrace>,
81-
builder_name: String,
81+
builder_algorithm_name: String,
8282
_best_bid_value: alloy_primitives::U256,
8383
_relays: &RelaySet,
8484
_sent_to_relay_at: OffsetDateTime,
@@ -89,7 +89,7 @@ impl BidObserver for BestTrueValueObserver {
8989
built_block_trace.true_bid_value,
9090
built_block_trace.bid_value,
9191
built_block_trace.subsidy,
92-
builder_name,
92+
builder_algorithm_name,
9393
slot_data.timestamp().unix_timestamp() as u64,
9494
);
9595
self.best_local_value.update_value_safe(block_info);

crates/rbuilder/src/live_builder/block_output/bid_observer_multiplexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl BidObserver for BidObserverMultiplexer {
2828
slot_data: &MevBoostSlotData,
2929
submit_block_request: &SubmitBlockRequest,
3030
built_block_trace: &BuiltBlockTrace,
31-
builder_name: String,
31+
builder_algorithm_name: String,
3232
best_bid_value: alloy_primitives::U256,
3333
) {
3434
for obs in &self.observers {

crates/rbuilder/src/live_builder/block_output/bidding_service_interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait BidObserver: std::fmt::Debug {
3131
slot_data: &MevBoostSlotData,
3232
submit_block_request: Arc<AlloySubmitBlockRequest>,
3333
built_block_trace: Arc<BuiltBlockTrace>,
34-
builder_name: String,
34+
builder_algorithm_name: String,
3535
best_bid_value: U256,
3636
relays: &RelaySet,
3737
sent_to_relay_at: OffsetDateTime,
@@ -47,7 +47,7 @@ impl BidObserver for NullBidObserver {
4747
_slot_data: &MevBoostSlotData,
4848
_submit_block_request: Arc<AlloySubmitBlockRequest>,
4949
_built_block_trace: Arc<BuiltBlockTrace>,
50-
_builder_name: String,
50+
_builder_algorithm_name: String,
5151
_best_bid_value: U256,
5252
_relays: &RelaySet,
5353
_sent_to_relay_at: OffsetDateTime,

0 commit comments

Comments
 (0)