@@ -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
0 commit comments