Skip to content

Commit b927b3f

Browse files
committed
resolve merge conflicts
1 parent c3afbbd commit b927b3f

File tree

15 files changed

+112
-58
lines changed

15 files changed

+112
-58
lines changed

core/src/client/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::client::node::Node;
1111
#[cfg(not(target_arch = "wasm32"))]
1212
use crate::client::rpc::Rpc;
1313
use crate::consensus::Consensus;
14+
use crate::fork_schedule::ForkSchedule;
1415
use crate::network_spec::NetworkSpec;
1516
use crate::time::interval;
1617
use crate::types::BlockTag;
@@ -29,9 +30,10 @@ impl<N: NetworkSpec, C: Consensus<N::BlockResponse>> Client<N, C> {
2930
pub fn new(
3031
execution_rpc: &str,
3132
consensus: C,
33+
fork_schedule: ForkSchedule,
3234
#[cfg(not(target_arch = "wasm32"))] rpc_address: Option<SocketAddr>,
3335
) -> Result<Self> {
34-
let node = Node::new(execution_rpc, consensus)?;
36+
let node = Node::new(execution_rpc, consensus, fork_schedule)?;
3537
let node = Arc::new(node);
3638

3739
#[cfg(not(target_arch = "wasm32"))]

core/src/client/node.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::execution::evm::Evm;
1212
use crate::execution::rpc::http_rpc::HttpRpc;
1313
use crate::execution::state::State;
1414
use crate::execution::ExecutionClient;
15+
use crate::fork_schedule::ForkSchedule;
1516
use crate::network_spec::NetworkSpec;
1617
use crate::time::{SystemTime, UNIX_EPOCH};
1718
use crate::types::BlockTag;
@@ -20,22 +21,29 @@ pub struct Node<N: NetworkSpec, C: Consensus<N::BlockResponse>> {
2021
pub consensus: C,
2122
pub execution: Arc<ExecutionClient<N, HttpRpc<N>>>,
2223
pub history_size: usize,
24+
fork_schedule: ForkSchedule,
2325
}
2426

2527
impl<N: NetworkSpec, C: Consensus<N::BlockResponse>> Node<N, C> {
26-
pub fn new(execution_rpc: &str, mut consensus: C) -> Result<Self, ClientError> {
28+
pub fn new(
29+
execution_rpc: &str,
30+
mut consensus: C,
31+
fork_schedule: ForkSchedule,
32+
) -> Result<Self, ClientError> {
2733
let block_recv = consensus.block_recv().take().unwrap();
2834
let finalized_block_recv = consensus.finalized_block_recv().take().unwrap();
2935

3036
let state = State::new(block_recv, finalized_block_recv, 256, execution_rpc);
3137
let execution = Arc::new(
32-
ExecutionClient::new(execution_rpc, state).map_err(ClientError::InternalError)?,
38+
ExecutionClient::new(execution_rpc, state, fork_schedule.clone())
39+
.map_err(ClientError::InternalError)?,
3340
);
3441

3542
Ok(Node {
3643
consensus,
3744
execution,
3845
history_size: 64,
46+
fork_schedule,
3947
})
4048
}
4149

@@ -46,14 +54,24 @@ impl<N: NetworkSpec, C: Consensus<N::BlockResponse>> Node<N, C> {
4654
) -> Result<Bytes, ClientError> {
4755
self.check_blocktag_age(&block).await?;
4856

49-
let mut evm = Evm::new(self.execution.clone(), self.chain_id(), block);
57+
let mut evm = Evm::new(
58+
self.execution.clone(),
59+
self.chain_id(),
60+
self.fork_schedule.clone(),
61+
block,
62+
);
5063
evm.call(tx).await.map_err(ClientError::EvmError)
5164
}
5265

5366
pub async fn estimate_gas(&self, tx: &N::TransactionRequest) -> Result<u64, ClientError> {
5467
self.check_head_age().await?;
5568

56-
let mut evm = Evm::new(self.execution.clone(), self.chain_id(), BlockTag::Latest);
69+
let mut evm = Evm::new(
70+
self.execution.clone(),
71+
self.chain_id(),
72+
self.fork_schedule.clone(),
73+
BlockTag::Latest,
74+
);
5775

5876
evm.estimate_gas(tx).await.map_err(ClientError::EvmError)
5977
}

core/src/execution/constants.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ pub const PARALLEL_QUERY_BATCH_SIZE: usize = 20;
33
// We currently limit the max number of logs to fetch,
44
// to avoid blocking the client for too long.
55
pub const MAX_SUPPORTED_LOGS_NUMBER: usize = 5;
6-
pub const BLOB_BASE_FEE_UPDATE_FRACTION: u64 = 3338477;
7-
pub const MIN_BASE_FEE_PER_BLOB_GAS: u64 = 1;

core/src/execution/evm.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,37 @@ use revm::{
1515
};
1616
use tracing::trace;
1717

18-
use crate::execution::{
19-
constants::PARALLEL_QUERY_BATCH_SIZE,
20-
errors::{EvmError, ExecutionError},
21-
rpc::ExecutionRpc,
22-
ExecutionClient,
23-
};
2418
use crate::network_spec::NetworkSpec;
2519
use crate::types::BlockTag;
20+
use crate::{
21+
execution::{
22+
constants::PARALLEL_QUERY_BATCH_SIZE,
23+
errors::{EvmError, ExecutionError},
24+
rpc::ExecutionRpc,
25+
ExecutionClient,
26+
},
27+
fork_schedule::ForkSchedule,
28+
};
2629

2730
pub struct Evm<N: NetworkSpec, R: ExecutionRpc<N>> {
2831
execution: Arc<ExecutionClient<N, R>>,
2932
chain_id: u64,
3033
tag: BlockTag,
34+
fork_schedule: ForkSchedule,
3135
}
3236

3337
impl<N: NetworkSpec, R: ExecutionRpc<N>> Evm<N, R> {
34-
pub fn new(execution: Arc<ExecutionClient<N, R>>, chain_id: u64, tag: BlockTag) -> Self {
38+
pub fn new(
39+
execution: Arc<ExecutionClient<N, R>>,
40+
chain_id: u64,
41+
fork_schedule: ForkSchedule,
42+
tag: BlockTag,
43+
) -> Self {
3544
Evm {
3645
execution,
3746
chain_id,
3847
tag,
48+
fork_schedule,
3949
}
4050
}
4151

@@ -100,7 +110,8 @@ impl<N: NetworkSpec, R: ExecutionRpc<N>> Evm<N, R> {
100110
.await
101111
.ok_or(ExecutionError::BlockNotFound(tag))
102112
.unwrap();
103-
env.block = N::block_env(&block);
113+
114+
env.block = N::block_env(&block, &self.fork_schedule);
104115

105116
env.cfg.chain_id = self.chain_id;
106117
env.cfg.disable_block_gas_limit = true;

core/src/execution/mod.rs

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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};
1514
use eyre::Result;
1615
use futures::future::try_join_all;
17-
use revm::primitives::KECCAK_EMPTY;
16+
use revm::primitives::{BlobExcessGasAndPrice, KECCAK_EMPTY};
1817
use tracing::warn;
1918

19+
use crate::fork_schedule::ForkSchedule;
2020
use crate::network_spec::NetworkSpec;
2121
use crate::types::BlockTag;
2222

@@ -37,12 +37,17 @@ pub mod types;
3737
pub struct ExecutionClient<N: NetworkSpec, R: ExecutionRpc<N>> {
3838
pub rpc: R,
3939
state: State<N, R>,
40+
fork_schedule: ForkSchedule,
4041
}
4142

4243
impl<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> {

core/src/fork_schedule.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Clone, Copy, Serialize, Deserialize, Default, Debug)]
4+
pub struct ForkSchedule {
5+
pub prague_timestamp: u64,
6+
}

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod client;
22
pub mod consensus;
33
pub mod errors;
44
pub mod execution;
5+
pub mod fork_schedule;
56
pub mod network_spec;
67
pub mod time;
78
pub mod types;

core/src/network_spec.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use alloy::{network::Network, rpc::types::Log};
22
use revm::primitives::{BlockEnv, TxEnv};
33

4+
use crate::fork_schedule::ForkSchedule;
5+
46
pub trait NetworkSpec: Network {
57
fn encode_receipt(receipt: &Self::ReceiptResponse) -> Vec<u8>;
68
fn is_hash_valid(block: &Self::BlockResponse) -> bool;
79
fn receipt_contains(list: &[Self::ReceiptResponse], elem: &Self::ReceiptResponse) -> bool;
810
fn receipt_logs(receipt: &Self::ReceiptResponse) -> Vec<Log>;
911
fn tx_env(request: &Self::TransactionRequest) -> TxEnv;
10-
fn block_env(block: &Self::BlockResponse) -> BlockEnv;
12+
fn block_env(block: &Self::BlockResponse, fork_schedule: &ForkSchedule) -> BlockEnv;
1113
}

ethereum/src/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ impl EthereumClientBuilder {
206206
data_dir: None,
207207
chain: base_config.chain,
208208
forks: base_config.forks,
209+
execution_forks: base_config.execution_forks,
209210
max_checkpoint_age: base_config.max_checkpoint_age,
210211
fallback,
211212
load_external_fallback,
@@ -226,6 +227,7 @@ impl EthereumClientBuilder {
226227
Client::<Ethereum, ConsensusClient<MainnetConsensusSpec, HttpRpc, DB>>::new(
227228
&config.execution_rpc.clone(),
228229
consensus,
230+
config.execution_forks.clone(),
229231
#[cfg(not(target_arch = "wasm32"))]
230232
socket,
231233
)

ethereum/src/config/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::net::{IpAddr, Ipv4Addr};
33
use std::path::PathBuf;
44

55
use alloy::primitives::B256;
6+
use helios_core::fork_schedule::ForkSchedule;
67
use serde::Serialize;
78

89
use helios_consensus_core::types::Forks;
@@ -18,6 +19,7 @@ pub struct BaseConfig {
1819
pub default_checkpoint: B256,
1920
pub chain: ChainConfig,
2021
pub forks: Forks,
22+
pub execution_forks: ForkSchedule,
2123
pub max_checkpoint_age: u64,
2224
pub data_dir: Option<PathBuf>,
2325
pub load_external_fallback: bool,
@@ -35,6 +37,7 @@ impl Default for BaseConfig {
3537
forks: Default::default(),
3638
max_checkpoint_age: 0,
3739
data_dir: None,
40+
execution_forks: ForkSchedule::default(),
3841
load_external_fallback: false,
3942
strict_checkpoint_age: false,
4043
}

0 commit comments

Comments
 (0)