Preview. Stack v4.0 has not been released, and what is documented here can still change before it does. The current release is v3.2, which covers this as Verifying integrity.Go to v3.2
Ledger

Verify Ledger Integrity

Run integrity checks, understand their boundaries, and respond without modifying evidence.

Run an integrity check after a restore, before and after high-risk maintenance, and whenever accounting state differs from an external source of truth. The checker reports inconsistencies; it does not repair them.

Run a primary-store check#

Use JSON output when you need a durable result for an incident or recovery record:

bash
ledgerctl store check --json > ledger-integrity-check.json
jq -e '.valid == true and .errorCount == 0' ledger-integrity-check.json

The command takes a consistent point-in-time view of Ledger's primary data store, verifies the available audit chain, and compares selected stored values with state reconstructed from that chain. With structured output, ledgerctl can exit successfully even when the result contains integrity errors; the jq assertion is therefore the gate for automation.

Capture the following alongside the output:

  • the Ledger release and node you checked;
  • the cluster and environment identifiers;
  • the check start and completion times;
  • the latest expected log and audit sequences;
  • the backup or maintenance event that prompted the check.

Run the check against a stable, healthy cluster. For an incident investigation, preserve the affected data and logs before restarting nodes or changing storage.

Understand what the checker verifies#

The following table shows representative coverage in the current preview. It is a guide to the current checks, not a claim that every file and service in a deployment is covered.

Sample stateWhat the checker compares
Audit boundariesAudit hashes and sequence continuity.
Transactions and balancesTransaction state, posting-derived input and output volumes, reversion state and bitsets, and transaction references.
Account metadataTyped account metadata values and deletions reconstructed from the log. Metadata on accounts deliberately excluded by transient or purged-ephemeral processing is not compared.
Ledger definitionThe live ledger set, metadata schema, account types, and operational boundaries such as the next transaction and log IDs.
Retry and indexing projectionsFrozen idempotency outcomes, allowed skipped-order results, the index registry's presence and identity, and transient or purged-volume exclusion records.

Mirror acceptance has a separate set of migration proofs. Follow Monitor Mirror Progress instead of treating this primary-store check as a migration approval.

Know the limits#

The primary-store checker has these explicit implementation boundaries:

  • it opens the peer read-side index store for exactly one pass, the reverse-map orphan scan, and skips that pass with an informational log when no peer store is attached to the checker. That is the case for restore validate and store bootstrap --validate, which validate a staged store with no peer index beside it. The pass also narrows to key decoding when the peer index has not yet folded the whole verified log range, so a check run against a lagging replica proves less on this axis than one run against a caught-up replica;
  • it does not re-derive read-side index contents. No index type has content verification today, and per-replica build state is outside its scope: the live and pending forward-encoding versions and the backfill cursor that ledgerctl indexes list reports come from each replica's own index store, not from the verified registry. Registry entries are compared for presence and identity — the index ID and the ledger it belongs to — only;
  • it does not compare ledger-level metadata or the default account-type enforcement mode (LedgerInfo.DefaultEnforcementMode); restore rebuilds those values from retained verified state;
  • it does not compare stored prepared-query definitions. These definitions are authoritative business-shaping state because they determine which records named queries return. Export them and compare them with reviewed configuration as code separately;
  • it does not open the local usage store at <data-dir>/usage/usagedb. None of the derived ledger statistics or Numscript template-usage records are checked there;
  • it does not verify bloom filters, snapshot files, or the transient spool.

These exclusions are not a statement that the data cannot matter. For example, a corrupted read-side index can affect query results even when the primary-store check passes; verify index readiness and rebuild health separately.

The checker also does not prove that:

  • an application sent the intended business transaction;
  • an external database, payment provider, or event consumer matches Ledger;
  • permissions, certificates, and signing keys follow your security policy;
  • every query index is ready or returns the result you expect;
  • a backup can meet your recovery-time objective.

Combine the integrity result with business reconciliation, index readiness, event-sink status, and a restore exercise.

The restore validate command applies the same class of primary-store checks to staged restore data before finalization. It validates the staged Ledger state, not the rest of your recovered application or the usage projection that will be reconstructed after startup.

If usage figures look wrong while this check passes, inspect formance.ledger.usage.builder.last_indexed_sequence, formance.ledger.usage.builder.audit_last_sequence, and formance.ledger.usage.builder.lag on the affected member. Audit history is permanent in the primary store, so a member holding the full range and reporting zero lag has processed all of it — a wrong figure there points at the projection or at the recovered store, not at missing history. The current preview has no public full-rebuild command, so reconcile critical figures against your application records without deleting the local store during the investigation.

Respond to a finding#

Do not delete, compact, rebuild, or overwrite the affected data as an initial response. Those actions can remove evidence and make the recovery boundary harder to establish.

When a check reports an error:

  1. Stop routing new writes to the affected cluster.
  2. Record the complete checker output, Ledger version, node, and sequence boundaries.
  3. Preserve node logs, storage snapshots, and backup manifests.
  4. Run the same read-only check on another healthy replica when available.
  5. Determine whether the problem affects one replica, the shared committed history, or an external comparison.
  6. Choose recovery from a previously verified backup only after identifying the last trusted boundary.
  7. Reconcile the recovered state with application-level records before reopening traffic.

Ledger does not auto-fix integrity errors. Treat a confirmed mismatch as a correctness incident.

Use Sentinel mode in test environments#

Sentinel mode adds runtime assertions around volume updates and stored state during every applied write. It checks:

  • that cumulative volumes do not decrease;
  • that posting deltas match volume updates;
  • that aggregated input and output volumes remain balanced;
  • that values committed to disk match the values Ledger expected to write.

Enable it on a test or staging cluster when you are investigating correctness or running fault-injection tests. Add the boolean --sentinel-mode server flag to that cluster's complete ledger run invocation. Keep its required identity, storage, network, bootstrap or join, TLS, and authentication flags unchanged.

Sentinel mode adds work to the write path, including expensive scans for some checks. It is not a replacement for scheduled primary-store checks, backup validation, or business reconciliation.

Keep Sentinel mode disabled for normal production traffic unless Formance support asks you to enable it for a bounded investigation. Measure its effect with production-like data before using it on a live workload.

Keep verification evidence#

For every scheduled check or recovery exercise, retain:

  • the command output and exit status;
  • the verified log and audit boundaries;
  • representative business reconciliation results;
  • the backup identifiers used for recovery testing;
  • the decision and approver for reopening writes.

This record establishes what you verified, with which artifacts, and at which point in the cluster history.