Skip to content

feature: implement eth_simulateV1 #8406

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

Merged

Conversation

Gabriel-Trintinalia
Copy link
Contributor

PR description

Adds support for eth_simulateV1

Spec: ethereum/execution-apis#484
Fixes: #6203

Currently passing 87/97 hive tests

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements support for eth_simulateV1 by introducing new parameter and result classes, updating related method implementations, and adding accompanying tests. Key changes include:

  • New JSON-RPC parameter and result classes for simulation (e.g. JsonBlockStateCallParameter, SimulateV1Parameter, BlockStateCallResult).
  • Updates to the EthSimulateV1 method and registration in the RPC methods.
  • Modifications in existing classes (e.g. BlockOverridesParameter, TransactionCompleteResult) and test updates to support simulation.

Reviewed Changes

Copilot reviewed 44 out of 44 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonBlockStateCallParameter.java New parameter class for block state calls in simulation.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/SimulateV1Parameter.java New parameter class for eth_simulateV1.
ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/bonsai/EthSimulateV1BySpecTest.java New Bonsai tests for simulation.
ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/SimulateV1ParameterTest.java New tests verifying validation errors and parameter ordering.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockStateCallResult.java New result class for simulation responses.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResult.java Adjusted access list handling in simulation transaction response.
ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSimulateV1Test.java Test cases validating the EthSimulateV1 method behavior.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSimulateV1.java Implementation of the new eth_simulateV1 JSON-RPC method.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/BlockOverridesParameter.java Renamed parameter and updated handling for mixHash/prevRandao input.
ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/AbstractJsonRpcHttpServiceTest.java Updated service test configuration to use DEFAULT_GAS_CAP.
besu/src/main/java/org/hyperledger/besu/services/BlockSimulatorServiceImpl.java Introduced fake signature logic and refactored simulation parameter creation.
consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validator/ValidatorContractControllerTest.java Adjusted test calls with additional Optional.empty() parameter.
datatypes/src/main/java/org/hyperledger/besu/datatypes/StateOverride.java Added builder method documentation block.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlockResult.java Removed outdated call processing results field from BlockResult.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/CallProcessingResult.java Refactored error handling to use JsonRpcError.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EthJsonRpcMethods.java Registered EthSimulateV1 in the available RPC methods.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java Added ETH_SIMULATE_V1 as a supported RPC method.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java Updated method factory to pass miningConfiguration for simulation.
Comments suppressed due to low confidence (1)

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/BlockOverridesParameter.java:73

  • Ensure that falling back to 'prevRandao' when 'mixHash' is not present is appropriate given the changed type from Optional to Optional. Consider applying an explicit type conversion or validation to avoid potential runtime type issues.
mixHash.isPresent() ? mixHash : prevRandao);

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

few comments. needs a changelog entry

Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

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

Partial review. A question about support for pending block tag

}

@Override
protected BlockParameterOrBlockHash blockParameterOrBlockHash(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this method also support pending as block tag?

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

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

LGTM, some minor optimizations, the open question about the behavior of the pending block tag, and what about the remaining failing Hive tests.


BlockHeader finalBlockHeader =
BlockHeaderBuilder.createDefault()
.populateFrom(blockHeader)
.ommersHash(BodyValidation.ommersHash(List.of()))
.stateRoot(blockOverrides.getStateRoot().orElseGet(ws::rootHash))
.stateRoot(blockOverrides.getStateRoot().orElseGet(ws::frontierRootHash))
Copy link
Contributor

Choose a reason for hiding this comment

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

why frontierRootHash?

Copy link
Contributor Author

@Gabriel-Trintinalia Gabriel-Trintinalia Mar 27, 2025

Choose a reason for hiding this comment

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

@fab-10 Good question! Since eth_simulationV1 can simulate up to 256 blocks in the future, I need to retain the changes from each block in the accumulator to build the next block, while also needing the state root to construct the block header. The Frontier Root Hash does not clear the accumulator as the rootHash method does. One option could be to rename it to "intermediateRootHash." Perhaps @matkt has a better suggestion on how I could achieve this?

Copy link
Contributor

Choose a reason for hiding this comment

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

why you need to keep what you have in the accumulator ? you just have to persist in your worldstate for each block and start with empty accumulator for each block . no ?

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
@Gabriel-Trintinalia
Copy link
Contributor Author

@fab-10 Thanks for the review. I have addressed the suggestions. Regarding the pending block, eth_simulateV1 will simulate a full block. So when the user chooses "latest", the block simulator will create a pending block whose parent is the latest. So this means that running the simulation on the pending tag would actually skip one block number. If this is required, it can be achieved by overriding the block number using the blockOverrides to the latest + 2. The outcome will be two blocks, one which is an empty block, and another with the actual simulation with the empty block as a parent.

@fab-10
Copy link
Contributor

fab-10 commented Mar 28, 2025

@fab-10 Thanks for the review. I have addressed the suggestions. Regarding the pending block, eth_simulateV1 will simulate a full block. So when the user chooses "latest", the block simulator will create a pending block whose parent is the latest. So this means that running the simulation on the pending tag would actually skip one block number. If this is required, it can be achieved by overriding the block number using the blockOverrides to the latest + 2. The outcome will be two blocks, one which is an empty block, and another with the actual simulation with the empty block as a parent.

Fine to ship for me

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
@Gabriel-Trintinalia Gabriel-Trintinalia added the doc-change-required Indicates an issue or PR that requires doc to be updated label Apr 4, 2025
@Gabriel-Trintinalia Gabriel-Trintinalia enabled auto-merge (squash) April 4, 2025 06:41
@Gabriel-Trintinalia Gabriel-Trintinalia changed the title Implement eth_simulateV1 feature: implement eth_simulateV1 Apr 4, 2025
@Gabriel-Trintinalia Gabriel-Trintinalia merged commit 1976ad1 into hyperledger:main Apr 4, 2025
43 checks passed
@alexandratran alexandratran removed the doc-change-required Indicates an issue or PR that requires doc to be updated label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement eth_simulatev1
5 participants