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

chore(core/types): remove Blocks's Timestamp() method #1429

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

Conversation

qdm12
Copy link
Collaborator

@qdm12 qdm12 commented Jan 22, 2025

Why this should be merged

See ava-labs/coreth#749

How this works

See commit messages, but TLDR:

  • change easy-to-change Timestamp calls to Time calls
  • change arguments from blockContext -> blockNumber + blockTime
  • New PrecompileBlockContext implementing a now changed BlockContext interface (Timestamp -> Time)

How this was tested

Existing CI passing

Need to be documented?

Maybe? The template changed 🤔

Need to update RELEASES.md?

@qdm12 qdm12 force-pushed the qdm12/block-remove-timestamp branch 2 times, most recently from 1926d99 to 1bc820a Compare January 23, 2025 08:36
@qdm12 qdm12 force-pushed the qdm12/block-remove-timestamp branch from 1bc820a to 2cf8ef3 Compare January 23, 2025 08:38
@qdm12 qdm12 marked this pull request as ready for review January 23, 2025 08:38
@qdm12 qdm12 requested review from ceyonur, darioush and a team as code owners January 23, 2025 08:38
@@ -43,10 +44,10 @@ func (*configurator) MakeConfig() precompileconfig.Config {

// Configure configures [state] with the given [cfg] precompileconfig.
// This function is called by the EVM once per precompile contract activation.
func (c *configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error {
func (c *configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockNumber *big.Int) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we keep both the block number and time here even if the time is unused? As we previously exposed this interface in precompile-evm and it seems it could be used in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, one of the last commits removes the time argument, I wanted to see your opinion on this 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, similar question: what would be the cost to change the function signature in the future?

Copy link
Collaborator

@darioush darioush Jan 31, 2025

Choose a reason for hiding this comment

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

It would require changes to all precompiles, both those that we have developed and any external code bases that may have developed precompiles for use in subnet-evm or precompile-evm.
So I think we should avoid changing it without good reason, but we can still change it to deliver improvements, features, and a better interface.

It seems the code that sets up a precompile may want to have access to both the timestamp and the number of the block where it's activated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Interesting, should we then not change the signature, such that the block context interface (now removed) can be later extended?

@@ -21,8 +21,8 @@ type AllowListConfig struct {
}

// Configure initializes the address space of [precompileAddr] by initializing the role of each of
// the addresses in [AllowListAdmins].
func (c *AllowListConfig) Configure(chainConfig precompileconfig.ChainConfig, precompileAddr common.Address, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error {
// the addresses in [AllowListConfig].
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we keep the arguments for this method for symmetry with the other methods (even though unused)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I understand what symmetry you are thinking about? With the Configurator.Configure??

Copy link
Collaborator

Choose a reason for hiding this comment

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

That was my thought, even though the AllowList is not a precompile it follows through the phases of Configure along with the precompile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Related question: what would be the cost of changing the signature of AllowListConfig.Configure if needed in the future? 🤔

Copy link
Collaborator

@darioush darioush Jan 31, 2025

Choose a reason for hiding this comment

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

Less than the other method, as the AllowList is not part of the precompile interface but more a partial implementation that's used by some of the precompiles.

As I mentioned I have a subjective preference for methods that do similar things to all take the same arguments but this is not a strong preference.

@qdm12 qdm12 force-pushed the qdm12/block-remove-timestamp branch from 2cf8ef3 to a9b334c Compare January 23, 2025 16:54
Copy link
Collaborator

@ceyonur ceyonur left a comment

Choose a reason for hiding this comment

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

changes in the subnet-evm context are lgtm, but we should consider that this will break all precompiles (including precompiles in precompile-evm + subnet-evm forks)

@@ -59,7 +60,7 @@ func (*configurator) MakeConfig() precompileconfig.Config {
// This function is called by the EVM once per precompile contract activation.
// You can use this function to set up your precompile contract's initial state,
// by using the [cfg] config and [state] stateDB.
func (*configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error {
func (*configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockNumber *big.Int, blockTime uint64) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a breaking change to all precompiles (external and internal precompiles). While having a simple params is better, we should also evaluate this with the future extension possibilities. IMO having a blockContext interface is less cumbersome to extend.

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.

3 participants