Introducing a new way to review your PRs.

Read the announcement

solana-foundation / surfpool

Surfpool is where developers start their Solana journey.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / surfnet-virtual-network

Surfnet virtual network

Surfnet is a local Solana-like network that runs transactions in a lightweight Solana Virtual Machine (SVM). It can run from local state alone or use an upstream RPC source to fill missing chain and account data. In both modes, the local SVM owns execution and the virtual network's visible state. See State and Surfnet execution for the wider state model. See Account storage for persistence and Database backends for storage choices.

Execution modes

Surfnet provides local execution and remote-backed execution through the same local RPC view. The modes differ only in how they obtain state that is not already available in the local network.

Local execution

Local execution keeps the network independent from an upstream source. The SVM starts with its feature set, built-in programs, sysvars, and native mint. Clients then add state through transactions, snapshots, airdrops, and other local actions.

This mode gives tests a self-contained chain. Its starting state depends on local settings and supplied state rather than on network access.

References: crates/…/surfnet.rs• L55-83 crates/…/surfnet_lite_svm.rs• L27-103 crates/…/svm.rs• L468-498

Remote-backed execution

Remote-backed execution keeps all transaction processing local while using an upstream Solana RPC source for missing accounts and initial epoch data. The caller selects the source URL. When remote mode is enabled without a URL, the runtime uses its default source.

Remote state is treated as a fill for the local fork. It does not become an automatic replacement for state that a local operation has already settled. Startup also keeps remote chain context, including the genesis hash and restart-slot boundary, available to the local chain.

References: crates/…/locker.rs• L263-285 crates/…/remote.rs• L50-103 crates/…/remote.rs• L105-191 crates/…/remote.rs• L236-252

Account resolution

Account resolution uses local state first. Surfnet checks active SVM state and local account storage before it asks the remote source for a missing account. Accounts marked offline are not fetched. An offline owner can also block downloads of accounts that it owns.

Surfnet labels account data by source and applies a matching update policy. Remote and stored data normally hydrate only missing local state. Explicit local and snapshot writes may replace state. Generated program data is a best-effort fallback, not a source that can replace an existing account. This prevents a slower source response from replacing a newer local write.

The same rule applies to dependent state. A program account may need its program-data account. A token account may need its mint. Surfnet fills missing dependencies without replacing newer local dependencies. After a batch merge, it rebuilds dependent results from live state so the caller sees the same program-data or mint account that the SVM kept.

Account writes also update the local indexes used by owner and token queries. A closed account is recorded as offline so a later remote read does not silently restore it.

The flow below shows the shared path for local and remote-backed account reads.

flowchart TD
    A[Account request] --> B[Read live SVM]
    B -->|Found| C[Return local account]
    B -->|Missing| D{Offline account or owner?}
    D -->|Yes| E[Return not found]
    D -->|No, local mode| E
    D -->|No, remote-backed mode| F[Query upstream RPC]
    F -->|Found| G[Recheck local state]
    F -->|Missing or error| E
    G -->|Local write won| C
    G -->|Still absent| H[Fill live SVM]
    H --> C

References: crates/…/locker.rs• L287-453 crates/…/locker.rs• L455-654 crates/…/svm.rs• L152-190 crates/…/svm.rs• L2970-3117

SVM execution model

The SVM is the local chain state and execution boundary. It joins the active LiteSVM view with chain records, account indexes, transaction status, and event streams needed by local RPC and execution clients.

Feature and chain setup

Surfnet starts from LiteSVM's mainnet feature set and applies explicit enable and disable changes. This gives the virtual network a known Solana-like baseline while allowing a test to select feature differences at startup. Built-in programs, sysvars, feature accounts, and the native mint are then made available to local execution.

Some sysvars are managed by the virtual chain itself. Direct account writes to the clock, slot hashes, recent blockhashes, epoch schedule, or last restart slot are rejected so the account view cannot diverge from the SVM's sysvar view.

When remote mode supplies chain context, Surfnet also loads the upstream LastRestartSlot sysvar. Network resets and garbage collection preserve this value with the other chain sysvars so a remote-backed network keeps the source's restart boundary.

Persistent account storage supports restart and recovery. Live SVM state takes priority over stored state. Garbage collection rebuilds the in-memory view without losing persistent accounts or the sysvars needed for time, blockhash, address lookup, restart behavior, and Geyser slot history. Slot checkpoints and local block data let the network recover its latest position and reconstruct sparse blocks.

Maintenance intervals represent simulated time rather than a fixed slot count. Surfnet converts the one-hour cache cleanup and one-minute slot checkpoint periods into slots using the current slot duration. Explicit slot-count settings can override either period, and the calculated interval never falls below one slot.

References: crates/…/surfnet_lite_svm.rs• L30-49 crates/…/surfnet_lite_svm.rs• L54-152 crates/…/svm.rs• L723-741 crates/…/svm.rs• L2505-2587 crates/…/svm.rs• L1665-1681

Commitment-aware blockhashes

Commitment is the level of chain certainty requested by a caller. Surfnet maps processed, confirmed, and finalized requests to visible slots. It then selects a recent blockhash that is old enough for that view.

The same rule checks a transaction's supplied blockhash. A hash that is too new for the requested commitment is not visible unless blockhash checks are disabled. Durable nonce transactions are accepted only when the nonce account has the current supported format, holds the signed blockhash, and the nonce authority signed the advance instruction.

References: crates/…/svm.rs• L1625-1819 crates/…/svm.rs• L1840-1940 crates/…/locker.rs• L3859-3886 crates/…/locker.rs• L3989-4005

Transaction and block lifecycle

Transaction submission validates signatures and transaction lifetime before the local SVM executes the transaction. Simulation and compute-unit estimation use the same lifetime checks without publishing state changes. Successful execution is stored and then moves through processed, confirmed, and finalized stages as slots advance.

Block production controls when the local chain closes its current slot and starts the next one. Clock mode follows timer ticks. Transaction mode advances after transaction processing. Manual mode advances only after an explicit slot-forward action. Each confirmed block updates chain metadata and publishes its lifecycle.

Simulated time advances in milliseconds and becomes Unix time only when Surfnet builds block and clock data. Slot-time arithmetic saturates before that conversion, so very large simulated times do not wrap into invalid negative timestamps. Time travel rejects the largest possible slot before it changes the network.

Geyser and slotsUpdatesSubscribe expose the same slot lifecycle to external observers. When a slot opens, Surfnet publishes its clock and slot-hash account state before the created-bank status. When a block closes, it records slot history and recent blockhash state before the entry and block metadata. This ordering gives downstream consumers the account context they need to accept the block stream.

The virtual network produces one entry per block and mirrors confirmed and rooted status into slot-update notifications. It does not model the full set of validator-side slot events because local execution has no gossip layer.

References: crates/…/svm.rs• L2365-2478 crates/…/svm.rs• L2480-2587 crates/…/svm.rs• L2758-2941 crates/…/svm.rs• L3206-3365 crates/…/svm.rs• L4430-4463 crates/…/locker.rs• L4075-4125 crates/…/time_travel.rs• L216-264 crates/…/mod.rs• L220-229 crates/…/mod.rs• L352-364 crates/…/mod.rs• L375-415 crates/…/mod.rs• L460-515 crates/…/types.rs• L60-91

Access coordination

Surfnet shares one SVM across RPC handlers, runloops, plugins, and embedded callers. A shared lock boundary lets reads use a consistent view while state changes use exclusive access.

SVM locking

SurfnetSvmLocker is the access boundary for the shared SVM. A read captures chain context such as slot, epoch, and blockhash with its result. A write gets exclusive mutable access and advances the state revision.

The locker also joins local state, persistent account data, and optional remote data. Remote waits happen before the final write-locked merge when possible. The final merge rechecks live state, offline rules, and dependent accounts. A concurrent local write therefore wins over a stale fetch, and a batch merge becomes visible as one related update.

The state revision protects atomic bundle work. A bundle records the revision used to create its isolated view. The commit is rejected when live state changed before the bundle tries to publish its result, even when the slot did not change.

References: crates/…/locker.rs• L177-253 crates/…/locker.rs• L307-434 crates/…/svm.rs• L560-567 crates/…/svm.rs• L985-1037

Isolated execution

Some work must inspect or run transactions without exposing partial changes to live clients. Surfnet creates an isolated SVM view with buffered storage and no live subscription targets. A failed operation is discarded. A successful bundle commits state and then replays its events to the live SVM.

The sandbox carries the live state revision from the time it was created. Commit first applies state and storage. It then replays account, transaction, log, and Geyser effects. This order keeps observers from seeing an event before the state that supports it exists.

References: crates/…/svm.rs• L682-721 crates/…/svm.rs• L817-929 crates/…/svm.rs• L958-1037 crates/…/svm.rs• L1047-1135

Startup and service behavior

Surfnet startup creates the local SVM, prepares optional remote and snapshot context, starts local RPC services, and begins block production. SDK, CLI, and MCP callers use this core runtime with different startup and endpoint choices.

Runtime startup

The runloop creates the remote client when remote mode is enabled. It loads epoch context, the upstream restart-slot sysvar, and snapshot accounts, applies startup airdrops, starts RPC and plugin services, and announces that the core is running. Startup readiness follows the declared startup plan. The runtime seals an empty plan when it owns planning. An external planner must seal its own work.

References: crates/…/mod.rs• L174-235 crates/…/mod.rs• L267-348 crates/…/locker.rs• L263-285 crates/…/surfnet.rs• L140-241 crates/…/start_surfnet.rs• L59-163

Snapshot loading

Snapshot loading restores explicit account data and can fetch null entries from the upstream source. Normal loading is best effort: invalid or unavailable accounts produce warnings and do not stop the other accounts from loading. Strict loading turns those problems into one reported failure and checks that requested executable programs and their required program-data accounts are valid in the live SVM. Strict loading can install some accounts before it returns the error.

Snapshot loading reports startup account updates only for accounts that are present in the live SVM after the load. A persistent store hit alone does not make an account live. This keeps startup observers aligned with the state that execution can actually read.

Strict snapshot loading does not create synthetic program data. Best-effort remote hydration still uses the normal fallback so an executable program can be usable while its real program-data account is not yet available. Explicit snapshot data remains authoritative, while fetched data fills absent state.

References: crates/…/locker.rs• L620-985 crates/…/svm.rs• L3008-3179

Service shutdown

Shutdown closes SVM storage and asks both local RPC services to stop. The SDK waits for both acknowledgements and reports a timeout because an unfinished service can keep its port in use.

Orderly shutdown also completes storage cleanup such as a SQLite WAL checkpoint. This keeps persistent account state and later endpoint reuse reliable. See Account storage for the storage boundary.

References: crates/…/mod.rs• L516-524 crates/…/locker.rs• L185-195 crates/…/svm.rs• L801-815 crates/…/surfnet.rs• L317-369

Supporting program behavior

Surfnet supplies the supporting account state that local Solana execution needs. It also supports scenario-driven account changes when a program exposes an IDL or a declared byte layout.

Program account hydration

When an executable upgradeable program arrives without program data, best-effort Surfnet loading creates a minimal valid program-data account. The placeholder lets the loader accept the program until real program data is available. It is replaced when actual data is written. The related program-data account is written before the program account.

Strict snapshot loading follows a different contract. It does not create a placeholder and reports an error when the requested program or its required program-data account cannot be installed and validated. This lets snapshot restore detect incomplete executable state instead of hiding it behind generated state.

Snapshot and remote loading use the same dependency order. Explicit local or snapshot data is authoritative. Remote and stored data fill only missing components. A real program-data account already in memory or persistent storage therefore remains preferred to generated state.

References: crates/…/svm.rs• L2970-3155 crates/…/locker.rs• L132-166 crates/…/locker.rs• L670-979

Native token state

The SVM creates the native mint during setup and adds it to execution state and token indexes. This gives local token actions a valid base account from startup.

Token account reads connect an account to its mint for local and remote data. Cached mint data includes the decimal count and UI-amount extension settings. Surfnet evaluates rate-based settings against the current simulated clock when it prepares a token account response. This keeps displayed token amounts aligned with the current chain time rather than the time when the mint was last written.

When a mint exists only on Surfnet, the upstream “could not find mint” response means that the remote side has no matching accounts. Local token accounts can then answer the request. Other provider failures and invalid parameters remain visible as errors.

References: crates/…/surfnet_lite_svm.rs• L324-346 crates/…/svm.rs• L621-639 crates/…/svm.rs• L2429-2466 crates/…/remote.rs• L105-120 crates/…/remote.rs• L497-557

Scenario account overrides

Scenario overrides change account data at a selected future slot. The override system first separates values used to derive an address or choose a catalog value from values that belong in account data. Programs with a declared byte layout use that layout before IDL lookup. Programs with an IDL use the typed account path. This lets scenario state changes work for both decoded accounts and programs that expose only raw bytes.

The locker schedules an omitted scenario base at the next slot. It rejects a base slot that has already been produced. Surfnet checks every relative-slot sum before it stores any override, so an overflow does not leave a partial schedule.

An override can request fresh remote account data before it applies its values. The fetched account and any coupled program-data or mint account fill missing local state without replacing a local account that was already settled for the slot. A materialized local change updates account subscribers and Geyser consumers. If materialization stops part way through a slot, unprocessed overrides are retained for a later attempt.

References: crates/…/locker.rs• L3021-3054 crates/…/svm.rs• L5184-5235 crates/…/svm.rs• L203-288 crates/…/svm.rs• L3310-3610 crates/…/svm.rs• L2318-2337

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep local-first lookup, offline rules, and remote fallback aligned so reads and execution see the same account state.
  • Keep account source labels and update policy aligned. Remote and stored data must hydrate absent state unless the operation is explicitly authoritative.
  • Keep dependent-account refresh aligned with the final live merge. A newer local program-data or mint account must be returned to the caller.
  • Keep account indexes and the backing account store aligned with each account mutation. Closed accounts must remain unavailable to remote fallback.
  • Keep managed sysvars protected across direct writes, reset paths, and garbage collection.
  • Keep the datasource LastRestartSlot value aligned across remote startup, network reset, snapshot restore, and garbage collection paths.
  • Keep SlotHistory and other streamed sysvars aligned across garbage collection, block close, and open-slot announcements so Geyser consumers receive a complete slot context.
  • Keep slot lifecycle status and slotsUpdatesSubscribe notifications aligned. A status change must not be visible on only one stream.
  • Keep simulated-time maintenance periods aligned with the current slot duration. A slot-count override must remain explicit and must not produce a zero interval.
  • Keep simulated millisecond time and Unix-second values aligned at block close and clock updates. Saturating arithmetic must not allow a large time value to wrap.
  • Keep time-travel boundary checks in the shared calculation path so callers cannot dispatch the largest slot.
  • Keep sandbox state and storage behind one exclusive commit boundary. Reject a sandbox based on an older state revision, even if the slot is unchanged.
  • Keep sandbox state changes ahead of buffered event replay. Subscribers must not observe data that is not yet live.
  • Keep raw-layout overrides ahead of IDL lookup for templates without an IDL. Selector values and address seed values must not become account fields.
  • Keep scenario registration after the current slot and validate all relative-slot sums before storing any scheduled override.
  • Keep strict snapshot validation aligned with its promise to report missing or invalid requested accounts without synthetic program-data fallback.
  • Keep startup account notifications limited to accounts that are present in the live SVM after hydration.
  • Keep scenario account writes and Geyser notifications aligned so local override state and external observers receive the same update.
  • Keep startup readiness after snapshot and planner work. A ready event allows clients to submit transactions.
  • Keep shutdown connected to storage cleanup and both RPC acknowledgements.

Important failure modes

TriggerConsequenceGuard
A required account is missing in local or offline modeA dependent read, snapshot load, or transaction can failPreload the account or enable a reachable remote source when fallback is required
A local write occurs while a remote fetch is in flightStale source data can replace newer local stateRecheck live state and apply the fill-if-absent rule under the final writer lock
A dependent account is returned from an old fetchThe caller can receive stale program-data or mint dataRebuild dependent results from live SVM state after the merge
A closed account is not marked offlineA later remote lookup can restore state that a local action removedRecord the account as offline when the local account becomes empty
A managed sysvar is written as an ordinary accountThe account view and SVM sysvar cache can disagreeReject writes to the managed sysvar set
Garbage collection drops SlotHistory or another streamed sysvarGeyser block and slot streams can miss the context expected by consumersPreserve the chain sysvars when rebuilding LiteSVM and stream them in the slot lifecycle order
A slot status is sent without its matching slot-update eventGeyser and WebSocket consumers can report different chain stateEmit both views from the same status transition
A bundle commits after live state changesThe bundle can overwrite assumptions from an older viewCompare the sandbox base revision with the live revision, even when the slot did not change
A sandbox emits live events before commitClients observe state that may later be discardedBuffer events and replay them only after state and storage commit
An executable program lacks usable program dataThe loader rejects the program or execution cannot resolve its codeHydrate or generate related program-data state before the program account
Strict snapshot loading cannot install or validate a requested accountSome accounts may be installed but the restore reports failureUse strict mode only when partial installation is acceptable, then inspect the returned error
Startup observers receive a store-only account updateConsumers believe an account is executable or readable when live execution cannot read itPublish startup updates only after checking the live SVM
A raw-layout scenario override follows the IDL-only pathA valid byte-layout change is skipped when no IDL existsResolve raw-layout templates before requiring a registered IDL
A scenario base slot is already produced or a relative slot overflowsThe override never applies or the schedule request failsUse the next unproduced slot and validate every sum before storing the plan
A slot duration changes but maintenance intervals stay fixedCache cleanup or recovery checkpoints occur at the wrong simulated timeDerive the slot intervals from the current slot duration unless an explicit override is set
The datasource restart-slot sysvar is not loaded or is lost during a rebuildRemote-backed programs can use the wrong chain restart boundaryLoad it during remote startup and preserve it through reset, snapshot restore, and garbage collection
A time value grows beyond the supported Unix timestamp rangeBlock or clock data can wrap or become invalidSaturate simulated time before conversion and cap time-travel clock timestamps
A time-travel request targets the largest possible slotThe request is rejected before the chain changesUse a smaller future slot; time travel validates this boundary before dispatch
A startup planner does not seal its planThe network does not become publicly readySeal the declared plan or use the runtime's empty plan
Shutdown times out or skips SVM cleanupPorts can remain bound and persistent writes can remain in the SQLite WALUse the terminate path and treat an unconfirmed shutdown as a failure

Key files

FileWhy to read it
crates/…/svm.rsDefines the local SVM boundary, account update policy, feature setup, chain view, maintenance timing, scenario scheduling, isolated execution, event commit, and slot lifecycle publication. It also controls best-effort versus strict account hydration, preserves remote chain sysvars across rebuilds, and converts simulated time safely for block and clock data.
crates/…/locker.rsShows shared SVM access, local-first account resolution, remote merge rules, offline filtering, snapshot loading modes, commitment-aware reads, scenario scheduling checks, remote startup initialization, and time-travel dispatch.
crates/…/time_travel.rsDefines the shared rules for future time-travel targets, timestamp limits, and the largest-slot boundary.
crates/…/surfnet_lite_svm.rsShows the execution engine, persistent account view, native mint setup, managed-sysvar protection, reset behavior, and preservation of chain sysvars during garbage collection.
crates/…/remote.rsDefines upstream RPC access, its worker-independent datasource runtime, startup chain-context reads, deadlines, safe errors, account batching, transaction error handling, and token-account fallbacks.
crates/…/mod.rsDefines account provenance, dependent-account results, shared event types, and the slot-update subscription contract.
crates/…/mod.rsConnects remote setup, startup readiness, block production, transaction handling, and shutdown.
crates/…/noop_program.rsDefines the minimal program image used while executable program accounts are hydrated.
crates/…/surfnet.rsShows how embedded callers select local or remote mode and manage the service lifecycle.
crates/…/start_surfnet.rsShows headless and command-based startup for MCP callers.
crates/…/types.rsDefines shared local or remote network settings and block production modes.