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

Conversation

jsvisa
Copy link
Contributor

@jsvisa jsvisa commented Feb 18, 2024

close #6453

@jsvisa jsvisa requested a review from gakonst as a code owner February 18, 2024 08:39
@jsvisa
Copy link
Contributor Author

jsvisa commented Feb 18, 2024

@Rjected PTAL

@emhane emhane requested a review from Rjected February 18, 2024 13:18
@emhane emhane added A-consensus Related to the consensus engine A-networking Related to networking in general C-enhancement New feature or request A-cli Related to the reth CLI and removed A-consensus Related to the consensus engine A-networking Related to networking in general labels Feb 18, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, perhaps this is the easiest solution.

but we only need this for displaying, and adding an additional field just for that seems a bit odd, especially if we already have something like this on the Chainspec struct:

/// The block at which [Hardfork::Paris] was activated and the final difficulty at this block.
#[serde(skip, default)]
pub paris_block_and_final_difficulty: Option<(u64, U256)>,

perhaps we use that in DisplayHardforks instead for the None case?
wdyt @Rjected

@@ -31,7 +31,7 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
// <https://etherscan.io/block/15537394>
paris_block_and_final_difficulty: Some((
15537394,
U256::from(58_750_003_716_598_352_816_469u128),
U256::from(58_750_003_716_598_352_816_469_u128),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
U256::from(58_750_003_716_598_352_816_469_u128),
U256::from(58_750_003_716_598_352_816_469u128),

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, as I mentioned in the issue, we should be using paris_block_and_total_difficulty

@jsvisa
Copy link
Contributor Author

jsvisa commented Feb 19, 2024

yeah, as I mentioned in the issue, we should be using paris_block_and_total_difficulty

@Rjected Sorry, I missed the previous comments. I would like to confirm if I truly understand what you mean, is that correct? We can pass paris_block_and_total_difficulty to DisplayHardforks::new, something like below:

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

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

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

            match condition {
                ForkCondition::Block(_) => {
                    pre_merge.push(display_fork);
                }
                ForkCondition::TTD { .. } => {
                    with_merge.push(display_fork);
                }
                ForkCondition::Timestamp(_) => {
                    post_merge.push(display_fork);
                }
                ForkCondition::Never => continue,
            }
        }

        Self { pre_merge, with_merge, post_merge }
    }
}

@mattsse
Copy link
Collaborator

mattsse commented Feb 19, 2024

yeah, we can remove the from iter impl, and add known_paris_block: Option<u64> to that

and we can add displayforks(&self) function to the chainspec type

@jsvisa jsvisa force-pushed the fork-display-merge branch from 27132cc to e2a2369 Compare February 19, 2024 12:27
@jsvisa jsvisa requested a review from onbjerg as a code owner February 19, 2024 12:27
@jsvisa
Copy link
Contributor Author

jsvisa commented Feb 19, 2024

@mattsse thanks for the advice, adjusted, and PTAL

Signed-off-by: jsvisa <[email protected]>
Signed-off-by: jsvisa <[email protected]>
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

pending @Rjected + lint fixes

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me, thanks!

@mattsse mattsse enabled auto-merge February 19, 2024 18:14
@mattsse mattsse added this pull request to the merge queue Feb 19, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 19, 2024
@Rjected Rjected added this pull request to the merge queue Feb 19, 2024
Merged via the queue into paradigmxyz:main with commit 2641251 Feb 19, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Related to the reth CLI C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use terminalTotalDifficultyPassed to determine "network is known to be merged"
4 participants