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

feat(anvil): support mining with same block.timestamp #9160

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

yash-atreya
Copy link
Member

Motivation

Closes #9142 + Closes #7931

Solution

Replace the check next_timestamp <= last_timestamp with next_timestamp < last_timestamp.

Anvil can now mine blocks with the same timestamp as the previous block timestamp. This aids in running forks or testing chains that have sub-second block times, wherein block.timestamp stays constant until exactly one second has passed.

Added relevant tests.

@yash-atreya
Copy link
Member Author

yash-atreya commented Oct 22, 2024

@mattsse this effectively undos the fix for #6096. See here:

assert!(block.header.timestamp >= latest_block.header.timestamp);
.

If users expect the next_block_timestamp after revert to be always greater than block.timestamp the snapshot was taken at, we can probably just add 1s here

let reset_time = block.header.timestamp;
while resetting. wdyt?

@yash-atreya yash-atreya merged commit 4d7435e into master Oct 23, 2024
21 checks passed
@yash-atreya yash-atreya deleted the yash/support-same-timestamp branch October 23, 2024 06:29
domob1812 added a commit to xaya/xayax that referenced this pull request Oct 25, 2024
Anvil now (foundry-rs/foundry#9160) supports
blocks with constant timestamp, so there is no need to explicitly
bump the mock time when generating a new block (it can remain the same).

This simplifies testing logic potentially, as tests do not need to
expect increasing timestamps after setting a mock time.
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
)

* feat(`anvil`): support mining with same block.timestamp

* fix timestamp tests

* fix
@grandizzy grandizzy added T-feature Type: feature C-anvil Command: anvil labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-anvil Command: anvil T-feature Type: feature
Projects
Status: Completed
3 participants