Running Astraea
A working setup has four processes. Only astraea-ingest is needed to serve the API; the other three feed the Proof Engine and keep its archive.
| Process | Job |
|---|---|
witness-unl | keeps every signed UNL list the publishers serve |
witness-archiver | keeps raw signed validations from a node |
astraea-ingest | loads and checks ledgers, confirms them by quorum, serves the API |
astraea-xrpla + astraea-state | one-off tools for loading older history |
§What you need
- An xrpld node with gRPC enabled and a WebSocket port that streams validations. The node’s
[secure_gateway]should list the Astraea host if you don’t want it rate-limited. - Disk: the hot store grows with state versions; full mainnet history in the cold store takes on the order of 1.2 TB.
- Memory: the cache of decoded cold blocks grows to about 4 GiB, and up to 1 GiB of it for one segment (
COLD_BUDGETandBLOCK_BUDGETincrates/ledger-engine/src/cold.rs). Allow for that on top of what the rest of the server uses. - Rust 1.99.1 to build (pinned in
rust-toolchain.toml).
§Building
cargo build --release gives a binary for any x86-64 processor. If the server’s processor has AVX2 (Intel since 2013, AMD since 2017), build for that level:
RUSTFLAGS="-C target-cpu=x86-64-v3" cargo build --releaseOn a mix of history and state requests (expanded ledgers across the whole range, transactions by hash, account_tx pages, account state, book_changes) this cut p99 latency by 14% and CPU per request by 5%. We also measured mimalloc in place of the system allocator: peak memory fell from 8.3 to 4.8 GB, but 16 parallel clients got 19% fewer requests per second, so the system allocator stays.
§UNL archive
witness-unl --data-dir /var/lib/astraea/unlIt polls every 600 seconds by default (--interval-secs). Publishers come from --sites name=url,..., with vl.ripple.com and unl.xrplf.org by default. Start it first and leave it running: publishers only serve the current list, so a list you missed is gone.
§Validation archive
witness-archiver \
--url ws://<node-host>:6006 \
--source <node-name> \
--data-dir /var/lib/astraea/validations \
--unl-dir /var/lib/astraea/unlIt writes a journal that is flushed every second, closes segments of 1024 ledgers with a chained seal, and records every disconnect and reconnect in gaps.jsonl, so holes in the archive are visible instead of guessed. --metrics-addr exposes Prometheus metrics.
§Ingest and API
astraea-ingest \
--grpc http://<node-host>:50051 \
--data-dir /var/lib/astraea/engine \
--validations-ws ws://<node-host>:6006 \
--unl-dir /var/lib/astraea/unl \
--api-addr 127.0.0.1:51233 \
--forward-rpc http://<node-host>:51234| Option | Meaning |
|---|---|
--grpc | xrpld gRPC endpoint that ledgers are loaded from |
--data-dir | where state and history live |
--validations-ws | one or more WebSocket endpoints for the validations stream, comma separated |
--unl-dir | the witness-unl archive |
--publishers | UNL publisher keys to trust, hex; defaults to vl.ripple.com and unl.xrplf.org |
--api-addr | where to serve JSON-RPC and WebSocket, one or more addresses, comma separated; no API without it. An address that is busy is retried every 10 s, so Astraea takes over a port as soon as the server holding it stops |
--forward-rpc | node JSON-RPC endpoints for forwarded methods; without them those methods return unknownCmd |
--forward-timeout | per-node timeout for forwarding, seconds (default 5); one request has 8 seconds over all nodes |
--forward-submissions | forward submit and simulate on --api-addr; off by default, and never on a public listener |
--public-api-addr | addresses for public clients, with their own slots and limits; see Public access |
--network-id | network ID for CTIDs, 0 for mainnet |
--metrics-addr | Prometheus metrics, described in metrics.md |
--max-requests | weighted requests per client per interval; with none of the three limits, clients are not limited |
--max-response-bytes | response bytes per client per interval |
--max-connections | connections per client open at once: HTTP requests in progress and WebSocket sessions |
--work-ms | milliseconds of request handling that count as one more request against --max-requests; off if not given |
--sweep-secs | the interval the request and byte budgets cover, seconds (default 1) |
--limit-whitelist | addresses or CIDR networks that are never limited, comma separated |
--trusted-proxies | proxies whose CF-Connecting-IP, Forwarded or X-Forwarded-For header names the client, comma separated |
Before the first start, take a snapshot of the full ledger state with astraea-snapshot (it downloads every object over gRPC and refuses the result unless the rebuilt state tree matches the header’s account_hash) and load it with astraea-state --db <data-dir>/state load <snapshot>. From then on astraea-ingest follows the network. History before the snapshot comes from the cold store.
Astraea serves at most 32 requests at once, 4 of them proofs, and gives each request 10 seconds. It doesn’t terminate TLS: put it behind a reverse proxy or a tunnel for anything public.
§Public access
Serve the public on its own address, --public-api-addr, and keep your own services on --api-addr. Limits per client alone don’t protect your services: many addresses, each within its budget, can still fill every request slot. So the two doors don’t share slots:
--api-addr | --public-api-addr | |
|---|---|---|
| Requests at a time | 32 | --public-max-inflight, 8 |
| Proof bundles at a time | 4 | --public-max-proofs, 1 |
| Requests to a node at a time | 16 | --public-max-forwards, 4 |
| Time for one request | 10 s | 5 s |
| Wait for a slot | 5 s | 0.5 s |
| Limits per client | none | required, see below |
submit, simulate | with --forward-submissions | never |
ripple_path_find | forwarded | never |
| Largest request | 2 MiB over HTTP | 256 KiB |
| WebSocket sessions | no cap | --public-max-sessions, 256 |
| Accounts per session | 10,000 per subscribe | --public-max-accounts, 100 |
When --api-addr has fewer than 8 free slots, the public door answers tooBusy at once. This protects the queue, not the machine: disk and CPU stay shared, so limit traffic at the edge too and measure the public slots under load before raising them. Metrics count public requests under the transports public_http and public_ws, and astraea_api_inflight has a pool for each budget.
Without --public-api-addr, the limits apply to --api-addr.
Per-client limits work like Clio’s dos_guard. A client over its request or byte budget, or at its connection cap, gets slowDown until the interval ends: over HTTP as status 503, over WebSocket as an error response. Requests that walk many objects count more: a proof 10, ledger_data and a ledger with expanded transactions 5, forwarded requests 3, account_tx, nft_history, book_changes and nfts_by_issuer 2, the rest 1. Addresses that must never be limited go in --limit-whitelist.
Weights are a guess made before the request runs; with --work-ms the request is also charged for what it actually cost. Every --work-ms milliseconds a request spent being handled count as one more request against the client’s budget, so a request that reads much cold history costs more than one answered from the cache, whatever its method. With --max-requests 100 --sweep-secs 10 --work-ms 50, a client gets about 5 seconds of handling every 10 seconds. The charge comes after the request, so the request that crosses the budget is answered and the next one gets slowDown.
Refusals are counted in astraea_api_rejected_total by door and reason: connections (at the client’s cap), budget (over its requests, bytes or work), sessions (all public WebSocket sessions taken) and busy (no free slot in time, tooBusy). A rise of door="own" means your own services are being turned away and is worth an alert.
Behind a proxy every request comes from the proxy’s address. List the proxy in --trusted-proxies (for cloudflared on the same host, 127.0.0.1), and the client is taken from CF-Connecting-IP, the last for= of Forwarded, or the first address of X-Forwarded-For. These headers are ignored from anyone else, so a client can’t pose as another.
§Behind a Cloudflare Tunnel
A tunnel needs no open port and gives TLS (HTTPS and WSS) with certificates Cloudflare renews:
- Keep
--public-api-addron a loopback address, for example127.0.0.1:51301, and set--trusted-proxies 127.0.0.1. - Create a tunnel whose ingress sends your hostname to
http://127.0.0.1:51301and everything else tohttp_status:404, and runcloudflared tunnel run --token-file <file>as its own user, with--no-autoupdate. - Until you open the service, put the hostname behind Cloudflare Access and set
originRequest.access.requiredwith the application’s audience tag, socloudflareditself refuses requests without a valid Access token. - To open it, remove the Access application (or give it a bypass policy) and the origin check. Rate rules at the edge are a sensible addition: Cloudflare sees floods that never reach the machine.
The tunnel adds CF-Connecting-IP, so the per-client limits and astraea_api_rejected_total see real clients.
Answers that can never change (a transaction, or anything about a ledger named by sequence or hash) carry Cache-Control: public, max-age=86400, immutable; the rest carry no-store. JSON-RPC requests are POSTs, which CDNs don’t cache by default, so an edge cache needs a rule or worker that keys on the request body; the header tells it what it may keep.
§Updating for an xrpld release
Astraea reads XRPL binary with the tables of one xrpld release: fields, transaction and object types and result codes in crates/ledger-engine/definitions.json (now xrpld 3.4.1), and the amendments in crates/ledger-engine/src/amendments.rs, which feature answers from. A newer xrpld can bring parts that are not in them. The loader does not stop on such a ledger: it stores it as it came, so hashes, root checks and proofs stay valid, and indexes a transaction whose metadata it cannot read under its hash and sender only. What it cannot do is turn the new parts into JSON: a request that has to render them gets an error until a release with new tables is running.
So the order is:
- An xrpld release comes out, or the loader says the network uses something new:
astraea_ingest_unknown_amendments_majorityabove 0 (an amendment two weeks from enabling),_unknown_amendments_enabledor_unknown_findings_totalgrowing (metrics), with the details in the log (not known to this build). - Compare the tables:
python3 -I scripts/astraea-definitions-check.py --node <url> --macro features.macro, with a node running the new release (or an Astraea in front of one) andinclude/xrpl/protocol/detail/features.macroof the release. It lists what is new, removed or changed. - Update the codec: take
definitions.jsonfrom the new node’sserver_definitions, regenerate the amendment table fromfeatures.macro(keep the dropped amendments at the end), add rendering for a new field type if there is one inxrpl_json.rsandwitness-core’sstobject.rs, and the new object types toaccount_objectsfilters andledger_entryselectors as Clio does. Run the tests andscripts/astraea-clio-check.py. - Release Astraea before the amendment is enabled. Ledgers written before the update need nothing: they were stored as they came, and are read with the new tables. Transactions indexed under their sender only stay so in the hot store: there is no command to reindex it yet. Once those ledgers are in cold segments,
astraea-state history-cold-indexover them builds the full account history with the new tables.
§Loading older history
scripts/astraea-full-history.sh downloads the XRPLA archive in chunks of 32,768 ledgers from the top down, several chunks at a time, and writes each into cold segments. scripts/astraea-full-publish.py picks up finished chunks in order, groups them, builds indexes, checks that each group joins the history already served, and publishes it into the live directory without restarting the server. Both scripts can be stopped and restarted at any point. Segments written by this version come with a seal, so the server checks each block once instead of on every load; for segments written earlier, run astraea-state history-cold-seal <dir> on the live directory. Segments are written as ASTJ6, whose blocks are cut into parts read on their own; astraea-state history-cold-recode <dir> rewrites older ASTJ5 segments in place, a few at a time (--threads), while the server keeps serving them. A recent segment takes about two and a half minutes per thread.
Segments in the older astraea-cold/1 format hold every state patch. astraea-state history-cold-recode <dir> rewrites them too, keeping only the patches the metadata doesn’t give. Upgrade the server first: earlier versions refuse the new format, and a version that has read it can’t be swapped for an earlier one.
Segments written before 0.3 also carry ASIX2 indexes (cold-F.asix) that nothing reads; astraea-state history-cold-drop-index <dir> removes them, the manifest first and then the file. Run it after the server has been upgraded to 0.3: earlier versions refuse a segment whose manifest lacks the file.
astraea-state history-state-replay checks the state patches of the cold history: starting from a state snapshot, it applies each ledger’s patches and compares the state root with the header. Use it before building a version index; it stops at the first ledger that differs. astraea-state history-state-index then builds the index for the checked range from the same snapshot (--base) and the cold directory, and checks every file it wrote. The index answers only for the range in its manifest. Start astraea-ingest with --old-state <index dir> to serve it: account_info, ledger_entry, account_lines, account_objects and vault_info then answer on those ledgers on --api-addr, and server_info reports the range as astraea.old_state_ledgers. Public listeners don’t serve it yet. The server checks the index’s manifest, block directories and base state when it starts and refuses to start if they don’t match; each block is checked when it is read.
Their settings come from environment variables; ASTRAEA_HOME defaults to /var/lib/astraea:
| Variable | Default | Meaning |
|---|---|---|
B | $ASTRAEA_HOME/src/target/release | where the binaries are |
R | $ASTRAEA_HOME/history-full | working directory: chunks, groups, logs |
T | $ASTRAEA_HOME/tmp | temporary downloads |
LIVE | $ASTRAEA_HOME/engine/history | the live history directory of astraea-ingest |
TOP | required | the ledger just below the history already served |
BOTTOM | 32571 | the first ledger to load |
STREAMS | 8 | chunks in parallel |
MIN_FREE_GB | 300 | stop starting new chunks below this free space |
A chunk of recent mainnet history (2 to 4 million transactions) takes 15 to 30 minutes and up to 3.5 GB of memory to write. Early history is much lighter. On a 32-core machine the whole archive takes several days.
§Comparing with Clio
One command checks a running Astraea against a Clio, local or public:
python3 -I scripts/astraea-clio-check.py --astraea http://127.0.0.1:51300 --clio https://s2.ripple.com:51234 --report check.jsonIt picks random ledgers in the range both servers hold, half of them recent, and builds requests from what they contain: the ledgers themselves, one transaction of each type and some random ones, the accounts, objects, NFTs and MPT issuances they touch. Every Clio method Astraea serves is asked, in API versions 1 and 2, JSON and binary, with filters, a second page through the marker Clio returned, and a set of malformed requests whose errors must match too. State methods are asked at ledgers where Astraea has state, which the script finds by probing. The lending group sends the requests of a lending dashboard in its own shapes: type-filtered ledger_data pages for vaults, loan brokers and loans, each object by ID, the ledgers that changed them, and feature (api.md). A request that does not name an API version names 2, because the two servers have different defaults.
Each answer is OK, DIFF, KNOWN or ERR. KNOWN is a difference listed in the script’s KNOWN table with its reason, for example Clio 2.8 printing the issuance object’s key as mpt_issuance_id. ERR means a server did not answer after retries. The script prints each difference with its path, a table by method, and exits with 0 only when there is no DIFF and no ERR. The report holds every request, both answers for each DIFF, and the seed: --seed repeats a run. A public Clio gets 0.4 s between requests (--pace), so a default run of 8 ledgers, about 900 requests, takes about 15 minutes; --ledgers and --only history,state,lending,errors make it shorter or longer.
Run it after every upgrade of Astraea or xrpld, and before a release.
The older scripts in scripts/ cover what the check does not:
astraea-client-replay.pyreplays recorded client requests against both servers and compares the answers;astraea-cold-compare.pysamples ledgers, transactions and account history across a range;astraea-forward-compare.py,astraea-subs-compare.py,astraea-ws-compare.pycover forwarding,server_infoand subscriptions;astraea-clio-bench.pymeasures latency and throughput of both servers on the same requests;astraea-client-latency.pydoes the same on a client’s real requests from the Clio log, in their real mix.
What those comparisons found, and how the two servers differ, is in compared-with-clio.md.