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