RPC surface and subscriptions
Surfpool exposes a Solana-compatible JSON-RPC service for reading chain state, submitting and simulating transactions, changing a local test network, and watching live events. The HTTP surface combines standard RPC methods with Surfpool extensions. The WebSocket surface delivers selected state and execution changes as subscriptions.
The parent page, Runtime and RPC service, explains how this service fits into the running system. The Runtime execution loops page explains the process that advances slots, processes commands, and produces the events that subscriptions consume.
RPC boundary
The RPC boundary gives clients one view of the current local SVM state. A request can read local data or use the configured remote data source when the local network needs account or history data. Responses use Solana response shapes so standard clients can build transactions, inspect accounts, and follow transaction status.
Commitment selects the slot used for request context and freshness checks. The local SVM keeps one account state view, so a response can report the requested context slot while the value already reflects later local execution.
The service separates normal chain access from local test controls:
| Surface | Main purpose | Transport |
|---|---|---|
| Standard RPC | Read chain state and submit or simulate transactions | HTTP JSON-RPC |
| Surfnet extensions | Change test state, control time, inspect local state, and run test helpers | HTTP JSON-RPC |
| Administrative RPC | Stop the service or manage runtime plugins | HTTP JSON-RPC |
| Jito RPC | Submit, inspect, and simulate transaction bundles | HTTP JSON-RPC |
| PubSub RPC | Receive live account, transaction, log, slot, block, and snapshot events | WebSocket JSON-RPC |
The middleware gives each request access to the SVM and the service command channels. It also checks surfnet_* methods before they reach their handlers. This check applies to each method in a JSON-RPC batch, so one disabled cheatcode fails its own call while other calls can still run. Notifications do not produce response objects.
HTTP API families
The HTTP API is assembled from focused method families. The families share the same local state and response conventions, but each one has a clear client goal.
Minimal API
The minimal API supplies the small set of node and ledger methods that clients need to identify the service and track its basic progress. It reports balances, epoch and slot data, health, identity, version, transaction count, vote accounts, and leader schedule information.
This family is useful for client startup and liveness checks. It also gives clients a common time view through slot and block-height values. In a simulated network, validator-oriented results can be empty or represent the Surfpool identity rather than a live validator set.
References: crates/…/minimal.rs• L39-52 crates/…/minimal.rs• L580-827
Full API
The full API covers the normal transaction and ledger workflow. It lets clients request airdrops, submit signed transactions, simulate transactions, obtain blockhashes and fees, inspect blocks and transactions, query signatures, and read performance or prioritization data.
Transaction history supports both standard address-signature lookup and the combined getTransactionsForAddress view. The combined view can return signature summaries or full transaction data. It uses a pagination token and filters for slot, block time, success, and token-account activity. The current combined view reads from the local ledger and does not fan out to remote history.
Block range reads accept either an explicit end slot or a context configuration. Limited range reads use the same local and remote slot view while applying a caller-supplied result limit. When a client sends the configuration in the wrapper form used for a request without an end slot, the RPC uses that configuration for commitment and minimum-context checks. The default commitment for block-range reads remains processed so a query can reach the current local tip. Results combine the local slot range with any needed remote history.
Submitted transactions are preflight-checked against the configured preflight commitment before they enter the runtime command path. If the transaction blockhash is not visible at that commitment, sendTransaction returns a simulation-style BlockhashNotFound error and does not queue the transaction. getLatestBlockhash also selects a blockhash at the requested commitment and derives its validity height from that blockhash’s age, so a finalized blockhash can trail the current tip and expire sooner than a processed blockhash.
The transaction boundary accepts base58 and base64 data. It rejects unsupported encodings and payloads above the wire-size limit before deserialization. The default transaction configuration supports version 1, while legacy and version 0 transactions retain the packet-size limit and version 1 transactions use the larger protocol limit.
Simulation is read-only from the caller’s point of view. It reports execution errors, logs, compute use, return data, loaded account data size, and optional account views without submitting the transaction to the live network state. A caller can ask for a replacement blockhash for simulation results. Submission returns a signature that clients can use with status and history methods.
The full API also reports local fee signals. Recent prioritization fees come from recent locally processed transactions, so they describe the simulated network rather than a remote cluster fee market.
Validator-facing full-API views describe the local simulation. Inflation rewards are zero-valued for requested addresses, cluster-node discovery reports the Surfpool identity and configured endpoints, and performance samples come from local execution data.
References: crates/…/full.rs• L194-1521 crates/…/full.rs• L1524-2083 crates/…/full.rs• L2148-2662 crates/…/utils.rs• L150-245 crates/…/utils.rs• L273-292
Account data access
The account data families expose both direct account reads and indexed scans. They support native account data, token accounts, token mints, program-owned accounts, and supply views. Account responses can preserve the requested order and can use standard encodings such as raw, base64, or parsed data.
Use direct reads when the caller already knows the account address. Use scans when the caller needs to discover accounts owned by a program or token accounts related to an owner, delegate, or mint. Program scans accept size and byte-match filters, which lets clients narrow large sets without first downloading every account.
The account surface includes these broad query types:
- Single and multiple account information.
- Native balances and token-account balances.
- Token supply and the largest token holders.
- Program-owned account scans.
- Token accounts by owner or delegate.
- Network supply and the largest native accounts.
When a remote data source is configured, account reads can hydrate local state from that source. Later RPC calls then see the account through the same local state view as accounts created by local execution.
Token amount views use the current local clock when a mint has time-based Token-2022 extensions. This keeps account, balance, supply, and largest-holder responses consistent while simulated time changes. Account reads capture their response context before remote hydration, so the context remains tied to the read that authorized the lookup.
References: crates/…/accounts_data.rs• L25-345 crates/…/accounts_data.rs• L348-627 crates/…/accounts_scan.rs• L22-456 crates/…/accounts_scan.rs• L458-728
Bank data access
The bank data family exposes network rules and leader information that clients need when they prepare transactions or inspect chain progress. It reports rent-exemption balances, inflation settings, epoch schedule data, slot leaders, and block production ranges.
These methods describe the simulated bank rather than a live validator marketplace. Inflation values come from the local bank configuration. Slot-leader calls identify Surfpool as the local leader for valid ranges, while block-production responses return the requested range with no validator production records. Clients should use these methods for protocol-compatible reads, not as proof of real cluster participation.
References: crates/…/bank_data.rs• L17-392 crates/…/bank_data.rs• L395-543
Administrative operations
The administrative family controls the running service and its plugin set. It can request shutdown, load or unload a runtime plugin, reload a plugin with a new configuration, list loaded plugins, and report service start time.
These calls have effects beyond a single RPC request. Shutdown sends a termination command to the runtime. Plugin actions pass through the plugin lifecycle and return the result to the caller. They therefore belong to trusted operational clients rather than ordinary application traffic.
References: crates/…/admin.rs• L9-191 crates/…/admin.rs• L193-317
Jito bundle support
The Jito family adds bundle operations for clients that need ordered groups of transactions. sendBundle runs up to five transactions in order and commits their combined execution state only when every transaction succeeds. A failed bundle discards its execution state and publishes no execution events, although accounts prefetched from a configured remote source may remain cached.
Before execution, a bundle can hydrate the accounts it needs from the configured remote source. Execution then uses an isolated view of the live state. If live state changes before commit, the service discards the stale view and retries from a fresh view a limited number of times. This preserves atomicity without hiding concurrent local changes.
getBundleStatuses maps locally known bundle IDs to their transaction signatures and an aggregate status. It accepts at most five IDs and returns null for an unknown local bundle. simulateBundle runs the transactions in order against a temporary view and always discards that view. Later transactions can see earlier simulated changes, but simulation stops at the first failure and never changes live state.
Bundle simulation can return account snapshots before and after each transaction. It accepts base64 transaction and account snapshot data only. Snapshot configuration lists must match the bundle length. Blockhash replacement is allowed only with signature checks disabled. The bundle wire contract also fixes transaction encoding and the maximum bundle size so clients receive predictable validation errors.
The bundle lifecycle is summarized below.
flowchart LR
A[Encoded transactions] --> B{Bundle request}
B --> C[Ordered sandbox execution]
C -->|sendBundle: all succeed| D[Commit combined state]
C -->|sendBundle: any failure| E[Discard sandbox]
C -->|simulateBundle| E
D --> F[Store bundle status and publish events]
E --> G[Return failure or simulation result]
References: crates/…/jito.rs• L25-246 crates/…/jito.rs• L249-447 crates/…/jito.rs• L450-967 crates/…/jito_bundles.rs• L26-165
Cheatcodes
Cheatcodes are surfnet_* RPC methods for test setup and controlled local-state changes. They let a test fund or patch accounts, create or change token accounts, clone programs, control time, reset state, manage remote account behavior, export snapshots, and register test metadata such as IDLs and scenarios.
The cheatcode groups map to common test needs:
| Group | Goal |
|---|---|
| Account and token state | Create or update native and token account state without a normal transaction flow. |
| Program and metadata | Write program data in chunks, change a program authority, register IDLs, and inspect IDLs. |
| Time and reset | Move, pause, or resume the local clock and reset an account or network. |
| Data control | Mark accounts offline, stream accounts into the local view, and export snapshots. |
| Inspection | Read local signatures, profiles, Surfnet startup status, and profile results. |
| Scenario control | Register account overrides for later slot-based execution. |
Direct account patching can replace a complete account or apply selected fields to an existing account. Managed sysvars are not valid patch targets. Token-account updates preserve existing account extensions. For wrapped SOL accounts, the helper keeps lamports aligned with the updated token amount and the account’s actual layout. This lets Token-2022 accounts keep their extension data while tests change balances or other account fields.
Scenario registration uses an explicit base slot or the current slot. The service materializes overrides for that base slot at registration time, so setup state is available before later slot-based execution.
The token-account helpers also support Token-2022 confidential-transfer test data. surfnet_setTokenAccount can configure and fund a confidential account. surfnet_getConfidentialBalance reads the available or pending balance when the caller supplies the matching AES or ElGamal secret key. surfnet_deriveConfidentialKeys turns one wallet-produced signature over the canonical seed into the public and secret values needed by the other helpers, so the signing key itself does not cross the RPC boundary.
The derived secret material and the input signature can reveal confidential balances to anyone who obtains them. Treat this flow as a local test aid, not as a key-management pattern for a live cluster.
Cheatcodes are guarded by a shared filter. A caller can enable or disable named cheatcodes or disable all of them. A lockout can also prevent the enable and disable controls from being used again. Locking all cheatcodes also blocks the airdrop, snapshot-import subscription, and administrative controls that can stop the service or load plugins. The registered method manifest must match the exposed trait methods, so the service and typed client bindings agree on the available helpers.
The changed cheatcode surface also reports startup and runbook state through surfnet_getSurfnetInfo. Its response combines the current startup status with runbook execution state, so clients can distinguish an unsealed startup plan from a ready service while setup work is still in progress.
References: crates/…/surfnet_cheatcodes.rs• L146-376 crates/…/surfnet_cheatcodes.rs• L1525-1922 crates/…/surfnet_cheatcodes.rs• L2088-2555 crates/…/surfnet_cheatcodes.rs• L2588-2679 crates/…/mod.rs• L144-169 crates/…/mod.rs• L476-508 crates/…/mod.rs• L18-197 crates/…/mod.rs• L252-439
WebSocket subscriptions
The WebSocket API turns runtime events into long-lived client streams. A client first receives a numeric subscription ID. It then receives notifications until the subscription completes, the client sends the matching unsubscribe call, or the WebSocket connection closes.
The WebSocket middleware gives each subscription the same SVM and runtime command context as HTTP requests. It also carries the connection session so the subscription handler can send notifications and remove them when the client unsubscribes. Cheatcode gating applies here too, so a locked Surfnet refuses gated subscriptions such as snapshot import.
The supported live streams are:
| Subscription | Event view | Lifetime |
|---|---|---|
signatureSubscribe | A transaction is received or reaches the requested commitment | Usually ends after the first matching status notification |
accountSubscribe | Changes to one account, with a chosen encoding and commitment | Continuous |
programSubscribe | Changes to accounts owned by a program, with optional size or byte filters | Continuous |
logsSubscribe | Transaction logs filtered by all transactions, a signature, or account mentions | Continuous |
slotSubscribe | Simple slot progress | Continuous |
slotsUpdatesSubscribe | Tagged slot lifecycle events such as bank creation, freeze, confirmation, and root | Continuous |
blockSubscribe | Confirmed or finalized block updates, optionally limited to blocks mentioning an account or program | Continuous |
snapshotSubscribe | Progress for a snapshot import | Until the client removes it or the stream ends |
The slot-update stream reports the lifecycle events that the simulated bank can produce. It includes bank creation, freeze, optimistic confirmation, and root. It does not produce shred, completed, or dead events because Surfpool has no gossip or shred layer.
Block subscriptions require at least confirmed commitment. They can request all blocks or only blocks that mention an account or program. The block payload follows the selected block encoding and transaction-detail settings.
The service also defines root and vote subscription names for protocol shape compatibility. Their current handlers do not publish live data. Clients that need those views should use the supported slot, slot-update, block, account, or log streams instead.
Subscription notifications are fed by the same execution events that update the local SVM. A successful transaction can therefore produce signature, account, program, block, and log notifications. A bundle simulation produces none because it uses discarded state, while a successful committed bundle publishes events like regular transaction submission.
The subscription flow is summarized below.
sequenceDiagram
participant C as Client
participant W as WebSocket RPC
participant S as Local SVM events
C->>W: subscribe(method, filter)
W-->>C: subscription ID
S-->>W: matching runtime event
W-->>C: notification with context
C->>W: unsubscribe(subscription ID)
W-->>C: true
References: crates/…/ws.rs• L35-1047 crates/…/ws.rs• L1086-1327 crates/…/ws.rs• L1359-1720 crates/…/ws.rs• L1735-2287 crates/…/mod.rs• L447-508
RPC assembly
The local service builds the HTTP handler from the cheatcode, minimal, full, Jito, account, bank, scan, and administrative families. It builds the WebSocket handler from the subscription family and attaches a session to each connection. Both handlers receive the same SVM state and runtime command context.
The shared middleware creates that request context and applies cross-cutting rules before method handlers run. It supports single calls and non-empty JSON-RPC batches. In a batch, disabled cheatcodes are rejected per method while valid calls continue, and the final response remains correlated by request ID rather than by order. Notifications still execute through registered method handlers but are removed from the response.
This arrangement keeps the client contract broad without giving every module ownership of the runtime. Read methods query the state view. Mutating methods send work through the runtime command path. Event methods listen for state changes and stop when their subscription is removed.
References: crates/…/mod.rs• L943-985 crates/…/mod.rs• L987-1127 crates/…/mod.rs• L45-121 crates/…/mod.rs• L143-347 crates/…/mod.rs• L350-508
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the HTTP delegate list aligned with every RPC family. A new trait alone does not expose its methods.
- Keep
surfnet_*method registration aligned with the cheatcode filter, the canonical method manifest, and generated client bindings. A mismatch can make a valid helper unavailable or leave it outside the disable controls. - Keep batch filtering aligned with JSON-RPC response rules. A disabled method must fail only its own call, while notifications must remain absent from the response.
- Keep full-API block-range argument handling aligned with Solana wrapper forms. A client may send commitment and minimum-context settings in the wrapper when it does not send an end slot.
- Keep full-API simulation fields aligned with the client response contract. Changes to replacement blockhash, loaded account data size, return data, or transaction encoding can break callers without changing the method name.
- Keep transaction decoding limits aligned with legacy, version 0, and version 1 transaction limits and with the base58/base64 encoding contract. A change can reject valid clients or admit oversized payloads.
- Keep account response context aligned with remote hydration. Moving the context read can make a response claim a slot that did not authorize the fetched value.
- Keep confidential-transfer key, account, and balance contracts aligned. A change to one helper can make the setup, read, or decrypt step incompatible.
- Keep token-account update behavior aligned with Token-2022 extension layouts and native-mint lamport accounting. A change can alter account size or wrapped-SOL balances without changing the RPC method name.
- Keep current-clock Token-2022 amount conversion aligned across account, balance, supply, and largest-holder responses. A change in mint-extension data can silently change UI amounts without changing raw token balances.
- Keep Jito wire types and RPC validation aligned. Bundle size, transaction encoding, snapshot-array lengths, and blockhash replacement rules are client-visible contracts.
- Keep Jito sandbox freshness and retry behavior aligned with runtime writes. A stale snapshot must not commit over newer local state.
- Keep WebSocket notification names, payload wrappers, and unsubscribe maps aligned. A change in one can break clients that already hold subscription IDs.
- Keep block-subscription commitment limits, filters, encoding, and transaction-detail settings aligned with the block event producer. A mismatch can reject valid clients or return incomplete block views.
- Keep event-producing transaction paths aligned with subscriptions. A path that changes state without publishing its matching event creates stale account, log, block, or signature views.
- Keep commitment, blockhash visibility, and context-slot behavior aligned across standard reads and subscriptions. Clients use those values to decide whether data is safe to consume.
- Keep startup-status and runbook execution fields aligned in
surfnet_getSurfnetInfo. A change can make clients report readiness before the startup plan is sealed or hide work that is still running.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| RPC context is missing or the runtime command channel is closed | The request returns a node-unhealthy or internal RPC error | Start requests only after the local service has created its runtime context. |
| A public key, signature, filter, or encoded transaction is malformed | The request is rejected as invalid parameters before state is changed | Validate client input at the RPC boundary and use the method’s expected encoding. |
| An encoded transaction uses an unsupported encoding or exceeds its version-specific size limit | The request returns invalid parameters before the transaction is deserialized | Use base58 or base64 and keep legacy/version 0 payloads within 1232 bytes or version 1 payloads within 4096 bytes. |
| A caller sends an empty batch or a request shape other than a method call | The service returns an invalid-request error instead of invoking an RPC method | Send a single method call or a non-empty batch of method calls. |
| A disabled cheatcode appears in a batch | That batch element returns an invalid-request error, while other method calls can still complete | Enable the helper before use and correlate batch results by request ID. |
| A program scan has too many or invalid filters | The scan is rejected instead of running an unbounded or invalid query | Use valid filters within the RPC filter limit. |
| A caller asks for a slot below the requested minimum context | The read fails instead of returning data that is too old | Retry after the local slot reaches the requested value or lower the minimum when safe. |
| A block-range request puts commitment or minimum context in neither supported config position | The query can use the wrong commitment or fail to honor the caller’s freshness bound | Use the standard wrapper form for an end slot or the wrapper config form when no end slot is sent. |
| A submitted transaction uses a blockhash that is not visible at its preflight commitment | sendTransaction returns a simulation-style BlockhashNotFound error and does not enqueue the transaction | Fetch the blockhash at the same commitment, set a matching preflightCommitment, or skip preflight only when appropriate. |
| Simulation requests both signature verification and recent-blockhash replacement | The simulation is rejected because the two options cannot be used together | Use signature verification with the transaction’s blockhash, or replace the blockhash without signature verification. |
| A Jito bundle exceeds five transactions or one transaction fails | sendBundle changes no execution state; simulateBundle stops at the first failure | Split the work into valid bundles and inspect the returned per-bundle or per-transaction error. |
| Live state changes while a Jito bundle sandbox is ready to commit | The stale sandbox is discarded and retried; repeated changes eventually return an error | Avoid conflicting writes or retry the bundle after the runtime settles. |
| A confidential balance read uses no key, a wrong key, or a non-Token-2022 account | The read is rejected instead of returning a misleading balance | Supply the matching AES key or ElGamal secret key for the requested balance and use a configured Token-2022 confidential account. |
| A direct account patch targets a managed sysvar | The cheatcode is rejected and the sysvar is not changed | Patch ordinary test accounts instead of runtime-managed sysvars. |
| A block subscription requests a commitment below confirmed or has an invalid mention filter | The subscription is rejected before it receives a subscription ID | Use confirmed or finalized commitment and a valid account or program public key. |
| A client uses root or vote subscriptions expecting live events | The current handler does not provide those notifications | Use supported account, log, signature, slot, slot-update, or block streams. |
| A cheatcode is disabled by its filter or lockout | The method is rejected even though the RPC server is running | Enable the named helper before lockout, or start a new test network with the needed controls. |
| A client treats an unsealed startup plan as ready | It can send setup-dependent requests before required startup work completes | Poll surfnet_getSurfnetInfo and wait for the startup status to report readiness. |
Key files
| File | Why to read it |
|---|---|
| crates/…/mod.rs | Shows how the HTTP and WebSocket RPC surfaces are assembled and connected to the running service. |
| crates/…/mod.rs | Defines the shared request context, HTTP and WebSocket middleware, batch behavior, and cheatcode gating used by all RPC families. |
| crates/…/utils.rs | Defines shared context-slot checks, transaction decoding limits, encoding validation, and default transaction compatibility. |
| crates/…/minimal.rs | Defines the small node and ledger API used for startup and basic chain state. |
| crates/…/full.rs | Defines the main transaction, block, history, fee, blockhash, range, simulation, status, and local prioritization-fee workflow. |
| crates/…/accounts_data.rs | Defines direct account and token data access, including remote hydration and current-clock token amount views. |
| crates/…/accounts_scan.rs | Defines program, token, supply, and largest-account queries. |
| crates/…/bank_data.rs | Defines rent, inflation, epoch, leader, and simulated block-production views. |
| crates/…/admin.rs | Defines service shutdown and plugin control operations. |
| crates/…/jito.rs | Defines bundle submission, status, isolated bundle simulation, remote account hydration, and atomic commit behavior. |
| crates/…/surfnet_cheatcodes.rs | Defines local test-state controls, token-account extension handling, confidential-transfer test helpers, scenario setup, startup status, and their enable or disable policy. |
| crates/…/ws.rs | Defines WebSocket subscription contracts, block streams, and live event streams. |
| crates/…/jito_bundles.rs | Defines the shared Jito request and response wire shapes. |
| crates/…/mod.rs | Shows the typed Rust entry points for common cheatcode workflows. |