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: Implement evm_increaseTime and evm_setNextBlockTimestamp #93

Merged
merged 14 commits into from
Sep 11, 2023
82 changes: 75 additions & 7 deletions SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The `status` options are:
| `ETH` | `eth_uninstallFilter` | `NOT IMPLEMENTED`<br />[GitHub Issue #38](https://github.com/matter-labs/era-test-node/issues/38) | Uninstalls a filter with given id |
| `ETH` | `eth_unsubscribe` | `NOT IMPLEMENTED` | Cancel a subscription to a particular event |
| `EVM` | `evm_addAccount` | `NOT IMPLEMENTED` | Adds any arbitrary account |
| `EVM` | `evm_increaseTime` | `NOT IMPLEMENTED`<br />[GitHub Issue #66](https://github.com/matter-labs/era-test-node/issues/66) | Jump forward in time by the given amount of time, in seconds |
| [`EVM`](#evm-namespace) | [`evm_increaseTime`](#evm_increasetime) | `SUPPORTED` | Jump forward in time by the given amount of time, in seconds |
| `EVM` | `evm_mine` | `NOT IMPLEMENTED`<br />[GitHub Issue #67](https://github.com/matter-labs/era-test-node/issues/67) | Force a single block to be mined |
| `EVM` | `evm_removeAccount` | `NOT IMPLEMENTED` | Removes an account |
| `EVM` | `evm_revert` | `NOT IMPLEMENTED`<br />[GitHub Issue #70](https://github.com/matter-labs/era-test-node/issues/70) | Revert the state of the blockchain to a previous snapshot |
Expand All @@ -85,8 +85,8 @@ The `status` options are:
| `EVM` | `evm_setAutomine` | `NOT IMPLEMENTED` | Enables or disables the automatic mining of new blocks with each new transaction submitted to the network |
| `EVM` | `evm_setBlockGasLimit` | `NOT IMPLEMENTED` | Sets the Block Gas Limit of the network |
| `EVM` | `evm_setIntervalMining` | `NOT IMPLEMENTED` | Enables (with a numeric argument greater than 0) or disables (with a numeric argument equal to 0), the automatic mining of blocks at a regular interval of milliseconds, each of which will include all pending transactions |
| `EVM` | `evm_setNextBlockTimestamp` | `NOT IMPLEMENTED`<br />[GitHub Issue #68](https://github.com/matter-labs/era-test-node/issues/68) | Works like `evm_increaseTime`, but takes the exact timestamp that you want in the next block, and increases the time accordingly |
| `EVM` | `evm_setTime` | `NOT IMPLEMENTED` | Sets the internal clock time to the given timestamp |
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there's actually a need for both here. Ganache only supports evm_setTime, while Hardhat only support evm_setNextBlockTimestamp ... but I think they both do the same thing. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can either implement evm_setTime in this PR, or leave the line here in this table.

Also, it looks like this change leaves 2 rows/entries for evm_setNextBlockTimestamp

Copy link
Contributor Author

@nbaztec nbaztec Sep 7, 2023

Choose a reason for hiding this comment

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

I think there's actually a need for both here. Ganache only supports evm_setTime, while Hardhat only support evm_setNextBlockTimestamp ... but I think they both do the same thing. Thoughts?

Yeah they do exactly the same thing with the following differences:

  • setNextBlockTimestamp allows only setting a timestamp forward in future, while setTime supports setting it backwards.
  • setNextBlockTimestamp returns the newly set timestamp in response, whereas setTime returns the difference between the current and the new timestamp.

AFAIK setTime can be seen as a superset of setNextBlockTimestamp and from most examples out there no one seems to be using the return value to do anything meaningful.

I'm fine with supporting both, though it must be explicitly mentioned (to avoid any confusion for users) that these two achieve the same result and are mostly arising out of API differences between hardhat and ganache - though it does tend to make our API interface a bit messy.

| [`EVM`](#evm-namespace) | [`evm_setNextBlockTimestamp`](#evm_setnextblocktimestamp) | `SUPPORTED` | Works like `evm_increaseTime`, but takes the exact timestamp that you want in the next block, and increases the time accordingly |
| [`EVM`](#evm-namespace) | [`evm_setTime`](#evm_settime) | `SUPPORTED` | Sets the internal clock time to the given timestamp |
| `EVM` | `evm_snapshot` | `NOT IMPLEMENTED`<br />[GitHub Issue #69](https://github.com/matter-labs/era-test-node/issues/69) | Snapshot the state of the blockchain at the current block |
| `HARDHAT` | `hardhat_addCompilationResult` | `NOT IMPLEMENTED` | Add information about compiled contracts |
| `HARDHAT` | `hardhat_dropTransaction` | `NOT IMPLEMENTED` | Remove a transaction from the mempool |
Expand Down Expand Up @@ -753,10 +753,6 @@ The new nonce must be greater than the existing nonce.
+ `address: Address` - The `Address` whose nonce is to be changed
+ `nonce: U256` - The new nonce

#### Status

`SUPPORTED`

#### Example

```bash
Expand All @@ -774,6 +770,78 @@ curl --request POST \
}'
```

## `EVM NAMESPACE`

### `evm_increaseTime`

[source](src/evm.rs)

Increase the current timestamp for the node

#### Arguments

+ `time_delta_seconds: U64`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "evm_increaseTime","params": [10]}'
```

### `evm_setNextBlockTimestamp`

[source](src/evm.rs)

Sets the timestamp of the next block but doesn't mine one..

#### Arguments

+ `timestamp: U64`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "evm_setNextBlockTimestamp","params": [1672527600]}'
```

### `evm_setTime`

[source](src/evm.rs)

Set the current timestamp for the node. Warning: This will allow you to move _backwards_ in time, which
may cause new blocks to appear to be mined before old blocks. This will result in an invalid state.

#### Arguments

+ `time: U64`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "evm_setTime","params": [1672527600]}'
```

## `ZKS NAMESPACE`

### `zks_estimateFee`
Expand Down
Loading