library / Blockchain ideas / BI0027
Hot account write-lock report
A script that reads recent blocks and ranks accounts by how many transactions wrote them and how many compute units those transactions used, so you can see which accounts carry the most write load in each block. It comes with a runnable main.ts.
Who uses it
Three readers ask how often an account can be written to in one block. A protocol team sees transactions fail or never land during a launch and wants to know whether one shared account is the choke point. A client developer sees a priority fee stop helping and wants the reason. A hackathon team wants a data product that few dashboards carry: a live ranking of the hottest accounts on the chain.
There is no fixed count. Solana runs transactions in parallel when they touch different accounts and one after another when they write the same account. On top of that, the cluster caps the compute units that all writers of one account may add up to in a single block. The cap belongs to the cost model of the validator release and has changed over time, so read the current value from the Agave version you run. What you can measure today is how close each account came to a full block.
What it shows
The report reads a few of the newest blocks and prints one ranking per block. Each row is one writable account.
| Column | Where it comes from | What it tells you |
|---|---|---|
| Writers | count of transactions that list the account as writable | how many transactions queued on one account in this block |
| Compute units | sum of computeUnitsConsumed over those writers | how much of the account's per-block budget the block spent |
| Share of block | that sum divided by all compute units the block used | how much of the whole block ran through this one lane |
| Failed | writers whose err is set | how much of the contention produced nothing |
Shares add up to more than 100% across rows, because one transaction usually writes several accounts and is counted under each. Mainnet blocks carry no vote transactions since Alpenglow, so every writer in the count is a user or program transaction.
How a write lock behaves
- A transaction names every account it touches and flags each one writable or read-only. Any number of read-only users run side by side. A writer runs alone on that account.
- The lock sits on the account listed as writable, whether or not the program changes its data. A program that lists an account as writable out of habit blocks everyone else for nothing.
- A slot lasts about 200 ms. Writers of one account run one after another inside the slot, and once their compute units reach the account's cap, no more writers of it fit in that block.
- When the leader cannot fit another writer of a full account into the block, that transaction waits for a later block. It leaves no failed record on chain, so the report shows how full the accounts were and says nothing about who was turned away.
The build
The report is one file that needs @solana/kit and what Node 24 ships. It is read-only: no private key, nothing sent.
- Create one RPC client for https://services.carbium.sh with the key in the x-api-key header.
- Read the current slot at confirmed commitment, then step back two slots so the first block exists on the node you ask.
- For each of the last N slots (3 by default, at most 6), call getBlock with jsonParsed encoding, full transactions and rewards off. A skipped slot answers with an error or null, and the loop prints it and moves on.
- In the parsed form every account key carries writable and signer flags, and keys loaded from address lookup tables are already resolved. Count each writable, non-signer key per transaction.
- Print the top 8 accounts by compute units for each block, with writers, share of the block and failures.
// BI0027 · Hot account write-lock report// https://carbium.sh/library/blockchainideas/hot-account-write-lock-report// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { createDefaultRpcTransport, createSolanaRpcFromTransport, type Slot } from "@solana/kit";const apiKey = process.env.CARBIUM_KEY ?? "";if (apiKey === "") { 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 client = createSolanaRpcFromTransport( createDefaultRpcTransport({ url, headers: { "x-api-key": apiKey } }),);type Key = { pubkey: string; signer: boolean; writable: boolean };type Entry = { meta: { err: unknown; computeUnitsConsumed?: number | bigint } | null; transaction: { message: { accountKeys: Key[] } };};type Lane = { pubkey: string; writers: number; units: number; failed: number };const count = Math.min(Math.max(parseInt(process.argv[2] ?? "", 10) || 3, 1), 6);function lanesOf(txs: Entry[]): { lanes: Lane[]; total: number } { const byKey: Record<string, Lane> = {}; let total = 0; for (const { meta, transaction } of txs) { const units = Number(meta?.computeUnitsConsumed ?? 0); total += units; const written = transaction.message.accountKeys.filter((k) => k.writable && !k.signer); for (const { pubkey } of written) { const lane = (byKey[pubkey] ??= { pubkey, writers: 0, units: 0, failed: 0 }); lane.writers++; lane.units += units; if (meta?.err) lane.failed++; } } return { lanes: Object.values(byKey).sort((a, b) => b.units - a.units), total };}async function fetchBlock(slot: Slot): Promise<Entry[] | null> { const block = await client .getBlock(slot, { commitment: "confirmed", encoding: "jsonParsed", transactionDetails: "full", rewards: false, maxSupportedTransactionVersion: 1, }) .send(); return block ? (block.transactions as unknown as Entry[]) : null;}const head = await client.getSlot({ commitment: "confirmed" }).send();for (let back = 2; back < count + 2; back++) { const slot = (head - BigInt(back)) as Slot; try { const txs = await fetchBlock(slot); if (txs === null) { console.log(`slot ${slot}: no block (skipped or not available yet)`); continue; } const { lanes, total } = lanesOf(txs); console.log(`slot ${slot}: ${txs.length} transactions, ${total} compute units`); for (const l of lanes.slice(0, 8)) { const pct = total > 0 ? (l.units / total) * 100 : 0; console.log( ` ${l.pubkey.padEnd(44)} writers=${l.writers} units=${l.units} share=${pct.toFixed(1)}% failed=${l.failed}`, ); } } catch (e) { console.error(`slot ${slot} failed:`, e instanceof Error ? e.message : e); }}
run: CARBIUM_KEY=<YOUR_KEY> node main.ts 3
Both calls ask for confirmed. Signers are skipped on purpose: a fee payer is writable but belongs to one transaction, so it would only add noise. The request sets maxSupportedTransactionVersion: 1 because mainnet carries v1 transactions, and a block holding one answers -32015 without it.
What it costs
A full block with parsed transactions is a large reply, often over a megabyte, so the report reads blocks one after another and defaults to three. The single getSlot read at the start is one cheap cached call at 1 cell.
Limits are per account, so other tools on your keys draw on the same budget while the report runs. A report run every few seconds across six blocks adds up quickly, so start with one run per minute and run it more often or read more blocks once the replies come back clean.
What to add next
- A rolling store: write each ranking to SQLite with node:sqlite and chart the peak share per account over an hour.
- A fee comparison: call getRecentPrioritizationFees with the hot account's address to get the smallest priority fee paid in each recent slot among transactions that write-lock it, and set that minimum beside the account's compute share. Priority fee per compute unit covers reading that number.
- An owner label: call getAccountInfo for each top account (10 cells a call) and print its owner, so a program's own state account and a token account are told apart.
- An alert: post to a channel when one account's share of a block passes a threshold in three blocks running.
Where it ends
- Only transactions that landed appear in a block. A transaction held back by a full account is invisible here.
- The report sums computeUnitsConsumed, the units a run used. The cluster's cost model also charges signatures, write locks and data size, so treat the sum as close to the budget and short of an exact reading.
- The cap itself is not read from the chain. This tool shows usage per account and leaves the limit to your validator version.
- Three blocks are a sample of about 600 ms. Contention comes in bursts, so one quiet sample says little and a long run says more.
- Signers are left out, so an authority account that signs and writes in many transactions does not appear.
- A slot its leader never produced has no block, and a missing slot in the output is normal.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| getBlock answers null or an error for a slot. | The slot was skipped or the node has no block for it yet. The code prints the slot and continues. If every slot fails, raise the start value let back = 2 in the loop of main.ts to 3 or 4 and raise the + 2 in the loop bound by the same amount. |
| getBlock answers -32015. | The request lacks maxSupportedTransactionVersion: 1, and the block holds a v1 transaction. Keep the option on every getBlock and getTransaction call. |
| A call answers 429. | Wait the retry-after seconds, then lower the block count or run the report less often. |
| The rankings show the same shared accounts in every block. | Some accounts are written by most transactions of a busy program, and that is the finding. To look past them, label the top rows with getAccountInfo and skip the owners you already know. |
| Every share is tiny and every writer count is 1. | The sample was quiet. Run again during a busy period, or raise the block count toward 6 once your plan's rate allows. |
| The call answers 401 UNKNOWN_KEY. | Attach the whole key in CARBIUM_KEY, with no truncation or quotes copied in. |
Questions
Is there a fixed number of writes to one account per block?
No. Writers of one account run in sequence, and the sum of their compute units is capped per block. The number of writes that fit depends on how many units each uses, so a light write fits many times and a heavy one a few.
Does reading an account take the same lock?
No. Read-only use of an account runs beside other readers and beside no writer of it. Only the writable flag takes the exclusive lock, and it takes it even if the program leaves the data unchanged.
Will a higher priority fee fit more writes into a full account?
A fee changes the order in which the scheduler picks transactions. It cannot raise the account's cap, so a full account stays full and the fee decides who gets the space.
Why do the shares add up to more than 100%?
A transaction writing three accounts counts once under each of them. The share on a row answers how much of the block ran through that account, one row at a time.
Do accounts loaded from address lookup tables count as writers?
Yes. A key loaded from a lookup table takes a write lock when the transaction marks it writable, the same as a key listed in the message. The parsed block resolves those keys with their flags, so main.ts counts them like any other writable key.