Written October 2026, looking back at Markets13 min read
Racing relays without paying twice
An independent execution engine that turned social signals into on-chain trades, and how it raced several relays at once while guaranteeing only one trade lands.
From Solana and pump.fun · 2025 – 2026
Outside of work I built an execution engine that turned social signals into on-chain trades on Solana, as part of my pump.fun launch project. It was independent of Print, and it ran against live mainnet traffic, so the design was tested by reality rather than by me. The signal side is its own story (see the missing 300ms). This post is about the execution side: getting a trade on-chain in milliseconds, without accidentally doing it twice.
Racing relays
To get a transaction included quickly, you submit it to block builders through relays. No single relay wins every time, so the obvious move is to send to several in parallel and let the fastest one land.
The catch is that each relay wants its own tip, paid to its own account, inside the transaction. So you can't send one transaction to everyone. You build one transaction per relay, each with a different tip instruction.
Buys raced three relays: 0slot, Nozomi, and Astralane. Every copy carried the same tip, 10,000 lamports (0.00001 SOL) by default, plus a 100,000-lamport priority fee; the only thing that differed between copies was where the tip went. Each relay publishes a pool of tip accounts and wants one picked from it, so each copy pays a randomly chosen account from its own relay's pool. Those tip accounts stay out of the lookup table on purpose, because relays check for their tip account directly in the transaction and can't see it through a table.
Different tip destinations mean different bytes, so different signatures. That's the important consequence. Solana dedupes identical transactions by signature, which is why resending the same signed bytes to several endpoints of one relay is safe: at most one copy can land. Three copies with three different tips get no such protection.
Which raises the real problem: if you send three different transactions that each buy the same thing, what stops two of them landing?
One winner by construction
For buys, every copy uses the same nonce account instead of a recent blockhash. A nonce-based transaction is valid only while the nonce holds a specific value, and landing it advances the nonce. So whichever copy lands first advances the nonce, and every other copy instantly becomes invalid.
There's no coordination, no cancel message, no race to clean up. Exactly one copy can succeed because of how the transactions are built.
It also answers the cost question in the title. A losing copy fails validation (its nonce value no longer matches) before it can be included in a block, so it never executes and never pays its tip or priority fee. Racing three relays costs one buy's fees, not three. The thing "paying twice" would really cost is a duplicated position: two buys of the same token at slightly different prices, which is far more than any tip.
Launches didn't need the nonce at all. A launch creates a brand-new mint account, and an account can only be created once, so if two copies of the same launch both reached a leader, the second would fail on-chain because its mint already exists. The uniqueness is in the data either way; for a buy there's no account being created, so the nonce supplies it.
The trade-off to design around: a nonce transaction never expires on its own. If no copy lands, every copy stays valid until the nonce moves, so a stale copy could still land later at a worse price. The protection is a hard ceiling on what every buy may spend: on the bonding curve, a maximum SOL cost of 1.15x the quoted amount (a 1,500 bps slippage setting), enforced by the program itself, so a late copy can't spend more than that whatever the price has done. The advance-nonce instruction also has to be the first instruction in the transaction.
That ceiling bounds the damage; it doesn't cancel the copy. If none of a buy's copies land, the nonce is handed back to the pool, after 5 seconds if it never moved, or 60 seconds if it's stuck in flight. The next trade on that account signs against the same nonce value, so it and the stale copies are racing for one slot: at most one of them can land, but it might be the stale one. The clean fix is to advance the nonce deliberately before reusing it, which costs one small transaction and invalidates every outstanding copy at once. It's the first thing I'd add. The ceiling is also weaker on the second venue a buy can route to (PumpSwap, the AMM a token moves to after its bonding curve), where the SOL in is exact, so spend is capped, but the minimum tokens out is zero, so a late copy can still get a much worse fill. A minimum-out derived from the quote closes that.
The next issue was rapid back-to-back trades. If two different trades share one nonce account, the first one invalidates the second. So there's a small pool of nonce accounts, handed out round-robin, so consecutive trades don't collide while copies of the same trade still do.
The pool is three accounts. Round-robin skips any account still in flight, and if all three are busy, the buy doesn't wait and doesn't share: it goes to a single relay with a regular blockhash. Racing without a free nonce is exactly how you'd buy twice, so the fallback gives up speed rather than safety. An account is in flight from send until its advance is observed on-chain, polled every 400 ms; that lag was about 0.4 to 2 seconds after the relay accepted the transaction. Reusing an account inside that window would sign the next trade against the old value and get it rejected once the chain caught up. As an estimate from those inputs, three accounts sustain somewhere between 3 / 2 = 1.5 and 3 / 0.4 = 7.5 raced buys a second before buys start falling back to single-relay sends. At 10x, the fix is more accounts, and they're cheap: a nonce account is 80 bytes, so its rent-exempt deposit is (80 + 128) x 3,480 x 2 = 1,447,680 lamports, about 0.00145 SOL, refundable when it's closed. Keeping the pool's view of each account fresh is a smaller cost than it looks: a nonce only changes when one of my own trades lands, and each account is re-read on release anyway. A background refresh every 30 seconds was about 2,880 RPC calls a day spent detecting changes that essentially never happen, so it runs hourly, as a defensive sync against someone touching an account by hand.
On top of that, each relay has several regional endpoints, and the same signed bytes go to more than one of them at once. More isn't automatically better: every endpoint costs rate-limit budget on the relay's side, and four regional endpoints per launch on one relay ate four times the budget and caused silent drops on back-to-back sends. So I cut that relay to two: its global edge, which re-broadcasts to every region server-side, and the regional gateway nearest my server. Every submission logs how many relays accepted it, which one answered first, and how long each took. That's how I learned where to deploy: across 214 live launches, the global edge accepted in about 35 ms and was consistently first, while the regional gateway ranged from 46 ms to over 500 ms. First-success-wins makes that tail free; the regional path only has to win the cases the edge fumbles.
One honest gap in that logging: "answered first" means accepted first, not landed. A relay acknowledging a transaction means it received it, not that it got into a block. What I never built was a per-relay table of which copy actually landed and how many slots it took, and that's the number that really decides which relays are worth their tip.
Taking round-trips out of the click path
The second half of speed is not waiting for things you could have done earlier. The rule I used: if a step can happen before the signal arrives, it should.
- a pool of pre-fetched blockhashes, so grabbing one takes under a millisecond when warm
- keep-alive pings so connections are already open
- metadata, blockhash, and lookup-table loads run in parallel instead of in sequence
- return as soon as the transaction is submitted, and confirm in the background
- deploy the engine physically near the relays
The blockhash pool shows how the numbers fit together. A blockhash is valid for about 150 blocks, roughly a minute at 400 ms a slot. The pool keeps 5 entries and refreshes every 3 seconds, drops anything older than 10 seconds, and only hands out the freshest if it's under 8 seconds old. So a transaction signed from the pool starts with at least 50 seconds of validity, plenty for a send and one rebroadcast, and a pool read is a synchronous array lookup instead of a ~200 ms RPC round-trip. In a run of 92 live launches, the blockhash came from the warm pool 92 times out of 92, with a median of 0 ms. Keep-alive pings go out every 10 seconds with a 3-second timeout, and they go through the same connection pool the real sends use, so the connection that's kept warm is the one that's actually used.
Warm state, shared on purpose
The first version ran as Next.js API routes, which is not where a latency-critical engine belongs, and it showed: Next.js bundles each route with its own copy of every module it imports. That's fine for stateless code and quietly wrong for warm pools: a pool warmed in one route is invisible to another.
The sharpest version of that bug is startup. The server's startup hook and the boot route that triggers it compile into separate bundles, so a module-local "already started" flag is two different variables, and both triggers run the full startup: background services start twice and the second one fails to bind its port. So the guard that makes startup run exactly once lives on globalThis, the one object every bundle in the process shares, and so do the caches every route reads (creator lookups and pump.fun's global config). Routes only pass plain data between each other. Every submission also logs how many relays it actually raced and how many accepted, so "are we racing three relays or one" is in the logs, not an assumption. Today I'd run the engine as one long-lived process and skip the problem entirely.
Fitting in 1,232 bytes
Solana transactions have a hard size limit of 1,232 bytes. A swap plus tip plus nonce instructions plus all the accounts gets close fast. Each account address is 32 bytes. With a lookup table, the transaction can reference an account by a 1-byte index instead, which made the difference between fitting and not fitting. My table held 142 addresses (programs, fee and config accounts, fixed wallets), and every address moved into it saves 31 bytes. Signers can't move (they always cost a 32-byte key plus a 64-byte signature), and neither can tip accounts, for the reason above. The launch transaction shows how tight it gets: 945 bytes on its own and 1,216 with four wallets inline, 16 bytes under the limit (more in nights and weekends on Solana).
- Inline addresses
- Via lookup table
Show data
| accounts | Inline addresses | Via lookup table |
|---|---|---|
| 10 accounts | 320 | 10.00 |
| 20 accounts | 640 | 20.00 |
| 30 accounts | 960 | 30.00 |
Compute limits follow the same philosophy. The priority fee is charged per unit of the compute limit you request, so an oversized limit is money for nothing, and an undersized one fails on-chain. Limits come from measured usage plus headroom, not from a guess at what the code should cost.
I set the priority fee as a total budget in lamports and derive the per-unit price from the limit: price = budget x 10^6 / limit, in micro-lamports per compute unit. So an oversized limit doesn't charge more lamports, it does something subtler: it dilutes the per-unit price the leader's scheduler ranks on. As an estimate: a 100,000-lamport budget over a 110,000-unit limit bids about 909,000 micro-lamports per unit. Spread over 200,000 units (the default per-instruction allowance if you don't set a limit), the same lamports bid 500,000, a 45% lower bid for the same spend.
The headroom isn't one fixed number, because each transaction type was measured on its own:
- Requested limit
- Measured usage
Show data
| tx | Requested limit | Measured usage |
|---|---|---|
| Bonding-curve buy | 110,000 | 99,790 |
| PumpSwap sell | 260,000 | 211,732 |
| Launch | 230,000 | 215,000 |
| Fee share | 220,000 | 144,259 |
| Donation | 40,000 | 35,258 |
Headroom runs from about 7% on the launch to about 50% on the fee-share transaction, and that last one is the obvious one to tighten next.
Safety
Because this moved real money, demo and real executors are completely separate code paths, and every spending action checks at runtime that the demo path can never send a real transaction. I didn't want the difference between a test and a real trade to be one flag someone forgets. Concretely: the real and simulated executors are injected by two different page layouts, and there's no default, so a page that forgets to choose one throws instead of quietly getting the real one. Each executor checks on every spending action (six of them) that it's running where it's supposed to: the real one refuses to run under the demo path, and the simulated one refuses to run anywhere else. On the server, dry-run is on by default, and only the exact string false turns it off, so a typo, an empty value, or a missing variable all fail safe.
The EVM side
I also supported EVM chains (BNB Smart Chain first), where the problems look different. Nonces there are per wallet and strictly sequential, so I kept a local nonce manager per wallet behind a lock, and resynced from chain whenever a node said "nonce too low".
The details matter more than the idea. The local cursor for each chain and address is the maximum of what I've handed out and the chain's own pending count, and it expires after 60 seconds, so a cursor that drifted (a send that never reached the mempool, a transaction made from another tool) heals itself instead of wedging the wallet. A reservation that fails before sending is handed back, so one failed build doesn't leave a permanent gap that every later transaction queues behind. Sends on a chain go through a single promise queue, one at a time, which is the "lock": simpler than a mutex, and it makes nonce order equal to send order by construction. On "nonce too low", the nonce is released, the pending count re-read, and the send retried exactly once; a second failure is a real error, not something to loop on. One subtlety from account-abstraction (EIP-7702) transactions: they can bump the nonce by two, so the resync takes the maximum of the pending and latest counts rather than trusting either.
Submission there isn't a race. It goes through a fallback provider in priority order, with a 1.5-second stall timeout before trying the next RPC. EVM gives you the same uniqueness for free that the durable nonce gives on Solana: two transactions with the same nonce from the same wallet can't both be mined. So sending one signed transaction to several RPCs at once would be safe, and it's the obvious next step when one RPC's tail matters.
What I took from it
Two things. First, build the "only one can win" guarantee into the data, not into coordination logic. The nonce trick is robust because there's nothing to get wrong at runtime. Second, make the race observable. Logging which paths every trade raced, and which one won, is what turns "it feels fast" into a design you can reason about and tune.