Skip to content

Commit 2e8028d

Browse files
tizocdannywillems
authored andcommitted
docs(handover): Add ledger/summary.md
1 parent 34c83df commit 2e8028d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

docs/handover/ledger-crate.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ zkApp functionality, providing a direct port of the OCaml implementation. For
88
developers familiar with the OCaml codebase, this maintains the same
99
architecture and business logic while adapting to Rust idioms.
1010

11+
For technical debt and critical issues, see [`ledger/summary.md`](../../ledger/summary.md).
12+
1113
## Architecture
1214

1315
### Core Components
@@ -23,6 +25,7 @@ architecture and business logic while adapting to Rust idioms.
2325

2426
- Port of OCaml's `Ledger.Mask` with identical copy-on-write semantics
2527
- Provides layered ledger views for efficient state management
28+
- Uses `Arc<Mutex<MaskImpl>>` for cheap reference counting; `Mask::clone()` is fast
2629
- Used extensively in transaction processing to create temporary ledger states
2730

2831
**Database** (`src/database/`)

ledger/summary.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Ledger Crate Summary
2+
3+
The ledger crate is the most complex component in the codebase. For architecture overview and design details, see [docs/handover/ledger-crate.md](../docs/handover/ledger-crate.md).
4+
5+
## Quick Reference
6+
7+
**Core Ledger**
8+
- `src/base.rs` - BaseLedger trait (fundamental interface)
9+
- `src/database/` - In-memory account storage
10+
- `src/mask/` - Layered ledger views with Arc-based sharing
11+
- `src/tree.rs` - Merkle tree operations
12+
13+
**Transaction Processing**
14+
- `src/transaction_pool.rs` - Mempool with fee-based ordering
15+
- `src/staged_ledger/` - Block validation and transaction application
16+
- `src/scan_state/` - SNARK work coordination and parallel scan
17+
18+
**Proof System**
19+
- `src/proofs/` - Transaction, block, and zkApp proof generation/verification
20+
- `src/sparse_ledger/` - Minimal ledger representation for proofs
21+
- `src/zkapps/` - zkApp transaction processing
22+
23+
**Account Management**
24+
- `src/account/` - Account structures, balances, permissions
25+
26+
## Critical Issues
27+
28+
**Error Handling**
29+
- Too many `.unwrap()` and `.expect()` calls in production code paths (excluding tests)
30+
- Critical transaction processing paths could panic the node
31+
- Inconsistent error handling across modules
32+
- Verification key lookup bug fix from upstream Mina Protocol needs to be ported (https://github.com/MinaProtocol/mina/pull/16699)
33+
34+
**Monolithic Structure**
35+
- Single massive crate with files exceeding 6,000+ lines
36+
- Deep coupling between components that should be independent
37+
- Hard to maintain, test, and develop in parallel
38+
39+
**Performance**
40+
- Excessive cloning of large structures in hot paths:
41+
- `SparseLedger::of_ledger_subset_exn()` calls `oledger.copy()` creating unnecessary deep clones for sparse ledger construction
42+
- Transaction pool operations clone transaction objects with acknowledged TODO comments about performance
43+
- No memory pooling or reuse strategies (could help with memory fragmentation in WASM)
44+
45+
**Memory Management**
46+
- Memory-only implementation, no persistence for production
47+
- There's an unused `ondisk` implementation but we were planning a more comprehensive global solution (see persistence.md)
48+
- Thread-local caching holds memory indefinitely
49+
50+
## Refactoring Plan
51+
52+
**Phase 1: Safety**
53+
- Replace `.unwrap()` with proper error propagation in production code
54+
- Reduce cloning in hot paths
55+
- Standardize error types
56+
57+
**Phase 2: Decomposition**
58+
Break into focused crates: `mina-account`, `mina-ledger`, `mina-transaction-logic`, `mina-scan-state`, `mina-transaction-pool`, `mina-proofs`
59+
60+
Changes must maintain strict OCaml compatibility while improving performance for production.

0 commit comments

Comments
 (0)