05Core Dev Bootcamp
Codebase Navigation Guide
Introduction
This appendix helps you navigate the rippled codebase to find SHAMap and NodeStore implementations.
Directory Structure
SHAMap Source Files
rippled/src/xrpld/shamap/
├── SHAMap.h # Main SHAMap class
├── SHAMapInnerNode.h # Inner node implementation
├── SHAMapLeafNode.h # Leaf node implementations
├── SHAMapNodeID.h # Node identification
├── SHAMapHash.h # Hash computation
├── SHAMapMissingNode.h # Missing node tracking
├── detail/
│ ├── SHAMap.cpp # Core algorithms
│ ├── SHAMapSync.cpp # Synchronization logic
│ └── SHAMapDelta.cpp # Tree traversal
NodeStore Source Files
rippled/src/xrpld/nodestore/
├── Database.h # Database interface
├── Backend.h # Backend interface
├── Manager.h # NodeStore manager
├── Types.h # Type definitions
├── Task.h # Async task definitions
├── Scheduler.h # Scheduling
├── backend/
│ ├── RocksDBFactory.cpp # RocksDB backend
│ ├── NuDBFactory.cpp # NuDB backend
│ ├── MemoryFactory.cpp # In-memory backend
│ └── NullFactory.cpp # No-op backend
├── detail/
│ ├── Database.cpp # Database implementation
│ ├── ManagerImp.cpp # Manager implementation
│ ├── BatchWriter.h/cpp # Batch write handling
│ ├── DatabaseNodeImp.h # Single-backend implementation
│ ├── DatabaseRotatingImp.h # Rotating-database implementation
│ ├── NodeObject.cpp # NodeObject implementation
│ ├── EncodedBlob.h # Encoding/decoding
│ ├── DecodedBlob.h # Blob structure
│ └── varint.h # Variable-length integers
Integration Points
rippled/src/xrpld/app/
├── misc/SHAMapStore.h # SHAMap-NodeStore integration
├── misc/SHAMapStoreImp.h/cpp # Implementation
└── main/NodeStoreScheduler.h/cpp # Background scheduling
Key Classes and Their Locations
SHAMap Classes
| Class | File | Purpose |
|---|---|---|
SHAMap | shamap/SHAMap.h | Main tree class |
SHAMapTreeNode | shamap/SHAMapTreeNode.h | Base node class |
SHAMapInnerNode | shamap/SHAMapInnerNode.h | Inner nodes (branches) |
SHAMapLeafNode | shamap/SHAMapLeafNode.h | Leaf nodes (data) |
SHAMapNodeID | shamap/SHAMapNodeID.h | Node identification |
SHAMapItem | shamap/SHAMapItem.h | Data in leaf nodes |
NodeStore Classes
| Class | File | Purpose |
|---|---|---|
Database | nodestore/Database.h | High-level interface |
Backend | nodestore/Backend.h | Low-level interface |
NodeObject | nodestore/detail/NodeObject.h | Storage unit |
DatabaseNodeImp | nodestore/detail/DatabaseNodeImp.h | Single backend |
DatabaseRotatingImp | nodestore/detail/DatabaseRotatingImp.h | Rotating backend |
TaggedCache | nodestore/detail/TaggedCache.h | Cache implementation |
Navigation by Task
Understanding SHAMap Structure
- Start:
SHAMap.h- Overview of the class - Read:
SHAMapTreeNode.h- Base class and type system - Explore:
SHAMapInnerNode.h- Branch structure - Explore:
SHAMapLeafNode.h- Data storage - Study:
detail/SHAMap.cpp- Implementation details
Understanding Node Synchronization
- Start:
shamap/SHAMapMissingNode.h- Missing node representation - Study:
detail/SHAMapSync.cpp- Synchronization algorithm - Cross-reference:
nodestore/Database.h- Fetch operations called during sync - Understand:
shamap/SHAMapNodeID.h- How nodes are identified
Understanding NodeStore Architecture
- Start:
nodestore/Database.h- Public interface - Understand:
nodestore/Backend.h- Storage abstraction - Explore:
nodestore/detail/NodeObject.h- Storage unit - Study:
nodestore/detail/DatabaseNodeImp.h- Standard implementation - Study:
nodestore/detail/DatabaseRotatingImp.h- Rotation implementation
Understanding Database Rotation
- Read:
nodestore/detail/DatabaseRotatingImp.h- Architecture - Study:
nodestore/detail/DatabaseRotatingImp.cpp- Implementation - Understand: Synchronization with
app/misc/SHAMapStoreImp.h
Understanding Cache Layer
- Explore:
nodestore/detail/TaggedCache.h- Cache implementation - Study usage in:
nodestore/detail/DatabaseNodeImp.cpp - Understand metrics in: Database metrics methods
Common Code Patterns
Accessing a Node in SHAMap
// In shamap/SHAMap.h or detail/SHAMap.cpp
std::shared_ptr<SHAMapTreeNode> node = getNodePointer(nodeID);
Storing a Node in NodeStore
// In app/misc/SHAMapStoreImp.cpp
auto obj = NodeObject::createObject(type, data, hash);
mNodeStore->store(obj);
Retrieving a Node
// In nodestore/detail/DatabaseNodeImp.cpp
auto obj = mDatabase->fetchNodeObject(hash);
Cache Hit Path
// In nodestore/detail/DatabaseNodeImp.cpp
auto cached = mCache.get(hash); // L1 cache
if (!cached) {
cached = mBackend->fetch(hash); // L2 backend
if (cached) mCache.insert(hash, cached);
}
Important Files to Read
Essential (Required Reading)
shamap/SHAMap.h- Core APIshamap/SHAMapNodeID.h- Navigation understandingnodestore/Database.h- NodeStore APInodestore/Backend.h- Abstraction principle
Important (Strongly Recommended)
shamap/detail/SHAMap.cpp- Implementationnodestore/detail/DatabaseNodeImp.h- Cache logicapp/misc/SHAMapStoreImp.h- Integration
Reference (For Deep Understanding)
shamap/SHAMapInnerNode.h- Branch structure detailsshamap/SHAMapLeafNode.h- Leaf implementationsnodestore/detail/SHAMapSync.cpp- Sync algorithmnodestore/detail/DatabaseRotatingImp.h- Rotation details
Building and Exploring
Compile rippled
cd rippled
mkdir build && cd build
cmake ..
make -j4
Navigate with IDE
Using VS Code or similar:
- Open rippled repository
- Go to Definition (Ctrl+Click) to jump to class definitions
- Find All References (Shift+Ctrl+F) to see usage patterns
- Use search to navigate between related classes
Debug and Trace
// Add to your code to trace execution
#include <iostream>
std::cout << "Node hash: " << node->getHash() << std::endl;
std::cout << "Node type: " << (int)node->getNodeType() << std::endl;
Test Files
Locate tests in:
rippled/src/test/*/shamap* and */nodestore*
Study how these are tested to understand expected usage patterns.
Configuration Reference
Configuration Files
NodeStore configuration in rippled.cfg:
[node_db]
type = RocksDB # Backend choice
path = /data/node.db # Location
cache_size = 256 # Cache size in MB
cache_age = 60 # Max age in seconds
# For NuDB
# type = NuDB
# path = /data/nudb
# For Rotating
# online_delete = 256 # Keep last N ledgers
Common Configuration Patterns
# Small validator (less memory available)
[node_db]
cache_size = 64
cache_age = 30
# Large validator (plenty of resources)
[node_db]
cache_size = 512
cache_age = 120
Quick Reference
| Task | File | Function |
|---|---|---|
| Create NodeObject | nodestore/detail/NodeObject.h | createObject() |
| Fetch Node | nodestore/Database.h | fetchNodeObject() |
| Store Node | nodestore/Database.h | store() |
| Find in SHAMap | shamap/SHAMap.h | findLeaf() |
| Add to SHAMap | shamap/detail/SHAMap.cpp | addNode() |
| Check Cache | nodestore/detail/TaggedCache.h | get() |
| Rotate Database | nodestore/detail/DatabaseRotatingImp.h | rotate() |
| Get Metrics | nodestore/Database.h | getCountsJson() |
Learning Path
- Week 1: Understand architecture (Chapters 1-4 of this module)
- Week 2: Read
SHAMap.hand understand node types - Week 3: Study
shamap/detail/SHAMap.cpp- implementation - Week 4: Read
nodestore/Database.hand understand NodeStore design - Week 5: Study
nodestore/detail/DatabaseNodeImp.h- caching - Week 6: Trace actual code execution (single transaction flow)
- Week 7: Build and run tests
- Week 8: Modify and experiment
This progression takes you from conceptual understanding to implementation mastery.