services
Get a key

library / How to use Solana / History and parsing / HS0162

Log truncation detector

One TypeScript file reads the newest signatures of a program, fetches each transaction and reports which ones carry the runtime's log truncation marker. It only reads, with no keypair, signature or state change.

By Carbium · History and parsing · HS0162 · updated 2026-11-23

01

What the check reads

A Solana transaction keeps its program logs in its metadata as meta.logMessages, one string per line. The runtime caps how many bytes of log one transaction can write, at about 10 KB. Once the cap is reached, the runtime stops writing and adds a line reading Log truncated. The messages after the cut are missing from that transaction's log array, but the transaction itself ran as normal, and its balances and instructions are intact.

The check takes the newest signatures of one program with getSignaturesForAddress, then reads each transaction with getTransaction and looks for that marker. It does not parse the log text. A program writes its log lines for people, so the check matches one fixed line and leaves the rest to the reader. A signature the first call lists can still come back as null from the second, and the code handles that case on its own line of output.

02

The code

Install @solana/kit at 8.6.0, export CARBIUM_KEY and run the file with Node 24. The first argument is the program address and defaults to Jupiter's aggregator program. The second is how many signatures to check, from 1 to 20. Each getTransaction call passes commitment: "confirmed" and maxSupportedTransactionVersion: 1, because mainnet carries v1 transactions and a call without that value answers -32015 for them.

main.ts
// HS0162 · Log truncation detector// https://carbium.sh/library/howsolana/log-truncation-detector// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { setTimeout as sleep } from "node:timers/promises";import {  address,  createDefaultRpcTransport,  createSolanaRpcFromTransport,  isSolanaError,  signature,  SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR,} from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) {  console.error("Set CARBIUM_KEY to your Carbium API key.");  process.exit(1);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(  createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),);const [programArg = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4", countArg = "5"] =  process.argv.slice(2);const program = address(programArg);const count = Math.min(Math.max(Number(countArg) || 5, 1), 20);// One retry after the retry-after wait when Carbium answers 429.async function withRetry<T>(call: () => Promise<T>): Promise<T> {  try {    return await call();  } catch (e) {    if (!isSolanaError(e, SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR) || e.context.statusCode !== 429) throw e;    const seconds = Number(e.context.headers.get("retry-after")) || 1;    await sleep(seconds * 1000);    return call();  }}const sigs = await withRetry(() =>  rpc.getSignaturesForAddress(program, { limit: count, commitment: "confirmed" }).send(),);console.log(`checking ${sigs.length} newest signatures of ${program}`);let truncated = 0;let unknown = 0;let failed = 0;// One call at a time: a Free key gets a low getTransaction rate.for (const { signature: sig } of sigs) {  try {    const tx = await withRetry(() =>      rpc        .getTransaction(signature(sig), {          commitment: "confirmed",          encoding: "json",          maxSupportedTransactionVersion: 1,        })        .send(),    );    const logs: readonly string[] | null | undefined = tx?.meta?.logMessages;    if (!logs) {      unknown++;      console.log(`unknown   ${sig} no transaction or log array`);      continue;    }    const marker = logs.find((line) => line.includes("Log truncated"));    if (marker) truncated++;    console.log(`${marker ? "TRUNCATED" : "complete "} ${sig} lines=${logs.length}`);  } catch (e) {    failed++;    console.log(`failed    ${sig}: ${(e as Error).message}`);  }}console.log(`truncated=${truncated} unknown=${unknown} failed=${failed}`);

run: node main.ts <program-address> [count]

The reads go to https://services.carbium.sh with the key in the x-api-key header. The calls run one after another, so a Free key never has more than one getTransaction in flight. A 429 waits for the retry-after seconds and tries that call once more. A missing transaction or log array is counted as unknown, and any other error is counted as failed. The loop then moves on to the next signature.

03

Reading the answer

OutputMeaning
TRUNCATEDThe log array holds a line with Log truncated. Some program messages after the cut are missing.
completeNo marker found. The array is the full log the runtime wrote for that transaction.
unknownCarbium returned no transaction, or the transaction has no log array. Record it as unknown.
failedThe call failed after its retry. The message after the colon names the cause.
$A complete log describes one transaction's log array only. Balances and instructions in the same response are the record of what the transaction did.

The last line totals the run. A small line count can still hide a cut, so read the marker and not the number of lines.

04

Logs as an index

Logs work well as a pointer and poorly as the only record. A log line can say that an instruction ran, name a program's event or carry an order id that a later read can check. Logs grouped by instruction shows how to keep that structure. Three properties make them weak as the record.

  • The runtime cuts them at a byte limit, so the last messages of a busy transaction can be gone, and the only sign is the marker.
  • The text belongs to each program. A release can rename a line, and nothing in the runtime checks the wording.
  • A log line says nothing about amounts that moved. The pre and post balances in the same response record those, and token amounts sit there too.

The sound pattern is to use logs for candidates and to name events, then take values from balances and inner instructions. When the marker shows up, the indexer should mark the row as needing a second read, and should not write a total from the log alone. This check gives the marker its own count on every run, so the gap is visible.

05

On Carbium

getTransaction costs 50 cells per call. RPC methods lists it as a ledger lookup, at 0.24 requests a second on Free and 1.2 on Dev. getSignaturesForAddress also costs 50 cells. A run of 20 signatures therefore spends 1,050 cells in total, and on a plan with a low rate the 429 handling does most of the waiting.

The signature list comes from the address index, which keeps up to 30 days. The check reads only the newest page, so that limit does not change what it prints. For rate limits, a call over its rate waits once and is served if its cells refill within one second. Past that, it gets a 429 with a retry-after hint.

06

Where it ends

The check shows that a log array was cut. It cannot rebuild the lines that were lost, and it cannot say which lines they were. For a lost line, the instructions and balance changes are the only source left, so an indexer has to read those before it writes a row.

The marker is a fixed string written by the runtime. A program that prints its own text with the same words would also match. The check accepts that small risk, since a false flag costs one extra read.

The window is the newest signatures only. A run of five signatures says nothing about last week, and the address index reaches 30 days back, so a backfill needs another source for older history.

This check reads history and does not watch live traffic. A live feed through logsSubscribe carries the same log lines as they happen, so a live consumer needs the same marker test on each notification.

07

When it goes wrong

what goes wrongwhat to do
getTransaction returns null for a signature the list just showed.The code prints it as unknown and moves on. Carbium's address index keeps 30 days, and a transaction below the validator's ledger floor can answer null. Record the signature as unknown and read it from another source.
HTTP 429 with a retry-after hint.The code waits for the seconds in the header and tries that call once more. If the second try also fails, lower the count or move to a plan with a higher getTransaction rate.
Error -32015 on a transaction you know is version 1.Pass maxSupportedTransactionVersion: 1, as the code does. With the field absent or 0, the answer is -32015 for a v1 transaction or a block that holds one.
The output shows unknown for every transaction.The transaction has no log array in the response. Check that the call asks for encoding: "json" and a commitment, then read one signature by hand to see whether meta is present.
Every run prints complete.A clean run covers only the newest transactions of that one program. Run the check on the program whose logs you index, with a larger count, before you trust the output for that program.
08

Questions

Is it good practice to rely on program logs for indexing?

Use logs to find candidates and to name events, then take amounts and status from balances and instructions in the same transaction. Keep a marker row for any transaction whose log array was cut, so a later read can fill it in.

Does a truncated transaction still happen on chain?

Yes. The cut limits what the runtime wrote to the log array, and the transaction's effects are not changed. A row built from balances and instructions stays correct.

How many transactions can one run check?

The code caps the count at 20, which costs 1,050 cells with the signature list. The plan's getTransaction rate sets how fast the run finishes, and the retry handles a 429.

Why not subscribe to logs and skip history?

A live subscription sends the same logs as they happen, so it can use the same marker test. History from getTransaction fills the gap after a restart, and this check reads it.