You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+83-10Lines changed: 83 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,79 @@
1
-
# Reth Development Guide for AI Agents
1
+
# BNB Chain Reth (bnb-chain/reth) — Development Guide
2
2
3
-
This guide provides comprehensive instructions for AI agents working on the Reth codebase. It covers the architecture, development workflows, and critical guidelines for effective contributions.
3
+
This guide provides comprehensive instructions for AI agents working on the **BNB Chain fork** of the Reth codebase. This is a production-grade execution layer client specifically adapted for **BNB Smart Chain (BSC)**.
**Upstream**: Fork of `paradigmxyz/reth` (v1.7.0 baseline)
7
+
**Main branch**: `main`
8
+
9
+
---
10
+
11
+
## Relationship: reth-bsc and reth
12
+
13
+
`bnb-chain/reth` (this repo) is the **core library layer** — a fork of upstream `paradigmxyz/reth` with BSC-specific modifications (Parlia consensus, TrieDB, system transactions, custom RPC, etc.).
14
+
15
+
`bnb-chain/reth-bsc` is the **application layer** that depends on this repo. It is the actual BSC node binary that imports crates from `bnb-chain/reth` as git dependencies. Issues reported in `reth-bsc` (e.g., RPC returning wrong data during staged sync) often have root causes in this repo's provider/storage layer.
16
+
17
+
When fixing issues from `reth-bsc`:
18
+
1. Trace the call path from RPC through the provider layer in this repo
19
+
2. Apply fixes here in `bnb-chain/reth`
20
+
3. The `reth-bsc` project will pick up fixes via git dependency updates
21
+
22
+
---
23
+
24
+
## BSC Fork Summary
25
+
26
+
This fork adapts the Ethereum-focused Reth client for BNB Smart Chain. Key differences from upstream:
1.**Parlia Consensus Engine**: BSC's Proof-of-Staked-Authority (PoSA) consensus replacing Ethereum's PoS. Implementation in `examples/bsc-p2p/src/block_import/parlia.rs`. Canonical head: highest block number wins; for equal heights, lower hash wins.
41
+
42
+
2.**TrieDB State Storage Backend**: Alternative state database alongside MDBX. Configured via `StateDbConfig` in `crates/config/src/config.rs`. Supports genesis init, staged sync, live sync, and io-uring. Dependencies from `bnb-chain/reth-bsc-triedb`.
43
+
44
+
3.**BSC System Transactions**: Special transactions identified by `gas_limit == u64::MAX/2 && caller == beneficiary`. Exempted from block gas limit validation. Handled across all RPC tracers via `handle_bsc_system_transaction()` in `crates/rpc/rpc/src/debug.rs`.
45
+
46
+
4.**Custom RPC Methods**: `eth_getFinalizedBlock(verified_validator_num)` and `eth_getFinalizedHeader(verified_validator_num)` in `crates/rpc/rpc-eth-api/src/core.rs` and `helpers/block.rs`.
47
+
48
+
5.**Proxied Peer Support**: Enhanced P2P networking with proxy peer definitions in `crates/net/network/` and `crates/net/eth-wire-types/`.
49
+
50
+
6.**Validator Block Snapshot Table**: BSC validator support integrated into the engine with a dedicated database table.
51
+
52
+
7.**Blob Fee Validation**: Enhanced blob storage with extended time support and fee checks for EIP-4844 compatibility on BSC.
-`crates/rpc/rpc-eth-api/src/helpers/block.rs` — Finalized block logic with validator count
63
+
-`crates/transaction-pool/src/validate/eth.rs` — Blob fee and EIP-1559 validation for BSC
64
+
-`crates/net/network/` — Proxied peer support
65
+
-`crates/storage/provider/` — TrieDB integration in state provider
66
+
67
+
### Custom Dependencies
68
+
69
+
```toml
70
+
# In Cargo.toml — BSC TrieDB support
71
+
rust-eth-triedb = { git = "https://github.com/bnb-chain/reth-bsc-triedb.git", tag = "v0.0.1" }
72
+
rust-eth-triedb-common = { ... }
73
+
rust-eth-triedb-state-trie = { ... }
74
+
```
75
+
76
+
---
4
77
5
78
## Project Overview
6
79
@@ -10,21 +83,22 @@ Reth is a high-performance Ethereum execution client written in Rust, focusing o
10
83
11
84
### Core Components
12
85
13
-
1.**Consensus (`crates/consensus/`)**: Validates blocks according to Ethereum consensus rules
14
-
2.**Storage (`crates/storage/`)**: Hybrid database using MDBX + static files for optimal performance
15
-
3.**Networking (`crates/net/`)**: P2P networking stack with discovery, sync, and transaction propagation
16
-
4.**RPC (`crates/rpc/`)**: JSON-RPC server supporting all standard Ethereum APIs
86
+
1.**Consensus (`crates/consensus/`)**: Validates blocks according to consensus rules (Parlia for BSC)
87
+
2.**Storage (`crates/storage/`)**: Hybrid database using MDBX + static files + TrieDB (BSC) for optimal performance
88
+
3.**Networking (`crates/net/`)**: P2P networking stack with discovery, sync, transaction propagation, and proxied peer support
89
+
4.**RPC (`crates/rpc/`)**: JSON-RPC server supporting standard Ethereum APIs + BSC custom methods
17
90
5.**Execution (`crates/evm/`, `crates/ethereum/`)**: Transaction execution and state transitions
18
91
6.**Pipeline (`crates/stages/`)**: Staged sync architecture for blockchain synchronization
19
92
7.**Trie (`crates/trie/`)**: Merkle Patricia Trie implementation with parallel state root computation
20
93
8.**Node Builder (`crates/node/`)**: High-level node orchestration and configuration
21
94
9.**The Consensus Engine (`crates/engine/`)**: Handles processing blocks received from the consensus layer with the Engine API (newPayload, forkchoiceUpdated)
95
+
10.**Configuration (`crates/config/`)**: Node configuration including StateDbConfig for TrieDB/MDBX backend selection
22
96
23
97
### Key Design Principles
24
98
25
99
-**Modularity**: Each crate can be used as a standalone library
26
100
-**Performance**: Extensive use of parallelism, memory-mapped I/O, and optimized data structures
27
-
-**Extensibility**: Traits and generic types allow for different implementations (Ethereum, Optimism, etc.)
101
+
-**Extensibility**: Traits and generic types allow for different implementations (Ethereum, BSC, Optimism, etc.)
28
102
-**Type Safety**: Strong typing throughout with minimal use of dynamic dispatch
29
103
30
104
## Development Workflow
@@ -175,7 +249,7 @@ Before submitting changes, ensure:
175
249
5.**Commit Messages**: Follow conventional format (feat:, fix:, chore:, etc.)
176
250
177
251
178
-
### Opening PRs against <https://github.com/paradigmxyz/reth>
252
+
### Opening PRs against <https://github.com/bnb-chain/reth>
179
253
180
254
Label PRs appropriately, first check the available labels and then apply the relevant ones:
0 commit comments