Skip to content

Commit 0cf9e61

Browse files
committed
only allow builder coinbase
1 parent ae641a0 commit 0cf9e61

23 files changed

+75
-373
lines changed

crates/rbuilder/src/backtest/build_block/landed_block_from_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<ConfigType: LiveBuilderConfig>
123123
self.blocklist.clone(),
124124
signer.address,
125125
self.block_data.winning_bid_trace.proposer_fee_recipient,
126-
Some(signer),
126+
signer,
127127
Arc::new(MockRootHasher {}),
128128
self.config.base_config().evm_caching_enable,
129129
))

crates/rbuilder/src/backtest/execute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ where
7878
blocklist,
7979
builder_signer.address,
8080
block_data.winning_bid_trace.proposer_fee_recipient,
81-
Some(builder_signer),
81+
builder_signer,
8282
Arc::from(provider.root_hasher(parent_num_hash)?),
8383
evm_caching_enable,
8484
);

crates/rbuilder/src/backtest/restore_landed_orders/resim_landed_block.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
ThreadBlockBuildingContext,
66
},
77
provider::StateProviderFactory,
8-
utils::{extract_onchain_block_txs, find_suggested_fee_recipient, signed_uint_delta},
8+
utils::{extract_onchain_block_txs, find_suggested_fee_recipient, signed_uint_delta, Signer},
99
};
1010
use ahash::{HashMap, HashSet};
1111
use alloy_primitives::{TxHash, B256, I256};
@@ -45,14 +45,16 @@ where
4545
let coinbase = onchain_block.header.beneficiary;
4646
let parent_num_hash = onchain_block.header.parent_num_hash();
4747

48+
let builder_signer = Signer::random(); // signer will not be used here as we just replay onchain transactions
49+
4850
let ctx = BlockBuildingContext::from_onchain_block(
4951
onchain_block,
5052
chain_spec,
5153
None,
5254
HashSet::default(),
5355
coinbase,
5456
suggested_fee_recipient,
55-
None,
57+
builder_signer,
5658
Arc::from(provider.root_hasher(parent_num_hash)?),
5759
false,
5860
);

crates/rbuilder/src/bin/debug-bench-machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rbuilder::{
1212
},
1313
live_builder::{base_config::load_config_toml_and_env, cli::LiveBuilderConfig, config::Config},
1414
provider::StateProviderFactory,
15-
utils::{extract_onchain_block_txs, find_suggested_fee_recipient, http_provider},
15+
utils::{extract_onchain_block_txs, find_suggested_fee_recipient, http_provider, Signer},
1616
};
1717
use reth_provider::StateProvider;
1818
use std::{path::PathBuf, sync::Arc, time::Instant};
@@ -72,7 +72,7 @@ async fn main() -> eyre::Result<()> {
7272
Default::default(),
7373
coinbase,
7474
suggested_fee_recipient,
75-
None,
75+
Signer::random(),
7676
Arc::from(provider_factory.root_hasher(parent_num_hash)?),
7777
config.base_config().evm_caching_enable,
7878
);

crates/rbuilder/src/bin/run-bundle-on-prefix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl LandedBlockInfo {
137137
Default::default(),
138138
coinbase,
139139
suggested_fee_recipient,
140-
Some(signer),
140+
signer,
141141
Arc::new(MockRootHasher {}),
142142
false,
143143
))

crates/rbuilder/src/building/builders/block_building_helper.rs

Lines changed: 26 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ pub trait BlockBuildingHelper: Send + Sync {
5555
failed_orders_statistics: OrderStatistics,
5656
);
5757

58-
/// Only if can_add_payout_tx you can pass Some(payout_tx_value) to finalize_block (a little ugly could be improved...)
59-
fn can_add_payout_tx(&self) -> bool;
60-
6158
/// Accumulated coinbase delta - gas cost of final payout tx (if can_add_payout_tx).
6259
/// This is the maximum profit that can reach the final fee recipient (max bid!).
6360
/// Maximum payout_tx_value value to pass to finalize_block.
@@ -70,7 +67,7 @@ pub trait BlockBuildingHelper: Send + Sync {
7067
fn finalize_block(
7168
self: Box<Self>,
7269
local_ctx: &mut ThreadBlockBuildingContext,
73-
payout_tx_value: Option<U256>,
70+
payout_tx_value: U256,
7471
seen_competition_bid: Option<U256>,
7572
) -> Result<FinalizeBlockResult, BlockBuildingHelperError>;
7673

@@ -129,8 +126,7 @@ pub struct BlockBuildingHelperFromProvider<
129126
block_state: BlockState,
130127
partial_block: PartialBlock<GasUsedSimulationTracer, PartialBlockExecutionTracerType>,
131128
/// Gas reserved for the final payout txs from coinbase to fee recipient.
132-
/// None means we don't need this final tx since coinbase == fee recipient.
133-
payout_tx_gas: Option<u64>,
129+
payout_tx_gas: u64,
134130
/// Name of the builder that pregenerated this block.
135131
/// Might be ambiguous if several building parts were involved...
136132
builder_name: String,
@@ -154,8 +150,6 @@ pub enum BlockBuildingHelperError {
154150
BundleConsistencyCheckFailed(#[from] BuiltBlockTraceError),
155151
#[error("Error finalizing block: {0}")]
156152
FinalizeError(#[from] FinalizeError),
157-
#[error("Payout tx not allowed for block")]
158-
PayoutTxNotAllowed,
159153
#[error("Provider historical block hashes error: {0}")]
160154
HistoricalBlockError(#[from] HistoricalBlockError),
161155
}
@@ -235,19 +229,15 @@ impl<
235229
partial_block
236230
.pre_block_call(&building_ctx, local_ctx, &mut block_state)
237231
.map_err(|_| BlockBuildingHelperError::PreBlockCallFailed)?;
238-
let payout_tx_gas = if building_ctx.coinbase_is_suggested_fee_recipient() {
239-
None
240-
} else {
241-
let payout_tx_space = estimate_payout_gas_limit(
242-
building_ctx.attributes.suggested_fee_recipient,
243-
&building_ctx,
244-
local_ctx,
245-
&mut block_state,
246-
BlockSpace::ZERO,
247-
)?;
248-
partial_block.reserve_block_space(payout_tx_space);
249-
Some(payout_tx_space.gas())
250-
};
232+
let payout_tx_space = estimate_payout_gas_limit(
233+
building_ctx.attributes.suggested_fee_recipient,
234+
&building_ctx,
235+
local_ctx,
236+
&mut block_state,
237+
BlockSpace::ZERO,
238+
)?;
239+
partial_block.reserve_block_space(payout_tx_space);
240+
let payout_tx_gas = payout_tx_space.gas();
251241

252242
let mut built_block_trace = BuiltBlockTrace::new();
253243
built_block_trace.available_orders_statistics = available_orders_statistics;
@@ -296,8 +286,6 @@ impl<
296286
blobs,
297287
gas_used,
298288
sim_gas_used,
299-
use_suggested_fee_recipient_as_coinbase =
300-
building_ctx.coinbase_is_suggested_fee_recipient(),
301289
"Built block",
302290
);
303291
}
@@ -306,31 +294,20 @@ impl<
306294
fn finalize_block_execution(
307295
&mut self,
308296
local_ctx: &mut ThreadBlockBuildingContext,
309-
payout_tx_value: Option<U256>,
297+
payout_tx_value: U256,
310298
) -> Result<(), BlockBuildingHelperError> {
311299
self.built_block_trace.coinbase_reward = self.partial_block.coinbase_profit;
312300

313-
let (bid_value, true_value, use_last_tx_payment) =
314-
if let Some((payout_tx_gas, payout_tx_value)) = self.payout_tx_gas.zip(payout_tx_value)
315-
{
316-
self.partial_block.insert_refunds_and_proposer_payout_tx(
317-
payout_tx_gas,
318-
payout_tx_value,
319-
&self.building_ctx,
320-
local_ctx,
321-
&mut self.block_state,
322-
)?;
323-
(payout_tx_value, self.true_block_value()?, true)
324-
} else {
325-
(
326-
self.partial_block.coinbase_profit,
327-
self.partial_block.coinbase_profit,
328-
false,
329-
)
330-
};
301+
self.partial_block.insert_refunds_and_proposer_payout_tx(
302+
self.payout_tx_gas,
303+
payout_tx_value,
304+
&self.building_ctx,
305+
local_ctx,
306+
&mut self.block_state,
307+
)?;
308+
309+
let (bid_value, true_value) = (payout_tx_value, self.true_block_value()?);
331310

332-
// Since some extra money might arrived directly the suggested_fee_recipient (when suggested_fee_recipient != coinbase)
333-
// we check the fee_recipient delta and make our bid include that! This is supposed to be what the relay will check.
334311
let fee_recipient_balance_after = self.block_state.balance(
335312
self.building_ctx.attributes.suggested_fee_recipient,
336313
&self.building_ctx.shared_cached_reads,
@@ -340,18 +317,7 @@ impl<
340317
.checked_sub(self._fee_recipient_balance_start)
341318
.unwrap_or_default();
342319

343-
if use_last_tx_payment {
344-
self.built_block_trace.bid_value = max(bid_value, fee_recipient_balance_diff);
345-
} else {
346-
// When the coinbase address is the fee recipient, we exclusively use fee_recipient_balance_diff
347-
// since this is the value used by validation nodes
348-
//
349-
// Using fee_recipient_balance_diff may cause block validation failures in certain edge cases
350-
// Example: If the fee recipient is a contract that sweeps its balance to another address on each call,
351-
// and we include a bundle paying directly to coinbase, the fee recipient balance would be 0
352-
// causing validation nodes to reject the block
353-
self.built_block_trace.bid_value = fee_recipient_balance_diff;
354-
}
320+
self.built_block_trace.bid_value = max(bid_value, fee_recipient_balance_diff);
355321
self.built_block_trace.true_bid_value = true_value;
356322
Ok(())
357323
}
@@ -388,8 +354,6 @@ impl<
388354
)
389355
}
390356
Err(err) => {
391-
self.built_block_trace
392-
.modify_payment_when_no_signer_error(&err);
393357
self.built_block_trace.add_failed_order(order);
394358
(Ok(Err(err)), false)
395359
}
@@ -409,29 +373,18 @@ impl<
409373
self.built_block_trace.orders_closed_at = orders_closed_at;
410374
}
411375

412-
fn can_add_payout_tx(&self) -> bool {
413-
!self.building_ctx.coinbase_is_suggested_fee_recipient()
414-
}
415-
416376
fn true_block_value(&self) -> Result<U256, BlockBuildingHelperError> {
417-
if let Some(payout_tx_gas) = self.payout_tx_gas {
418-
Ok(self
419-
.partial_block
420-
.get_proposer_payout_tx_value(payout_tx_gas, &self.building_ctx)?)
421-
} else {
422-
Ok(self.partial_block.coinbase_profit)
423-
}
377+
Ok(self
378+
.partial_block
379+
.get_proposer_payout_tx_value(self.payout_tx_gas, &self.building_ctx)?)
424380
}
425381

426382
fn finalize_block(
427383
mut self: Box<Self>,
428384
local_ctx: &mut ThreadBlockBuildingContext,
429-
payout_tx_value: Option<U256>,
385+
payout_tx_value: U256,
430386
seen_competition_bid: Option<U256>,
431387
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
432-
if payout_tx_value.is_some() && self.building_ctx.coinbase_is_suggested_fee_recipient() {
433-
return Err(BlockBuildingHelperError::PayoutTxNotAllowed);
434-
}
435388
let start_time = Instant::now();
436389
let step_start = Instant::now();
437390

crates/rbuilder/src/building/builders/block_building_helper_stats_logger.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ impl BlockBuildingHelper for BlockBuildingHelperStatsLogger<'_> {
195195
.set_trace_orders_closed_at(orders_closed_at);
196196
}
197197

198-
fn can_add_payout_tx(&self) -> bool {
199-
self.block_building_helper.can_add_payout_tx()
200-
}
201-
202198
fn true_block_value(
203199
&self,
204200
) -> Result<alloy_primitives::U256, super::block_building_helper::BlockBuildingHelperError>
@@ -209,7 +205,7 @@ impl BlockBuildingHelper for BlockBuildingHelperStatsLogger<'_> {
209205
fn finalize_block(
210206
self: Box<Self>,
211207
_local_ctx: &mut crate::building::ThreadBlockBuildingContext,
212-
_payout_tx_value: Option<alloy_primitives::U256>,
208+
_payout_tx_value: alloy_primitives::U256,
213209
_seen_competition_bid: Option<alloy_primitives::U256>,
214210
) -> Result<
215211
super::block_building_helper::FinalizeBlockResult,

crates/rbuilder/src/building/builders/mock_block_building_helper.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,18 @@ use super::{
2727
pub struct MockBlockBuildingHelper {
2828
built_block_trace: BuiltBlockTrace,
2929
block_building_context: BlockBuildingContext,
30-
can_add_payout_tx: bool,
3130
builder_name: String,
3231
}
3332

3433
impl MockBlockBuildingHelper {
35-
pub fn new(true_block_value: U256, can_add_payout_tx: bool) -> Self {
34+
pub fn new(true_block_value: U256) -> Self {
3635
let built_block_trace = BuiltBlockTrace {
3736
true_bid_value: true_block_value,
3837
..Default::default()
3938
};
4039
Self {
4140
built_block_trace,
4241
block_building_context: BlockBuildingContext::dummy_for_testing(),
43-
can_add_payout_tx,
4442
builder_name: "Mock".to_string(),
4543
}
4644
}
@@ -79,27 +77,19 @@ impl BlockBuildingHelper for MockBlockBuildingHelper {
7977
self.built_block_trace.orders_closed_at = orders_closed_at;
8078
}
8179

82-
fn can_add_payout_tx(&self) -> bool {
83-
self.can_add_payout_tx
84-
}
85-
8680
fn true_block_value(&self) -> Result<U256, BlockBuildingHelperError> {
8781
Ok(self.built_block_trace.true_bid_value)
8882
}
8983

9084
fn finalize_block(
9185
mut self: Box<Self>,
9286
_local_ctx: &mut ThreadBlockBuildingContext,
93-
payout_tx_value: Option<U256>,
87+
payout_tx_value: U256,
9488
seen_competition_bid: Option<U256>,
9589
) -> Result<FinalizeBlockResult, BlockBuildingHelperError> {
9690
self.built_block_trace.update_orders_sealed_at();
9791
self.built_block_trace.seen_competition_bid = seen_competition_bid;
98-
self.built_block_trace.bid_value = if let Some(payout_tx_value) = payout_tx_value {
99-
payout_tx_value
100-
} else {
101-
self.built_block_trace.true_bid_value
102-
};
92+
self.built_block_trace.bid_value = payout_tx_value;
10393
let block = Block {
10494
builder_name: "BlockBuildingHelper".to_string(),
10595
trace: self.built_block_trace,

0 commit comments

Comments
 (0)