Core Dev Bootcamp
Docs

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

text
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

text
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

text
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

ClassFilePurpose
SHAMapshamap/SHAMap.hMain tree class
SHAMapTreeNodeshamap/SHAMapTreeNode.hBase node class
SHAMapInnerNodeshamap/SHAMapInnerNode.hInner nodes (branches)
SHAMapLeafNodeshamap/SHAMapLeafNode.hLeaf nodes (data)
SHAMapNodeIDshamap/SHAMapNodeID.hNode identification
SHAMapItemshamap/SHAMapItem.hData in leaf nodes

NodeStore Classes

ClassFilePurpose
Databasenodestore/Database.hHigh-level interface
Backendnodestore/Backend.hLow-level interface
NodeObjectnodestore/detail/NodeObject.hStorage unit
DatabaseNodeImpnodestore/detail/DatabaseNodeImp.hSingle backend
DatabaseRotatingImpnodestore/detail/DatabaseRotatingImp.hRotating backend
TaggedCachenodestore/detail/TaggedCache.hCache implementation

Understanding SHAMap Structure

  1. Start: SHAMap.h - Overview of the class
  2. Read: SHAMapTreeNode.h - Base class and type system
  3. Explore: SHAMapInnerNode.h - Branch structure
  4. Explore: SHAMapLeafNode.h - Data storage
  5. Study: detail/SHAMap.cpp - Implementation details

Understanding Node Synchronization

  1. Start: shamap/SHAMapMissingNode.h - Missing node representation
  2. Study: detail/SHAMapSync.cpp - Synchronization algorithm
  3. Cross-reference: nodestore/Database.h - Fetch operations called during sync
  4. Understand: shamap/SHAMapNodeID.h - How nodes are identified

Understanding NodeStore Architecture

  1. Start: nodestore/Database.h - Public interface
  2. Understand: nodestore/Backend.h - Storage abstraction
  3. Explore: nodestore/detail/NodeObject.h - Storage unit
  4. Study: nodestore/detail/DatabaseNodeImp.h - Standard implementation
  5. Study: nodestore/detail/DatabaseRotatingImp.h - Rotation implementation

Understanding Database Rotation

  1. Read: nodestore/detail/DatabaseRotatingImp.h - Architecture
  2. Study: nodestore/detail/DatabaseRotatingImp.cpp - Implementation
  3. Understand: Synchronization with app/misc/SHAMapStoreImp.h

Understanding Cache Layer

  1. Explore: nodestore/detail/TaggedCache.h - Cache implementation
  2. Study usage in: nodestore/detail/DatabaseNodeImp.cpp
  3. Understand metrics in: Database metrics methods

Common Code Patterns

Accessing a Node in SHAMap

C++
// In shamap/SHAMap.h or detail/SHAMap.cpp
std::shared_ptr<SHAMapTreeNode> node = getNodePointer(nodeID);

Storing a Node in NodeStore

C++
// In app/misc/SHAMapStoreImp.cpp
auto obj = NodeObject::createObject(type, data, hash);
mNodeStore->store(obj);

Retrieving a Node

C++
// In nodestore/detail/DatabaseNodeImp.cpp
auto obj = mDatabase->fetchNodeObject(hash);

Cache Hit Path

C++
// 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 API
  • shamap/SHAMapNodeID.h - Navigation understanding
  • nodestore/Database.h - NodeStore API
  • nodestore/Backend.h - Abstraction principle
  • shamap/detail/SHAMap.cpp - Implementation
  • nodestore/detail/DatabaseNodeImp.h - Cache logic
  • app/misc/SHAMapStoreImp.h - Integration

Reference (For Deep Understanding)

  • shamap/SHAMapInnerNode.h - Branch structure details
  • shamap/SHAMapLeafNode.h - Leaf implementations
  • nodestore/detail/SHAMapSync.cpp - Sync algorithm
  • nodestore/detail/DatabaseRotatingImp.h - Rotation details

Building and Exploring

Compile rippled

Shell
cd rippled
mkdir build && cd build
cmake ..
make -j4

Using VS Code or similar:

  1. Open rippled repository
  2. Go to Definition (Ctrl+Click) to jump to class definitions
  3. Find All References (Shift+Ctrl+F) to see usage patterns
  4. Use search to navigate between related classes

Debug and Trace

C++
// 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:

text
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:

text
[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

text
# 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

TaskFileFunction
Create NodeObjectnodestore/detail/NodeObject.hcreateObject()
Fetch Nodenodestore/Database.hfetchNodeObject()
Store Nodenodestore/Database.hstore()
Find in SHAMapshamap/SHAMap.hfindLeaf()
Add to SHAMapshamap/detail/SHAMap.cppaddNode()
Check Cachenodestore/detail/TaggedCache.hget()
Rotate Databasenodestore/detail/DatabaseRotatingImp.hrotate()
Get Metricsnodestore/Database.hgetCountsJson()

Learning Path

  1. Week 1: Understand architecture (Chapters 1-4 of this module)
  2. Week 2: Read SHAMap.h and understand node types
  3. Week 3: Study shamap/detail/SHAMap.cpp - implementation
  4. Week 4: Read nodestore/Database.h and understand NodeStore design
  5. Week 5: Study nodestore/detail/DatabaseNodeImp.h - caching
  6. Week 6: Trace actual code execution (single transaction flow)
  7. Week 7: Build and run tests
  8. Week 8: Modify and experiment

This progression takes you from conceptual understanding to implementation mastery.