@@ -11,12 +11,12 @@ use alloy_trie::{
1111 root:: ordered_trie_root_with_encoder,
1212 { Nibbles , TrieAccount } ,
1313} ;
14- use constants:: { BLOB_BASE_FEE_UPDATE_FRACTION , MIN_BASE_FEE_PER_BLOB_GAS } ;
1514use eyre:: Result ;
1615use futures:: future:: try_join_all;
17- use revm:: primitives:: KECCAK_EMPTY ;
16+ use revm:: primitives:: { BlobExcessGasAndPrice , KECCAK_EMPTY } ;
1817use tracing:: warn;
1918
19+ use crate :: fork_schedule:: ForkSchedule ;
2020use crate :: network_spec:: NetworkSpec ;
2121use crate :: types:: BlockTag ;
2222
@@ -37,12 +37,17 @@ pub mod types;
3737pub struct ExecutionClient < N : NetworkSpec , R : ExecutionRpc < N > > {
3838 pub rpc : R ,
3939 state : State < N , R > ,
40+ fork_schedule : ForkSchedule ,
4041}
4142
4243impl < N : NetworkSpec , R : ExecutionRpc < N > > ExecutionClient < N , R > {
43- pub fn new ( rpc : & str , state : State < N , R > ) -> Result < Self > {
44+ pub fn new ( rpc : & str , state : State < N , R > , fork_schedule : ForkSchedule ) -> Result < Self > {
4445 let rpc: R = ExecutionRpc :: new ( rpc) ?;
45- Ok ( ExecutionClient :: < N , R > { rpc, state } )
46+ Ok ( ExecutionClient :: < N , R > {
47+ rpc,
48+ state,
49+ fork_schedule,
50+ } )
4651 }
4752
4853 pub async fn check_rpc ( & self , chain_id : u64 ) -> Result < ( ) > {
@@ -157,42 +162,21 @@ impl<N: NetworkSpec, R: ExecutionRpc<N>> ExecutionClient<N, R> {
157162
158163 pub async fn blob_base_fee ( & self , block : BlockTag ) -> U256 {
159164 let block = self . state . get_block ( block) . await ;
160- if block . is_none ( ) {
165+ let Some ( block ) = block else {
161166 warn ! ( target: "helios::execution" , "requested block not found" ) ;
162167 return U256 :: from ( 0 ) ;
163- }
164- let parent_hash = block. unwrap ( ) . header ( ) . parent_hash ( ) ;
168+ } ;
169+
170+ let parent_hash = block. header ( ) . parent_hash ( ) ;
165171 let parent_block = self . get_block_by_hash ( parent_hash, false ) . await ;
166172 if parent_block. is_none ( ) {
167173 warn ! ( target: "helios::execution" , "requested parent block not foundß" ) ;
168174 return U256 :: from ( 0 ) ;
169175 } ;
170176
171- let blob_base_fee = Self :: calculate_base_fee_per_blob_gas (
172- parent_block. unwrap ( ) . header ( ) . excess_blob_gas ( ) . unwrap ( ) ,
173- ) ;
174-
175- U256 :: from ( blob_base_fee)
176- }
177-
178- fn calculate_base_fee_per_blob_gas ( parent_excess_blob_gas : u64 ) -> u64 {
179- Self :: fake_exponential (
180- MIN_BASE_FEE_PER_BLOB_GAS ,
181- parent_excess_blob_gas,
182- BLOB_BASE_FEE_UPDATE_FRACTION ,
183- )
184- }
185- //https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md#helpers
186- fn fake_exponential ( factor : u64 , numerator : u64 , denominator : u64 ) -> u64 {
187- let mut i = 1 ;
188- let mut output = 0 ;
189- let mut numerator_accum = factor * denominator;
190- while numerator_accum > 0 {
191- output += numerator_accum;
192- numerator_accum = numerator_accum * numerator / ( denominator * i) ;
193- i += 1 ;
194- }
195- output / denominator
177+ let excess_blob_gas = parent_block. unwrap ( ) . header ( ) . excess_blob_gas ( ) . unwrap ( ) ;
178+ let is_prague = block. header ( ) . timestamp ( ) >= self . fork_schedule . prague_timestamp ;
179+ U256 :: from ( BlobExcessGasAndPrice :: new ( excess_blob_gas, is_prague) . blob_gasprice )
196180 }
197181
198182 pub async fn get_block_by_hash ( & self , hash : B256 , full_tx : bool ) -> Option < N :: BlockResponse > {
0 commit comments