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

Next block after evm_revert does not have increased timestamp #5518

Closed
2 tasks done
Tracked by #8269
michprev opened this issue Aug 1, 2023 · 4 comments
Closed
2 tasks done
Tracked by #8269

Next block after evm_revert does not have increased timestamp #5518

michprev opened this issue Aug 1, 2023 · 4 comments
Labels
C-anvil Command: anvil T-bug Type: bug T-to-investigate Type: to investigate
Milestone

Comments

@michprev
Copy link
Contributor

michprev commented Aug 1, 2023

Component

Anvil

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

anvil 0.1.0 (25d3ce7 2023-08-01T00:20:13.496244391Z)

What command(s) is the bug in?

anvil --prune-history 100 --steps-tracing --silent --port 36655

Operating System

Linux

Describe the bug

It seems that the next block mined after an evm_revert JSON-RPC request does not have the timestamp increased. I believe this can be considered a bug since timestamps of blocks mined without evm_snapshot and evm_revert are always increased by 1.

I think this may be the relevant part of the code:

// Note: In [`TimeManager::compute_next_timestamp`] we ensure that the next timestamp is
// always increasing by at least one. By subtracting 1 here, this is mitigated.
let reset_time = block.timestamp.as_u64().saturating_sub(1);
self.time.reset(reset_time);
self.set_block_number(num.into());

The current behavior is (described in Woke testing framework):

from woke.testing import *

@default_chain.connect()
def test_reverting():
    t1 = default_chain.blocks["latest"].timestamp
    with default_chain.snapshot_and_revert():
        default_chain.mine()

    t2 = default_chain.blocks["latest"].timestamp
    assert t1 == t2

    default_chain.mine()
    t3 = default_chain.blocks["latest"].timestamp
    assert t3 == t2

while the expected behavior is

    assert t3 == t2 + 1
@michprev michprev added the T-bug Type: bug label Aug 1, 2023
@gakonst gakonst added this to Foundry Aug 1, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Aug 1, 2023
@mattsse
Copy link
Member

mattsse commented Aug 1, 2023

@Evalir I think the self.time.reset(reset_time); is the culprit here

@mattsse mattsse added the C-anvil Command: anvil label Aug 1, 2023
@Evalir Evalir self-assigned this Aug 1, 2023
@Evalir Evalir added this to the v1.0.0 milestone Aug 1, 2023
@Evalir
Copy link
Member

Evalir commented Aug 1, 2023

Hey @michprev — i cannot seem reproduce this either manually or with woke. i haven't used woke before, maybe you can provide a repo that i can clone and run the test to detect this?

@michprev
Copy link
Contributor Author

michprev commented Aug 4, 2023

Hey @Evalir, I have modified the script to call eth_getBlockByNumber directly to provide a proof the issue is not in the testing framework.

The steps to reproduce the issue are:

  1. pip3 install -U woke
  2. Create test_xyz.py containing the Python code below
  3. Run woke test test_xyz.py

The script:

import logging
from woke.testing import *
from woke.development.json_rpc.communicator import logger

@default_chain.connect()
def test_reverting():
    logger.setLevel(logging.INFO)

    t1 = int(default_chain.chain_interface.get_block("latest")['timestamp'], 16)
    with default_chain.snapshot_and_revert():
        default_chain.mine()

    t2 = int(default_chain.chain_interface.get_block("latest")['timestamp'], 16)
    assert t1 == t2

    default_chain.mine()
    t3 = int(default_chain.chain_interface.get_block("latest")['timestamp'], 16)
    assert t3 == t2 + 1

The script now performs full logging of JSON-RPC communication. I am attaching the log file. Please take a look at requests with id 14 and 16 (eth_getBlockByNumber). Both blocks have the same timestamp but a different block number.
log.txt

@klkvr
Copy link
Member

klkvr commented Jul 13, 2024

Confirming that issue was the case on 25d3ce7 but is fixed now

@klkvr klkvr closed this as completed Jul 13, 2024
@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 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-bug Type: bug T-to-investigate Type: to investigate
Projects
Archived in project
Development

No branches or pull requests

5 participants