Skip to content

feat: let localnet fork from a remote datasource - #28

Open
beeman wants to merge 1 commit into
mainfrom
beeman/solana-localnet-datasource-b8a004
Open

feat: let localnet fork from a remote datasource#28
beeman wants to merge 1 commit into
mainfrom
beeman/solana-localnet-datasource-b8a004

Conversation

@beeman

@beeman beeman commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

solana-mobile localnet always started the validator as an empty, isolated chain: the surfpool engine was launched with a hardcoded --offline, and neither engine's datasource flags were reachable through the command. This exposes them.

  • --network devnet|mainnet|testnet forks the validator from a public cluster, and --rpc-url <url> from any RPC endpoint. With surfpool, every account the app touches — programs included, at their original addresses — is fetched from that cluster on first access, and the validator reports the cluster's genesis hash.
  • solana-test-validator does not fetch lazily, so there the datasource is cloned up front: --clone <address> and --clone-upgradeable-program <address> (both repeatable) name what to copy in, and the network id is translated to the mainnet-beta moniker the validator expects. The image's default command is replaced when arguments are passed, so the binary name is repeated in front of the flags.
  • Invalid combinations are rejected with specific messages instead of being silently ignored: both datasource flags at once, clone flags with surfpool (which needs none), and clone flags with no datasource to clone from. Validation runs after the engine is resolved, since the engine may be inherited from a running container rather than passed.
  • The datasource is recorded in a localnet.datasource container label, so localnet status reports it and a later localnet start refuses to reuse a running validator as a datasource it was not started with — the same shape as the existing engine conflict. A matching or omitted datasource reuses cleanly.
  • When localnet attaches to a validator it did not start, it now says that datasource options do not apply rather than pretending they did.

Verification

  • 20 new unit tests: exact argv per engine, validation errors, label round-trip (including | inside an RPC URL), reuse conflicts, the attach caveat, and CLI flag parsing.
  • New integration test boots surfpool with --network devnet and asserts the reported genesis hash is devnet's (EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG) and the label survives a real Docker round trip; verified passing locally.
  • Verified live against both images: forked surfpool lazily served the devnet USDC mint, and solana-test-validator --url devnet --clone <mint> served the cloned account.

Expose the validator engines' datasource support through the localnet
command instead of always starting an empty, offline chain. --network
forks from a public cluster (devnet, mainnet, or testnet) and --rpc-url
from any RPC endpoint; surfpool then fetches every account lazily at its
original address, while --clone and --clone-upgradeable-program name
what the test-validator clones up front, with mainnet translated to the
mainnet-beta moniker it expects. Invalid combinations — both datasource
flags, clone flags with surfpool, clone flags with no datasource — are
rejected after the engine is resolved, since it may be inherited from a
running container. The datasource is recorded in a container label so
status reports it and a later start refuses to reuse a running validator
as a datasource it was not started with; attaching to a validator we did
not start says the options do not apply rather than pretending they did.
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 404b399

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
solana-mobile Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

bun add https://pkg.pr.new/solana-mobile/solana-mobile-cli/solana-mobile@28

commit: 404b399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant