Adapter interface
The replay harness (shapekit harness run) feeds recorded chains to an indexer and checks
what the indexer stored against the meta oracle. It never talks to the indexer directly. An
adapter sits in between: a program that starts the indexer, points it at the harness's
ledger delivery endpoints, reports how far it got, and reads back what it stored in the
oracle's vocabulary.
Protocol version: 2. The harness still drives version 1 adapters (see "Versions"). The
machine-readable form is schema/adapter-protocol.schema.json,
generated from crates/shapekit-harness/src/protocol.rs together with the vocabulary section
at the end of this page (shapekit harness schema --write; cargo test -p shapekit-harness
fails when either is stale).
The reference adapter is adapters/walletbackend (wallet-backend, Go). An indexer that runs in
Docker and stores in PostgreSQL needs no adapter program: shapekit's mapped adapter runs it from a
mapping file (Connecting a PostgreSQL indexer with a mapping file).
What the harness does with an adapter
For each chain (one recorded ledger sequence per shape family, protocol and passphrase):
- Starts the adapter program and sends
describe. When the chain's protocol is outside the adapter'sprotocols, the harness sendsstopright away and the chain's entries areout-of-scope. - Creates a Docker network with
--internaland starts the replay server (shapekit-serve, in process) bound to that network's gateway address on a free port. The visible head is set to the bootstrap ledger (see "Bootstrap"). - Sends
start, then waits untilstatusreportslast_ingested_ledgerat or past the bootstrap ledger. - For every later ledger of the chain in order: moves the server's head to it, checks that
the server answers
getLedgersfor it (a ledger the server cannot serve is a harness error, never a target verdict), sendsadvance, and pollsstatusuntil the target has ingested it, the target died, or it stopped making progress. - Sends
exportfor the ledgers from the one after the bootstrap ledger to the last ledger the target ingested, and compares the records with the oracle files of the chain's corpus entries. When the adapter offersdump, it then asks for every stored table and keeps the answer (see "dump"). - Sends
stop, keeps the returned logs, stops the replay server, and removes the network and the work directory.
The harness starts a new adapter process for every chain, so a target that halts in one family does not hide the others.
Transport
- The harness starts the adapter as a child process with the command line it was given and talks to it over stdin and stdout. The working directory is the harness's.
- Every message is one JSON object encoded as UTF-8 on one line, terminated by
\n. No pretty printing, no blank lines, no byte order mark. - The harness sends one request and reads response lines until the final line for that
request (
statusokorerror) before it sends the next. Every response line carries the request'sid. A line with anotheridis a protocol violation and ends the chain's run. - Only
exportanddumphave more than one response line: any number ofrecordlines (export) ortableandrowlines (dump), then the final line. - stdout carries responses only. Logs go to stderr; the harness saves the adapter's stderr
next to the report (
logs/<chain>.<network>.adapter.log). - Ignore members you do not know; later protocol versions can add optional members.
- When stdin reaches end of file the adapter tears the target down as for
stopand exits. - The harness enforces a timeout per request. Defaults:
describe60 s,start30 min (the adapter can build images duringstart),advance120 s,status300 s,exportanddump10 min,restartandstop5 min.--start-timeoutand--status-timeoutchange the two that depend on the host. A status timeout ends the chain, so the status default leaves room for a heavily loaded host. - Two more limits apply to the target's progress, not to single requests: how long the
target can go without ingesting a ledger while it bootstraps (
--bootstrap-timeout, default 600 s) and after each released ledger (--ledger-timeout, default 120 s). When one passes, the target has stopped at that ledger (see "Verdicts"). - Once it has sent
start, the harness sendsstopafter a timeout, a protocol violation, an error response or a failed ledger, unless the adapter has exited; a failure beforestartsends nostop. It records every entry of the chain asnot-evaluatedwith the reason. On every path it then closes the adapter's stdin, waits up to 30 s for the adapter to exit, and then kills it. - When a request times out, the harness stops waiting for it but remembers its id. If that
request's lines arrive later, while the harness waits for the reply to a later request
(in practice
stop), the harness skips them, up to and including their final line, and lists the first 16 in the chain'snotes, then their count. This is the one exception to the id rule above. A line with an id the harness never sent, or with the id of a request that was already answered, is still a protocol violation. - Attach every container the adapter starts to
docker_network. Before the harness removes the network, it removes every container still attached to it, so a killed adapter leaves nothing behind.
Request
{"id": "3", "cmd": "advance", "head": 65}id: string, unique within one adapter process.cmd:describe,start,advance,status,export,dump,restartorstop. The command's members sit next tocmd.
Response
{"id": "3", "status": "ok", "result": {"head": 65}}
{"id": "7", "status": "record", "record": {"type": "transaction", "ledger": 65, "hash": "...", "participants": [], "changes": []}}
{"id": "4", "status": "error", "error": {"class": "target", "message": "timescaledb did not accept connections within 3m0s"}}Error classes
| class | meaning | what the harness does |
|---|---|---|
bad-request | the request does not follow this protocol | stops the chain, a harness bug |
unsupported | valid, but the adapter cannot do it (a delivery mode it lacks) | stops the chain |
target | the target could not be built, started or queried | stops the chain; its entries are not-evaluated with the message |
internal | the adapter itself failed | as target |
An error never stands for a verdict. A target that crashes or halts while ingesting is
reported through status, not through an error response.
Commands
describe
Request: {"id": "0", "cmd": "describe", "protocol": 2}
Result:
| member | type | meaning |
|---|---|---|
protocol | integer | the version the adapter speaks: the requested one, or an older one the harness drives (1) |
adapter, adapter_version | string | the adapter program and its version |
target | string | the indexer, for example wallet-backend |
target_version | string | the exact build, for example a full commit hash, never a branch name |
delivery_modes | array | modes the adapter can drive: sep54-filesystem, sep54-s3, sep54-gcs (protocol 2), rpc |
default_delivery | string | mode used unless the harness is given --delivery; one of delivery_modes |
bootstrap | checkpoint or ledger | how the target starts, see "Bootstrap" |
vocab_version | integer | the oracle vocabulary version the claims and exports use; must equal the harness's |
protocols | {"min", "max"} | ledger protocols the target build ingests; chains outside are out-of-scope |
claims | object | what the target records, see "Claims" |
capabilities | array | optional commands the adapter answers: dump, restart. Version 2; absent means none |
Versions
The harness asks for version 2. An adapter that does not speak it answers with an
unsupported error, and the harness sends describe again with "protocol": 1 in the same
process. A version 1 adapter runs exactly as before: no capabilities, no dump, and so no carry check. Any other error, or an answer
naming a version above the one asked for, ends the chain.
start
Request members (besides id and cmd):
| member | type | meaning |
|---|---|---|
chain | string | chain id, for example cap40.signed-payload-signer.p28 |
network | string | testnet or mainnet, the passphrase variant replayed |
network_passphrase | string | the passphrase to configure the target with |
protocol | integer | ledger protocol of the chain |
delivery.mode | string | the mode the harness picked |
delivery.rpc_url | string | JSON-RPC endpoint of the replay server (Replay server: methods, batch and response limits, paging, error codes); present in every mode |
delivery.archive_url | string | history archive root; the archive as it stood at the newest checkpoint at or below the head |
delivery.lake.url | string | SEP-54 lake root over HTTP: .config.json and the batches whose ledgers are all visible |
delivery.lake.path | string | the same lake as a directory on the harness host (every batch, including unreleased ones) |
delivery.lake.ledgers_per_batch, batches_per_partition | integer | the lake's layout |
ledgers.bootstrap | integer | the visible head while start runs |
ledgers.last | integer | the chain's last ledger |
ledgers.checkpoint_frequency | integer | 64 |
limits.memory_bytes | integer | memory limit to apply to the target's ingesting process or containers (--memory-limit <bytes>, default 4 GiB) |
docker_network | string | the internal network the target's containers must join; absent with --no-docker |
workdir | string | an empty directory for this chain; the harness removes it afterwards |
The adapter brings the target up and answers once the ingesting process runs. It configures
the target with the passphrase and the endpoints of its delivery mode only. The target gets
no other network access: containers join docker_network only, which has no route off the
host. The replay server URLs point at the gateway address of that network.
Result: components, an object of free-form strings (image ids, versions of services the
target needs) that the report keeps.
advance
Request: {"cmd": "advance", "head": N}. Ledgers up to N are now visible on the replay
server. In rpc mode the target sees them through getLedgers on its own and the adapter
answers at once. In the sep54-* modes the adapter copies the batches whose
last ledger is at or below N (from lake.url, or from lake.path skipping later batches)
into the directory or bucket the target reads, then answers.
Result: head, equal to N.
status
Result:
| member | type | meaning |
|---|---|---|
last_ingested_ledger | integer or null | highest ledger durably ingested, read from the target's own store (wallet-backend: ingest_store cursor). Not a log line, not a metric that runs ahead of the commit |
health | string | starting (bootstrapping), running (ingest process alive), crashed (exited or killed, not by the memory limit), oom (killed for exceeding limits.memory_bytes) |
last_error | string or null | the most recent error the target reported since start, verbatim |
peak_memory_bytes | integer or null | peak memory of the target since start |
health: running does not mean healthy. A target that retries the same ledger forever is
alive and running; the harness calls it halted when it stops advancing while last_error
is set (see "Verdicts").
export
Request: {"cmd": "export", "from": A, "to": B}. Stream one record line per stored
transaction in ledgers A to B inclusive, in ledger and apply order, then
{"status": "ok", "result": {"records": N}} where N counts the record lines. Stream from
the database cursor; do not build the whole answer in memory. A records count that differs
from the lines sent, or a hash that is not 64 lowercase hex digits, is a protocol violation
and ends the chain.
Records are of two types:
{"type": "transaction", "ledger": 65, "hash": "6f9d...", "participants": [...], "changes": [...], "unmapped": [...]}
{"type": "unattributed", "ledger": 65, "unmapped": [...]}transaction:
| member | meaning |
|---|---|
ledger | ledger sequence |
hash | lowercase hex transaction hash. For a fee bump, the outer hash (the oracle's hash) |
participants | every participant stored for the transaction: {"address", "mux_ids", "raw"} |
changes | every stored state change the adapter maps to a vocabulary kind |
unmapped | stored rows of this transaction the adapter has no mapping for |
A participant's address is the canonical strkey (G, C, L or B; never M, the mux
id goes in mux_ids as decimal strings). When the stored bytes do not decode, address is
null and raw says why.
A change is a vocabulary change (see the generated section below) with only the fields the
target stores: kind, the claimed fields, optionally scope and op_index, and
raw: for every address field read from stored bytes,{"column", "hex", "strkey"}when the bytes decode or{"column", "hex", "error"}when they do not. In the second case the field itself isnull.hexis the stored value exactly, for wallet-backend'sAddressByteathe version byte followed by the key bytes. Adapters must not repair, pad or truncate the bytes before decoding: a 33-byte value that cannot hold a 40-byte muxed key is exactly what the harness is looking for.source:{"table", "category", "reason"}, the row the change came from.
Values use the vocabulary's encodings exactly: amounts, balances, limits, ids and sequence
numbers as decimal strings ("-100"), 32-bit values as JSON integers, assets as native or
CODE:ISSUER (SEP-11), pool-share trustline assets as pool-share:<L strkey of the pool id>, hashes and
XDR as lowercase hex or base64 as the field's description says, signers as full strkeys
including P... signed-payload signers and their payload.
unmapped rows: {"table", "category", "reason", "row", "note"}. row holds every column
(byte columns as lowercase hex); note says why there is no mapping. Rows are never dropped
silently: an adapter that cannot map a row reports it here, and the report lists it next to
the entry so a reviewer can tell an indexer drop from an adapter gap.
stop
Result: logs, the tail of the target's logs (at most 1 MiB). The adapter removes every
container, volume and file it created, then exits with status 0.
dump
Version 2, sent only to an adapter whose describe lists the dump capability. Request:
{"cmd": "dump"}, or {"cmd": "dump", "tables": ["state_changes"]} for named tables only.
Stream every table the target stored, each as one table line followed by its row lines,
then {"status": "ok", "result": {"tables": T, "rows": R}} where T and R count the lines
sent:
{"id": "9", "status": "table", "table": {"name": "transactions_accounts", "columns": [{"name": "tx_to_id", "type": "bigint"}, {"name": "account_id", "type": "bytea"}]}}
{"id": "9", "status": "row", "row": {"table": "transactions_accounts", "cells": ["279172878336", "30aa..."]}}
{"id": "9", "status": "ok", "result": {"tables": 1, "rows": 1}}columns[].typeis the store's own type name (PostgreSQL:format_type, for examplebytea,bigint,character varying(255)).cellsfollowcolumns. A byte column's cell is the stored bytes as lowercase hex with no prefix. Every other cell is the store's own text form of the value (PostgreSQL: the value cast totext). SQL NULL isnull.- Dump what is stored, unchanged: no decoding, no mapping, no repair. The dump is the
evidence the relations search; anything the adapter would interpret belongs in
export. - A row of a table whose
tableline has not been sent, a table sent twice, and a row with a different number of cells than its table has columns are protocol violations. - Unknown table names in
tablesare abad-requesterror.
The harness sends dump after export and before stop, only when the target ingested a
ledger after the bootstrap ledger, and writes the answer to
logs/<chain>.<network>.dump.json. --no-dump skips it. A failed dump does not change any
verdict; the chain lists the error and the run exits non-zero.
restart
Version 2, sent only to an adapter whose describe lists the restart capability, and only
with harness run --restart. Request: {"cmd": "restart"}. Stop the target's ingesting
process and start it again on the same store, the way a deployment restarts it, then answer
{}. The harness then releases the next ledger as usual; a target that does not resume
stops there like any other.
Claims
describe.claims says which oracle facts the target records:
{
"participants": {"address_kinds": ["account", "contract"], "mux_ids": true},
"changes": [
{"kind": "signer-added", "fields": ["account", "signer", "weight"]},
{"kind": "trustline-created", "fields": ["account", "asset", "limit"]},
{"kind": "token-event", "where": {"event": ["transfer", "mint", "burn", "clawback"]},
"fields": ["event", "contract", "from", "to", "amount"]}
]
}participants: the oracle's actual participants (never the envelope's declared ones) whose address kind is listed are expected among the exported participants. Withmux_ids, their mux ids are compared too.- each
changesitem claims the oracle changes ofkindthat satisfywhere(every listed field equals one of its values; an absent field equalsnull), compared onfieldsonly.
A claim is a promise. Anything inside it that the export lacks is a finding; anything
outside it is out-of-scope. Claim what the target is meant to record, not what it happens
to get right.
Bootstrap
describe.bootstrap says how the target starts:
checkpoint: the target reads the archive's.well-known/stellar-history.json, loads the ledger state of that checkpoint, and starts ingesting at the checkpoint ledger. wallet-backend live mode on an empty database does this at every wallet-backend commit this repository runs (internal/services/ingest_live.go:archive.GetLatestLedgerSequence(), thenPopulateFromCheckpoint, then ingestion from that ledger). The harness therefore picks the newest checkpoint before the chain's first entry ledger asledgers.bootstrapand serves the archive as of that checkpoint.ledger: the target can be told a start ledger.ledgers.bootstrapis the chain's first ledger.
Every recipe chain has a checkpoint before its first shape: after the protocol upgrade in
ledger 2, shapekit gen chains closes empty ledgers through ledger 63 (core's first
checkpoint at the default frequency of 64) before it applies network settings and runs the
recipe. The archive in each chain's archive.tar holds that checkpoint. For a checkpoint
target, a chain with no checkpoint before its first entry ledger does not run: its entries are
not-evaluated, and the reason says to regenerate the chain with shapekit gen chains.
Entries at or before the bootstrap ledger are always not-evaluated: the harness compares
only the ledgers it releases after the bootstrap ledger.
Network access
Containers reach the replay server at the internal network's gateway address, which is the
host side of the network's bridge. A container on an --internal network has no route off
the host. The harness binds the replay server to the gateway address only, not to every
interface of the host.
This needs a Linux host. On macOS, Docker runs in a VM: the network's gateway and the
containers' addresses exist only inside it, so the harness cannot bind there and the adapter
cannot reach its containers. check indexer, harness run and harness reproduce therefore
stop on macOS with check indexer needs a Linux docker host, and shapekit doctor indexer
reports the same. The CI workflows run on Linux runners.
With --no-docker the harness creates no network and binds the server to 127.0.0.1, for
adapters whose target runs as a host process. The macOS check above does not
apply to it, and --no-docker is untested on macOS.
Verdicts
The harness gives every corpus entry of the chain that has an oracle file one verdict. The report counts the selected entries it cannot replay separately: entries with no chain (history captures, goldens, synthetic entries, vectors) and entries with no oracle file for the network (ledger entries and other values that are not a transaction or a ledger).
| verdict | reason | when |
|---|---|---|
pass | every in-scope fact of the entry's transactions was exported with equal values, and nothing undecodable or extra was stored | |
dropped | an in-scope participant or change has no counterpart in the export (or the target stored nothing for the transaction) | |
mishandled | wrong-value | an in-scope fact was stored with a different value (paired by the kind's key fields), or the target stored a participant or change the meta does not show |
mishandled | undecodable-address | a stored address in the entry's transactions does not decode (raw.error) |
mishandled | halted | the target stopped advancing at the entry's ledger with last_error set |
mishandled | crashed | the ingest process died at the entry's ledger (health: crashed) |
mishandled | oom | it was killed for its memory limit at the entry's ledger (health: oom), or status reported a peak_memory_bytes above limits.memory_bytes |
mishandled | timeout | it stopped advancing at the entry's ledger without reporting an error |
not-evaluated | the target stopped at an earlier ledger (the result names the entry), the entry is at or before the bootstrap ledger, or the chain could not be run (the result says why) | |
out-of-scope | the entry has no fact the target claims, the chain's protocol is outside protocols, or every comparable fact matched but a claimed event fact cannot be checked because the meta format has no place for it (see "Facts the meta cannot show") |
A target stops "at" ledger L when L is the first ledger it did not ingest. Every entry
in L gets the stop verdict (halted, crashed, oom or timeout) without a comparison,
and entries in later ledgers are not-evaluated. The harness compares every other entry,
lists every problem it finds in the report, and picks the verdict from the first problem in
the order undecodable-address, wrong-value, dropped.
Facts the meta cannot show
token-event and contract-event facts come only from events, and older meta formats have
no place for most events. The oracle records, per transaction, events:
events | meta | events present |
|---|---|---|
unified | TransactionMeta v4 (protocol 23 and later, and protocol 22 ledgers recorded with CAP-67 backfill) | every operation's events, classic operations included, and the fee events |
soroban-operation | v3 with Soroban meta | the invoked contract's own events, at operation scope |
none | v0 to v3 without Soroban meta | none |
A claim on an event kind can match events at certain scopes. With a where.stage filter,
those are the scopes of the listed stages: before-all-txs (fee processing), operation,
after-tx and after-all-txs (post-apply fee). Without one, the claim can match every event
scope. When the transaction's events coverage lacks any of those scopes, the claim is not
comparable for that transaction, and the harness compares neither side of it: an oracle fact
is not expected, an exported fact is not extra, and the entry lists the claim in its detail.
The verdict then follows the comparable facts. A problem there gives dropped or
mishandled as usual. Otherwise the entry is out-of-scope, never pass, because a pass
would say the event claims were checked. Example: on
cap67.unified-events.p22-payment-transfer (protocol 22, classic events off, meta v3)
wallet-backend derives a transfer and a fee from the operation. The meta shows neither, so
the export can be neither confirmed nor contradicted there.
The harness refuses an oracle file whose transactions have no events member; shapekit oracle run rewrites it.
Pairing for wrong-value: an expected change and an exported change of the same kind are a
pair when they agree on the kind's key fields that the claim compares:
| kind | key fields |
|---|---|
account-created, account-removed, thresholds, account-flags, home-domain, inflation-destination, sequence | account |
balance-change | holder, asset, held_in |
trustline-created, trustline-removed, trustline-flags, trustline-limit | account, asset |
signer-added, signer-removed, signer-weight | account, signer |
data-entry | account, name_hex |
sponsorship | target, signer |
claimable-balance-created, claimable-balance-claimed, claimable-balance-clawed-back | balance_id |
pool-shares | account, pool |
liquidity-pool | pool |
offer | offer_id |
contract-deployed | contract |
contract-code | hash |
contract-data | contract, key_xdr |
ttl | key_hash |
config-setting | setting |
trade | counterparty, offer_id |
contract-event | contract, stage |
token-event | event, contract, from, to |
Changes are compared as multisets: two equal transfers in one transaction must both be exported.
Carry check
When the adapter offers dump, the harness also checks what the target stored without any
mapping from its columns to the vocabulary. It collects every identifier and amount the
chain's ledgers carry, up to the last ledger the target ingested, from the ledgers' own
values: account, muxed, signed-payload, contract, pool and claimable balance strkeys, and
the integer amounts, balances, limits and fees. It adds what follows from those and the
passphrase alone: the genesis root account, the base G account of every M address and
P signer, and the Stellar Asset Contract id of every asset. Each value is known in these
encodings: the strkey text, the hex of the strkey's version byte and payload (the form of
wallet-backend's AddressBytea), the hex of the payload alone, and decimal for amounts.
Every non-null cell of the dump is then looked up:
| outcome | when |
|---|---|
| carried | the cell equals a known value in one of its encodings. Counted per column and encoding |
| truncated | the cell is a strict prefix of a known address's encoding (at least 17 bytes of hex or 20 strkey characters) and equals no known value: the target kept part of what it was given |
| fabricated | the cell decodes as a well-formed strkey (as text, or as version byte and payload in a byte column) that is not known; or the cell is in a column that holds carried addresses in other rows, starts with a strkey version byte and explains as nothing known: the target wrote an identifier the chain cannot account for |
Cells that match nothing and look like no address are not judged: they are the target's own
values (ids, timestamps, hashes of its own). A truncated or fabricated value is an error
whatever the column means, so no claim is needed for it. The carry check does not change any
verdict. The report keeps, per chain, the counts, the carried columns and the first 200
problems; HARNESS.md has a "Carry check" table. The carried columns are the evidence the
state comparison builds its column mapping from.
shapekit harness carry --dump <logs>/<chain>.<network>.dump.json --chain-dir corpus/chains/<chain>/<network> [--through <ledger>] runs the same check on a kept dump and
exits non-zero when it finds a problem.
Replay invariance
How ledgers reach the target, a restart in the middle, and which network passphrase the
chain was recorded under must not change what the target stores. shapekit harness relate
compares the dumps of two runs chain by chain:
shapekit harness run --adapter "$A" --chain <id> --network testnet --repeat 2 --out base
shapekit harness run --adapter "$A" --chain <id> --network testnet --delivery sep54-s3 --out s3
shapekit harness relate --base base/logs/round-1 --control base/logs/round-2 --other s3/logs- Tables are compared as multisets of rows; row order does not matter.
--controlnames a second run of the base configuration. Columns that differ between the base and the control (ingestion timestamps, for example) are noise: they are blanked on both sides and listed, never assumed.- When the other run holds the chain's other network variant (
--network mainnet), the harness walks the two chains' ledgers in step and translates every address and hash core wrote differently (transaction hashes, the genesis root, asset contract ids, in each encoding the carry check knows) before comparing. Numbers are not translated. Places where the two chains differ in shape (a network setting written as another arm) are listed and nothing under them is translated. A value the target derives from a translated one in another form stays a difference. --restartonharness runrestarts the target's ingesting process once, after the ledger halfway between the bootstrap ledger and the chain's last, through the version 2restartcommand (capabilityrestart): the adapter stops the process and starts it on the same store, as a deployment restart does. The chain'srestarted_aftersays where.
Each chain is reported same or DIFFERENT with, per table, the rows found on one side
only and the columns whose values differ. The command exits non-zero when any chain
differs; --out writes the reports as JSON.
State comparison
The verdicts compare what the target stored per transaction with the oracle's vocabulary. The state comparison looks at what the target holds at the end: its accounts, trustlines, Stellar Asset Contract balances and liquidity pools next to core's own final entries, which the harness rebuilds by applying the meta of every ingested ledger to genesis. It needs dumps.
Which table and column holds which entry and field is inferred, not written by hand:
shapekit harness state infer --run <run out> [--run ...] --network testnet --write mapping.toml
shapekit harness state check --run <run out> [--run ...] --mapping mapping.tomlinferreads the ordinary chains of the runs: chains that ran without an error, whose carry check is clean, where no entry ismishandledordropped, and where at least one entry passes. Chains run with--chain-dirhave no entries, so they never count. For each table it takes the entry kind and key columns that match the most rows: a column whose cells are account, contract or pool addresses in a known encoding, or ids of another table's rows that render as an asset ({code}:{issuer}) or a contract. A column is mapped to an entry field when it equals that field on every keyed row of every ordinary chain. A column that equals several fields everywhere is kept as ambiguous, unless one of them has the column's name. Tables with no such column (history tables that only name an account) are left out. A pool id column also counts as the asset of a pool-share trustline (pool-share:<L>). The mapping keeps, per key column, the forms of the keys the table held (GorCholders, credit or pool-share assets); a table covers only core entries of those forms.checkapplies the mapping to every chain and lists stored values that differ from core's (mismatched), rows for entries core no longer has (stale) and core entries with no row (missing), and counts core entries of forms the table never held (outside).--exclusions <file>names core entries a table leaves out on purpose, each rule with the target's source line that says so ([[exclusion]]withtable,field,equals(a literal ornative-asset-contract),reason,source); they are counted per reason, not listed as missing. A chain whose state differs where the oracle found no problem is a disagreement. A chain where the oracle found problems and the mapped tables equal core's is not one: the oracle reads each transaction's stored facts, this comparison the tables' end state, so both can hold; the facts the problems are about are listed. It exits non-zero when the mapping does not hold on an ordinary chain.
The wallet-backend mapping inferred this way is
adapters/walletbackend/state-mapping.toml; its header names the target build and the
chains it came from.
state check also runs the route equivalence check. Core's final entries are grouped by
their XDR with the holder zeroed (the account, the trustline's account, the balance holder,
the pool id): a group of two or more is a set of records core holds identically except for
whose they are, reached by different operations. For every group and every mapped table of
its kind, the rows the target keeps for the group's keys must be equal once the key columns
are left out; a row stored for some of them and not the others is a difference too.
Recipe pairs (corpus/recipes/explore.pairs/<pair>/) carry the same check across two chains: two recipes
from one start state that reach an entry in two ways, with the entries core writes
identically under both listed in pair.json. Run the target over each chain on its own with
harness run --chain-dir <name>=<dir>, which replays a chain outside the corpus from its
first checkpoint for its dump alone, then
shapekit harness state pair --a <run of a> --b <run of b> \
--pair corpus/recipes/explore.pairs/<pair>/pair.json --mapping adapters/walletbackend/state-mapping.tomlFor each listed entry it confirms core's entry is the same at the end of both chains, compares
the target's rows for it in every mapped table of its kind, and compares the changes the
target exported about it (an entry's own kinds, such as trustline-created for a trustline,
naming its account and asset; --chain-dir runs keep their export as
logs/<chain>.<network>.export.json). It exits non-zero on a difference.
Free field inertness
A field core does not validate can hold any value, and core treats the transaction the same
whatever it holds. An indexer must too. shapekit harness free-field --run <run out> reads
attempts that differ in one such field, each with core's outcome:
--validation registry/generated/validation.json: every field it records asnot-validated, with its attempts and their witness entries. The witnesses sit incandidate/; run the harness over the probe chains undercandidate/chains/first, on a copy of the candidate lane with oracle files (shapekit oracle run --corpus <copy>);--groups <toml>: hand-written groups over entries already in a corpus,[[group]] field = "..."withattempt = [{ label, entries, outcome }].crates/shapekit-harness/free-field/corpus.tomlgroups the memo arms of classic.memo-arms.p30.
Attempts in the same carrier transaction with the same outcome in core are compared per
network by what the run made of each: verdict, reason and the kinds of problems found (an attempt carried by an envelope
and a ledger entry takes the more severe of the two). Attempts run on their own funded
accounts, so their stored rows differ in keys and ledgers as well as in the field; the
comparison is per attempt against core's meta, not between the attempts' rows. A difference
means the value of a field core ignores changed what the indexer stored. Attempts the run
did not judge are counted. The command exits non-zero on a difference; --out writes the
report as JSON.
Output
shapekit harness run writes into --out (default harness-out/):
harness-report.json: run metadata (adapter, target and version, corpus manifest sha256 and replay digest, harness peak resident memory per round, the target memory check), per-chain results (delivery mode, bootstrap ledger, last ingested ledger, target peak memory, stop reason, dump and carry summary) and one row per entry withverdict,reason, the problems found and any unmapped rows.HARNESS.md: the same as tables, one row per entry.
The replay digest (manifest_replay_digest) is the sha256 of the manifest with keys sorted,
leaving out these fields of every entry: caps, arms, notes, fields_exercised,
linked_issues and obligations. It covers everything else: the header (corpus version, the
stack the corpus was generated with, the protocol tiers) and of every entry its id, kind,
family, protocol, XDR type, meta versions, source, flags, expected verdicts and every variant
with its file paths and the sha256 of its bytes, expected JSON and oracle file.
shapekit findings check compares a report's replay digest with the committed manifest's, so
retagging entries keeps a report current, while a change to the bytes, the entry set or an
oracle asks for a rerun.
logs/: adapter stderr (<chain>.<network>.adapter.log) and the target logsstopreturned (<chain>.<network>.target.log) per chain, and the dump (<chain>.<network>.dump.json:{"schema": 1, "tables": {<name>: {"columns", "rows"}}}) when the adapter offers one; with--repeat, onelogs/round-<n>/per round.
--repeat N runs the whole selection N times in one process. The run fails when a later
round's verdicts differ from the first round's, or when its peak resident memory exceeds the
first round's by more than --memory-slack of it (a fraction, default 0.1) or 16 MiB,
whichever is larger. It also fails when a chain's target peak memory in a later round exceeds
its first-round peak by more than --memory-slack or 64 MiB, whichever is larger, and when
any chain could not run or its dump failed.
--memory-budget fails a round over a fixed bound. On Linux the harness reads its peak memory
from /proc/self/status (VmHWM) and resets it between rounds through
/proc/self/clear_refs. macOS has no peak a process can reset, so there the harness reads
getrusage (ru_maxrss, the peak since the process started) and a round's peak is the
highest of that round and every round before it. A later round that grows past the first
still raises it, so both checks keep working.
--shard <index>/<count> replays one part of the selection, for a run split across machines
or CI jobs: the selected chains, sorted by name, are dealt out in turn, so every chain is in
exactly one shard and both networks of a chain are in the same one. The report records the
shard. shapekit harness merge --out <dir> <shard dir>... takes the reports of every shard of
one run, each once, and writes the harness-report.json and HARNESS.md the whole run would
have written: the same chains and entries in the same order, the verdict totals added up, the
memory checks holding where they hold in every shard, a round's seconds added up and its peaks
the largest shard's. It refuses shards of different runs (another adapter, target build,
corpus, memory limit or round count) and a set with a shard missing or given twice, and
--expect checks the merged report. shapekit findings refuses a single shard's report as an
input.
--expect <file> holds a run (or a merged report, or with harness expect --check a report
already written) to an expectations file that shapekit harness expect --write wrote from a
reviewed run. --expect-mode exact, the default, fails on any difference: a verdict or
reason, an entry missing or not listed, or another target build. --expect-mode regressions
(--mode for harness expect --check) accepts any build of the same target and fails only on
a new or changed mishandled, dropped or not-evaluated verdict, or a listed entry the run
did not judge; a fixed failure is printed as a note. Running the corpus in an indexer's
CI shows the rules as a table.
Reproductions
shapekit harness reproduce --table <toml> runs pairs of target builds over named chains and
checks the verdicts of named entries:
[adapter]
# the command line; {commit} is replaced by each case's commit
command = ["go", "-C", "adapters", "run", "./walletbackend/cmd/wb-adapter", "--commit", "{commit}", "--cpus", "2"]
[[reproduction]]
id = "wallet-backend-729"
issue = "https://github.com/stellar/wallet-backend/pull/729"
chain = "cap40.signed-payload-signer.p28"
network = "testnet"
[[reproduction.case]]
label = "pre-fix"
commit = "2a0a84ea12523b6c92e278c0c84b443041240095"
expect = [
{ entry = "cap40.signed-payload-signer.p28-set-options-payload-1-meta", verdict = "mishandled", reason = "halted" },
]
[[reproduction.case]]
label = "fixed"
commit = "2c873353c1f0f3c9b145e25a7d009023ad104a1c"
expect = [
{ entry = "cap40.signed-payload-signer.p28-set-options-payload-1-meta", verdict = "pass" },
]A case can also name the carry check's outcome on the chain:
carry = { truncated = ["state_changes.signer_account_id"], fabricated = [] }truncated and fabricated are the exact sets of table.column where the check finds such
values; the case holds only when both sets match, which needs an adapter that offers dump.
This excerpt is from adapters/walletbackend/reproductions.toml. The adapter command runs
with the harness's environment, so go must be on PATH for that table, and the command
must contain {commit}. A case holds when every listed entry has the listed verdict (and
reason, when given), and its chain ran without a harness error. shapekit harness reproduce exits non-zero when any case does not hold. It writes reproductions.json and
REPRODUCTIONS.md into --out (default harness-reproduce/), and each case's full report
into <out>/<reproduction id>/<case label>/.
Writing an adapter
shapekit init adapter --lang go|ts|python --target <name> --target-version <build> writes a
skeleton into adapter-<name>/ (or --out <dir>). Its protocol side is complete: describe
with no claims and the rpc delivery mode, start, advance, status, export and stop,
error classes and malformed lines. The part that knows your indexer is a Target type with
start, status, export and stop methods. Until a method is written, the adapter answers
the request that needs it with a target error naming the method, so a harness run reports
the chain as not-evaluated with that message. The TypeScript skeleton runs with
node adapter.ts, no build step; the Go one builds with go build. Every line each skeleton
answers follows schema/adapter-protocol.schema.json (crates/shapekit-cli/tests/init_skeletons.rs).
- Read
describeandstartabove, then the vocabulary below, and decide the claims: one item per vocabulary kind the target stores, with exactly the fields it keeps. - Map the target's rows to vocabulary changes. When the target stores something the
vocabulary has no kind for, report the rows as
unmapped. - Decode stored addresses with a strict strkey decoder and report the bytes in
raw. - Apply the memory limit and join only
docker_network. - Run
shapekit check indexer --adapter "<your command>" --chain <id>on a small chain and readHARNESS.md.
cargo test -p shapekit-harness checks the requests the harness builds and example response
lines against the schema (crates/shapekit-harness/tests/protocol_schema.rs). To check your
adapter's lines the same way, validate them against schema/adapter-protocol.schema.json.
The wallet-backend adapter
adapters/walletbackend (Go), command adapters/walletbackend/cmd/wb-adapter:
(cd adapters && go build -o bin/wb-adapter ./walletbackend/cmd/wb-adapter)
shapekit harness run --adapter "adapters/bin/wb-adapter --commit <full commit hash>"--commit is required and takes a full 40-character lowercase commit hash. --repo names a
wallet-backend clone (default: <user cache dir>/shapekit/wallet-backend, created on first
use with only the commits you run, each fetched from github.com/stellar/wallet-backend at
depth 1; a full clone you name stays full); --db-memory <bytes> caps the database
container (default 1 GiB); --builder names the buildx builder the image is built with
(default: the current builder); --cpus passes docker's --cpus to every container it starts (default: no
limit). The adapter offers the rpc (default) and sep54-s3 delivery modes, dump (every
base table of the database's public schema, rows ordered by every column) and restart
(docker restart of the ingest container).
- Build.
git archive <commit> | docker buildx build --load -with the commit's ownDockerfile, imageshapekit-wallet-backend:<commit>. EachFROMin that Dockerfile is replaced by its base image pinned by digest (--build-context <tag>=docker-image://<image>@<digest>, the tableBaseImagesindocker.go, the same digests aspins.toml); a Dockerfile naming a base with no pin is refused. The image carries a label with the set of pinned bases it was built on and is reused only when that label matches. Building needs network access; running does not. - Services.
timescale/timescaledb:2.28.2-pg17(by digest, as inpins.toml) with the settings of wallet-backend'sdocker-compose.yaml, thetimescaledbextension created beforewallet-backend migrate up, thenwallet-backend ingest(live mode) with--memoryand--memory-swapset tolimits.memory_bytesand--restart on-failure. All containers joindocker_networkonly. The restart policy stands in for the deployment's restart loop: wallet-backend gives up on a ledger after five persist attempts and exits, and when restarted it retries the same ledger, so a give-up is reported as a halt (running, cursor stuck,last_errorset).crashedmeans a Go runtime failure in the log or a container that stayed down;oommeans docker reports an OOM kill. - Configuration.
NETWORK_PASSPHRASE,RPC_URL,ARCHIVE_URL,CHECKPOINT_FREQUENCYfromstart;DATABASE_URLandINGEST_SERVER_PORTfor the containers it runs;LEDGER_BACKEND_TYPEalways set, torpcordatastore(commits before a9bac8d2 default to the datastore);STELLAR_ENVIRONMENTfor commits whose ingest command still requires it;LOG_LEVEL=INFO.sep54-s3addschrislusf/seaweedfs:4.46run as in wallet-backend's integration tests (weed server -s3, no auth, bucketledgers) and theDATASTORE_*variables.startuploads.config.jsonand every batch whose last ledger is at or below the bootstrap ledger fromlake.path; eachadvanceuploads the batches up to the new head. - Bootstrap.
checkpoint: an empty database makes live mode load the archive's latest checkpoint and start there. - Status.
last_ingested_ledgerisingest_store.latest_ingest_ledger.last_erroris the newest log line at level error, fatal or panic, a retry warning whose message starts withError(Error ingesting data ...,Error fetching ledger ...), or theError:/panic:line printed on exit. Peak memory is the ingest container's cgroupmemory.peak, sampled every second. - Protocols. From 1 up to 28 for commits on go-stellar-sdk v0.7.3, and up to 30 on v0.8.0.
A commit on another go-stellar-sdk version is refused with an error that names the version
(
sdkProtocolsinsource.go).
Read-back takes each transaction's hash and ledger from transactions, then reads its
participants from transactions_accounts and its rows from state_changes, both by the
transaction's to_id. It selects every column of state_changes, so commits with other
columns read as they are. Token ids (asset contract ids) on trustline rows are named by recomputing the asset
contract id of every asset in trustline_assets and the SAC rows of contract_tokens. Address
bytes (AddressBytea, SignerKeyBytea) are decoded as stored, version byte then payload, with
go-stellar-sdk's strict strkey decoder; account columns accept G and C, signer columns G,
T, X and P. Transaction ids are TOIDs: the operation index is the low 12 bits minus one,
operation_id 0 is the transaction's fee row.
state_change_category / reason | vocabulary change | fields exported |
|---|---|---|
BALANCE DEBIT/CREDIT, operation_id 0 | token-event fee | contract (token_id), from (account_id), amount (net: DEBIT as stored, CREDIT negated) |
BALANCE DEBIT + CREDIT, consecutive state_change_id, same token and amount | token-event transfer | contract, from, to, amount, to_muxed_id {"type":"u64"} from the CREDIT row |
BALANCE MINT (+ CREDIT at the next state_change_id) | token-event mint | contract, to (the CREDIT row, else the MINT row's account), amount, to_muxed_id |
BALANCE BURN (+ DEBIT at the next state_change_id) | token-event burn | contract, from (the DEBIT row, else the BURN row's account), amount |
| BALANCE DEBIT or CREDIT without a partner | token-event transfer | the side wallet-backend stored only (from or to) |
| ACCOUNT CREATE (G) | account-created | account |
| ACCOUNT CREATE (C) | contract-deployed | contract |
| ACCOUNT MERGE | account-removed | account |
| SIGNER ADD / REMOVE / UPDATE | signer-added / signer-removed / signer-weight | account, signer (signer_account_id), weight or before, after |
| SIGNATURE_THRESHOLD UPDATE (one row per threshold) | thresholds, one per account and operation | account |
| FLAGS SET / CLEAR | account-flags, one per account and operation | account |
| HOME_DOMAIN SET / UPDATE / CLEAR | home-domain | account, before, after from key_value old/new (absent as "") |
| DATA_ENTRY ADD / UPDATE / REMOVE | data-entry | account, action, name_hex, value_before_hex, value_after_hex (base64 key_value as hex) |
| TRUSTLINE ADD | trustline-created | account, asset, limit (stored in horizon's 7-decimal amount form, converted to stroops); flags from the BALANCE_AUTHORIZATION SET row written with it |
| (asset of a pool-share trustline) | pool-share: plus the pool's L strkey, from the hex liquidity_pool_id, which is how the oracle names it | |
| TRUSTLINE UPDATE / REMOVE | trustline-limit / trustline-removed | account, asset, before, after |
| BALANCE_AUTHORIZATION SET / CLEAR, G holder | trustline-flags, one per holder, asset and operation | account, asset |
| BALANCE_AUTHORIZATION SET / CLEAR, C holder | token-event set_authorized (not claimed) | contract, to, authorized |
BALANCE_AUTHORIZATION, holder byte neither G nor C | unmapped | the whole row; the version byte is compared with go-stellar-sdk's strkey.VersionByteAccountID and VersionByteContract |
| ALLOWANCE UPDATE | token-event approve | contract, from, spender, amount, live_until_ledger |
| BLEND_*, any other category, and rows the rules above cannot name (a token id of no known asset) | unmapped | the whole row, with the reason |
wallet-backend's trustline flag bits (bit 0 authorized, bit 5 clawback enabled, bit 6 authorized
to maintain liabilities) become core's TrustLineFlags values (1, 4, 2). Two BALANCE rows pair
only when the second has the next state_change_id after the first, the reason the pair needs,
and the same token and amount. wallet-backend writes the two rows of one token event next to
each other (createDebitCreditPair, handleMint, handleDefaultBurnOrClawback in
internal/indexer/processors/token_transfer.go) and numbers the state change rows 1..N per
operation in that order (AssignStateChangeOrdinals), so this pairs rows of one event and never
joins rows of two events that happen to agree on token and amount, such as a one-sided
liquidity-pool leg of a path payment followed by a transfer. State change and participant rows
whose transaction has no transactions row come out as unattributed records.
Claims follow from the table: participants of kind account only (wallet-backend does not record
event-emitting contracts as participants, and keeps no mux ids), every kind above on the
fields it stores, token-event transfer/mint/burn/clawback on event, contract,
from, to, amount, to_muxed_id, the fee event of stage before-all-txs on event,
contract, from (the stored fee row is net of any refund, so its amount and the refund event
are not claimed), and approve. Values wallet-backend does not keep (starting balances, threshold
values, account flag values, trustline flag values after authorization changes, executables)
are not claimed.
Two claims cover facts that wallet-backend at the current pin does not store in the oracle's form, and they are kept on purpose:
clawback. wallet-backend'sTokenTransferProcessorreceives the token transfer processor'sClawbackevent (handleClawback) and writes it as a BURN row for the issuer plus a DEBIT row for the holder, the same rows a payment to the issuer produces. The oracle, following CAP-67, records aclawbackevent. The information reaches wallet-backend and itsstate_change_reasoncolumn is an open vocabulary, so the loss happens in wallet-backend's mapping, not in what the ledger or its schema can carry. A wallet that shows this history would show a clawback as a voluntary payment. Each clawback therefore counts as one droppedclawbackand one extraburn, which is finding WB-W3.to_muxed_idon every arm. CAP-67 puts the destination's mux id or, without one, the transaction memo into a transfer'sto_muxed_id, typed as u64, string or bytes. wallet-backend'ssetToMuxedIDkeeps only the u64 arm, although itsto_muxed_idcolumn isTEXT. A text, hash or return memo is lost, which is finding WB-W4.
The rule for both: a claim says what wallet-backend is expected to record of a fact it ingests
and has a place for, judged against the oracle. Claiming only what it stores today would turn
these losses into out-of-scope and hide them. The verdict detail and the finding's text
name the cause, so a reader can see that the difference is a design choice in wallet-backend
and decide whether it matters for their use.
Where wallet-backend's history and the meta tell different things on purpose
wallet-backend writes its classic state changes from a port of Horizon's effects, and Horizon records an effect for what an operation did or named, not for what the ledger changed (Horizon's effect types list each effect with the operations that produce it). Four kinds of failure follow from that and are not defects:
- a set options that names thresholds or flags without changing them stores a
thresholdsoraccount-flagschange the meta does not show; - an allow trust stores a
trustline-flagschange even when the flags stay as they were; - a master key set to weight 0 is stored as the master key removed (
signer-removed), where the meta shows threshold 0 of the account going to 0 (signer-weight), because the signer list it compares holds the master key only while its weight is above 0; - a revoke sponsorship that only moves a data entry's sponsor is stored as a sponsorship change
and no
data-entrychange, where the vocabulary counts both.
The harness reports these as mishandled or dropped like any other failure. They are listed
with Horizon's source as the explanation in candidate/finding-candidates.toml, not as
findings.
The stellar-etl adapter
adapters/stellaretl (Go), command adapters/stellaretl/cmd/etl-adapter:
(cd adapters && go build -o bin/etl-adapter ./stellaretl/cmd/etl-adapter)
shapekit harness run --adapter "adapters/bin/etl-adapter --commit 7e3fc9af95359dad6ba939fa88791f49cdf531ae"That commit is stellar-etl v2.8.35, pinned in pins.toml (scripts/pin.sh git stellar-etl prints it). --repo names a clone (default:
<user cache dir>/shapekit/stellar-etl), --cpus passes docker's --cpus to every container
and --builder names the buildx builder the image is built with.
- Build.
git archive <commit> | docker buildx build -f docker/Dockerfile -with eachFROMreplaced by its pinned digest (BaseImagesinbuild.go, the same digests aspins.toml), imageshapekit-stellar-etl:<commit>. - Delivery. stellar-etl reads ledgers only from Google Cloud Storage, so the adapter offers
one delivery mode,
sep54-gcs: it runsfsouza/fake-gcs-server(pinned by digest) ondocker_network, uploads the lake's.config.jsonand every batch up to the released head fromdelivery.lake.path, and points stellar-etl at it throughSTORAGE_EMULATOR_HOST. stellar-etl knows two passphrases, testnet (--testnet) and pubnet, so both chain variants run. - Running. stellar-etl is a batch exporter. The adapter plays the orchestrator: after
each
advanceit runsexport_transactions,export_operations,export_effects,export_token_transferandexport_contract_eventsfor the new ledger inside one container limited tolimits.memory_bytes.last_ingested_ledgeris the last ledger all five exports finished for. A failed export is retried every two seconds with its error aslast_error, so a ledger that never exports is a halt.bootstrapisledger. - Claims. Changes from
export_effects:account-created(account,starting_balance),account-removed,signer-added,signer-removed(no weight is exported),signer-weight(after; a master key whose weight changes, and a master key set to 0, which stellar-etl writes as a removed signer),trustline-created,trustline-removed,trustline-limit(after),home-domain(after) anddata-entry. Token events fromexport_token_transfer: transfers, mints, burns and clawbacks withcontract,from,to,amount, and fee charges (before-all-txs) withcontractandfrom. A refund, which the export writes as a second fee row with a negative amount, isunmapped. Amounts written with seven decimals are converted to stroops. No participants are claimed: no export lists a transaction's participants. The created master key signer that stellar-etl adds to every new account, and every effect type outside the claims, areunmappedrows. - Dump. One table per export, the union of the rows' JSON members as columns; cells are
strings as written, numbers as written, booleans as
trueandfalse, objects and arrays as compact JSON.
The stellar-rpc adapter
adapters/stellarrpc (Go), command adapters/stellarrpc/cmd/rpc-adapter:
(cd adapters && go build -o bin/rpc-adapter ./stellarrpc/cmd/rpc-adapter)
shapekit harness run --adapter "adapters/bin/rpc-adapter --cpus 2"The adapter runs the stellar-rpc v30.0.1 release image, stellar/stellar-rpc:30.0.1 by the
digest in pins.toml. When the first serving process answers, the adapter checks that
getVersionInfo reports 30.0.1-6b6ec60c8bde5a93984b6290065d3882d384b25d, the commit of
the v30.0.1 tag, and stops the chain with a target error otherwise. The image carries the
stellar-core 30.0.0 build that its captive core runs. --cpus passes docker's --cpus to
the container. --events-from names the method the export reads events from: events
(getEvents, the default), transactions (getTransactions) or ledgers (getLedgers).
Run the harness once with each to check all three methods.
-
Delivery.
sep54-filesystem: stellar-rpc reads a filesystem datastore ([datastore_config],type = "Filesystem") in a directory of the work directory.startcopies the lake's.config.jsonand every batch up to the bootstrap ledger into it fromdelivery.lake.path, and eachadvancecopies the batches up to the new head. -
Ingestion. stellar-rpc ingests from a datastore only through its backfill (
BACKFILL = true, which needsSERVE_LEDGERS_FROM_DATASTORE = true). The backfill runs when the process starts, before the HTTP server, and then hands over to live ingestion, which runs captive core and follows the network over SCP. The harness network has no validators, so captive core never ingests a ledger, and stellar-rpc logscould not run ingestion. Retrying. After five retries a second apart, stellar-rpc exits (maxRetriesandFatal("could not run ingestion")inStart,rpcv1/ingest/service.go). The captive core configuration only has to pass stellar-rpc's checks: the archive URL fromstartand a quorum of one key that the adapter generates and that signs nothing. Two settings follow from the backfill's source (cmd/stellar-rpc/internal/rpcv1/ingest/backfill.goat v30.0.1):- The frontfill stops at the newest checkpoint at or below the datastore's newest ledger
(
PrevCheckpoint).CHECKPOINT_FREQUENCY = 1makes every ledger a checkpoint, so the backfill reaches the newest released ledger. Apart from the backfill, the setting reaches only captive core and its archive reads, and captive core ingests no ledger here. - The frontfill fills only when its first ledger is below its last
(
if bounds.frontfill.First < bounds.frontfill.Last). On a database at ledgerH, a restart with one new ledger in the datastore fills nothing. So everyadvancereplaces the container: a new stellar-rpc process on an empty database, whose backfill ingests every released ledger. The database that answersexportanddumpholds the whole chain from one backfill.
At
CHECKPOINT_FREQUENCY = 1the backfill process lives only about five seconds after its HTTP server starts: its database is more than two checkpoints past the archive's newest one, so captive core refuses to start (trying to start online mode too far), and the retries above end in the exit. A dump that takes longer would lose the process. So once the backfill process answers, or has exited after starting its HTTP server (stellar-rpc starts the server only after the backfill,MustNewinrpcv1/daemon/daemon.go), the adapter stops it and starts a serving process on the same database:BACKFILL = falseand the checkpoint frequency fromstart(64). That database head is within two checkpoints of the archive the harness serves, so captive core starts and waits for the next checkpoint, and the process stays up.status,exportanddumptalk to the serving process;exportanddumpwait until it answers, and report atargeterror if it exits instead.The backfill writes each ledger with the function that live ingestion uses too (
ingestLedgerCloseMetainrpcv1/ingest/service.go: the ledger, its transactions and its events). Only the fee statistics behindgetFeeStatsare left out, and the harness does not read them. - The frontfill stops at the newest checkpoint at or below the datastore's newest ledger
(
-
Bootstrap.
checkpoint. On an empty database, live ingestion starts at the archive's newest checkpoint (getNextLedgerSequenceinrpcv1/ingest/service.go), and the backfill ends on a checkpoint. -
Status.
last_ingested_ledgeris thesequencethatgetLatestLedgeranswers, which stellar-rpc reads from its database: the backfill process's answer, then the serving process's. While a new process backfills, the value stays at the newest one an earlier process of the chain answered.healthisstartinguntil the current serving process answers,crashedwhen a backfill process exited before its HTTP server started or a serving process exited, andoomwhen docker reports an OOM kill.last_erroris the newest log line at levelerrororfatal, or apanic:line. Lines of the live ingestion path, which cannot run here (the retry above and captive core's own log), are left out. Peak memory is the container's cgroupmemory.peak, sampled at everystatus, across all the containers of the chain. -
Protocols. 1 to 30.
-
Claims. The consensus events that the three methods serve.
token-event:event,stage,contract,from,to,spender,amount,to_muxed_id,authorized,live_until_ledgerandasset_topic.contract-event:contract,stage,topics_xdranddata_xdr. An event maps to atoken-eventwhen its topics and data have the shape the oracle reads as one (token_eventincrates/shapekit-oracle/src/interpret.rs, ported to Go inadapters/stellarrpc/events.go), and to acontract-eventotherwise.go test ./stellarrpcchecks the port: it maps the events of core's own meta in every corpus chain and compares them with the committed oracle files. The asset of a token event is not claimed, because the oracle proves it from the assets of the ledger's entries, and none of the three methods serves those. Participants and entry changes are not claimed: stellar-rpc derives no participants, and serves entry changes only inside the meta XDR. -
Read-back.
exportreads the transactions of the range fromgetTransactions(the ledger andtxHash, which is the outer hash of a fee bump) and their events from the chosen method.- From
getEvents(no filters,endLedgerone past the range), it takestype,contractId,topicandvalueas served, and the stage from where the event's id puts it, asStageSentinels(cmd/stellar-rpc/internal/store/event.go) writes it: transaction index 0 with operation index 0 is a fee event before all transactions, transaction index 1048575 is after all transactions, operation index 4095 is after the transaction, and any other id belongs to its operation. An event whosetxHashnames no served transaction is anunattributedrow. - From
getTransactions, it takesevents.transactionEventsXdr(eachTransactionEventwith its stage) andevents.contractEventsXdr(one list per operation). - From
getLedgers, it decodesmetadataXdrand reads each transaction's events from its meta as the oracle does.
Diagnostic events are
unmappedrows: the vocabulary records consensus events only. - From
-
Dump. Six tables.
ledgers,transactionsandeventshold the items thatgetLedgers,getTransactionsandgetEventsserve in their default base64 form, one row per item, with nested members as compact JSON.ledgers_json,transactions_jsonandevents_jsonhold the same answers withxdrFormat: json, one row per JSON leaf (key,path,value), so the carry check reads every address that stellar-rpc's XDR to JSON conversion wrote. Every table covers the ledgers fromoldestLedgertolatestLedger.
What the adapter cannot check, with the reason in stellar-rpc's source:
getLedgerEntries. stellar-rpc answers it from captive core's query server, at the newest ledger in its database (coreLedgerEntryGetterincmd/stellar-rpc/internal/ledgerentries/ledgerentries.go). Captive core holds a ledger's state only after it has applied the ledger, and it applies ledgers only through SCP. With a datastore and no network, every call fails. At the bootstrap ledger captive core runs but holds the archive's state, not the database's newest ledger (could not query captive core: http request failed with non-200 status code (404)). A few ledgers after the bootstrap ledger, the database is more than two checkpoints past the archive's newest one (a checkpoint is one ledger atCHECKPOINT_FREQUENCY = 1), so captive core does not start (trying to start online mode too far ... only two checkpoints in the future allowed), and the call cannot reach it (could not query captive core: ... connection refused). There is no stored state to compare, soharness stateand the route check do not apply.getHealth. It reports an error when the newest ledger closed more thanMAX_HEALTHY_LEDGER_LATENCY(30 s) ago. The chains carry the close times they were recorded with, so a replayed chain is never healthy. The adapter does not call it.- Retention.
HISTORY_RETENTION_WINDOWkeeps its default of 120,960 ledgers, longer than every chain, so no ledger of a chain leaves the window. Each method scans at most 10,000 ledgers per call (LedgerScanLimit), and the adapter refuses a longer range with anunsupportederror rather than read a short page as the end of the data.
Oracle vocabulary
What the oracle says each transaction changed, read only from LedgerCloseMeta, in
<variant>.oracle.json next to each eligible corpus entry. Conventions for every kind:
- Addresses are canonical strkeys:
Gaccounts,Ccontracts,Lliquidity pools,Bclaimable balances. A mux id never replaces the base address. - A participant's
mux_idscome only from addresses that are muxed in the meta itself (SC_ADDRESS_TYPE_MUXED_ACCOUNTor muxed contract addresses in event topics). A token event'sto_muxed_idis kept on the event as typed and never becomes a participant mux id: core writes the transaction memo there too, so a u64 there can be a memo id. - Signers keep their own strkey form:
G,T(pre-auth),X(hash-x),P(signed payload, with its payload). - Amounts, balances, limits, ids and sequence numbers are decimal strings; flags, weights, thresholds and ledger numbers are JSON integers.
- Assets are
nativeorCODE:ISSUER; a trustline asset can also bepool-share:<L strkey>, the pool id in its CAP-38Lstrkey form. Pools are named by the sameLstrkey everywhere. actioniscreated,updated,removedorrestored.
The oracle file of an entry is {"oracle_vocab_version", "network_passphrase", "ledgers": [{"ledger_seq", "ledger_hash", "protocol", "close_time", "transactions", "upgrades", "evicted"}]}; each transaction has hash, apply_index, successful, result,
inner_hash, fee {source, charged, balance_delta}, participants (actual, from meta and
events), changes, declared (what the envelope names, kept apart and never used as the
expected participants) and events (which events the meta format can carry, see "Facts the
meta cannot show").
Oracle vocabulary version 2 (ORACLE_VOCAB_VERSION in crates/shapekit-oracle/src/vocab.rs).
Every change also has scope (fee-processing, tx-before, operation, tx-after, post-apply-fee, upgrade) and, for operation scope, op_index (integer, from 0).
account-created
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
starting_balance | decimal string | yes |
account-removed
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
final_balance | decimal string | yes |
balance-change
A change in what an address holds of an asset: account native balance, trustline balance, claimable balance amount, pool reserve, or a Stellar Asset Contract balance entry. holder is the address whose holding changed.
| field | type | always present | meaning |
|---|---|---|---|
after | decimal string | yes | |
asset | string | yes | |
before | decimal string | yes | |
delta | decimal string | yes | |
held_in | string | yes | account, trustline, claimable-balance, liquidity-pool or contract. |
holder | string | yes |
trustline-created
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
asset | string | yes | native, CODE:ISSUER, or pool-share: followed by the pool id as an L strkey (CAP-38 form, not hex) for a pool-share trustline. |
flags | integer (uint32) | yes | |
limit | decimal string | yes |
trustline-removed
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
asset | string | yes | native, CODE:ISSUER, or pool-share: followed by the pool id as an L strkey (CAP-38 form, not hex) for a pool-share trustline. |
trustline-flags
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | integer (uint32) | yes | |
asset | string | yes | native, CODE:ISSUER, or pool-share: followed by the pool id as an L strkey (CAP-38 form, not hex) for a pool-share trustline. |
before | integer (uint32) | yes |
trustline-limit
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | decimal string | yes | |
asset | string | yes | native, CODE:ISSUER, or pool-share: followed by the pool id as an L strkey (CAP-38 form, not hex) for a pool-share trustline. |
before | decimal string | yes |
signer-added
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
signer | string | yes | |
weight | integer (uint32) | yes |
signer-removed
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
signer | string | yes | |
weight | integer (uint32) | yes |
signer-weight
Includes the master key, whose weight is threshold 0 of the account.
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | integer (uint32) | yes | |
before | integer (uint32) | yes | |
signer | string | yes |
thresholds
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | Thresholds | yes | |
before | Thresholds | yes |
account-flags
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | integer (uint32) | yes | |
before | integer (uint32) | yes |
home-domain
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | string | yes | |
before | string | yes |
inflation-destination
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | string | no | |
before | string | no |
sequence
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | decimal string | yes | |
before | decimal string | yes |
data-entry
Data entry name and values as hex, since neither has to be UTF-8.
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
action | "created" / "updated" / "removed" / "restored" | yes | |
name_hex | string | yes | |
value_after_hex | string | no | |
value_before_hex | string | no |
sponsorship
The sponsor of a ledger entry or of one signer changed (created, revoked, transferred, or the sponsored thing went away). target names the entry or signer.
| field | type | always present | meaning |
|---|---|---|---|
signer | string | no | |
sponsor_after | string | no | |
sponsor_before | string | no | |
target | string | yes |
claimable-balance-created
| field | type | always present | meaning |
|---|---|---|---|
amount | decimal string | yes | |
asset | string | yes | |
balance_id | string | yes | |
claimants | array of string | yes |
claimable-balance-claimed
Removed by a claim. The operation type tells a claim from a clawback, since the entry change itself is the same.
| field | type | always present | meaning |
|---|---|---|---|
amount | decimal string | yes | |
asset | string | yes | |
balance_id | string | yes |
claimable-balance-clawed-back
| field | type | always present | meaning |
|---|---|---|---|
amount | decimal string | yes | |
asset | string | yes | |
balance_id | string | yes |
pool-shares
A pool-share trustline balance.
| field | type | always present | meaning |
|---|---|---|---|
account | string | yes | |
after | decimal string | yes | |
before | decimal string | yes | |
delta | decimal string | yes | |
pool | string | yes | The pool id as an L strkey. |
liquidity-pool
| field | type | always present | meaning |
|---|---|---|---|
action | "created" / "updated" / "removed" / "restored" | yes | |
asset_a | string | yes | |
asset_b | string | yes | |
pool | string | yes | The pool id as an L strkey. |
reserve_a_after | decimal string | yes | |
reserve_a_before | decimal string | yes | |
reserve_b_after | decimal string | yes | |
reserve_b_before | decimal string | yes | |
shares_after | decimal string | yes | |
shares_before | decimal string | yes |
offer
| field | type | always present | meaning |
|---|---|---|---|
action | "created" / "updated" / "removed" / "restored" | yes | |
amount_after | decimal string | no | |
amount_before | decimal string | no | |
buying | string | yes | |
offer_id | decimal string | yes | |
price_d | integer (int32) | yes | |
price_n | integer (int32) | yes | |
seller | string | yes | |
selling | string | yes |
contract-deployed
A contract instance entry appeared. Read from meta, never from auth entries.
| field | type | always present | meaning |
|---|---|---|---|
contract | string | yes | |
executable | string | yes | wasm:<hex hash>, stellar-asset, or external-ref:<owner>:<hex tag> (CAP-85). |
contract-code
| field | type | always present | meaning |
|---|---|---|---|
action | "created" / "updated" / "removed" / "restored" | yes | |
hash | string | yes |
contract-data
| field | type | always present | meaning |
|---|---|---|---|
action | "created" / "updated" / "removed" / "restored" | yes | |
contract | string | yes | |
durability | string | yes | |
key_xdr | string | yes | The key ScVal as base64 XDR. |
ttl
| field | type | always present | meaning |
|---|---|---|---|
action | "created" / "updated" / "removed" / "restored" | yes | |
after | integer | no | |
before | integer | no | |
key_hash | string | yes | |
target | string | no | The entry the TTL belongs to, when its key is visible in this ledger. |
config-setting
| field | type | always present | meaning |
|---|---|---|---|
action | "created" / "updated" / "removed" / "restored" | yes | |
setting | string | yes |
trade
One offer or pool crossed by a manage-offer or path-payment operation, from the operation result's claim atoms. counterparty is the offer's seller or the pool.
| field | type | always present | meaning |
|---|---|---|---|
bought_amount | decimal string | yes | |
bought_asset | string | yes | What the counterparty received. |
counterparty | string | yes | |
offer_id | decimal string | no | |
sold_amount | decimal string | yes | |
sold_asset | string | yes | What the counterparty gave up. |
contract-event
A consensus contract event that is not a token event (for example a protocol's own events, such as Blend's supply or borrow), with topics and data as base64 XDR.
| field | type | always present | meaning |
|---|---|---|---|
contract | string | no | |
data_xdr | string | yes | |
stage | string | yes | before-all-txs, operation, after-tx or after-all-txs. |
topics_xdr | array of string | yes |
token-event
A token event (CAP-67 and SEP-41 shapes): transfer, mint, burn, clawback, set_authorized, fee, approve.
| field | type | always present | meaning |
|---|---|---|---|
amount | decimal string | no | |
asset | string | no | Set when the contract is the Stellar Asset Contract of this asset, which the oracle proves by recomputing the contract id. |
asset_topic | string | no | The SEP-11 asset string a SAC event carries as its last topic, verbatim. |
authorized | boolean | no | |
contract | string | yes | |
event | string | yes | |
from | string | no | |
live_until_ledger | integer | no | |
spender | string | no | |
stage | string | yes | before-all-txs, operation, after-tx or after-all-txs. |
to | string | no | |
to_muxed_id | ToMuxedId | no | The data map's to_muxed_id as the event typed it: {"type": "u64", "value": "<decimal>"}, {"type": "string", "value": "<hex>"} or {"type": "bytes", "value": "<hex>"}. Core writes the destination's mux id here when the destination is muxed and otherwise the transaction memo (id as u64, text as string, hash and return as bytes), so a u64 may be either a mux id or a memo id. It is not a participant mux id. |
Generated from docs/adapter-interface.md
Edit on GitHub