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

Add eth_simulate , support array of eth_call for simulation across multiple blocks #5530

Merged
merged 290 commits into from
Jun 10, 2024

Conversation

OlegJakushkin
Copy link
Contributor

@OlegJakushkin OlegJakushkin commented Apr 3, 2023

This is a PR in progress; changes to it will happen.
In this PR we are implementing eth_simulate proposal.

Changes to be made:

  • Support for RPC types
  • Unit testing of the main algorithm (in progress)
  • Implementation (account states, blocks, precompiled codes)
  • Implementation unit testing
  • Implementation precompile redirects
  • Start from not head block (shall be tested shall be real-life - state reversal)
  • Implementation of RPC pipeline
  • Implementation of Configuration pipeline (added a basic multiplier to eth_call)
  • Have block numbers independent from chain head
  • Add Transfer log events on eth transfer (added to tracers shall be real life tested - tags correctness)
  • test out insufficient funds errors like others have on eth_call
  • Error codes from protocol
  • Protocol response serialisation checks
  • Gas limits
  • eth_call like behavior (no validation)
  • 100000+ blocks performance test

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

Also requires comparison with Geth implementation

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Remarks

Work in progress.

Docker image from commit 2684fba created at nethermindeth/nethermind:eth_multicall (08.06.2023)

Important configuration options:

  • in JsonRpcConfig
    • GasCap (default: 100000000)
    • GasCapMultiplier, new (default: 2) applied as GasCap *GasCapMultiplier to limit totall max gas consumption over all blocks on a single eth_multicall

Important protocol expansions:

  • Added option to turn off additional Logs of eth transfers to function signature
  • Added to AccountOverride
    • MoveToAddress field for original code/precompiles redirection

Example call:

import requests
import json

# Define the JSON-RPC request payload
payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_multicall",
    "params": [
        "0x0",
        [
            {
                "stateOverrides": [
                    {
                        "nonce": "0x1",
                        "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                        "balance": "0xde0b6b3a7640000",
                        "state": {
                            "0x2292f0db49e1af24fbcac7f32b7537f334244455ad0ed0b46a78202982e7b70d": "0xde0b6b3a7640000",
                            "0x0x877bd4632ef8c8ddc43b67e5a4511d939eadb612553c8a060670e05ebb1bb83c": "0xde0b6b3a7640000"
                        }
                    }
                ],
                "calls": [
                    {
                        "from": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                        "to": "0x6b175474e89094c44da98b954eedeac495271d0f",
                        "data": "0x18160ddd"
                    }
                ]
            }
        ],
        "latest"
    ]
}

response = requests.post("http://localhost:8547", json=payload)

@LukaszRozmej LukaszRozmej self-requested a review June 1, 2023 13:03
@OlegJakushkin OlegJakushkin marked this pull request as ready for review June 7, 2023 11:11
Copy link
Contributor

@smartprogrammer93 smartprogrammer93 left a comment

Choose a reason for hiding this comment

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

Wanted to merge this so i can use the new processingEnv, but the spec is not finalized yet. :(

OlegJakushkin and others added 4 commits July 4, 2023 21:30
…allCallResult.cs


Fixes for Success/Failure at  MultiCallCallResult

Co-authored-by: Ahmad Bitar <33181301+smartprogrammer93@users.noreply.github.com>
Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

Hm... I see potential need for ReportEvent due to injecting artificial events in tracer. But would love to avoid it, maybe we can inject those events directly in MultiCallVirtualMachine to original collection? Need to think about it.

Apart of that low code hygene, lot of unused stuff, potential exceptions, nulls handled wrong, some bugs.

src/Nethermind/Nethermind.Evm/Tracing/ITxTracer.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Facade/BlockchainBridge.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Facade/BlockchainBridge.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Facade/MultiCallBlockTracer.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Facade/MultiCallTxTracer.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Evm/VirtualMachine.cs Outdated Show resolved Hide resolved
Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

Hm... I see potential need for ReportEvent due to injecting artificial events in tracer. But would love to avoid it, maybe we can inject those events directly in MultiCallVirtualMachine to original collection? Need to think about it.

Apart of that low code hygene, lot of unused stuff, potential exceptions, nulls handled wrong, some bugs.

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

I think we don't have multiple block gas constraints enforced either

@flcl42
Copy link
Contributor

flcl42 commented Jun 1, 2024

Can I simulate invalid chain?

Copy link
Contributor

@ak88 ak88 left a comment

Choose a reason for hiding this comment

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

Very nice work!

Comment on lines 200 to 209
|| results.Error.Contains("InsufficientBalanceException")
))
results.ErrorCode = ErrorCodes.InvalidTransaction;

if (results.Error is not null && results.Error.Contains("InvalidBlockException"))
results.ErrorCode = ErrorCodes.InvalidParams;


if (results.Error is not null && results.Error.Contains("below intrinsic gas"))
results.ErrorCode = ErrorCodes.InsufficientIntrinsicGas;
Copy link
Member

Choose a reason for hiding this comment

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

Can we pass the ErrorCode explicitly rather than parsing string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly "InvalidBlockException" happens for multiple cases here and differs only by its text currently...

@OlegJakushkin OlegJakushkin merged commit 97c597f into master Jun 10, 2024
68 checks passed
@OlegJakushkin OlegJakushkin deleted the feature/eth_multicall branch June 10, 2024 14:56
@OlegJakushkin
Copy link
Contributor Author

Merging for ease of core development.
Future to-do items will be shipped in alternative PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants