Skip to content

Commit fc9e037

Browse files
authored
Subsidy value propagated on tbv stream. (#767)
## πŸ“ Summary Subsidy is propagated from the bidder to the tbv stream since it's an important info if the bid. ## βœ… I have completed the following steps: * [X] Run `make lint` * [X] Run `make test` * [ ] Added tests (if applicable)
1 parent 2cbadf8 commit fc9e037

File tree

13 files changed

+89
-14
lines changed

13 files changed

+89
-14
lines changed

β€Žcrates/rbuilder-operator/src/bidding_service_wrapper/fast_streams/types.rsβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Types used to communicate with the bidding service via iceoryx.
22
//! They are mostly mappings of the originals but supporting ZeroCopySend.
3-
use alloy_primitives::U256;
3+
use alloy_primitives::{I256, U256};
44
use bid_scraper::types::ScrapedRelayBlockBid;
55
use iceoryx2::prelude::ZeroCopySend;
66
use iceoryx2_bb_container::byte_string::FixedSizeByteString;
@@ -196,6 +196,7 @@ pub struct SlotBidderSealBidCommandRPC {
196196
pub session_id: u64,
197197
pub block_id: u64,
198198
pub payout_tx_value: [u8; U256_DATA_LENGTH],
199+
pub subsidy: [u8; U256_DATA_LENGTH],
199200
pub seen_competition_bid: Option<[u8; U256_DATA_LENGTH]>,
200201
/// When this bid is a reaction so some event (eg: new block, new competition bid) we put here
201202
/// the creation time of that event so we can measure our reaction time.
@@ -213,6 +214,7 @@ impl From<SlotBidderSealBidCommandWithSessionId> for SlotBidderSealBidCommandRPC
213214
.0
214215
.trigger_creation_time
215216
.map(offset_datetime_to_timestamp_us),
217+
subsidy: value.0.subsidy.to_le_bytes(),
216218
}
217219
}
218220
}
@@ -222,6 +224,7 @@ impl From<SlotBidderSealBidCommandRPC> for SlotBidderSealBidCommand {
222224
SlotBidderSealBidCommand {
223225
block_id: BuiltBlockId(val.block_id),
224226
payout_tx_value: U256::from_le_bytes(val.payout_tx_value),
227+
subsidy: I256::from_le_bytes(val.subsidy),
225228
seen_competition_bid: val.seen_competition_bid.map(|k| U256::from_le_bytes(k)),
226229
trigger_creation_time: val
227230
.trigger_creation_time_us

β€Žcrates/rbuilder-operator/src/true_block_value_push/best_true_value_observer.rsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl BidObserver for BestTrueValueObserver {
8383
slot_data.slot(),
8484
built_block_trace.true_bid_value,
8585
built_block_trace.bid_value,
86+
built_block_trace.subsidy,
8687
builder_name,
8788
slot_data.timestamp().unix_timestamp() as u64,
8889
);

β€Žcrates/rbuilder-operator/src/true_block_value_push/best_true_value_pusher.rsβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! This module is responsible for syncing the best true value bid between the local state and redis.
22
3-
use alloy_primitives::U256;
3+
use alloy_primitives::{I256, U256};
44

55
use parking_lot::Mutex;
66
use rbuilder::utils::{
7+
i256decimal_serde_helper,
78
reconnect::{run_loop_with_reconnect, RunCommand},
89
u256decimal_serde_helper,
910
};
@@ -27,6 +28,9 @@ pub struct BuiltBlockInfo {
2728
/// Bid we made to the relay.
2829
#[serde(with = "u256decimal_serde_helper")]
2930
pub bid: U256,
31+
#[serde(with = "i256decimal_serde_helper")]
32+
pub subsidy: I256,
33+
3034
pub builder: String,
3135
pub slot_end_timestamp: u64,
3236
}
@@ -37,6 +41,7 @@ impl BuiltBlockInfo {
3741
slot_number: u64,
3842
best_true_value: U256,
3943
bid: U256,
44+
subsidy: I256,
4045
builder: String,
4146
slot_end_timestamp: u64,
4247
) -> Self {
@@ -46,6 +51,7 @@ impl BuiltBlockInfo {
4651
slot_number,
4752
best_true_value,
4853
bid,
54+
subsidy,
4955
builder,
5056
slot_end_timestamp,
5157
}

β€Žcrates/rbuilder/src/building/builders/block_building_helper.rsβ€Ž

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy_primitives::{utils::format_ether, Address, TxHash, U256};
1+
use alloy_primitives::{utils::format_ether, Address, TxHash, I256, U256};
22
use reth_provider::StateProvider;
33
use std::{
44
cmp::max,
@@ -68,10 +68,12 @@ pub trait BlockBuildingHelper: Send + Sync {
6868
/// Finalize block for submission.
6969
/// if adjust_finalized_block is implemented, finalize_blocks should prepare helper
7070
/// for faster adjustments.
71+
/// subsidy is how much of payout_tx_value we consider to be subsidy.
7172
fn finalize_block(
7273
&mut self,
7374
local_ctx: &mut ThreadBlockBuildingContext,
7475
payout_tx_value: U256,
76+
subsidy: I256,
7577
seen_competition_bid: Option<U256>,
7678
) -> Result<FinalizeBlockResult, BlockBuildingHelperError>;
7779

@@ -96,6 +98,7 @@ pub trait BlockBuildingHelper: Send + Sync {
9698
&mut self,
9799
local_ctx: &mut ThreadBlockBuildingContext,
98100
payout_tx_value: U256,
101+
subsidy: I256,
99102
seen_competition_bid: Option<U256>,
100103
) -> Result<FinalizeBlockResult, BlockBuildingHelperError>;
101104
}
@@ -337,6 +340,7 @@ impl<
337340
&mut self,
338341
local_ctx: &mut ThreadBlockBuildingContext,
339342
payout_tx_value: U256,
343+
subsidy: I256,
340344
adjust_finalized_block: bool,
341345
finalize_revert_state: &mut FinalizeRevertStateCurrentIteration,
342346
) -> Result<(), BlockBuildingHelperError> {
@@ -364,6 +368,7 @@ impl<
364368
.unwrap_or_default();
365369

366370
self.built_block_trace.bid_value = max(bid_value, fee_recipient_balance_diff);
371+
self.built_block_trace.subsidy = subsidy;
367372
self.built_block_trace.true_bid_value = true_value;
368373
self.built_block_trace.mev_blocker_price = self.building_context().mev_blocker_price;
369374
Ok(())
@@ -373,6 +378,7 @@ impl<
373378
&mut self,
374379
local_ctx: &mut ThreadBlockBuildingContext,
375380
payout_tx_value: U256,
381+
subsidy: I256,
376382
seen_competition_bid: Option<U256>,
377383
adjust_finalized_block: bool,
378384
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
@@ -403,6 +409,7 @@ impl<
403409
self.finalize_block_execution(
404410
local_ctx,
405411
payout_tx_value,
412+
subsidy,
406413
adjust_finalized_block,
407414
&mut finalize_adjustment_state.revert_state,
408415
)?;
@@ -590,9 +597,16 @@ impl<
590597
&mut self,
591598
local_ctx: &mut ThreadBlockBuildingContext,
592599
payout_tx_value: U256,
600+
subsidy: I256,
593601
seen_competition_bid: Option<U256>,
594602
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
595-
self.finalize_block_impl(local_ctx, payout_tx_value, seen_competition_bid, false)
603+
self.finalize_block_impl(
604+
local_ctx,
605+
payout_tx_value,
606+
subsidy,
607+
seen_competition_bid,
608+
false,
609+
)
596610
}
597611

598612
fn built_block_trace(&self) -> &BuiltBlockTrace {
@@ -624,8 +638,15 @@ impl<
624638
&mut self,
625639
local_ctx: &mut ThreadBlockBuildingContext,
626640
payout_tx_value: U256,
641+
subsidy: I256,
627642
seen_competition_bid: Option<U256>,
628643
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
629-
self.finalize_block_impl(local_ctx, payout_tx_value, seen_competition_bid, true)
644+
self.finalize_block_impl(
645+
local_ctx,
646+
payout_tx_value,
647+
subsidy,
648+
seen_competition_bid,
649+
true,
650+
)
630651
}
631652
}

β€Žcrates/rbuilder/src/building/builders/block_building_helper_stats_logger.rsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
time::{Duration, Instant},
55
};
66

7-
use alloy_primitives::{utils::format_ether, U256};
7+
use alloy_primitives::{utils::format_ether, I256, U256};
88

99
use crate::{
1010
building::{builders::block_building_helper::BlockBuildingHelper, ThreadBlockBuildingContext},
@@ -208,6 +208,7 @@ impl BlockBuildingHelper for BlockBuildingHelperStatsLogger<'_> {
208208
&mut self,
209209
_local_ctx: &mut crate::building::ThreadBlockBuildingContext,
210210
_payout_tx_value: alloy_primitives::U256,
211+
_subsidy: alloy_primitives::I256,
211212
_seen_competition_bid: Option<alloy_primitives::U256>,
212213
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
213214
panic!("finalize_block not implemented. This is only for testing.");
@@ -238,6 +239,7 @@ impl BlockBuildingHelper for BlockBuildingHelperStatsLogger<'_> {
238239
&mut self,
239240
_local_ctx: &mut ThreadBlockBuildingContext,
240241
_payout_tx_value: U256,
242+
_subsidy: I256,
241243
_seen_competition_bid: Option<U256>,
242244
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
243245
unimplemented!()

β€Žcrates/rbuilder/src/building/builders/mock_block_building_helper.rsβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
provider::RootHasher,
88
roothash::RootHashError,
99
};
10-
use alloy_primitives::{Address, Bytes, B256, U256};
10+
use alloy_primitives::{Address, Bytes, B256, I256, U256};
1111
use eth_sparse_mpt::utils::{HashMap, HashSet};
1212
use rbuilder_primitives::{order_statistics::OrderStatistics, SimValue, SimulatedOrder};
1313
use reth_primitives::SealedBlock;
@@ -85,11 +85,13 @@ impl BlockBuildingHelper for MockBlockBuildingHelper {
8585
&mut self,
8686
_local_ctx: &mut ThreadBlockBuildingContext,
8787
payout_tx_value: U256,
88+
subsidy: I256,
8889
seen_competition_bid: Option<U256>,
8990
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
9091
self.built_block_trace.update_orders_sealed_at();
9192
self.built_block_trace.seen_competition_bid = seen_competition_bid;
9293
self.built_block_trace.bid_value = payout_tx_value;
94+
self.built_block_trace.subsidy = subsidy;
9395
let block = Block {
9496
builder_name: "BlockBuildingHelper".to_string(),
9597
trace: self.built_block_trace.clone(),
@@ -127,6 +129,7 @@ impl BlockBuildingHelper for MockBlockBuildingHelper {
127129
&mut self,
128130
_local_ctx: &mut ThreadBlockBuildingContext,
129131
_payout_tx_value: U256,
132+
_subsidy: I256,
130133
_seen_competition_bid: Option<U256>,
131134
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
132135
unimplemented!()

β€Žcrates/rbuilder/src/building/builders/ordering_builder.rsβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::{
2525
utils::NonceCache,
2626
};
2727
use ahash::{HashMap, HashSet};
28+
use alloy_primitives::I256;
2829
use derivative::Derivative;
2930
use rbuilder_primitives::{AccountNonce, OrderId, SimValue, SimulatedOrder};
3031
use reth_provider::StateProvider;
@@ -198,7 +199,7 @@ where
198199

199200
let payout_tx_value = block_builder.true_block_value()?;
200201
let finalize_block_result =
201-
block_builder.finalize_block(&mut local_ctx, payout_tx_value, None)?;
202+
block_builder.finalize_block(&mut local_ctx, payout_tx_value, I256::ZERO, None)?;
202203
Ok(finalize_block_result.block)
203204
}
204205

β€Žcrates/rbuilder/src/building/builders/parallel_builder/mod.rsβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod order_intake_store;
77
pub mod results_aggregator;
88
pub mod simulation_cache;
99
pub mod task;
10+
use alloy_primitives::I256;
1011
pub use groups::*;
1112

1213
use ahash::HashMap;
@@ -377,6 +378,7 @@ where
377378
let finalize_block_result = block_building_helper.finalize_block(
378379
&mut block_building_result_assembler.local_ctx,
379380
payout_tx_value,
381+
I256::ZERO,
380382
None,
381383
)?;
382384
let building_duration = building_start.elapsed();

β€Žcrates/rbuilder/src/building/built_block_trace.rsβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::building::builders::BuiltBlockId;
22

33
use super::ExecutionResult;
44
use ahash::{AHasher, HashMap, HashSet};
5-
use alloy_primitives::{Address, TxHash, U256};
5+
use alloy_primitives::{Address, TxHash, I256, U256};
66
use rbuilder_primitives::{
77
order_statistics::OrderStatistics, Order, OrderId, OrderReplacementKey, SimulatedOrder,
88
};
@@ -18,6 +18,8 @@ pub struct BuiltBlockTrace {
1818
pub included_orders: Vec<ExecutionResult>,
1919
/// How much we bid (pay to the validator)
2020
pub bid_value: U256,
21+
/// Subsidy used in the bid.
22+
pub subsidy: I256,
2123
/// coinbase balance delta before the payout tx.
2224
pub coinbase_reward: U256,
2325
/// True block value (coinbase balance delta) excluding the cost of the payout to validator
@@ -96,6 +98,7 @@ impl BuiltBlockTrace {
9698
sent_to_sealer: OffsetDateTime::now_utc(),
9799
picked_by_sealer_at: OffsetDateTime::now_utc(),
98100
build_block_id,
101+
subsidy: I256::ZERO,
99102
}
100103
}
101104

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use alloy_primitives::{BlockHash, BlockNumber, U256};
3+
use alloy_primitives::{BlockHash, BlockNumber, I256, U256};
44
use bid_scraper::{
55
bid_sender::{BidSender, BidSenderError},
66
types::ScrapedRelayBlockBid,
@@ -104,6 +104,8 @@ impl BuiltBlockDescriptorForSlotBidder {
104104
pub struct SlotBidderSealBidCommand {
105105
pub block_id: BuiltBlockId,
106106
pub payout_tx_value: U256,
107+
/// Subsidy used in the bid.
108+
pub subsidy: I256,
107109
pub seen_competition_bid: Option<U256>,
108110
/// When this bid is a reaction so some event (eg: new block, new competition bid) we put here
109111
/// the creation time of that event so we can measure our reaction time.

0 commit comments

Comments
Β (0)