Skip to content

Commit 71b9741

Browse files
committed
add blob_gas_used to space used
1 parent 00137c2 commit 71b9741

File tree

15 files changed

+78
-117
lines changed

15 files changed

+78
-117
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ where
159159
println!(
160160
"{:>74} gas: {:>8} profit: {}",
161161
order_result.order.id().to_string(),
162-
order_result.space_used.gas(),
162+
order_result.space_used.gas,
163163
format_ether(order_result.coinbase_profit),
164164
);
165165
if let Order::Bundle(_) | Order::ShareBundle(_) = order_result.order {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ where
9191
&mut local_ctx.cached_reads,
9292
)?;
9393
let coinbase_profit = signed_uint_delta(coinbase_balance_after, coinbase_balance_before);
94-
space_state.use_space(result.space_used(), result.blob_gas_used);
94+
space_state.use_space(result.space_used());
9595

9696
let mut conflicting_txs: HashMap<B256, Vec<SlotKey>> = HashMap::default();
9797
for (slot, _) in accumulator_tracer.used_state_trace.read_slot_values {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async fn main() -> eyre::Result<()> {
105105
format!("Failed to commit tx: {} {:?}", idx, tx.hash())
106106
})?
107107
};
108-
space_state.use_space(result.space_used(), result.blob_gas_used);
108+
space_state.use_space(result.space_used());
109109
}
110110

111111
let build_time = build_time.elapsed();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<
258258
BlockSpace::ZERO,
259259
)?;
260260
partial_block.reserve_block_space(payout_tx_space);
261-
let payout_tx_gas = payout_tx_space.gas();
261+
let payout_tx_gas = payout_tx_space.gas;
262262

263263
let mut built_block_trace = BuiltBlockTrace::new();
264264
built_block_trace.available_orders_statistics = available_orders_statistics;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl BlockBuildingHelperCommitLog {
6060
Some(ExecutionResult {
6161
landed_tx_count: exec_ok.tx_infos.len(),
6262
coinbase_profit: exec_ok.coinbase_profit,
63-
gas_used: exec_ok.space_used.gas(),
63+
gas_used: exec_ok.space_used.gas,
6464
})
6565
} else {
6666
None

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl OrderingBuilderContext {
387387
let success = commit_result.is_ok();
388388
match commit_result {
389389
Ok(res) => {
390-
gas_used = res.space_used.gas();
390+
gas_used = res.space_used.gas;
391391
// This intermediate step is needed until we replace all (Address, u64) for AccountNonce
392392
let nonces_updated: Vec<_> = res
393393
.nonces_updated

crates/rbuilder/src/building/builders/parallel_builder/block_building_result_assembler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl BlockBuildingResultAssembler {
224224
let success = commit_result.is_ok();
225225
match commit_result {
226226
Ok(res) => {
227-
gas_used = res.space_used.gas();
227+
gas_used = res.space_used.gas;
228228
}
229229
Err(err) => execution_error = Some(err),
230230
}
@@ -285,7 +285,7 @@ impl BlockBuildingResultAssembler {
285285
tracing::trace!(
286286
order_id = ?sim_order.id(),
287287
success = true,
288-
gas_used = res.space_used.gas(),
288+
gas_used = res.space_used.gas,
289289
"Executed order in backtest"
290290
);
291291
}

crates/rbuilder/src/building/conflict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn find_conflict_slow(
8888
let mut space_state = BlockBuildingSpaceState::ZERO;
8989
match fork.commit_order(order1, space_state, true, &combined_refunds)? {
9090
Ok(res) => {
91-
space_state.use_space(res.space_used, res.blob_gas_used);
91+
space_state.use_space(res.space_used);
9292
}
9393
Err(_) => {
9494
results.insert(pair, Conflict::Fatal);

crates/rbuilder/src/building/mod.rs

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -469,38 +469,36 @@ impl PartialBlockForkExecutionTracer for NullPartialBlockExecutionTracer {
469469
}
470470

471471
/// Models consumed/reserved space on a block to be able to insert payout tx when finished filling the block.
472-
/// @Pending: Add blob gas?
473472
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
474473
pub struct BlockSpace {
475474
pub gas: u64,
476475
/// EIP-7934 limits the size of the final rlp block.
477476
/// Estimation of the sum of the rlp txs sizes.
478477
pub rlp_length: usize,
478+
pub blob_gas: u64,
479479
}
480480

481481
impl BlockSpace {
482-
pub fn new(gas: u64, rlp_length: usize) -> Self {
483-
Self { gas, rlp_length }
482+
pub fn new(gas: u64, rlp_length: usize, blob_gas: u64) -> Self {
483+
Self {
484+
gas,
485+
rlp_length,
486+
blob_gas,
487+
}
484488
}
485489

486490
pub const ZERO: Self = Self {
487491
gas: 0,
488492
rlp_length: 0,
493+
blob_gas: 0,
489494
};
490-
491-
pub fn gas(&self) -> u64 {
492-
self.gas
493-
}
494-
495-
pub fn rlp_length(&self) -> usize {
496-
self.rlp_length
497-
}
498495
}
499496

500497
impl AddAssign for BlockSpace {
501498
fn add_assign(&mut self, other: Self) {
502499
self.gas += other.gas;
503500
self.rlp_length += other.rlp_length;
501+
self.blob_gas += other.blob_gas;
504502
}
505503
}
506504

@@ -511,6 +509,7 @@ impl Add for BlockSpace {
511509
Self {
512510
gas: self.gas + other.gas,
513511
rlp_length: self.rlp_length + other.rlp_length,
512+
blob_gas: self.blob_gas + other.blob_gas,
514513
}
515514
}
516515
}
@@ -521,26 +520,19 @@ pub struct BlockBuildingSpaceState {
521520
space_used: BlockSpace,
522521
/// Reserved gas/size for later use (usually final payout tx). When simulating we subtract this from the block gas limit.
523522
reserved_block_space: BlockSpace,
524-
blob_gas_used: u64,
525523
}
526524

527525
impl BlockBuildingSpaceState {
528-
pub fn new(
529-
space_used: BlockSpace,
530-
reserved_block_space: BlockSpace,
531-
blob_gas_used: u64,
532-
) -> Self {
526+
pub fn new(space_used: BlockSpace, reserved_block_space: BlockSpace) -> Self {
533527
Self {
534528
space_used,
535529
reserved_block_space,
536-
blob_gas_used,
537530
}
538531
}
539532

540533
pub const ZERO: Self = Self {
541534
space_used: BlockSpace::ZERO,
542535
reserved_block_space: BlockSpace::ZERO,
543-
blob_gas_used: 0,
544536
};
545537

546538
pub fn free_reserved_block_space(&mut self) {
@@ -557,11 +549,11 @@ impl BlockBuildingSpaceState {
557549
}
558550

559551
pub fn gas_used(&self) -> u64 {
560-
self.space_used.gas()
552+
self.space_used.gas
561553
}
562554

563555
pub fn blob_gas_used(&self) -> u64 {
564-
self.blob_gas_used
556+
self.space_used.blob_gas
565557
}
566558

567559
pub fn space_used(&self) -> BlockSpace {
@@ -572,9 +564,8 @@ impl BlockBuildingSpaceState {
572564
self.reserved_block_space += space;
573565
}
574566

575-
pub fn use_space(&mut self, space: BlockSpace, blob_gas_used: u64) {
567+
pub fn use_space(&mut self, space: BlockSpace) {
576568
self.space_used += space;
577-
self.blob_gas_used += blob_gas_used;
578569
}
579570
}
580571

@@ -788,8 +779,7 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
788779
}
789780
}
790781

791-
self.space_state
792-
.use_space(ok_result.space_used, ok_result.blob_gas_used);
782+
self.space_state.use_space(ok_result.space_used);
793783
self.coinbase_profit += ok_result.coinbase_profit;
794784
self.executed_tx_infos.extend(ok_result.tx_infos.clone());
795785

@@ -879,8 +869,7 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
879869
return Err(InsertPayoutTxErr::CombinedRefundTxReverted);
880870
}
881871

882-
self.space_state
883-
.use_space(refund_result.space_used(), refund_result.blob_gas_used);
872+
self.space_state.use_space(refund_result.space_used());
884873
self.executed_tx_infos.push(refund_result.tx_info);
885874

886875
nonce += 1;
@@ -903,8 +892,7 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
903892
return Err(InsertPayoutTxErr::PayoutTxReverted);
904893
}
905894

906-
self.space_state
907-
.use_space(ok_result.space_used(), ok_result.blob_gas_used);
895+
self.space_state.use_space(ok_result.space_used());
908896
self.executed_tx_infos.push(ok_result.tx_info);
909897

910898
Ok(())
@@ -957,8 +945,7 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
957945
return Err(InsertPayoutTxErr::CombinedRefundTxReverted);
958946
}
959947

960-
self.space_state
961-
.use_space(refund_result.space_used(), refund_result.blob_gas_used);
948+
self.space_state.use_space(refund_result.space_used());
962949
self.executed_tx_infos.push(refund_result.tx_info);
963950

964951
nonce += 1;
@@ -997,8 +984,7 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
997984
return Err(InsertPayoutTxErr::PayoutTxReverted);
998985
}
999986

1000-
self.space_state
1001-
.use_space(ok_result.space_used(), ok_result.blob_gas_used);
987+
self.space_state.use_space(ok_result.space_used());
1002988
self.executed_tx_infos.push(ok_result.tx_info);
1003989

1004990
Ok(())
@@ -1353,13 +1339,11 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
13531339
state: &mut BlockState,
13541340
) -> eyre::Result<()> {
13551341
// We "pre-use" the RLP overhead for the withdrawals and the block header.
1356-
self.space_state.use_space(
1357-
BlockSpace::new(
1358-
0,
1359-
ctx.attributes.withdrawals.length() + BLOCK_HEADER_RLP_OVERHEAD,
1360-
),
1342+
self.space_state.use_space(BlockSpace::new(
13611343
0,
1362-
);
1344+
ctx.attributes.withdrawals.length() + BLOCK_HEADER_RLP_OVERHEAD,
1345+
0,
1346+
));
13631347

13641348
let mut db = state.new_db_ref(&ctx.shared_cached_reads, &mut local_ctx.cached_reads);
13651349
let mut system_caller = SystemCaller::new(ctx.chain_spec.clone());
@@ -1448,7 +1432,6 @@ pub fn create_sim_value(
14481432
order_ok.coinbase_profit,
14491433
non_mempool_coinbase_profit,
14501434
order_ok.space_used,
1451-
order_ok.blob_gas_used,
14521435
order_ok.paid_kickbacks.clone(),
14531436
)
14541437
}
@@ -1480,19 +1463,17 @@ mod test {
14801463
coinbase_profit: Default::default(),
14811464
space_used: Default::default(),
14821465
cumulative_space_used: Default::default(),
1483-
blob_gas_used: Default::default(),
1484-
cumulative_blob_gas_used: Default::default(),
14851466
tx_infos: vec![
14861467
TransactionExecutionInfo {
14871468
tx: tx1,
14881469
receipt: Default::default(),
1489-
gas_used: Default::default(),
1470+
space_used: Default::default(),
14901471
coinbase_profit: profit_1,
14911472
},
14921473
TransactionExecutionInfo {
14931474
tx: tx2,
14941475
receipt: Default::default(),
1495-
gas_used: Default::default(),
1476+
space_used: Default::default(),
14961477
coinbase_profit: profit_2,
14971478
},
14981479
],
@@ -1531,12 +1512,10 @@ mod test {
15311512
coinbase_profit: profit.unsigned_abs(),
15321513
space_used: Default::default(),
15331514
cumulative_space_used: Default::default(),
1534-
blob_gas_used: Default::default(),
1535-
cumulative_blob_gas_used: Default::default(),
15361515
tx_infos: vec![TransactionExecutionInfo {
15371516
tx,
15381517
receipt: Default::default(),
1539-
gas_used: Default::default(),
1518+
space_used: Default::default(),
15401519
coinbase_profit: profit,
15411520
}],
15421521
delayed_kickback: None,

0 commit comments

Comments
 (0)