This document provides a high-level introduction to stellar-core, the reference implementation of the Stellar network protocol. It covers the major architectural components, their relationships, and how they map to code entities within the codebase. This page serves as an entry point for understanding stellar-core's design before diving into specific subsystems.
For detailed information about specific subsystems, see:
Sources: src/main/ApplicationImpl.cpp1-100 src/main/Config.h1-80 docs/stellar-core_example.cfg1-120
Stellar-core is a replicated state machine that maintains a distributed ledger through the Stellar Consensus Protocol (SCP). Each instance of stellar-core:
The codebase is organized around a main Application class that coordinates several manager subsystems, each responsible for a distinct concern.
Sources: src/main/ApplicationImpl.cpp86-209 src/main/Application.h1-50
The architecture follows a layered design where ApplicationImpl acts as the central coordinator, instantiating and managing lifecycle for all major subsystems. Each subsystem exposes an interface and interacts with others through well-defined boundaries.
Sources: src/main/ApplicationImpl.cpp241-344 src/main/ApplicationImpl.h1-100
ApplicationImpl is the root object that owns and coordinates all subsystems. It manages:
Config classasio::io_context instances for different thread typesKey members include mVirtualClock for event scheduling, mDatabase for SQL persistence, mBucketManager for state snapshots, mHerder for consensus, mLedgerManager for state transitions, and mOverlayManager for networking.
Sources: src/main/ApplicationImpl.cpp86-209 src/main/ApplicationImpl.h24-100
The Config class holds all configuration parameters loaded from stellar-core.cfg. Major configuration categories:
| Category | Key Settings | Description |
|---|---|---|
| Network | NETWORK_PASSPHRASE, NODE_SEED | Network identity and node keypair |
| Consensus | QUORUM_SET, VALIDATORS | SCP quorum configuration |
| Networking | PEER_PORT, TARGET_PEER_CONNECTIONS | P2P overlay settings |
| Database | DATABASE | PostgreSQL or SQLite connection string |
| Storage | BUCKET_DIR_PATH, ENTRY_CACHE_SIZE | Bucket storage and caching |
| HTTP | HTTP_PORT, HTTP_QUERY_PORT | Command and query endpoints |
| Protocol | LEDGER_PROTOCOL_VERSION | Protocol version to use |
Sources: src/main/Config.h72-400 src/main/Config.cpp125-374 docs/stellar-core_example.cfg1-300
HerderImpl orchestrates the Stellar Consensus Protocol. It:
TransactionQueue for pending transactionsHerderSCPDriverPendingEnvelopes to track SCP messagesLedgerManager when consensus externalizes valuesThe Herder state machine transitions between HERDER_BOOTING_STATE, HERDER_SYNCING_STATE, and HERDER_TRACKING_NETWORK_STATE based on sync status.
Sources: src/herder/HerderImpl.cpp89-117 src/herder/HerderImpl.h37-100
LedgerManagerImpl manages ledger state and coordinates ledger close. Core responsibilities:
ApplyState which encapsulates in-memory Soroban state and module cacheBucketManager and DatabaseLedgerCloseMeta for downstream consumersmLastClosedLedgerState with bucket snapshotsThe manager transitions between LM_BOOTING_STATE, LM_SYNCED_STATE, and LM_CATCHING_UP_STATE.
Sources: src/ledger/LedgerManagerImpl.cpp333-405 src/ledger/LedgerManagerImpl.h58-150
The overlay network manages peer-to-peer connections:
OverlayManager maintains authenticated and pending peer listsTCPPeer handles individual TCP connections with authentication flowFlowControl implements backpressure and capacity managementConnection establishment follows: TCP connect → HELLO exchange → AUTH verification → authenticated state.
Sources: src/overlay/Peer.cpp134-158 src/overlay/TCPPeer.cpp34-110 src/overlay/Peer.h67-130
BucketManager maintains two bucket lists as Merkle trees:
Buckets are immutable, content-addressed .xdr.gz files. The bucket list structure enables efficient state snapshots and catchup. Each ledger close adds entries to level 0, with periodic merges into higher levels following an exponential schedule.
Sources: src/bucket/BucketManager.h1-100 src/ledger/LedgerManagerImpl.cpp470-487
This diagram traces the critical path from startup through consensus to state commitment, using actual function names from the codebase.
Sources: src/main/main.cpp1-50 src/main/ApplicationImpl.cpp240-345 src/herder/HerderImpl.cpp236-502 src/ledger/LedgerManagerImpl.cpp505-750
A transaction flows through multiple stages from submission to finalization:
TransactionQueue::tryAdd() validates basic requirementsHerder::valueExternalized() triggered when consensus reachedLedgerManager::closeLedger() applies transactions
LedgerCloseMeta emitted to streamFor detailed transaction processing, see Transaction Flow End-to-End.
Sources: src/herder/HerderImpl.cpp596-660 src/herder/TransactionQueue.cpp1-100 src/ledger/LedgerManagerImpl.cpp800-1200
Thread types are tracked in ApplicationImpl::mThreadTypes map. The main thread handles coordination and must not block. CPU-intensive or I/O-bound work is posted to appropriate thread pools. Thread safety is maintained through message passing and careful phase management during ledger close.
Sources: src/main/ApplicationImpl.cpp167-207 src/main/ApplicationImpl.h90-130 src/ledger/LedgerManagerImpl.h90-150
Stellar-core initialization sequence:
stellar-core.cfg via Config::load()ApplicationImpl with configLedgerManager::startNewLedger() creates genesisLedgerManager::loadLastKnownLedger() restores from DBThe config file format is TOML with sections for database, networking, consensus, and operational settings.
Sources: src/main/main.cpp1-100 src/main/ApplicationImpl.cpp240-345 src/main/Config.cpp830-876 src/ledger/LedgerManagerImpl.cpp408-502 docs/stellar-core_example.cfg1-120
Stellar-core maintains ledger state across multiple layers:
| Layer | Component | Purpose |
|---|---|---|
| In-Memory | InMemorySorobanState | Hot cache for contract data and code |
| Module Cache | SharedModuleCache | Compiled WASM modules per protocol |
| Transaction | LedgerTxn | Transactional snapshot isolation layer |
| Entry Cache | LedgerTxnRoot | LRU cache of ledger entries |
| Bucket List | BucketManager | Merkle tree snapshots (Live + Hot Archive) |
| SQL Database | Database | Persistent storage (PostgreSQL/SQLite) |
Reads flow from top to bottom: check cache → check bucket list → query database. Writes accumulate in LedgerTxn and flush to bucket list and database on commit.
Sources: src/ledger/LedgerManagerImpl.h117-240 src/ledger/LedgerTxn.cpp1-100 src/bucket/BucketManager.h1-100
After understanding this overview, dive into specific subsystems:
Refresh this wiki
This wiki was recently refreshed. Please wait 5 days to refresh again.