fix(ws): reject EncodingJSONParsed in BlockSubscribe#426
Open
ozpool wants to merge 1 commit intosolana-foundation:mainfrom
Open
fix(ws): reject EncodingJSONParsed in BlockSubscribe#426ozpool wants to merge 1 commit intosolana-foundation:mainfrom
ozpool wants to merge 1 commit intosolana-foundation:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #291.
Bug
BlockSubscribecurrently listssolana.EncodingJSONParsedas a valid value foropts.Encoding, butBlockResultembeds*rpc.GetBlockResult— the non-parsed transaction layout. When a caller passesEncodingJSONParsedthe request goes out fine and only fails on the first notification:The repro from the linked issue reproduces this verbatim.
Fix
A sibling
Client.ParsedBlockSubscribealready exists for the parsed case and uses*rpc.GetParsedBlockResult, so the right move is to fail fast whenEncodingJSONParsedis requested throughBlockSubscribeand steer the caller at the correct helper.solana.EncodingJSONParsedfrom theIsAnyOfEncodingTypeallow-list inBlockSubscribe(keeping the// TODOline forEncodingJSONuntouched — that gap is a separate piece of work).ParsedBlockSubscribe, so the user immediately sees what to do.BlockSubscribeOpts.Encodingdoc to enumerate the supported encodings and steer parsed-output users atParsedBlockSubscribe.Tests
rpc/ws/blockSubscribe_test.go(new):TestBlockSubscribeRejectsJSONParsedEncoding— asserts the new rejection path fires and the error mentionsParsedBlockSubscribe.TestBlockSubscribeRejectsUnsupportedEncoding— pins the existing rejection path for arbitrary garbage.Both tests use a zero-value
Client{}so they don't need a live websocket.Diff size