Nethermind Documentation

repository·master·Indexed 23 days ago

https://github.com/nethermindeth/nethermind

A high-performance Ethereum execution client built on .NET, supporting Ethereum, Gnosis, and L2s like Optimism and Linea. Features include a modular plugin system for extending consensus engines and RPC namespaces, Snap sync for fast synchronization, and a dedicated RPC benchmarking suite for measuring state-reading JSON-RPC performance. The project also includes Nethermind.Kademlia, providing generic routing-table and lookup primitives.

Tokens
33K
Snippets
61
Records
138
Agent score
82%

What's inside Nethermind

  1. Overview of RPC Benchmarking Scripts

    master

    The RPC benchmarking scripts are designed to measure an execution client's state-reading JSON-RPC performance (e.g., eth_call, eth_getBalance, trace_*, debug_*).

    Key features include:

    • Target Clients: Primarily Nethermind, but also supports Geth and Reth.
    • Comparison Mode: Allows diffing two clients side-by-side (e.g., Nethermind vs Geth) using the same block snapshot to ensure correctness.
    • Profiling: Supports JetBrains dotTrace capture and XML post-processing for Nethermind to identify RPC-call hot spots.
    • Isolation: Uses various database isolation mechanisms to ensure that the underlying DB snapshots remain uncorrupted during read-only benchmarks.
  2. XDC Consensus Performance Characteristics

    master

    Consensus Latency

    • MinePeriod (default): 2s
    • Network Propagation: ~100-500ms
    • Vote Collection: ~100-500ms
    • QC Formation: ~10-50ms
    • Total: ~2.2 - 3.0 seconds/block

    Finality

    • Finalization Depth: 3 blocks (3-chain rule)
    • Time to Finality: ~6 seconds (optimal) to 8-12 seconds (practical)

    Throughput

    • Gas Limit: 84,000,000
    • Block Time: 2 seconds
    • Theoretical TPS: 1000 - 2500 tx/s
    • Practical TPS: 500 - 1000 tx/s
  3. Use RpcTests.Generator to create RPC test cases

    master

    RpcTests.Generator is a tool that converts JSONL request recordings into RPC test case files compatible with the Erigon rpc-tests format. It supports two operational modes based on how the Nethermind RPC recorder was configured:

    1. Report mode: Used when recordings were captured with --JsonRpc.RpcRecorderState All. In this mode, the JSONL file already contains both requests and responses; the tool simply matches them by ID.
    2. Live mode: Used when recordings were captured with --JsonRpc.RpcRecorderState Request. In this mode, the file contains only requests. The tool will send these requests to a provided reference client URL (--client) and record the responses.

    The output is a JSON file containing the request and response pairs.

    [
      {
        "request": {
          "jsonrpc": "2.0",
          "id": 1,
          "method": "eth_blockNumber",
          "params": []
        },
        "response": {
          "jsonrpc": "2.0",
          "id": 1,
          "result": "0x12345"
        }
      }
    ]
  4. Understand JitAsm instruction annotations

    master

    When annotations are enabled, each instruction line includes an end-of-line comment containing performance metrics in the following format:

    [TP:0.25 | Lat: 1 | Uops:1 | 1*FP_LD]

    FieldMeaningDescription
    TPReciprocal throughputCycles per instruction. Lower is faster.
    LatLatencyCycles from input ready to output ready.
    UopsMicro-op countNumber of micro-ops; fewer reduces execution engine pressure.
    PortsExecution port usageShows functional units used (e.g., 1*p0156).

    Note on Mappings: The tool automatically maps Intel-style mnemonics (used by .NET JIT) to canonical uops.info forms (e.g., je $\rightarrow$ jz).

  5. How Nethermind.Kademlia works

    master

    Nethermind.Kademlia provides generic Kademlia routing-table and lookup primitives. It is designed to be decoupled from the specific transport, authentication, and node record implementations of your protocol.

    What it provides:

    • Shared routing table mechanics.
    • Iterative lookup logic.
    • Node-health tracking.
    • Random-walk discovery mechanics.

    What you must provide:

    • Key hashing.
    • XOR-distance operations.
    • Wire message transport.
    • Peer admission logic.
  6. Merge snapshots using PersistedSnapshotMerger

    master

    The PersistedSnapshotMerger performs a compaction/merge of multiple sorted snapshot runs.

    Merge Logic:

    • Complexity: It performs an $O(N)$ find-min walk through the input runs in ascending key order.
    • Conflict Resolution: When multiple sources contain the same key, the newest-source-wins.
    • Ref-id Deduping: Ref-id records are merged to yield the union of all referenced IDs.
    • Self-destruct Truncation: Slots are buffered per address. If a newer source indicates a self-destruct for an address, any slots contributed only by older sources are dropped.
    • Metadata Handling: Metadata is written separately, combining from_* fields from the oldest source with to_* and version from the newest source.
  7. How the 3-chain finalization rule works

    master

    XDC uses a 3-chain rule to finalize blocks. A block (the grandparent) is committed and finalized when three consecutive rounds of blocks exist.

    Conditions for Finalization: To finalize a grandparent based on a proposedBlock:

    1. proposedRound - 1 == parent.round
    2. proposedRound - 2 == grandparent.round
    3. proposedRound > grandparent.round + 1

    Visual Flow:

    • Round N-2 (Block B) -> Round N-1 (Block C) -> Round N (Block D)
    • When Block D is proposed, Block B is finalized.
  8. Define parameterized test files

    master

    Test files use a JSON format where requests and responses can be parameterized using C# expressions wrapped in {{ expression }}. These expressions are evaluated using DynamicExpresso and can access helpers from TestContext (e.g., EveryBlocks, Recent, Hex, Topic).

    Test Fields

    • run (required): A boolean expression evaluated once per new head to decide if the test should run.
    • request (required): The JSON-RPC request object with parameterized properties.
    • response (optional): A fixed expected value to validate against. If this is provided, a --reference node is not required.
    • ignore (optional): A single response path or an array of JSON paths to exclude from the comparison.
    • test (optional): Metadata for the test.
    [
      {
        "run": "EveryBlocks(5)",
        "test": {
          "description": "WETH transfers to Uniswap V3"
        },
        "request": {
          "jsonrpc": "2.0",
          "method": "eth_getLogs",
          "params": [{
            "fromBlock": "{{Hex(Recent.Number - 9)}}",
            "toBlock": "{{Hex(Recent.Number)}}",
            "address": ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", "0xdAC17F958D2ee523a2206206994597C13D831ec7"],
            "topics": [
              "{{Topic.Transfer}}",
              null,
              "0x0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad"
            ]
          }],
          "id": "{{Request.Number}}"
        }
      }
    ]
  9. How Engine API Proxy validation modes work

    master

    The Engine API Proxy intercepts Engine API calls (specifically engine_forkchoiceUpdated, engine_newPayload, and engine_getPayload) to optimize the processing sequence. It supports four validation modes:

    1. ForkChoiceUpdated Mode: Validates through the ForkChoiceUpdated pipeline.
    2. NewPayload Mode: Validates through the NewPayload pipeline.
    3. Merged Mode: Validates through the ForkChoiceUpdated pipeline and stores PayloadID without validation; validation occurs at the next new_payload request.
    4. Lighthouse Mode: Similar to Merged, but intercepts PayloadAttributes from existing FCU requests instead of generating them.

    Note: For Lighthouse mode, use the Lighthouse consensus client with the --always-prepare-payload flag enabled. This is currently considered the most accurate validation mode.

  10. Handle timeouts with TimeoutCertificateManager

    master

    The TimeoutCertificateManager ensures network liveness by handling timeouts when consensus progress stalls.

    Timeout Flow:

    1. OnCountdownTimer(): A node's timer expires.
    2. SendTimeout(round): The node broadcasts a timeout for the current round.
    3. Collection: Timeouts are collected in a pool. If Count >= threshold, a TimeoutCertificate (TC) is created.
    4. Broadcast: The TC and SyncInfo are broadcast to the network.
    5. ProcessTimeoutCertificate(): Nodes receiving a TC will:
      • Update HighestTC.
      • Advance to TC.Round + 1.
      • Reset the timeout counter.