Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the issue of network is not known to be merged #6649

Merged
merged 8 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bin/reth/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use reth_node_ethereum::{EthEngineTypes, EthEvmConfig};
#[cfg(feature = "optimism")]
use reth_node_optimism::{OptimismEngineTypes, OptimismEvmConfig};
use reth_payload_builder::PayloadBuilderHandle;
use reth_primitives::DisplayHardforks;
use reth_provider::{providers::BlockchainProvider, ProviderFactory};
use reth_prune::PrunerBuilder;
use reth_rpc_engine_api::EngineApi;
Expand Down Expand Up @@ -148,7 +147,7 @@ impl<DB: Database + DatabaseMetrics + DatabaseMetadata + 'static> NodeBuilderWit

let genesis_hash = init_genesis(Arc::clone(&self.db), self.config.chain.clone())?;

info!(target: "reth::cli", "{}", DisplayHardforks::new(self.config.chain.hardforks()));
info!(target: "reth::cli", "{}", self.config.chain.display_hardforks());

let consensus = self.config.consensus();

Expand Down
4 changes: 2 additions & 2 deletions crates/node-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use reth_node_core::{
};
use reth_primitives::{
constants::eip4844::{LoadKzgSettingsError, MAINNET_KZG_TRUSTED_SETUP},
ChainSpec, DisplayHardforks,
ChainSpec,
};
use reth_provider::{providers::BlockchainProvider, ChainSpecProvider, ProviderFactory};
use reth_prune::{PrunerBuilder, PrunerEvent};
Expand Down Expand Up @@ -367,7 +367,7 @@ where

let genesis_hash = init_genesis(database.clone(), config.chain.clone())?;

info!(target: "reth::cli", "{}", DisplayHardforks::new(config.chain.hardforks()));
info!(target: "reth::cli", "{}", config.chain.display_hardforks());

let consensus = config.consensus();

Expand Down
40 changes: 24 additions & 16 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,14 @@ impl ChainSpec {
&self.hardforks
}

/// Returns the hardfork display helper.
pub fn display_hardforks(&self) -> DisplayHardforks {
DisplayHardforks::new(
self.hardforks(),
self.paris_block_and_final_difficulty.map(|(block, _)| block),
)
}

/// Get the fork id for the given hardfork.
#[inline]
pub fn hardfork_fork_id(&self, fork: Hardfork) -> Option<ForkId> {
Expand Down Expand Up @@ -1542,8 +1550,7 @@ impl Display for DisplayFork {
///
/// ```
/// # use reth_primitives::MAINNET;
/// # use reth_primitives::DisplayHardforks;
/// println!("{}", DisplayHardforks::new(MAINNET.hardforks()));
/// println!("{}", MAINNET.display_hardforks());
/// ```
///
/// An example of the output:
Expand All @@ -1565,7 +1572,7 @@ impl Display for DisplayFork {
// - ArrowGlacier @13773000
// - GrayGlacier @15050000
// Merge hard forks:
// - Paris @58750000000000000000000 (network is not known to be merged)
// - Paris @58750000000000000000000 (network is known to be merged)
//
// Post-merge hard forks (timestamp based):
// - Shanghai @1681338455
Expand Down Expand Up @@ -1607,26 +1614,27 @@ impl Display for DisplayHardforks {

impl DisplayHardforks {
/// Creates a new [`DisplayHardforks`] from an iterator of hardforks.
pub fn new(hardforks: &BTreeMap<Hardfork, ForkCondition>) -> Self {
Self::from_iter(hardforks.iter())
}
}

impl<'a, 'b> FromIterator<(&'a Hardfork, &'b ForkCondition)> for DisplayHardforks {
fn from_iter<T: IntoIterator<Item = (&'a Hardfork, &'b ForkCondition)>>(iter: T) -> Self {
pub fn new(
hardforks: &BTreeMap<Hardfork, ForkCondition>,
known_paris_block: Option<u64>,
) -> Self {
let mut pre_merge = Vec::new();
let mut with_merge = Vec::new();
let mut post_merge = Vec::new();

for (fork, condition) in iter {
let display_fork =
for (fork, condition) in hardforks {
let mut display_fork =
DisplayFork { name: fork.to_string(), activated_at: *condition, eip: None };

match condition {
ForkCondition::Block(_) => {
pre_merge.push(display_fork);
}
ForkCondition::TTD { .. } => {
ForkCondition::TTD { total_difficulty, .. } => {
display_fork.activated_at = ForkCondition::TTD {
fork_block: known_paris_block,
total_difficulty: *total_difficulty,
};
with_merge.push(display_fork);
}
ForkCondition::Timestamp(_) => {
Expand Down Expand Up @@ -1702,7 +1710,7 @@ mod tests {
#[test]
fn test_hardfork_list_display_mainnet() {
assert_eq!(
DisplayHardforks::new(MAINNET.hardforks()).to_string(),
MAINNET.display_hardforks().to_string(),
"Pre-merge hard forks (block based):
- Frontier @0
- Homestead @1150000
Expand All @@ -1719,7 +1727,7 @@ mod tests {
- ArrowGlacier @13773000
- GrayGlacier @15050000
Merge hard forks:
- Paris @58750000000000000000000 (network is not known to be merged)
- Paris @58750000000000000000000 (network is known to be merged)

Post-merge hard forks (timestamp based):
- Shanghai @1681338455
Expand All @@ -1737,7 +1745,7 @@ Post-merge hard forks (timestamp based):
.with_fork(Hardfork::Shanghai, ForkCondition::Never)
.build();
assert_eq!(
DisplayHardforks::new(spec.hardforks()).to_string(),
spec.display_hardforks().to_string(),
"Pre-merge hard forks (block based):
- Frontier @0
"
Expand Down
Loading