Appendix : Codebase Navigation Guide
← Back to SHAMap and NodeStore: Data Persistence and State Management
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 traversalNodeStore Source Files
Integration Points
Key Classes and Their Locations
SHAMap Classes
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
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 classRead:
SHAMapTreeNode.h- Base class and type systemExplore:
SHAMapInnerNode.h- Branch structureExplore:
SHAMapLeafNode.h- Data storageStudy:
detail/SHAMap.cpp- Implementation details
Understanding Node Synchronization
Start:
shamap/SHAMapMissingNode.h- Missing node representationStudy:
detail/SHAMapSync.cpp- Synchronization algorithmCross-reference:
nodestore/Database.h- Fetch operations called during syncUnderstand:
shamap/SHAMapNodeID.h- How nodes are identified
Understanding NodeStore Architecture
Start:
nodestore/Database.h- Public interfaceUnderstand:
nodestore/Backend.h- Storage abstractionExplore:
nodestore/detail/NodeObject.h- Storage unitStudy:
nodestore/detail/DatabaseNodeImp.h- Standard implementationStudy:
nodestore/detail/DatabaseRotatingImp.h- Rotation implementation
Understanding Database Rotation
Read:
nodestore/detail/DatabaseRotatingImp.h- ArchitectureStudy:
nodestore/detail/DatabaseRotatingImp.cpp- ImplementationUnderstand: Synchronization with
app/misc/SHAMapStoreImp.h
Understanding Cache Layer
Explore:
nodestore/detail/TaggedCache.h- Cache implementationStudy usage in:
nodestore/detail/DatabaseNodeImp.cppUnderstand metrics in: Database metrics methods
Common Code Patterns
Accessing a Node in SHAMap
Storing a Node in NodeStore
Retrieving a Node
Cache Hit Path
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
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
Test Files
Locate tests in:
Study how these are tested to understand expected usage patterns.
Configuration Reference
Configuration Files
NodeStore configuration in rippled.cfg:
Common Configuration Patterns
Quick Reference
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 typesWeek 3: Study
shamap/detail/SHAMap.cpp- implementationWeek 4: Read
nodestore/Database.hand understand NodeStore designWeek 5: Study
nodestore/detail/DatabaseNodeImp.h- cachingWeek 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.
Last updated

