library / Use cases / Gaming / UC0127
Match start chain health gate
Decide at match start whether the chain and your connection are fit to lock entry fees and record a start slot. You get six checks with pass marks, a read-only Node script that prints open or closed, and the call costs.
Why gate the match start
A game team asking for the most reliable Solana RPC provider wants matches that start and settle without surprises. No provider name guarantees that, and a ranking compiled elsewhere says little about the path between your game servers and the chain on a busy night. What you control is a check at the moment of commitment: before you lock entry fees, draw a seed or record a start slot, ask the chain and your own connection whether they are in shape.
A match start is a poor time to find out. Once players have paid and loaded in, a stalled chain becomes a stuck lobby, a refund queue and support tickets. A gate that takes about a second lets the lobby hold, show a short message and try again.
The gate here is read only. It signs nothing and sends nothing. It prints a verdict with the reason for each check, and your match service decides what closed means for your game.
What the gate checks
| Check | Call | Pass mark |
|---|---|---|
| Health | getHealth | answers ok |
| Progress | getSlot at processed, twice, one second apart | at least 3 slots gained |
| Finalized lag | getSlot at processed and at finalized | 8 slots behind or fewer |
| Slot time | getRecentPerformanceSamples with a limit of 1 | 600 ms per slot or under, averaged over the sample |
| Round trip | time taken by the two progress calls, printed on the progress line | 1500 ms or under for the slower one |
| Blockhash | getLatestBlockhash at confirmed | one comes back |
Slots run about 200 ms apart, so a one second window should gain around 5 slots. The mark of 3 leaves room for jitter and still catches a chain that has slowed to a crawl or stopped.
The finalized check reads two commitment levels. Since the Alpenglow switch on 2026-10-21, finalized sits 0 to 1 slots behind processed. A mark of 8 is therefore generous, and a lag beyond it means finalization has stalled. Two reads can also land with finalized equal to processed or briefly ahead of it, so the script clamps a negative gap to zero instead of reporting it.
The performance sample covers a longer window than the live probes, a period the response states in seconds. It catches a chain that was slow a moment ago and looks fine on one read. The round trip check times your own path to the endpoint, which a chain-side number cannot see.
@solana/kit 8.6.0 fills in confirmed when a call leaves commitment out, while the JSON-RPC server's own default is finalized. The script names the commitment on every call that takes one, so the verdict does not depend on which default applies.
The gate script
The script takes two optional arguments: the largest finalized lag in slots and the slowest round trip in milliseconds. It runs the five check groups in parallel and settles each, so a failed call prints its own FAIL line and the others still report. It exits 0 when the gate is open and 1 when it is closed, which lets a deploy script or a lobby service branch on the exit code.
// UC0127 · Match start chain health gate// https://carbium.sh/library/usecase/match-start-chain-health-gate// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: a go/no-go check of the chain and this connection before a match starts.import { createDefaultRpcTransport, createSolanaRpcFromTransport } 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 maxLag = BigInt(process.argv[2] ?? "8"); // finalized behind processed, in slotsconst maxRttMs = Number(process.argv[3] ?? "1500"); // slowest single call, in msconst minAdvance = 3n; // slots gained in one secondconst maxSlotMs = 600; // average slot time in the newest sampleconst rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const timed = async <T>(call: () => Promise<T>) => { const start = performance.now(); const value = await call(); return { value, ms: performance.now() - start };};// kit would fill in confirmed when commitment is left out, so every call that takes one names its own.const slot = (commitment: "processed" | "finalized") => timed(() => rpc.getSlot({ commitment }).send());const checks: [string, () => Promise<{ ok: boolean; detail: string }>][] = [ ["health", async () => { const h = await rpc.getHealth().send(); return { ok: h === "ok", detail: `getHealth ${h}` }; }], ["progress", async () => { const a = await slot("processed"); await new Promise((r) => setTimeout(r, 1000)); const b = await slot("processed"); const gained = b.value - a.value; const rtt = Math.max(a.ms, b.ms); return { ok: gained >= minAdvance && rtt <= maxRttMs, detail: `${gained} slots in 1 s, slower call ${rtt.toFixed(0)} ms` }; }], ["finalized lag", async () => { const [p, f] = await Promise.all([slot("processed"), slot("finalized")]); const lag = p.value > f.value ? p.value - f.value : 0n; // two reads can show finalized equal or ahead return { ok: lag <= maxLag, detail: `finalized ${lag} slots behind processed (processed ${p.value})` }; }], ["slot time", async () => { const [s] = await rpc.getRecentPerformanceSamples(1).send(); if (!s) return { ok: false, detail: "no performance sample returned" }; const ms = (Number(s.samplePeriodSecs) * 1000) / Number(s.numSlots); return { ok: ms <= maxSlotMs, detail: `${ms.toFixed(0)} ms per slot over the last ${s.samplePeriodSecs} s` }; }], ["blockhash", async () => { const { context, value } = await rpc.getLatestBlockhash({ commitment: "confirmed" }).send(); return { ok: value.blockhash.length > 0, detail: `slot ${context.slot}, valid through block height ${value.lastValidBlockHeight}` }; }],];const results = await Promise.allSettled(checks.map(([, run]) => run()));let open = true;results.forEach((r, i) => { const ok = r.status === "fulfilled" && r.value.ok; open = open && ok; console.log(ok ? "pass" : "FAIL", checks[i][0].padEnd(14), r.status === "fulfilled" ? r.value.detail : String(r.reason).slice(0, 100));});console.log(open ? "GATE OPEN: start the match" : "GATE CLOSED: hold the lobby and retry");process.exit(open ? 0 : 1);
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts 8 1500
Each line starts with pass or FAIL, then the check name and the numbers behind it. The last line is the verdict. A call that throws, such as getHealth on a node that is behind, counts as a failed check with the error text shown.
Reading at processed makes progress visible within a second, and reading at finalized shows how far confirmation trails. For the transaction that records the start, keep the processed slot from the gate and pass it as minContextSlot on later reads, as Consistent reads with minContextSlot shows. That keeps a read from answering from a node that sits behind the slot you already saw.
Running it for many lobbies
One run makes seven calls: getHealth, four getSlot, one getRecentPerformanceSamples and one getLatestBlockhash. getHealth and getSlot are cheap cached reads that cost 1 cell each, and those five calls come to 5 cells. They run at 5, 30, 100 and 500 requests per second on Free, Dev, Business and Pro. Limits belong to the account, so every game server on your keys draws on one budget.
A rate class absorbs bursts up to 1,024 cells or one second of its rate, whichever is larger. At 5 cheap cells a run, Free holds about 200 gates started together, then refills at 5 cheap calls a second, which is one gate. So do not run the gate once per lobby. Run it on a timer in one place, keep the newest verdict in memory with its age, and let every lobby that starts in the same second read that one verdict. A thousand matches starting together then cost the same seven calls as one.
A game server that wants the verdict to stay fresh every second can drop the progress poll and hold one slot subscription on wss://services.carbium.sh with ?api-key= in the URL. Opening a slot subscription costs 5 credits, then 20 credits per MiB sent, and a refused one costs nothing. A slot that its leader never produced sends no notification, so a gap in the numbers is normal. Treat silence for several slot times as the signal, and fall back to the polled check to confirm it.
What to do when the gate closes
A closed gate is information, and the useful answer is to wait for the next verdict. Decide the policy before launch, then keep it dull.
- Hold the lobby and show players a message that the match is delayed. Do not take entry fees until the gate opens.
- Run the gate again after a short pause, and cap the retries so a lobby does not hang forever. After the cap, cancel the match and release anything already held.
- Record which check failed. A health failure, a finalized lag and a slow round trip point at different places, and the log tells you which one to chase.
- Keep the gate and the money path apart. The gate reads. The code that locks funds and signs lives in your game program and wallets, and it runs only after the gate opens.
A slow round trip with healthy chain numbers points at your network path or your own server load. A stalled slot count with a fast round trip points at the chain. Matching the failure to its place is most of the value of printing the numbers beside each verdict.
For a team that wants the same measurement in a release pipeline, RPC latency CI gate turns a round trip mark into a build check.
Where it ends
- The gate reports the state of the chain and one connection at one moment. It cannot promise the next minute, so a match that is already running needs its own handling when a later write fails.
- It judges from a single vantage point. Players in other regions can see a different path, and a gate run in one data center says nothing about theirs.
- You set the pass values. The defaults are starting values and no property of the network.
- The sample call covers a past window, so a stall that began a few seconds ago shows first in the progress and finalized checks.
- A passing gate does not make a transaction land. Sending, retrying and confirming belong to your game program and wallets, and none of that is read here.
- A call answered with -32601 means the method is not served: do not retry it, and keep to the methods the script uses.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The gate closes on the round trip while the chain numbers are healthy. | Your path to the endpoint is slow, or the game server is busy. Reuse one client for the gate instead of opening a connection per run, run it from the same region as the match service, and raise the mark only after you have seen the numbers from that host. |
| The finalized lag prints 0 and the progress line shows 0 slots gained in the same run. | Both can be true when the chain has stopped: with nothing advancing, processed and finalized are equal. The progress check is the one that closes the gate, so keep it in. |
| The gate flaps between open and closed from one run to the next. | One bad read closes the gate. Require two failures in a row before holding a lobby, and keep a failed verdict for a few seconds so lobbies do not alternate. |
| getHealth throws instead of returning a value. | A node that is behind answers with an error and @solana/kit throws. The script counts a throw as a failed check and prints the text, so read the text before changing anything. |
| Every lobby runs its own gate and the cheap read budget drains. | Run the gate in one place on a timer and share the newest verdict, with its age, among the lobbies. Seven calls a second cover every match that starts in that second. |
| The slot subscription goes quiet and the gate stays open. | A slot its leader never produced sends no notification, so one gap is normal. After several slot times of silence, run the polled progress check and close the gate if it also shows no gain. |
Questions
Which provider should a Solana game choose for reliability?
No list can answer that for your game. Measure from the servers that run your matches, with the pass values in the table, over a quiet period and a busy one, and keep the gate running in production so you see a change as it happens.
Should the gate read at finalized or confirmed?
It reads both, plus processed. Processed shows live progress, finalized shows how far confirmation trails, and the blockhash is read at confirmed because a transaction you build next will be checked against it.
How often should the gate run?
Once a second from one place is enough for most games, with the verdict shared across lobbies. On Free that alone takes the whole cheap read rate of 5 calls a second, so run it every few seconds there. A match start can use the latest verdict if it is only a few seconds old and run a fresh gate if it is older.
Can the gate stop a match that is already running?
It can report that the chain has gone bad, and your service can pause new settlements. What to do with a live match, such as freezing it or ending it with a refund, is a rule your game program has to carry.