Nethermind Documentation
repository·master·Indexed 23 days ago
https://github.com/nethermindeth/nethermindA 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.
What's inside Nethermind
- Kute is a benchmarking tool developed by Nethermind designed to simulate an Ethereum Consensus Layer. It works by sending JSON-RPC messages to a Nethermind Client and measuring the client's performance. It is intended to be used in conjunction with the Nethermind Client.
Overview of RPC Benchmarking Scripts
masterThe 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.
XDC Consensus Performance Characteristics
masterConsensus 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
Use RpcTests.Generator to create RPC test cases
masterRpcTests.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:
- 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. - 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" } } ]- Report mode: Used when recordings were captured with
What is RpcTests.Monitor
masterRpcTests.Monitor is a tool that continuously monitors an Ethereum RPC node by replaying parameterized test cases. It compares the responses from the target node against a reference node (or a static expected response) and reports any mismatches. It works by subscribing tonewHeadsvia WebSocket and evaluating test conditions on every new block.Understand JitAsm instruction annotations
masterWhen 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]Field Meaning Description TPReciprocal throughput Cycles per instruction. Lower is faster. LatLatency Cycles from input ready to output ready. UopsMicro-op count Number of micro-ops; fewer reduces execution engine pressure. PortsExecution port usage Shows 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).How Nethermind.Kademlia works
masterNethermind.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.
Merge snapshots using PersistedSnapshotMerger
masterThe
PersistedSnapshotMergerperforms 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 withto_*andversionfrom the newest source.
How the 3-chain finalization rule works
masterXDC 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
grandparentbased on aproposedBlock:proposedRound - 1 == parent.roundproposedRound - 2 == grandparent.roundproposedRound > 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.
Define parameterized test files
masterTest 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 fromTestContext(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--referencenode 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}}" } } ]How Engine API Proxy validation modes work
masterThe Engine API Proxy intercepts Engine API calls (specifically
engine_forkchoiceUpdated,engine_newPayload, andengine_getPayload) to optimize the processing sequence. It supports four validation modes:- ForkChoiceUpdated Mode: Validates through the
ForkChoiceUpdatedpipeline. - NewPayload Mode: Validates through the
NewPayloadpipeline. - Merged Mode: Validates through the
ForkChoiceUpdatedpipeline and storesPayloadIDwithout validation; validation occurs at the nextnew_payloadrequest. - Lighthouse Mode: Similar to Merged, but intercepts
PayloadAttributesfrom existingFCUrequests instead of generating them.
Note: For
Lighthousemode, use the Lighthouse consensus client with the--always-prepare-payloadflag enabled. This is currently considered the most accurate validation mode.- ForkChoiceUpdated Mode: Validates through the
Handle timeouts with TimeoutCertificateManager
masterThe
TimeoutCertificateManagerensures network liveness by handling timeouts when consensus progress stalls.Timeout Flow:
- OnCountdownTimer(): A node's timer expires.
- SendTimeout(round): The node broadcasts a timeout for the current round.
- Collection: Timeouts are collected in a pool. If
Count >= threshold, aTimeoutCertificate(TC) is created. - Broadcast: The TC and
SyncInfoare broadcast to the network. - ProcessTimeoutCertificate(): Nodes receiving a TC will:
- Update
HighestTC. - Advance to
TC.Round + 1. - Reset the timeout counter.
- Update