Appearance
Architecture overview
This page describes the current version
The internals on this page can change between v0.x versions. The thread counts and the limits are current values, not fixed ones.
This page shows the parts of Cinder and how they connect. Each section has one diagram and links to the page with the details:
- Block pipeline: how the node executes one block.
- Writing blocks: how the writer thread writes blocks to the database.
- State database: the tables, the tries, the undo records and the caches.
Processes and connections
One cinder process in engine mode does all the work of the execution layer. The consensus client drives it through the Engine API. The node keeps its state in one libmdbx database. A cinder --serve process can read the same database and answer JSON-RPC requests. It cannot write.
- Engine API. The only way to move the chain. Every request needs a JWT token. For the methods and the rules, read Engine API.
- JSON-RPC. Off by default. It reads its own database snapshot for each request. For the methods, read JSON-RPC.
- P2P. Off by default. It gets missing blocks, serves peers and receives transactions. Without P2P,
--backfill-rpccan get missing blocks from a reth node. For details, read P2P. - Database. Only the engine process writes it, mostly through the writer thread. Many readers use it at the same time: the engine thread, its pools, the JSON-RPC requests and serve processes. For the safe setup of the ports and the files, read Security.
Threads of the node
One engine thread runs the Engine API loop and executes every block. The other threads do work beside it. --threads N sets the size of the compute pool. With N of 1, the node starts no pools, and the prewarm, the sender thread and the pool work do not run. The coordinator thread of the streaming state root and the trie node table builder run with any N.
- Engine thread. It polls the Engine API, executes the transactions in order, computes the state root with the pools and answers. Between requests, it gives due blocks to the writer and publishes the batches that the writer finished. It also imports the blocks that P2P gets.
- Executing core. At the start, the node takes the first CPU that the process can use for the executing thread. It keeps the SMT siblings of that CPU free, and all other threads run on the other CPUs. During a block, the engine thread moves to that CPU and runs at nice -5. A negative nice needs the
CAP_SYS_NICEcapability. Without it, the thread keeps its nice and still gets the core. The node does not do this with fewer than 4 CPUs or with--no-exec-iso. For the setup, read Tuning. - State root coordinator. At the first write of each account or slot, the executing thread adds a pointer to a write log. At the end of each transaction it publishes the new entries. It does not copy or hash anything. The coordinator thread takes the keys and loads their trie paths while the block executes. When execution ends, the coordinator did most of the trie work for the root. For details, read Block pipeline.
- During a block. The sender thread recovers the senders on the compute pool. The prewarm runs the transactions ahead of execution, and the coordinator also loads the trie paths of the prewarm's writes. With the streaming root off, a drainer thread reads those paths on the same I/O pool. At the end of the block, a thread builds the table of the trie nodes that the block changed. The children of the block use it for their roots. For each step, read Block pipeline.
- Writer. It writes batches of blocks in the background. For details, read Writing blocks.
- Busy flag. While the node executes or writes a block, the mempool prewarm and the transaction validation thread pause.
- JSON-RPC. Each connection has its own thread. The WebSocket subscriptions get their notifications from one notifier thread.
- P2P. 32 dialer threads do handshakes in parallel. For discovery and the peer limits, read P2P.
The path of one block
This diagram follows one engine_newPayload call and the forkchoice update after it. The node answers before it writes the block. The writer writes it later, between requests.
- Steps 1 to 8 are the steps of the Block pipeline page.
- Until the writer writes it, the block stays in memory as a node of the block tree. A child of the block executes over its diff. The root of the child starts from the trie nodes of the block.
- If more than 4 canonical blocks below the persist depth are not written,
engine_newPayloadwaits for the writer. For this and the other waits, read What waits for the writer.
The state root does not wait for the end of execution. The next picture shows how the executing thread, the write log, the coordinator and the I/O pool work beside each other. The block pipeline page has the details.
Median state root after execution: 10 ms without the stream, 4 ms with it.
latency_ab). Database tables
The database has 14 tables in one libmdbx environment. The writer writes the state, the trie nodes, the history and the undo records of a batch in one transaction.
- Flat state. Execution reads an account or a slot with one lookup. The trie tables store only branch and extension nodes. The node rebuilds leaves and bottom branches from the flat state.
- Undo records. They serve reorgs below the database head, JSON-RPC requests for older blocks, and
cinder-bench-node. - For the key and value formats and the cache, read State database.
Source layout
The directories of the source tree:
src/util arenas, thread pool, hex, big-stack threads, .ecfx fixture reader
src/prim 256-bit integers, strict RLP, transactions / headers / blocks / receipts
src/crypto keccak (vendored C + s2n-bignum; 4-way AVX2 via XKCP), sha256, secp256k1
(libsecp256k1), P-256 and bn254 (vendored C), RIPEMD-160, BLAKE2F, MODEXP
src/state journaled world-state overlay over a pluggable backend
src/evm computed-goto interpreter, calls / creates / EIP-7702, all Osaka precompiles,
JUMPDEST analyses cached by code hash
src/trie Merkle Patricia Trie with lazy node resolution, parallel state root,
level-by-level AVX2 hashing
src/exec transaction and block rules, system calls, requests, witness backend
src/import read-only reader of a reth datadir (Compact decoders)
src/net HTTP/JSON-RPC client and server, JWT
src/db libmdbx database: schema, state view, cross-block cache, per-block commit, block history, loader
src/node Engine API: payloads, block tree, state diffs, block building; the JSON-RPC API; transaction
admission (reth's checks); mempool prewarming; the streaming state root
src/p2p discv4, DNS node list, RLPx, eth messages and fork ids, peers, block fetcher, serving peers, transaction pool
src/app cinder (engine / serve / shadow), cinder-import, cinder-replay, cinder-mirror, cinder-p2p-probe,
cinder-rpc-diff, cinder-bench-node, poc-exec, bench-gas
tests unit tests; EEST runners (statetest, blocktest, enginetest)
tools reth fixture fetcher, verification, A/B benchmark, fuzzing, vendoring scripts,
console dashboards (tools/measure)
deps vendored third-party code (each directory has SOURCE and LICENSE files)
docs results (docs/results)