ワンクリックで
subsystem-summary-of-main
read this skill for a token-efficient summary of the main subsystem
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
read this skill for a token-efficient summary of the main subsystem
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
extending yourself with a new reusable skill by interviewing the user
analyzing a change to determine what tests are needed and adding them to the test suite
modifying build configuration to enable/disable variants, switch compilers or flags, or otherwise prepare for a build
reviewing a change for semantic correctness, simplicity, design consistency, and completeness
reviewing a git diff for small localized coding mistakes that can be fixed without high-level understanding
how to run make correctly to get a good build, and otherwise understand the build system
| name | subsystem-summary-of-main |
| description | read this skill for a token-efficient summary of the main subsystem |
The main subsystem is the central orchestration layer of stellar-core. It defines the Application interface and its concrete ApplicationImpl, which owns all other subsystem managers and coordinates the application lifecycle: construction, initialization, startup, the main event loop, graceful shutdown, and thread management. It also provides configuration parsing (Config), persistent state management (PersistentState), HTTP command handling (CommandHandler), query serving (QueryServer), CLI entry point and command routing (CommandLine, main.cpp), and various utilities (XDR dumping, diagnostics, settings upgrade helpers, maintenance).
Application interface; factory method Application::create().Application access.Config class; TOML-based configuration parsing, defaults, validation.handleCommandLine().STELLAR_CORE_VERSION string constant.Application (abstract base class)Defines the interface for a stellar-core application instance. Multiple instances can coexist in a single process (used in tests/simulations). Key aspects:
State enum (Application::State):
APP_CREATED_STATE — Constructed but not started.APP_ACQUIRING_CONSENSUS_STATE — Out of sync with SCP peers.APP_CONNECTED_STANDBY_STATE — Tracking network but ledger subsystem still booting.APP_CATCHING_UP_STATE — Downloading/applying catchup data.APP_SYNCED_STATE — Fully synced, applying transactions.APP_STOPPING_STATE — Shutting down.ThreadType enum:
MAIN, WORKER, EVICTION, OVERLAY, APPLY.Key pure virtual methods:
initialize(bool newDB, bool forceRebuild) — Set up subsystems, DB.start() — Load last known ledger, start services.gracefulStop() / joinAllThreads() — Shutdown lifecycle.getLedgerManager(), getBucketManager(), getHerder(), getOverlayManager(), getDatabase(), getHistoryManager(), etc.postOnMainThread(), postOnBackgroundThread(), postOnOverlayThread(), postOnLedgerCloseThread(), postOnEvictionBackgroundThread().getWorkerIOContext(), getEvictionIOContext(), getOverlayIOContext(), getLedgerCloseIOContext().static Application::create(VirtualClock&, Config const&, ...) — creates ApplicationImpl.ApplicationImpl (extends Application)Concrete implementation. Central object that owns all subsystem managers and threads.
Owned io_contexts (field order matters for construction/destruction):
mWorkerIOContext — Worker thread pool IO context (WORKER_THREADS - 1 threads).mEvictionIOContext — Single-thread IO context for eviction scans (medium priority).mOverlayIOContext — Optional single-thread IO context for background overlay processing.mLedgerCloseIOContext — Optional single-thread IO context for parallel ledger apply.Owned subsystem managers (all unique_ptr):
mBucketManager, mDatabase, mOverlayManager, mLedgerManager, mHerder, mLedgerApplyManager, mHerderPersistence, mHistoryArchiveManager, mHistoryManager, mInvariantManager, mMaintainer, mPersistentState, mBanManager, mStatusManager, mLedgerTxnRoot, mAppConnector, mCommandHandler.mProcessManager, mWorkScheduler — shared_ptr.Thread management:
mWorkerThreads — vector<unique_ptr<thread>>, run low-priority CPU-bound work.mEvictionThread — Single medium-priority thread for eviction scans.mOverlayThread — Optional thread for background overlay processing.mLedgerCloseThread — Optional thread for parallel ledger close/apply.mThreadTypes — unordered_map<thread::id, ThreadType>, populated at construction (read-only thereafter for thread safety).Key methods:
initialize() — Creates all subsystem managers in order: AppConnector → BucketManager → Database → PersistentState → OverlayManager → LedgerManager → Herder → all others. Registers invariants. Runs newDB() or upgradeToCurrentSchemaAndMaybeRebuildLedger().start() — Loads last known ledger, enables Rust Dalek verification if protocol ≥ 25, calls startServices().startServices() — Starts InvariantManager, Herder, Maintainer, OverlayManager; publishes queued history; optionally bootstraps SCP.gracefulStop() — Sets mStopping, calls idempotentShutdown(true), schedules final IO context shutdown after a delay.idempotentShutdown(forgetBuckets) — Ordered shutdown: ledger close thread first, then CommandHandler, OverlayManager, WorkScheduler, ProcessManager, BucketManager (optionally forgets unreferenced buckets), Herder, main IO context, join all threads.joinAllThreads() — Releases work guards and joins ledger-close, worker, overlay, eviction threads.getState() — Derives application state from Herder and LedgerManager state.manualClose() — For testing: triggers manual ledger close via Herder.syncOwnMetrics() / syncAllMetrics() — Flushes crypto cache stats, process stats, overlay connection stats, and delegates to subsystem syncMetrics().postOnMainThread/BackgroundThread/OverlayThread/LedgerCloseThread() — Posts closures to respective io_contexts with jitter injection and delay metrics.AppConnectorThread-safe facade providing controlled access to Application from subsystems that may run on non-main threads.
Design: Holds a reference to Application and a copy of Config (to avoid thread-sanitizer warnings from accessing mApp config from background threads).
Main-thread-only methods: getHerder(), getLedgerManager(), getOverlayManager(), getBanManager(), shouldYield(), checkOnOperationApply().
Thread-safe methods: postOnMainThread(), postOnOverlayThread(), postOnBackgroundThread(), getConfig(), getMetrics(), now(), getOverlayMetrics(), isStopping(), getNetworkID(), getSorobanMetrics(), getModuleCache(), threadIsType(), copySearchableLiveBucketListSnapshot(), copySearchableHotArchiveBucketListSnapshot(), getOverlayThreadSnapshot().
ConfigComprehensive configuration object parsed from TOML files. Copied locally by each Application at construction (immutable thereafter).
Major configuration groups:
NODE_SEED (SecretKey), NODE_IS_VALIDATOR, NODE_HOME_DOMAIN.NETWORK_PASSPHRASE, PEER_PORT, peer connection limits, flood rates.QUORUM_SET, FORCE_SCP, FAILURE_SAFETY, UNSAFE_QUORUM.LEDGER_PROTOCOL_VERSION (current: 25), MAX_SLOTS_TO_REMEMBER.DATABASE connection string.HISTORY map of archive configurations.BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT, BUCKETLIST_DB_INDEX_CUTOFF, BUCKETLIST_DB_PERSIST_INDEX, BUCKETLIST_DB_MEMORY_FOR_CACHING.HTTP_PORT, HTTP_QUERY_PORT, PUBLIC_HTTP_PORT, HTTP_MAX_CLIENT.WORKER_THREADS, QUERY_THREAD_POOL_SIZE, COMPILATION_THREADS.AUTOMATIC_MAINTENANCE_PERIOD (default 359s), AUTOMATIC_MAINTENANCE_COUNT (default 400), AUTOMATIC_SELF_CHECK_PERIOD (default 3h).METADATA_OUTPUT_STREAM, METADATA_DEBUG_LEDGERS.BACKGROUND_OVERLAY_PROCESSING, PARALLEL_LEDGER_APPLY, BACKGROUND_TX_SIG_VERIFICATION.PEER_READING_CAPACITY, PEER_FLOOD_READING_CAPACITY, FLOW_CONTROL_SEND_MORE_BATCH_SIZE, byte-based flow control params.ARTIFICIALLY_* and *_FOR_TESTING parameters (guarded at config-load time against production use).VALIDATOR_WEIGHT_CONFIG for leader election.EMIT_CLASSIC_EVENTS, BACKFILL_STELLAR_ASSET_EVENTS, EMIT_SOROBAN_TRANSACTION_META_EXT_V1.Key methods: load(filename), load(istream), adjust() (fixes connection-related settings), logBasicInfo(), parallelLedgerClose(), setNoListen(), setNoPublish(), toShortString(), resolveNodeID().
TestDbMode enum: TESTDB_DEFAULT, TESTDB_IN_MEMORY, TESTDB_POSTGRESQL, TESTDB_BUCKET_DB_VOLATILE, TESTDB_BUCKET_DB_PERSISTENT.
PersistentStateManages critical node state persisted across restarts via two SQL tables: storestate (main/LCL data) and slotstate (SCP/consensus data).
Entry enum (key names):
kLastClosedLedger, kHistoryArchiveState, kDatabaseSchema, kNetworkPassphrase, kRebuildLedger.kMiscDatabaseSchema, kLedgerUpgrades, kLastSCPDataXDR, kTxSet.Key methods: getState(), setMainState(), setMiscState(), getSCPStateAllSlots(), setSCPStateV1ForSlot(), getTxSetsForAllSlots(), shouldRebuildForOfferTable(), hasTxSet(), deleteTxSets().
CommandHandlerHTTP admin server handling operational commands. Binds to HTTP_PORT on the main thread's io_context.
Routes (non-standalone): bans, connect, droppeer, peers, quorum, scp, surveyTopology*, unban.
Routes (always): info, ll, logrotate, manualclose, metrics, clearmetrics, tx, upgrades, dumpproposedsettings, self-check, maintenance, sorobaninfo.
Test-only routes: generateload, testacc, testtx, toggleoverlayonlymode.
Also optionally creates a QueryServer if HTTP_QUERY_PORT is configured.
QueryServerMulti-threaded HTTP query server running on its own thread pool. Serves read-only queries against BucketListDB snapshots.
Routes: getledgerentryraw, getledgerentry.
Threading: Each worker thread in the server pool gets its own SearchableSnapshotConstPtr (both live and hot-archive). Snapshots are refreshed via BucketSnapshotManager::maybeCopySearchableBucketListSnapshot() on each query.
MaintainerPeriodic background maintenance that prunes old data from history tables.
Key methods:
start() — Schedules periodic maintenance based on AUTOMATIC_MAINTENANCE_PERIOD.performMaintenance(count) — Calculates safe deletion boundary (respects pending checkpoint publications), trims SCP history and ledger header data up to that boundary.main.cpp, CommandLine.cpp)main(): Initializes logging, crypto (libsodium), global state, validates XDR hash identity between C++ and Rust, checks stellar-core major version matches protocol version, delegates to handleCommandLine().handleCommandLine(): Parses CLI via Clara library. Supports subcommands: run, catchup, publish, new-db, new-hist, self-check, convert-id, dump-xdr, print-xdr, sign-transaction, sec-to-pub, gen-seed, http-command, version, merge-bucket-list, dump-ledger, offline-info, report-last-history-checkpoint, check-quorum-intersection, dump-state-archival-stats, calculate-asset-supply, plus test-only commands (test, fuzz, gen-fuzz, load-xdr, rebuild-ledger-from-buckets, apply-load).ApplicationUtils.cpp)Higher-level functions used by CLI commands:
setupApp() — Creates an Application, validates history config.runApp() — Starts app, runs the main event loop (clock.crank() until io_context stops).selfCheck() — Four-phase check: async online checks, bucket hash verification, full BL/DB consistency, crypto benchmarking.catchup() / publish() — Orchestrate catchup or history publication.applyBucketsForLCL() — Rebuilds ledger state from bucket list.mergeBucketList() — Merges all BL levels into single output bucket.dumpLedger() — Dumps ledger entries from BucketList with optional filtering, grouping, and aggregation using XDR query engine.dumpStateArchivalStatistics() — Reports state archival metrics (expired/evicted entries).calculateAssetSupply() — Computes total asset supply across live and hot-archive BucketLists.dumpWasmBlob() — Extracts a specific Wasm contract blob by hash.minimalDBForInMemoryMode() — Constructs minimal SQLite DB path for in-memory/captive core modes.setAuthenticatedLedgerHashPair() — Sets authenticated hash for catchup starting points.getStellarCoreMajorReleaseVersion() — Regex extracts major version from version string.dumpxdr.cpp)dumpXdrStream() — Auto-detects XDR file type (ledger, bucket, transactions, results, meta, SCP, debug-tx-set) by filename regex and streams as JSON.printXdr() — Decodes single XDR values (auto/typed) from file or stdin, outputs JSON.signtxn() / signtxns() — Signs transaction envelopes with secret keys (interactive password input with terminal echo suppression).priv2pub() — Converts secret key from stdin to public key.SettingsUpgradeUtils.cpp)Helpers for constructing Soroban settings upgrade transactions:
getWasmRestoreTx() — Builds a restore-footprint TX for a Wasm contract.getUploadTx() — Builds an upload-contract-wasm TX.getCreateTx() — Builds a create-contract TX.getInvokeTx() — Builds an invoke-host-function TX that applies a ConfigUpgradeSet.Diagnostics.cpp)bucketStats() — Reads a bucket file, computes per-entry-type counts, byte sizes, averages; optionally aggregates per account. Outputs JSON.Application (abstract interface)
└── ApplicationImpl (concrete, 1:1 with VirtualClock)
├── mConfig (Config, local copy, immutable)
├── mNetworkID (Hash, derived from NETWORK_PASSPHRASE)
├── mMetrics (unique_ptr<MetricsRegistry>)
├── mAppConnector (unique_ptr<AppConnector>)
│
├── IO Contexts & Work Guards:
│ ├── mWorkerIOContext (asio::io_context, WORKER_THREADS-1)
│ ├── mEvictionIOContext (unique_ptr<asio::io_context>, 1 thread)
│ ├── mOverlayIOContext (unique_ptr, conditional on BACKGROUND_OVERLAY_PROCESSING)
│ ├── mLedgerCloseIOContext (unique_ptr, conditional on parallelLedgerClose())
│ └── mWork, mEvictionWork, mOverlayWork, mLedgerCloseWork (io_context::work guards)
│
├── Subsystem Managers:
│ ├── mBucketManager (unique_ptr<BucketManager>)
│ ├── mDatabase (unique_ptr<Database>)
│ ├── mPersistentState (unique_ptr<PersistentState>)
│ ├── mOverlayManager (unique_ptr<OverlayManager>)
│ ├── mLedgerManager (unique_ptr<LedgerManager>) [protected]
│ ├── mHerder (unique_ptr<Herder>) [protected]
│ ├── mLedgerApplyManager (unique_ptr<LedgerApplyManager>)
│ ├── mHerderPersistence (unique_ptr<HerderPersistence>)
│ ├── mHistoryArchiveManager (unique_ptr<HistoryArchiveManager>)
│ ├── mHistoryManager (unique_ptr<HistoryManager>)
│ ├── mInvariantManager (unique_ptr<InvariantManager>)
│ ├── mMaintainer (unique_ptr<Maintainer>)
│ ├── mProcessManager (shared_ptr<ProcessManager>)
│ ├── mWorkScheduler (shared_ptr<WorkScheduler>)
│ ├── mBanManager (unique_ptr<BanManager>)
│ ├── mStatusManager (unique_ptr<StatusManager>)
│ ├── mLedgerTxnRoot (unique_ptr<AbstractLedgerTxnParent>)
│ └── mCommandHandler (unique_ptr<CommandHandler>)
│ └── mQueryServer (unique_ptr<QueryServer>, optional)
│
├── Threads:
│ ├── mWorkerThreads (vector<unique_ptr<thread>>)
│ ├── mEvictionThread (unique_ptr<thread>)
│ ├── mOverlayThread (unique_ptr<thread>, conditional)
│ └── mLedgerCloseThread (unique_ptr<thread>, conditional)
│
└── mThreadTypes (unordered_map<thread::id, ThreadType>)
Construction/Destruction order is critical: IO contexts first, then managers, then threads. Destruction is reverse: threads joined first, then managers torn down.
VirtualClock's asio::io_context event loop.AppConnector assert threadIsMain().mWorkerIOContext, low priority.postOnMainThread().mEvictionIOContext, medium priority.mOverlayIOContext, normal priority.BACKGROUND_OVERLAY_PROCESSING.mLedgerCloseIOContext.parallelLedgerClose() (requires both PARALLEL_LEDGER_APPLY and BACKGROUND_OVERLAY_PROCESSING).mThreadTypes maps thread::id → ThreadType. Populated at construction, read-only thereafter.threadIsType(type) used for runtime assertions about which thread is executing.runApp() in ApplicationUtils.cpp)app->start()
asio::io_context::work mainWork(io)
while (!io.stopped()):
app->getClock().crank() // dispatches one batch of IO events/timers
Maintainer)AUTOMATIC_MAINTENANCE_PERIOD (default ~6 min).tick() → performMaintenance(count) → prunes old SCP history and ledger headers → re-schedules.AUTOMATIC_SELF_CHECK_PERIOD (default 3h).scheduleSelfCheck() → schedules WorkSequence (history archive report + checkpoint ledger check).mRunningSelfCheck weak_ptr.ApplicationImpl constructor: creates io_contexts, spawns worker/eviction/overlay/ledger-close threads, registers signal handlers.initialize(): creates all subsystem managers, registers invariants, initializes or upgrades DB.start(): loads last known ledger, starts services (Herder, Maintainer, OverlayManager, history publication).runApp(): enters main event loop.gracefulStop().mStopping = true.idempotentShutdown(true):
getState() derives Application::State from:
mStarted flag → APP_CREATED_STATE if not started.mStopping flag → APP_STOPPING_STATE.Herder::getState() → APP_ACQUIRING_CONSENSUS_STATE if not tracking.LedgerManager::getState() → APP_CONNECTED_STANDBY_STATE, APP_CATCHING_UP_STATE, or APP_SYNCED_STATE.postOnMainThread(), postOnBackgroundThread(), etc.LogSlowExecution).postOnLedgerCloseThread() additionally calls getClock().newBackgroundWork() / finishedBackgroundWork() to coordinate with the VirtualClock.validateNetworkPassphrase())PersistentState.safeRouter() wraps handler in try/catch.mApp reference.QUERY_THREAD_POOL_SIZE worker threads.Config::Config() sets all defaults.load(filename) parses TOML via cpptoml.processConfig() maps TOML keys to member variables, validates constraints.adjust() fixes derived connection settings.