library / Integrations / Relational databases / I0077
Postgres missing-signature audit
A Node script takes the newest transaction of a busy program, reads its static and lookup table addresses, asks getSignaturesForAddress about one of each, and prints Postgres rows that say found or missing with a reason class.
Two lists of addresses in one transaction
You have a signature, you can see an address in its account list, and getSignaturesForAddress for that address does not return the signature. Before you suspect the index, find out which list the address came from. A v0 transaction names its accounts in two places, and the two lists matter for reading the transaction. Solana's RPC lists a signature under a static address and a loaded address alike, and the audit checks one of each.
| Where | What it holds |
|---|---|
| message.accountKeys | The static keys the message carries itself: writable signers, readonly signers, writable non-signers, then readonly non-signers |
| meta.loadedAddresses.writable | Addresses the runtime pulled from address lookup tables and loaded as writable |
| meta.loadedAddresses.readonly | Addresses pulled from lookup tables and loaded as readonly |
The runtime orders the full account list as static keys, then loaded writable, then loaded readonly. With the default json encoding, accountKeys shows the static part only, and the loaded part lives in the transaction's metadata. An engineer who reads only accountKeys never sees the lookup table addresses, and one who reads a merged list sees both and cannot tell them apart without the source field.
The audit table
One row per signature and address. The row says where the address came from, whether the signature turned up in the page the index returned, and which cause fits when it did not.
- Create it with create table tx_address_audit (signature text not null, address text not null, source text not null, found boolean not null, reason text not null, checked_slot bigint, primary key (signature, address)).
- source is static, loaded_writable or loaded_readonly.
- reason is listed, page_boundary, index_behind, past_index_age or not_listed.
- checked_slot is the slot of the newest entry in the page the index returned, which tells you how far the index had reached when you looked.
The script writes with an upsert on (signature, address), so a second run over the same signature rewrites the row. A row that said index_behind an hour ago and says listed now is a finished answer: the index was late and caught up.
The script
Install with npm install @solana/[email protected], set "type": "module" in package.json, and use Node 24, which strips the types on load. The optional argument is the program address to sample, and a bare run uses the Jupiter v6 program, which has transactions in every few slots. CARBIUM_KEY is required and the script exits with a message when it is unset. Every call reads at confirmed commitment, named in the code.
It makes four calls. The first lists the program's newest five signatures and takes the first one that succeeded. The second reads that transaction with maxSupportedTransactionVersion: 1, so a v1 transaction does not answer -32015. The last two ask the address index about the fee payer, which is always a static key, and about the first loaded writable address, falling back to the first loaded readonly one. A transaction with no lookup tables gets one check and a comment that says so.
// I0077 · Postgres missing-signature audit// https://carbium.sh/library/integrate/postgres-missing-signature-audit// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { createDefaultRpcTransport, createSolanaRpcFromTransport, type Address } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY."); process.exit(1);}const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);const commitment = "confirmed"; // named on every callconst LIMIT = 100; // a small pageconst program = (process.argv[2] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4") as Address;const msg = (e: unknown) => (e instanceof Error ? e.message : String(e)).replace(/\s+/g, " ");type Entry = { slot: bigint };function reason(page: readonly Entry[], found: boolean, slot: bigint, blockTime: number | null): string { if (found) return "listed"; if (blockTime !== null && Date.now() / 1000 - blockTime > 30 * 86400) return "past_index_age"; if (page.length === LIMIT && page[LIMIT - 1].slot >= slot) return "page_boundary"; if (!page.length || page[0].slot < slot) return "index_behind"; return "not_listed";}async function main() { const head = await rpc.getSignaturesForAddress(program, { commitment, limit: 5 }).send(); // call 1 const sig = head.find((s) => s.err === null)?.signature; if (!sig) throw new Error("no successful signature on the program"); const tx = await rpc.getTransaction(sig, { commitment, encoding: "json", maxSupportedTransactionVersion: 1 }).send(); // call 2 if (!tx) throw new Error(`getTransaction answered null for ${sig}`); const loaded = tx.meta?.loadedAddresses; const checks: { address: Address; source: string }[] = [{ address: tx.transaction.message.accountKeys[0], source: "static" }]; if (loaded?.writable[0]) checks.push({ address: loaded.writable[0], source: "loaded_writable" }); else if (loaded?.readonly[0]) checks.push({ address: loaded.readonly[0], source: "loaded_readonly" }); else console.log("-- this transaction used no lookup table, so only the static key is checked"); console.log(`-- ${sig} slot ${tx.slot}, ${tx.transaction.message.accountKeys.length} static keys`); const blockTime = tx.blockTime === null ? null : Number(tx.blockTime); const pages = await Promise.allSettled( // calls 3 and 4 checks.map((c) => rpc.getSignaturesForAddress(c.address, { commitment, limit: LIMIT }).send()), ); pages.forEach((p, i) => { const { address, source } = checks[i]; if (p.status === "rejected") { console.log(`-- failed getSignaturesForAddress ${address}: ${msg(p.reason)}`); return; } const found = p.value.some((s) => s.signature === sig); const why = reason(p.value, found, tx.slot, blockTime); console.log(`-- ${source} ${address}: ${found ? "found" : "missing"} (${why})`); console.log( `insert into tx_address_audit (signature, address, source, found, reason, checked_slot) values ('${sig}', '${address}', '${source}', ${found}, '${why}', ${p.value[0]?.slot ?? "null"}) on conflict (signature, address) do update set found = excluded.found, reason = excluded.reason, checked_slot = excluded.checked_slot;`, ); });}main().catch((e) => { console.error(msg(e)); process.exit(1);});
run: node main.ts
Run it into psql
Pipe the output into the database: node main.ts | psql -v ON_ERROR_STOP=1. Lines that start with -- are comments, which psql ignores, and each remaining line is one upsert. To audit your own case, pass the program your transaction ran against, or replace the first call with your signature and keep the other three.
Each page is a hundred entries at most. Every call costs 50 cells, and the three signature calls and the one transaction call sit in different rate classes, so each class sees at most 150 cells per run, inside its 1,024-cell burst. Signature pages are rate-limited tightly on small plans, at 0.24 req/s on Free and 1.2 on Dev, so a loop over many signatures belongs on Business or Pro, or waits between runs.
A failed page is settled on its own. The script prints a -- failed getSignaturesForAddress comment with the message, still prints the other address, and exits normally. A 429 on one of the two checks therefore never costs you the other.
The usual causes of a missing signature
The reason column reads the page the index returned and compares it with the transaction's slot.
| Reason | What the page showed | What to do |
|---|---|---|
| listed | The signature is in the page | Nothing: the index has it |
| page_boundary | The page is full and its oldest entry is at or newer than the transaction's slot | The signature sits further back. Call again with before set to the oldest signature of the page, as in Signature history pagination |
| index_behind | The page is empty, or its newest entry is older than the transaction | The index has not caught up. Check again in a few seconds, and compare commitment levels |
| past_index_age | The transaction's block time is more than 30 days back | The address index keeps up to 30 days, so the answer is out of reach |
| not_listed | The page covers the transaction's slot and has no such signature | This is the one to keep: record the address and source, and raise it with the provider's support with the row as evidence |
Page boundary is the most common cause on a busy address. A program with thousands of transactions a minute fills a page of 1,000 in seconds, so a signature from a few minutes ago already needs several pages, and one from an hour ago needs hundreds. The script's page of 100 makes the boundary easy to hit on purpose, which is useful for seeing the reason class once.
Commitment is the second. A call that leaves commitment out reads at finalized on the JSON-RPC server, and @solana/kit 8.6.0 fills in confirmed. If one tool asks at finalized and another at confirmed, they can disagree for a short window. The script names confirmed on every call, and you should name the same level in your own query.
Where it ends
- It audits one transaction per run and two addresses of it. Loop it over your missed signatures to build a table, and mind the 0.24 and 1.2 req/s on Free and Dev for the signature pages.
- The index behind these pages keeps up to 30 days. A signature older than that comes back as past_index_age, and an empty page past 30 days marks the index's age limit while the address may have older transactions.
- It reads one provider's index only. A missing row says that this index did not list the signature in this page at this slot. It says nothing about any other index or about the ledger.
- A listed signature can still make getTransaction answer null, because the index pages reach below the validator's ledger floor. The script handles that null as an error with the signature in the message.
- A not_listed row is a finding you act on by hand. The script never re-queries it.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The script stops with getTransaction answered null. | The newest signature was listed but its transaction is not yet readable at confirmed commitment. For a signature you pass in, it can also be below the node's ledger floor. Run it again, which picks a newer one, or pass a busier program. |
| Every row says page_boundary. | The address is busier than a page of 100 can cover for that transaction. Raise LIMIT or page back with before until the page's oldest slot is below the transaction's slot. |
| The loaded address check never prints, only a comment about lookup tables. | The sampled transaction used no lookup table. Sample another program, or rerun a moment later for a newer transaction. |
| A -- failed getSignaturesForAddress comment names a 429. | The signature class allows 0.24 req/s on Free; wait for the retry-after hint and rerun. |
| getTransaction answers -32015 on a transaction you pass in. | The call left out maxSupportedTransactionVersion, or set it to 0, on a v1 transaction. Keep the value at 1. |
Questions
Why check a static key and a loaded address in the same run?
The two come from different lists in the transaction, and the index should list the signature under either one. Putting both in one table lets you compare them for the same signature, so a gap in one list stands out.
Does a missing row mean the transaction does not exist?
No. Read the signature with getTransaction or getSignatureStatuses to see whether the transaction landed. The audit only answers whether one address's page lists it.
Why store checked_slot instead of a timestamp?
The slot is the unit the pages and the transaction share, so comparing the two tells you whether the index had reached the transaction. A wall-clock stamp cannot show that.
Can I run it from Python?
The same four calls work from any client: getSignaturesForAddress, getTransaction with maxSupportedTransactionVersion 1, and the x-api-key header. The reason logic is a few comparisons on slots and page length.