subsystem-summary-of-util
Util Subsystem — Technical Summary
The src/util/ directory provides foundational infrastructure used across all of stellar-core. It covers timing, scheduling, logging, numeric safety, filesystem operations, serialization, data structures, threading, and various small helpers.
1. Virtual Clock & Timers (Timer.h, Timer.cpp)
VirtualClock
Central timing facility with two modes: REAL_TIME (wall clock) and VIRTUAL_TIME (simulated, for tests). Owns an asio::io_context for IO dispatch and a Scheduler for main-thread action scheduling.
- Key types:
time_point(steady clock),system_time_point(wall/calendar time),duration. crank(bool block): The main event-loop step. Dispatches pending timers, polls IO (with exponential priority biasing under overload), runs scheduled actions, and transfers items from the thread-safe pending queue to the scheduler. InVIRTUAL_TIMEmode, advances time to the next event if idle.postAction(): Thread-safe submission point for deferred work callbacks. Uses a mutex-protected pending queue; wakes the main thread viaasio::postwhen enqueueing into an empty queue.setCurrentVirtualTime(): Advance virtual time forward (monotonic; asserts forward progress).sleep_for(): Real sleep inREAL_TIME, virtual time advance inVIRTUAL_TIME.shouldYield(): InREAL_TIME, returns true after 500ms has elapsed (time-slice limit). Always returns true inVIRTUAL_TIME.- Time conversion helpers:
to_time_t,from_time_t,systemPointToTm,tmToSystemPoint,isoStringToTm,tmToISOString,systemPointToISOString.
More from stellar/stellar-core
running-tests
running tests at various levels from smoke tests to full suite to randomized tests
1subsystem-summary-of-test
read this skill for a token-efficient summary of the test subsystem
1subsystem-summary-of-scp
read this skill for a token-efficient summary of the scp subsystem
1running-make-to-build
how to run make correctly to get a good build, and otherwise understand the build system
1subsystem-summary-of-history
read this skill for a token-efficient summary of the history subsystem
1subsystem-summary-of-invariant
read this skill for a token-efficient summary of the invariant subsystem
1