Skip to content

Commit 91844e3

Browse files
efbigZanCorDX
andauthored
feat: whitelisted system recipients (#738)
## πŸ“ Summary Add ability to specify whitelisted system recipients. If the transaction is from the builder signer to the recipient, the value would not be counted towards block profit. ## βœ… I have completed the following steps: * [x] Run `make lint` * [x] Run `make test` * [ ] Added tests (if applicable) --------- Co-authored-by: Daniel Xifra <daniel@xifra.dev>
1 parent 8ee8dd5 commit 91844e3

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub struct BlockBuildingContext {
120120
pub mempool_tx_detector: Arc<MempoolTxsDetector>,
121121
pub faster_finalize: bool,
122122
pub adjustment_fee_payers: ahash::HashSet<Address>,
123+
pub whitelisted_system_recipients: Vec<Address>,
123124
/// Cached from evm_env.block_env.number but as BlockNumber. Avoid conversions all over the code.
124125
block_number: BlockNumber,
125126
}
@@ -142,6 +143,7 @@ impl BlockBuildingContext {
142143
payload_id: InternalPayloadId,
143144
evm_caching_enable: bool,
144145
faster_finalize: bool,
146+
whitelisted_system_recipients: Vec<Address>,
145147
adjustment_fee_payers: ahash::HashSet<Address>,
146148
) -> Option<BlockBuildingContext> {
147149
let attributes = EthPayloadBuilderAttributes::try_new(
@@ -216,6 +218,7 @@ impl BlockBuildingContext {
216218
max_blob_gas_per_block,
217219
mempool_tx_detector: Arc::new(MempoolTxsDetector::new()),
218220
faster_finalize,
221+
whitelisted_system_recipients,
219222
adjustment_fee_payers,
220223
block_number,
221224
})
@@ -321,6 +324,7 @@ impl BlockBuildingContext {
321324
max_blob_gas_per_block,
322325
mempool_tx_detector: Arc::new(MempoolTxsDetector::new()),
323326
faster_finalize: true,
327+
whitelisted_system_recipients: Default::default(),
324328
adjustment_fee_payers: Default::default(),
325329
block_number,
326330
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,13 @@ impl<
12301230
Ok(ok) => {
12311231
let coinbase_profit = if !ok.tx_info.coinbase_profit.is_negative() {
12321232
ok.tx_info.coinbase_profit.unsigned_abs()
1233+
} else if tx.tx_with_blobs.signer() == self.ctx.builder_signer.address
1234+
&& tx.tx_with_blobs.to().is_some_and(|to| {
1235+
self.ctx.whitelisted_system_recipients.contains(&to)
1236+
})
1237+
{
1238+
// This is a system transaction which should not be counted towards the block profit.
1239+
U256::ZERO
12331240
} else {
12341241
return Ok(Err(OrderErr::NegativeProfit(
12351242
ok.tx_info.coinbase_profit.unsigned_abs(),

β€Žcrates/rbuilder/src/building/testing/test_chain_state.rsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl TestBlockContextBuilder {
408408
true,
409409
true,
410410
Default::default(),
411+
Default::default(),
411412
)
412413
.unwrap()
413414
}

β€Žcrates/rbuilder/src/live_builder/base_config.rsβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ pub struct BaseConfig {
143143
/// See [OrderPool::time_to_keep_mempool_txs]
144144
pub time_to_keep_mempool_txs_secs: u64,
145145

146+
/// The array of senders incoming transactions from which will not be counted towards the coinbase profit.
147+
pub whitelisted_system_recipients: Vec<Address>,
148+
146149
// backtest config
147150
backtest_fetch_mempool_data_dir: EnvOrValue<String>,
148151
pub backtest_fetch_eth_rpc_url: String,
@@ -220,6 +223,7 @@ impl BaseConfig {
220223
coinbase_signer: self.coinbase_signer()?,
221224
extra_data: self.extra_data.clone(),
222225
blocklist_provider,
226+
whitelisted_system_recipients: self.whitelisted_system_recipients.clone(),
223227

224228
global_cancellation: cancellation_token,
225229

@@ -495,6 +499,7 @@ impl Default for BaseConfig {
495499
evm_caching_enable: false,
496500
faster_finalize: false,
497501
time_to_keep_mempool_txs_secs: DEFAULT_TIME_TO_KEEP_MEMPOOL_TXS_SECS,
502+
whitelisted_system_recipients: Vec::new(),
498503
}
499504
}
500505
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ where
129129
pub evm_caching_enable: bool,
130130
pub faster_finalize: bool,
131131
pub simulation_use_random_coinbase: bool,
132+
133+
pub whitelisted_system_recipients: Vec<Address>,
132134
}
133135

134136
impl<P> LiveBuilder<P>
@@ -304,6 +306,7 @@ where
304306
payload.payload_id,
305307
self.evm_caching_enable,
306308
self.faster_finalize,
309+
self.whitelisted_system_recipients.clone(),
307310
payload
308311
.relay_registrations
309312
.iter()

0 commit comments

Comments
Β (0)