Skip to content

fix(ws): reject EncodingJSONParsed in BlockSubscribe#426

Open
ozpool wants to merge 1 commit intosolana-foundation:mainfrom
ozpool:fix/blocksubscribe-reject-jsonparsed-291
Open

fix(ws): reject EncodingJSONParsed in BlockSubscribe#426
ozpool wants to merge 1 commit intosolana-foundation:mainfrom
ozpool:fix/blocksubscribe-reject-jsonparsed-291

Conversation

@ozpool
Copy link
Copy Markdown

@ozpool ozpool commented Apr 30, 2026

Closes #291.

Bug

BlockSubscribe currently lists solana.EncodingJSONParsed as a valid value for opts.Encoding, but BlockResult embeds *rpc.GetBlockResult — the non-parsed transaction layout. When a caller passes EncodingJSONParsed the request goes out fine and only fails on the first notification:

unable to decode client response:
ws.BlockResult.Value: Block: rpc.GetBlockResult.Transactions ...

The repro from the linked issue reproduces this verbatim.

Fix

A sibling Client.ParsedBlockSubscribe already exists for the parsed case and uses *rpc.GetParsedBlockResult, so the right move is to fail fast when EncodingJSONParsed is requested through BlockSubscribe and steer the caller at the correct helper.

  • Drop solana.EncodingJSONParsed from the IsAnyOfEncodingType allow-list in BlockSubscribe (keeping the // TODO line for EncodingJSON untouched — that gap is a separate piece of work).
  • Add an explicit check above the generic check that returns a targeted error mentioning ParsedBlockSubscribe, so the user immediately sees what to do.
  • Update the BlockSubscribeOpts.Encoding doc to enumerate the supported encodings and steer parsed-output users at ParsedBlockSubscribe.

Tests

rpc/ws/blockSubscribe_test.go (new):

  • TestBlockSubscribeRejectsJSONParsedEncoding — asserts the new rejection path fires and the error mentions ParsedBlockSubscribe.
  • TestBlockSubscribeRejectsUnsupportedEncoding — pins the existing rejection path for arbitrary garbage.

Both tests use a zero-value Client{} so they don't need a live websocket.

$ go test -count=1 ./rpc/ws/... ./rpc/
ok   github.com/gagliardetto/solana-go/rpc/ws   0.341s
ok   github.com/gagliardetto/solana-go/rpc      0.513s

Diff size

 rpc/ws/blockSubscribe.go      | +17 -2
 rpc/ws/blockSubscribe_test.go | +51   (new)

BlockSubscribe currently lists EncodingJSONParsed as a valid value for
opts.Encoding, but BlockResult is shaped for the non-parsed transaction
layout (it embeds *rpc.GetBlockResult). When a caller passes
EncodingJSONParsed the request goes out fine and only fails on the
first notification with:

    unable to decode client response:
    ws.BlockResult.Value: Block: rpc.GetBlockResult.Transactions ...

A sibling Client.ParsedBlockSubscribe already exists for the parsed
case and uses *rpc.GetParsedBlockResult, so the fix is to fail fast
when EncodingJSONParsed is requested through BlockSubscribe and
direct the caller at the right helper.

  - Drop EncodingJSONParsed from the IsAnyOfEncodingType allow-list.
  - Add an explicit check above the generic check that returns a
    targeted error mentioning ParsedBlockSubscribe.
  - Update the BlockSubscribeOpts doc to document supported encodings
    and steer parsed-output users at ParsedBlockSubscribe.
  - Add unit tests for both the new rejection path and the existing
    "unsupported encoding" rejection. Tests use a zero-value Client
    so they do not require a live websocket.

Closes solana-foundation#291.
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.

BlockSubscribe error :unable to decode client response

1 participant