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

Add Labels to ChainParameters to Enable Hardforks via Single Timestamp #7764

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

LuisDi98
Copy link

This PR introduces functionality to allow grouped EIP timestamps (e.g., dencun, cancun) in ChainParameters. This simplifies the process of activating multiple EIPs simultaneously through a single label, while preserving the ability to handle individual EIP timestamps.

Fixes #7738

Changes

  • Added DencunTransitionTimestamp and CancunTransitionTimestamp to ChainParameters class.
  • Implemented ValidateNoTimestampConflicts to detect and validate timestamp conflicts between labels and individual EIPs.
  • Updated ChainSpecParamsJson to support grouped label serialization/deserialization.
  • Added tests in ChainParametersTests to verify label functionality and conflict detection.

Types of Changes

What types of changes does your code introduce?

  • New feature (a non-breaking change that adds functionality)

Testing

Requires testing

  • Yes

If yes, did you write tests?

  • Yes

Notes on testing

Added unit tests in ChainParametersTests to verify:

  • Setting and getting label timestamps.
  • Conflict detection for mismatched individual EIP timestamps.
  • Valid behavior when all timestamps match.

Documentation

Requires documentation update

  • No

Requires explanation in Release Notes

  • Yes

Release Notes:

  • Added support for grouped EIP timestamps (dencun, cancun) in ChainParameters for simplifying hardfork activation.

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

We need to support all hardforks

Comment on lines 20 to 23
if (Eip4844TransitionTimestamp == Eip4788TransitionTimestamp &&
Eip4788TransitionTimestamp == Eip1153TransitionTimestamp &&
Eip1153TransitionTimestamp == Eip5656TransitionTimestamp &&
Eip5656TransitionTimestamp == Eip6780TransitionTimestamp)
Copy link
Member

Choose a reason for hiding this comment

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

We should have a helper method to have such comparisions as we will do it for every hardfork.

Copy link
Author

Choose a reason for hiding this comment

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

I created the helper method called "AreHardforkTimestampsEqual" in order to accomplish this one, which compares it instead of using the ifs inside each hardfork.

}
set
{
_dencunTransitionTimestamp = value;
Copy link
Member

Choose a reason for hiding this comment

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

Potentially we could have _dencunTransitionTimestamp and individual EIP's out of sync, so maybe always calculate it and don't have a separate field?

Copy link
Author

Choose a reason for hiding this comment

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

You are so right... I made the change using the helper method previously suggested and if it's true, we assign one of those timestamps values so it calculates it dynamically. (code lines 32-42 and 56-65)

}
set
{
_dencunTransitionTimestamp = value;
Copy link
Member

Choose a reason for hiding this comment

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

Potentially we could have _dencunTransitionTimestamp and individual EIP's out of sync, so maybe always calculate it and don't have a separate field? Then you also don't need Validate methods

Comment on lines 20 to 23
if (Eip4844TransitionTimestamp == Eip4788TransitionTimestamp &&
Eip4788TransitionTimestamp == Eip1153TransitionTimestamp &&
Eip1153TransitionTimestamp == Eip5656TransitionTimestamp &&
Eip5656TransitionTimestamp == Eip6780TransitionTimestamp)
Copy link
Member

Choose a reason for hiding this comment

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

You could potentially use more declarative style of Expression Api to map individual properties to Hardfork property, that might be useful outside of this class too?

Copy link
Author

Choose a reason for hiding this comment

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

Sure! In this refactor commit I created a dictionary at lines 15-22 so we can access only using the key tag, also a public static method GetHardforkMapping in case we need to get any value from this dictionary from any other classes outside

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

@LuisDi98 I think recent changes are step in wrong direction. Would prefer to avoid strings. Added complexity isn't bringing anything at the moment.

Comment on lines +30 to +74
public ulong? DencunTransitionTimestamp
{
get
{
if (AreHardforkTimestampsEqual(
"Dencun", "Cancun", "EIP-1153",
"EIP-5656", "EIP-6780"))
{
return Eip4844TransitionTimestamp;
}

return null;
}
set
{
Eip4844TransitionTimestamp = value;
Eip4788TransitionTimestamp = value;
Eip1153TransitionTimestamp = value;
Eip5656TransitionTimestamp = value;
Eip6780TransitionTimestamp = value;
}
}


public ulong? CancunTransitionTimestamp
{
get
{
if (AreHardforkTimestampsEqual(
"Dencun", "Cancun", "EIP-1153",
"EIP-5656", "EIP-6780"))
{
return Eip4844TransitionTimestamp;
}
return null;
}
set
{
Eip4844TransitionTimestamp = value;
Eip4788TransitionTimestamp = value;
Eip1153TransitionTimestamp = value;
Eip5656TransitionTimestamp = value;
Eip6780TransitionTimestamp = value;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Dencun and Cancun are same thing, confusing.

Comment on lines +15 to +22
private static readonly Dictionary<string, Func<ChainParameters, ulong?>> HardforkToEips = new()
{
{ "Dencun", cp => cp.Eip4844TransitionTimestamp },
{ "Cancun", cp => cp.Eip4788TransitionTimestamp },
{ "EIP-1153", cp => cp.Eip1153TransitionTimestamp },
{ "EIP-5656", cp => cp.Eip5656TransitionTimestamp },
{ "EIP-6780", cp => cp.Eip6780TransitionTimestamp }
};
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking of something more like:

    public static readonly IReadOnlyList<Expression<Func<ChainParameters, ulong?>>> DencunEIPs =
    [
        cp => cp.Eip4844TransitionTimestamp,
        cp => cp.Eip4788TransitionTimestamp,
        cp => cp.Eip1153TransitionTimestamp,
        cp => cp.Eip5656TransitionTimestamp,
        cp => cp.Eip6780TransitionTimestamp
    ];

If we had same interface for ChainParameters and ChainSpecParamsJson that could be potentially reusable.

But that maybe an overkill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Labels to chainspec to activate hardforks at once.
2 participants