@@ -23,6 +23,7 @@ use reth_interfaces::{
23
23
use reth_node_api:: { ConfigureEvm , EngineTypes } ;
24
24
use reth_primitives:: {
25
25
constants:: { EMPTY_RECEIPTS , EMPTY_TRANSACTIONS , ETHEREUM_BLOCK_GAS_LIMIT } ,
26
+ eip4844:: calculate_excess_blob_gas,
26
27
proofs, Block , BlockBody , BlockHash , BlockHashOrNumber , BlockNumber , BlockWithSenders , Bloom ,
27
28
ChainSpec , Header , ReceiptWithBloom , SealedBlock , SealedHeader , TransactionSigned , B256 ,
28
29
EMPTY_OMMER_ROOT_HASH , U256 ,
@@ -303,6 +304,27 @@ impl StorageInner {
303
304
parent_beacon_block_root : None ,
304
305
} ;
305
306
307
+ if chain_spec. is_cancun_active_at_timestamp ( timestamp) {
308
+ let parent = self . headers . get ( & self . best_block ) ;
309
+ header. parent_beacon_block_root =
310
+ parent. and_then ( |parent| parent. parent_beacon_block_root ) ;
311
+ header. blob_gas_used = Some ( 0 ) ;
312
+
313
+ let ( parent_excess_blob_gas, parent_blob_gas_used) = match parent {
314
+ Some ( parent_block)
315
+ if chain_spec. is_cancun_active_at_timestamp ( parent_block. timestamp ) =>
316
+ {
317
+ (
318
+ parent_block. excess_blob_gas . unwrap_or_default ( ) ,
319
+ parent_block. blob_gas_used . unwrap_or_default ( ) ,
320
+ )
321
+ }
322
+ _ => ( 0 , 0 ) ,
323
+ } ;
324
+ header. excess_blob_gas =
325
+ Some ( calculate_excess_blob_gas ( parent_excess_blob_gas, parent_blob_gas_used) )
326
+ }
327
+
306
328
header. transactions_root = if transactions. is_empty ( ) {
307
329
EMPTY_TRANSACTIONS
308
330
} else {
@@ -354,6 +376,7 @@ impl StorageInner {
354
376
bundle_state : & BundleStateWithReceipts ,
355
377
client : & S ,
356
378
gas_used : u64 ,
379
+ blob_gas_used : Option < u64 > ,
357
380
#[ cfg( feature = "optimism" ) ] chain_spec : & ChainSpec ,
358
381
) -> Result < Header , BlockExecutionError > {
359
382
let receipts = bundle_state. receipts_by_block ( header. number ) ;
@@ -381,6 +404,7 @@ impl StorageInner {
381
404
} ;
382
405
383
406
header. gas_used = gas_used;
407
+ header. blob_gas_used = blob_gas_used;
384
408
385
409
// calculate the state root
386
410
let state_root = client
@@ -425,6 +449,17 @@ impl StorageInner {
425
449
let Block { header, body, .. } = block. block ;
426
450
let body = BlockBody { transactions : body, ommers : vec ! [ ] , withdrawals : None } ;
427
451
452
+ let mut blob_gas_used = None ;
453
+ if chain_spec. is_cancun_active_at_timestamp ( header. timestamp ) {
454
+ let mut sum_blob_gas_used = 0 ;
455
+ for tx in & body. transactions {
456
+ if let Some ( blob_tx) = tx. transaction . as_eip4844 ( ) {
457
+ sum_blob_gas_used += blob_tx. blob_gas ( ) ;
458
+ }
459
+ }
460
+ blob_gas_used = Some ( sum_blob_gas_used) ;
461
+ }
462
+
428
463
trace ! ( target: "consensus::auto" , ?bundle_state, ?header, ?body, "executed block, calculating state root and completing header" ) ;
429
464
430
465
// fill in the rest of the fields
@@ -433,6 +468,7 @@ impl StorageInner {
433
468
& bundle_state,
434
469
client,
435
470
gas_used,
471
+ blob_gas_used,
436
472
#[ cfg( feature = "optimism" ) ]
437
473
chain_spec. as_ref ( ) ,
438
474
) ?;
0 commit comments