Skip to content

feat(rpc): forward MinContextSlot in getProgramAccounts and getTokenAccounts#431

Open
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:feat/min-context-slot-parity
Open

feat(rpc): forward MinContextSlot in getProgramAccounts and getTokenAccounts#431
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:feat/min-context-slot-parity

Conversation

@ozpool
Copy link
Copy Markdown

@ozpool ozpool commented May 13, 2026

Follow-up to #245.

Gap

The Solana RPC spec lists minContextSlot as an optional param on getProgramAccounts, getTokenAccountsByOwner, and getTokenAccountsByDelegate, but the Go bindings drop it on the floor — there is no way to pin these reads to a minimum slot.

Without it, callers on lagging RPC nodes can read state from a slot older than what they have already observed downstream, which breaks read-your-own-writes and slot-pinned pagination flows. The other account-reading methods (getAccountInfo, getMultipleAccounts, getSignaturesForAddress, simulateTransaction) already accept the field — this PR closes the parity gap.

Change

Purely additive — the pattern matches #245 (GetMultipleAccountsWithOpts):

  • GetProgramAccountsOpts.MinContextSlot *uint64 (forwarded in buildGetProgramAccountsParams)
  • GetTokenAccountsOpts.MinContextSlot *uint64 (forwarded in both GetTokenAccountsByOwner and GetTokenAccountsByDelegate)

The opts structs are public and additive; no existing call sites need changes. When MinContextSlot is nil, the wire shape is byte-identical to before.

Tests

rpc/getMinContextSlot_test.go (new) — three tests using the in-tree mockJSONRPC harness pin the exact params wire shape for each method:

  • TestClient_GetProgramAccountsWithOpts_MinContextSlot
  • TestClient_GetTokenAccountsByOwner_MinContextSlot
  • TestClient_GetTokenAccountsByDelegate_MinContextSlot
$ go test -count=1 ./...
ok   github.com/gagliardetto/solana-go             0.553s
ok   github.com/gagliardetto/solana-go/rpc         1.537s
ok   github.com/gagliardetto/solana-go/rpc/ws      1.483s
... (all packages pass)

Diff size

 rpc/types.go                       | +3
 rpc/getProgramAccounts.go          | +3
 rpc/getTokenAccountsByDelegate.go  | +6
 rpc/getTokenAccountsByOwner.go     | +3
 rpc/getMinContextSlot_test.go      | +138   (new)

…ccounts

Three Solana RPC methods accept an optional `minContextSlot` per the
spec but the Go bindings dropped it on the floor:

- getProgramAccounts          (via GetProgramAccountsOpts)
- getTokenAccountsByOwner     (via GetTokenAccountsOpts)
- getTokenAccountsByDelegate  (via GetTokenAccountsOpts)

Without `minContextSlot`, callers on lagging RPC nodes can read
state from a slot older than what they have already observed,
which breaks read-your-own-writes and slot-pinned pagination flows.

Follow-up to solana-foundation#245, which added the same field to
GetMultipleAccountsWithOpts. Pattern is identical: a new
`MinContextSlot *uint64` on the existing opts struct, forwarded
into the params object only when non-nil. Purely additive.

Tests pin the wire shape for each of the three methods using
the existing mockJSONRPC harness.
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