From a55cf1abdfe480ce5a8d95dbefc41647865120e5 Mon Sep 17 00:00:00 2001 From: File Large Date: Wed, 1 Oct 2025 12:39:31 +0200 Subject: [PATCH 1/3] feat: whitelisted system senders --- crates/rbuilder/src/building/mod.rs | 4 ++++ crates/rbuilder/src/building/order_commit.rs | 11 ++++++++++- .../rbuilder/src/building/testing/test_chain_state.rs | 1 + crates/rbuilder/src/live_builder/base_config.rs | 5 +++++ crates/rbuilder/src/live_builder/mod.rs | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/rbuilder/src/building/mod.rs b/crates/rbuilder/src/building/mod.rs index b583f10ee..cf276685f 100644 --- a/crates/rbuilder/src/building/mod.rs +++ b/crates/rbuilder/src/building/mod.rs @@ -120,6 +120,7 @@ pub struct BlockBuildingContext { pub mempool_tx_detector: Arc, pub faster_finalize: bool, pub adjustment_fee_payers: ahash::HashSet
, + pub whitelisted_system_senders: Vec
, /// Cached from evm_env.block_env.number but as BlockNumber. Avoid conversions all over the code. block_number: BlockNumber, } @@ -142,6 +143,7 @@ impl BlockBuildingContext { payload_id: InternalPayloadId, evm_caching_enable: bool, faster_finalize: bool, + whitelisted_system_senders: Vec
, adjustment_fee_payers: ahash::HashSet
, ) -> Option { let attributes = EthPayloadBuilderAttributes::try_new( @@ -216,6 +218,7 @@ impl BlockBuildingContext { max_blob_gas_per_block, mempool_tx_detector: Arc::new(MempoolTxsDetector::new()), faster_finalize, + whitelisted_system_senders, adjustment_fee_payers, block_number, }) @@ -321,6 +324,7 @@ impl BlockBuildingContext { max_blob_gas_per_block, mempool_tx_detector: Arc::new(MempoolTxsDetector::new()), faster_finalize: true, + whitelisted_system_senders: Default::default(), adjustment_fee_payers: Default::default(), block_number, } diff --git a/crates/rbuilder/src/building/order_commit.rs b/crates/rbuilder/src/building/order_commit.rs index 6e7b1f686..e74e14292 100644 --- a/crates/rbuilder/src/building/order_commit.rs +++ b/crates/rbuilder/src/building/order_commit.rs @@ -695,6 +695,15 @@ impl< logs: res.result.logs().to_vec(), }; let coinbase_balance_after = I256::try_from(self.coinbase_balance()?)?; + let coinbase_profit = if self + .ctx + .whitelisted_system_senders + .contains(tx.signer_ref()) + { + I256::ZERO + } else { + coinbase_balance_after - coinbase_balance_before + }; Ok(Ok(TransactionOk { exec_result: res.result, cumulative_space_used: space_state.space_used(), @@ -702,7 +711,7 @@ impl< tx: tx_with_blobs.clone(), receipt, space_used, - coinbase_profit: coinbase_balance_after - coinbase_balance_before, + coinbase_profit, }, nonce_updated: (tx.signer(), tx.nonce() + 1), })) diff --git a/crates/rbuilder/src/building/testing/test_chain_state.rs b/crates/rbuilder/src/building/testing/test_chain_state.rs index a73120433..1d6494756 100644 --- a/crates/rbuilder/src/building/testing/test_chain_state.rs +++ b/crates/rbuilder/src/building/testing/test_chain_state.rs @@ -408,6 +408,7 @@ impl TestBlockContextBuilder { true, true, Default::default(), + Default::default(), ) .unwrap() } diff --git a/crates/rbuilder/src/live_builder/base_config.rs b/crates/rbuilder/src/live_builder/base_config.rs index 268256a49..1efa780ac 100644 --- a/crates/rbuilder/src/live_builder/base_config.rs +++ b/crates/rbuilder/src/live_builder/base_config.rs @@ -143,6 +143,9 @@ pub struct BaseConfig { /// See [OrderPool::time_to_keep_mempool_txs] pub time_to_keep_mempool_txs_secs: u64, + /// The array of senders incoming transactions from which will not be counted towards the coinbase profit. + pub whitelisted_system_senders: Vec
, + // backtest config backtest_fetch_mempool_data_dir: EnvOrValue, pub backtest_fetch_eth_rpc_url: String, @@ -220,6 +223,7 @@ impl BaseConfig { coinbase_signer: self.coinbase_signer()?, extra_data: self.extra_data.clone(), blocklist_provider, + whitelisted_system_senders: self.whitelisted_system_senders.clone(), global_cancellation: cancellation_token, @@ -495,6 +499,7 @@ impl Default for BaseConfig { evm_caching_enable: false, faster_finalize: false, time_to_keep_mempool_txs_secs: DEFAULT_TIME_TO_KEEP_MEMPOOL_TXS_SECS, + whitelisted_system_senders: Vec::new(), } } } diff --git a/crates/rbuilder/src/live_builder/mod.rs b/crates/rbuilder/src/live_builder/mod.rs index 153f9b1a6..0cc4ce7d7 100644 --- a/crates/rbuilder/src/live_builder/mod.rs +++ b/crates/rbuilder/src/live_builder/mod.rs @@ -129,6 +129,8 @@ where pub evm_caching_enable: bool, pub faster_finalize: bool, pub simulation_use_random_coinbase: bool, + + pub whitelisted_system_senders: Vec
, } impl

LiveBuilder

@@ -304,6 +306,7 @@ where payload.payload_id, self.evm_caching_enable, self.faster_finalize, + self.whitelisted_system_senders.clone(), payload .relay_registrations .iter() From 286fef305b390ad1529208bf8752f03c1f1f5e43 Mon Sep 17 00:00:00 2001 From: File Large Date: Wed, 1 Oct 2025 15:53:15 +0200 Subject: [PATCH 2/3] change to whitelisted system recipients --- crates/rbuilder/src/building/mod.rs | 8 ++++---- crates/rbuilder/src/building/order_commit.rs | 20 +++++++++---------- .../rbuilder/src/live_builder/base_config.rs | 6 +++--- crates/rbuilder/src/live_builder/mod.rs | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/rbuilder/src/building/mod.rs b/crates/rbuilder/src/building/mod.rs index cf276685f..ae298de4a 100644 --- a/crates/rbuilder/src/building/mod.rs +++ b/crates/rbuilder/src/building/mod.rs @@ -120,7 +120,7 @@ pub struct BlockBuildingContext { pub mempool_tx_detector: Arc, pub faster_finalize: bool, pub adjustment_fee_payers: ahash::HashSet

, - pub whitelisted_system_senders: Vec
, + pub whitelisted_system_recipients: Vec
, /// Cached from evm_env.block_env.number but as BlockNumber. Avoid conversions all over the code. block_number: BlockNumber, } @@ -143,7 +143,7 @@ impl BlockBuildingContext { payload_id: InternalPayloadId, evm_caching_enable: bool, faster_finalize: bool, - whitelisted_system_senders: Vec
, + whitelisted_system_recipients: Vec
, adjustment_fee_payers: ahash::HashSet
, ) -> Option { let attributes = EthPayloadBuilderAttributes::try_new( @@ -218,7 +218,7 @@ impl BlockBuildingContext { max_blob_gas_per_block, mempool_tx_detector: Arc::new(MempoolTxsDetector::new()), faster_finalize, - whitelisted_system_senders, + whitelisted_system_recipients, adjustment_fee_payers, block_number, }) @@ -324,7 +324,7 @@ impl BlockBuildingContext { max_blob_gas_per_block, mempool_tx_detector: Arc::new(MempoolTxsDetector::new()), faster_finalize: true, - whitelisted_system_senders: Default::default(), + whitelisted_system_recipients: Default::default(), adjustment_fee_payers: Default::default(), block_number, } diff --git a/crates/rbuilder/src/building/order_commit.rs b/crates/rbuilder/src/building/order_commit.rs index e74e14292..e1b544e30 100644 --- a/crates/rbuilder/src/building/order_commit.rs +++ b/crates/rbuilder/src/building/order_commit.rs @@ -695,15 +695,6 @@ impl< logs: res.result.logs().to_vec(), }; let coinbase_balance_after = I256::try_from(self.coinbase_balance()?)?; - let coinbase_profit = if self - .ctx - .whitelisted_system_senders - .contains(tx.signer_ref()) - { - I256::ZERO - } else { - coinbase_balance_after - coinbase_balance_before - }; Ok(Ok(TransactionOk { exec_result: res.result, cumulative_space_used: space_state.space_used(), @@ -711,7 +702,7 @@ impl< tx: tx_with_blobs.clone(), receipt, space_used, - coinbase_profit, + coinbase_profit: coinbase_balance_after - coinbase_balance_before, }, nonce_updated: (tx.signer(), tx.nonce() + 1), })) @@ -1239,6 +1230,15 @@ impl< Ok(ok) => { let coinbase_profit = if !ok.tx_info.coinbase_profit.is_negative() { ok.tx_info.coinbase_profit.unsigned_abs() + } else if order.list_txs().first().is_some_and(|(tx, _)| { + order.list_txs_len() == 1 + && tx.signer() == self.ctx.builder_signer.address + && tx.to().is_some_and(|to| { + self.ctx.whitelisted_system_recipients.contains(&to) + }) + }) { + // This is a system transaction which should not be counted towards the block profit. + U256::ZERO } else { return Ok(Err(OrderErr::NegativeProfit( ok.tx_info.coinbase_profit.unsigned_abs(), diff --git a/crates/rbuilder/src/live_builder/base_config.rs b/crates/rbuilder/src/live_builder/base_config.rs index 1efa780ac..2e398d68b 100644 --- a/crates/rbuilder/src/live_builder/base_config.rs +++ b/crates/rbuilder/src/live_builder/base_config.rs @@ -144,7 +144,7 @@ pub struct BaseConfig { pub time_to_keep_mempool_txs_secs: u64, /// The array of senders incoming transactions from which will not be counted towards the coinbase profit. - pub whitelisted_system_senders: Vec
, + pub whitelisted_system_recipients: Vec
, // backtest config backtest_fetch_mempool_data_dir: EnvOrValue, @@ -223,7 +223,7 @@ impl BaseConfig { coinbase_signer: self.coinbase_signer()?, extra_data: self.extra_data.clone(), blocklist_provider, - whitelisted_system_senders: self.whitelisted_system_senders.clone(), + whitelisted_system_recipients: self.whitelisted_system_recipients.clone(), global_cancellation: cancellation_token, @@ -499,7 +499,7 @@ impl Default for BaseConfig { evm_caching_enable: false, faster_finalize: false, time_to_keep_mempool_txs_secs: DEFAULT_TIME_TO_KEEP_MEMPOOL_TXS_SECS, - whitelisted_system_senders: Vec::new(), + whitelisted_system_recipients: Vec::new(), } } } diff --git a/crates/rbuilder/src/live_builder/mod.rs b/crates/rbuilder/src/live_builder/mod.rs index 0cc4ce7d7..e62fca840 100644 --- a/crates/rbuilder/src/live_builder/mod.rs +++ b/crates/rbuilder/src/live_builder/mod.rs @@ -130,7 +130,7 @@ where pub faster_finalize: bool, pub simulation_use_random_coinbase: bool, - pub whitelisted_system_senders: Vec
, + pub whitelisted_system_recipients: Vec
, } impl

LiveBuilder

@@ -306,7 +306,7 @@ where payload.payload_id, self.evm_caching_enable, self.faster_finalize, - self.whitelisted_system_senders.clone(), + self.whitelisted_system_recipients.clone(), payload .relay_registrations .iter() From 7c918c703eff39db3c912a50473e72c473e129c0 Mon Sep 17 00:00:00 2001 From: Daniel Xifra Date: Wed, 1 Oct 2025 11:04:26 -0300 Subject: [PATCH 3/3] min improvement --- crates/rbuilder/src/building/order_commit.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/rbuilder/src/building/order_commit.rs b/crates/rbuilder/src/building/order_commit.rs index e1b544e30..1264a8fea 100644 --- a/crates/rbuilder/src/building/order_commit.rs +++ b/crates/rbuilder/src/building/order_commit.rs @@ -1230,13 +1230,11 @@ impl< Ok(ok) => { let coinbase_profit = if !ok.tx_info.coinbase_profit.is_negative() { ok.tx_info.coinbase_profit.unsigned_abs() - } else if order.list_txs().first().is_some_and(|(tx, _)| { - order.list_txs_len() == 1 - && tx.signer() == self.ctx.builder_signer.address - && tx.to().is_some_and(|to| { - self.ctx.whitelisted_system_recipients.contains(&to) - }) - }) { + } else if tx.tx_with_blobs.signer() == self.ctx.builder_signer.address + && tx.tx_with_blobs.to().is_some_and(|to| { + self.ctx.whitelisted_system_recipients.contains(&to) + }) + { // This is a system transaction which should not be counted towards the block profit. U256::ZERO } else {