|
| 1 | +# xrpld Codebase Skills Index |
| 2 | + |
| 3 | +## Description |
| 4 | +This is the top-level guide for all best-practices skills in this repository. Use this to understand the codebase organization and find the right skill for any task. |
| 5 | + |
| 6 | +## When to Use Skills |
| 7 | +Reference a skill whenever you are: |
| 8 | +- **Writing new code** in a module - check the skill first for established patterns |
| 9 | +- **Modifying existing code** - verify your changes follow module conventions |
| 10 | +- **Adding a new transaction type** - see `libxrpl/tx/transactors.md` for the full template |
| 11 | +- **Debugging** - skills list key files and common pitfalls per module |
| 12 | +- **Reviewing code** - skills document what "correct" looks like for each module |
| 13 | + |
| 14 | +## Codebase Architecture |
| 15 | + |
| 16 | +The codebase is split into two main areas: |
| 17 | + |
| 18 | +### `src/libxrpl/` — The Library (skills in `.claude/skills/libxrpl/`) |
| 19 | +Reusable library code: data types, serialization, cryptography, ledger state, transaction processing, and storage. This is the **protocol layer**. |
| 20 | + |
| 21 | +| Module | Responsibility | |
| 22 | +|--------|---------------| |
| 23 | +| `basics` | Foundational types: Buffer, Slice, base_uint, Number, logging, error contracts | |
| 24 | +| `beast` | Support layer: Journal logging, test framework, instrumentation, IP types | |
| 25 | +| `conditions` | Crypto-conditions (RFC): fulfillment validation, DER encoding | |
| 26 | +| `core` | Job queue, load monitoring, hash-based message dedup | |
| 27 | +| `crypto` | CSPRNG, secure erasure, RFC1751 encoding | |
| 28 | +| `json` | Json::Value, parsing, serialization, StaticString optimization | |
| 29 | +| `ledger` | ReadView/ApplyView, state tables, payment sandbox, credit ops | |
| 30 | +| `net` | HTTP/HTTPS client, SSL certs, async I/O | |
| 31 | +| `nodestore` | Persistent node storage: RocksDB, NuDB, Memory backends | |
| 32 | +| `protocol` | STObject hierarchy, SField, Serializer, TER codes, Features, Keylets | |
| 33 | +| `proto` | Protocol Buffer generated headers (gRPC API definitions) | |
| 34 | +| `rdb` | SOCI database wrapper, checkpointing | |
| 35 | +| `resource` | Rate limiting, endpoint tracking, abuse prevention | |
| 36 | +| `server` | Port config, SSL/TLS, WebSocket, admin networks | |
| 37 | +| `shamap` | SHA-256 Merkle radix tree (16-way branching, COW) | |
| 38 | +| `tx` | Transaction pipeline: Transactor base, preflight/preclaim/doApply | |
| 39 | + |
| 40 | +### `src/xrpld/` — The Server Application (skills in `.claude/skills/xrpld/`) |
| 41 | +The running rippled server: application lifecycle, consensus, networking, RPC, and peer management. This is the **application layer**. |
| 42 | + |
| 43 | +| Module | Responsibility | |
| 44 | +|--------|---------------| |
| 45 | +| `app` | Application singleton, ledger management, consensus adapters, services | |
| 46 | +| `app/main` | Application initialization and lifecycle | |
| 47 | +| `app/ledger` | Ledger storage, retrieval, immutable state management | |
| 48 | +| `app/consensus` | RCL consensus adapters (bridges generic algorithm to rippled) | |
| 49 | +| `app/misc` | Fee voting, amendments, SHAMapStore, TxQ, validators, NetworkOPs | |
| 50 | +| `app/paths` | Payment path finding algorithm, trust line caching | |
| 51 | +| `app/rdb` | Application-level database operations | |
| 52 | +| `app/tx` | Application-level transaction handling | |
| 53 | +| `consensus` | Generic consensus algorithm (CRTP-based, app-independent) | |
| 54 | +| `core` | Configuration (Config.h), time keeping, network ID | |
| 55 | +| `overlay` | P2P networking: peer connections, protocol buffers, clustering | |
| 56 | +| `peerfinder` | Network discovery: bootcache, livecache, slot management | |
| 57 | +| `perflog` | Performance logging and instrumentation | |
| 58 | +| `rpc` | RPC handler dispatch, coroutine suspension, 40+ command handlers | |
| 59 | +| `shamap` | Application-level SHAMap operations (NodeFamily) | |
| 60 | + |
| 61 | +### `include/xrpl/` — Header Files |
| 62 | +Headers live in `include/xrpl/` and mirror the `src/libxrpl/` structure. Each skill already references its corresponding headers in the "Key Files" section. |
| 63 | + |
| 64 | +## Cross-Cutting Conventions |
| 65 | + |
| 66 | +### Error Handling |
| 67 | +- **Transaction errors**: Return `TER` enum (tesSUCCESS, tecFROZEN, temBAD_AMOUNT, etc.) |
| 68 | +- **Logic errors**: `Throw<std::runtime_error>()`, `LogicError()`, `XRPL_ASSERT()` |
| 69 | +- **I/O errors**: `Status` enum or `boost::system::error_code` |
| 70 | +- **RPC errors**: Inject via `context.params` |
| 71 | + |
| 72 | +### Assertions |
| 73 | +```cpp |
| 74 | +XRPL_ASSERT(condition, "ClassName::method : description"); // Debug only |
| 75 | +XRPL_VERIFY(condition, "ClassName::method : description"); // Always enabled |
| 76 | +``` |
| 77 | +
|
| 78 | +### Logging |
| 79 | +```cpp |
| 80 | +JLOG(j_.warn()) << "Message"; // Always wrap in JLOG macro |
| 81 | +``` |
| 82 | + |
| 83 | +### Memory Management |
| 84 | +- `IntrusiveRefCounts` + `SharedIntrusive` for shared ownership in libxrpl |
| 85 | +- `std::shared_ptr` for shared ownership in xrpld |
| 86 | +- `std::unique_ptr` for exclusive ownership |
| 87 | +- `CountedObject<T>` mixin for instance tracking |
| 88 | + |
| 89 | +### Feature Gating |
| 90 | +```cpp |
| 91 | +if (ctx.rules.enabled(featureMyFeature)) { /* new behavior */ } |
| 92 | +``` |
| 93 | +
|
| 94 | +### Code Organization |
| 95 | +- Headers in `include/xrpl/`, implementations in `src/libxrpl/` or `src/xrpld/` |
| 96 | +- `#pragma once` (never `#ifndef` guards) |
| 97 | +- `namespace xrpl { }` for all code |
| 98 | +- `detail/` namespace for internal helpers |
| 99 | +- Factory functions: `make_*()` returning `unique_ptr` or `shared_ptr` |
0 commit comments