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

Hardhat 3 timestamps are broken if intervalMining is set to less than 1000 #6012

Open
2 tasks
kanej opened this issue Dec 3, 2024 · 6 comments
Open
2 tasks
Labels
status:ready This issue is ready to be worked on type:bug Something isn't working v-next A Hardhat v3 development task
Milestone

Comments

@kanej
Copy link
Member

kanej commented Dec 3, 2024

This was reported by @SebastienGllmt in Telegram.

timestamps are broken if intervalMining is set to less than 1000 on 3.0.0-next.16
the block timestamp advances faster than real clock time

Next steps

  • Reproduce in script
  • Check whether the configuration around interval mining is flowing through to EDR correctly
@kanej kanej added the v-next A Hardhat v3 development task label Dec 3, 2024
@kanej kanej added this to the Public Alpha milestone Dec 3, 2024
@kanej kanej added this to Hardhat Dec 3, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Hardhat Dec 3, 2024
@kanej kanej added the type:bug Something isn't working label Dec 3, 2024
@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Dec 3, 2024
@kanej kanej moved this from Backlog to To-do in Hardhat Dec 3, 2024
@kanej
Copy link
Member Author

kanej commented Dec 3, 2024

@SebastienGllmt can I check, a valid reproduction would be:

  1. Create a Hardhat script that connects to a Hardhat network with interval mining set to 500ms
  2. the script polls every half second for the latest block and prints the block number and timestamp

We expect the bug to express itself as the timestamp getting out of sync (into the future) from wall clock time.

@SebastienGllmt
Copy link

SebastienGllmt commented Dec 3, 2024

Specifically, this is the hardhat config I used

evmMain: {
      type: "edr",
      chainType: "l1",
      chainId: 31337,
      automine: true,
      intervalMining: 250, // matches Arbitrum (250ms)
    },

You can get the block using

const client = ; // initialize viem public client

while(true) {
    const blockNumber = client.getBlockNumber({ cacheTime: 0 });
    const block = client.getBlock({ blockNumber }); 
    console.log(block.timestamp)
}

@fvictorio
Copy link
Member

@SebastienGllmt can you try adding allowBlocksWithSameTimestamp: true to that config?

@SebastienGllmt
Copy link

@fvictorio that seems to have fixed it, so I guess the fix to this issue is either to make allowBlocksWithSameTimestamp: true implicit if intervalMining < 1000 or add an error message asking the user to set allowBlocksWithSameTimestamp: true in that case

@kanej
Copy link
Member Author

kanej commented Dec 4, 2024

I think a warning makes more sense here. I am not a fan of changes in the underlying configuration at unseen break points. We should be explicit.

@fvictorio
Copy link
Member

Yes, I think the options are:

  • A warning
  • A config validation error (good idea for HH3, probably not for HH2)
  • Making the default value of allowBlocksWithSameTimestamp depend on the value of intervalMining (I don't dislike this idea as much as @kanej, but don't love it either).

A warning is easy to add and non-controversial, so I'd say we go with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on type:bug Something isn't working v-next A Hardhat v3 development task
Projects
Status: To-do
Development

No branches or pull requests

3 participants