Skip to content

Commit 545a69d

Browse files
authored
Multi bid observer (#604)
## πŸ“ Summary New BidObserverMultiplexer to allow to plug multiple BidObserver. Some parameter changes on BidObserver::block_submitted. ## βœ… I have completed the following steps: * [X] Run `make lint` * [X] Run `make test` * [ ] Added tests (if applicable)
1 parent 063e64d commit 545a69d

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

β€Žcrates/rbuilder/src/live_builder/block_output/bid_observer.rsβ€Ž

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
use alloy_primitives::U256;
22
use reth_primitives::SealedBlock;
33

4-
use crate::{building::BuiltBlockTrace, mev_boost::submission::SubmitBlockRequest};
4+
use crate::{
5+
building::BuiltBlockTrace, live_builder::payload_events::MevBoostSlotData,
6+
mev_boost::submission::SubmitBlockRequest,
7+
};
58

69
/// Trait that receives every bid made by us to the relays.
710
pub trait BidObserver: std::fmt::Debug {
811
/// This callback is executed after the bid was made so it gives away ownership of the data.
912
/// This should NOT block since it's executed in the submitting thread.
1013
fn block_submitted(
1114
&self,
12-
sealed_block: SealedBlock,
13-
submit_block_request: SubmitBlockRequest,
14-
built_block_trace: BuiltBlockTrace,
15+
slot_data: &MevBoostSlotData,
16+
sealed_block: &SealedBlock,
17+
submit_block_request: &SubmitBlockRequest,
18+
built_block_trace: &BuiltBlockTrace,
1519
builder_name: String,
1620
best_bid_value: U256,
1721
);
@@ -23,9 +27,10 @@ pub struct NullBidObserver {}
2327
impl BidObserver for NullBidObserver {
2428
fn block_submitted(
2529
&self,
26-
_sealed_block: SealedBlock,
27-
_submit_block_request: SubmitBlockRequest,
28-
_built_block_trace: BuiltBlockTrace,
30+
_slot_data: &MevBoostSlotData,
31+
_sealed_block: &SealedBlock,
32+
_submit_block_request: &SubmitBlockRequest,
33+
_built_block_trace: &BuiltBlockTrace,
2934
_builder_name: String,
3035
_best_bid_value: U256,
3136
) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use reth_primitives::SealedBlock;
2+
3+
use crate::{
4+
building::BuiltBlockTrace, live_builder::payload_events::MevBoostSlotData,
5+
mev_boost::submission::SubmitBlockRequest,
6+
};
7+
8+
use super::bid_observer::BidObserver;
9+
10+
/// Implements BidObserver forwarding all calls to several BidObservers.
11+
#[derive(Default)]
12+
pub struct BidObserverMultiplexer {
13+
observers: Vec<Box<dyn BidObserver + Send + Sync>>,
14+
}
15+
16+
impl std::fmt::Debug for BidObserverMultiplexer {
17+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
18+
f.debug_struct("BidObserverMultiplexer").finish()
19+
}
20+
}
21+
22+
impl BidObserverMultiplexer {
23+
pub fn push(&mut self, obs: Box<dyn BidObserver + Send + Sync>) {
24+
self.observers.push(obs);
25+
}
26+
}
27+
28+
impl BidObserver for BidObserverMultiplexer {
29+
fn block_submitted(
30+
&self,
31+
slot_data: &MevBoostSlotData,
32+
sealed_block: &SealedBlock,
33+
submit_block_request: &SubmitBlockRequest,
34+
built_block_trace: &BuiltBlockTrace,
35+
builder_name: String,
36+
best_bid_value: alloy_primitives::U256,
37+
) {
38+
for obs in &self.observers {
39+
obs.block_submitted(
40+
slot_data,
41+
sealed_block,
42+
submit_block_request,
43+
built_block_trace,
44+
builder_name.clone(),
45+
best_bid_value,
46+
);
47+
}
48+
}
49+
}

β€Žcrates/rbuilder/src/live_builder/block_output/mod.rsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod bid_observer;
2+
pub mod bid_observer_multiplexer;
23
pub mod bid_value_source;
34
pub mod bidding;
45
pub mod block_sealing_bidder_factory;

β€Žcrates/rbuilder/src/live_builder/block_output/relay_submit.rsβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,10 @@ async fn run_submit_to_relays_job(
332332
submission_span.in_scope(|| {
333333
// NOTE: we only notify normal submission here because they have the same contents but different pubkeys
334334
config.bid_observer.block_submitted(
335-
block.sealed_block,
336-
normal_signed_submission.submission,
337-
block.trace,
335+
&slot_data,
336+
&block.sealed_block,
337+
&normal_signed_submission.submission,
338+
&block.trace,
338339
builder_name,
339340
bid_metadata.value.top_competitor_bid.unwrap_or_default(),
340341
);

0 commit comments

Comments
Β (0)