Skip to content

fix(ws): use spec "showRewards" key in blockSubscribe params#430

Open
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:fix/ws-block-subscribe-show-rewards
Open

fix(ws): use spec "showRewards" key in blockSubscribe params#430
ozpool wants to merge 1 commit into
solana-foundation:mainfrom
ozpool:fix/ws-block-subscribe-show-rewards

Conversation

@ozpool
Copy link
Copy Markdown

@ozpool ozpool commented May 13, 2026

Closes #208.

Bug

BlockSubscribe and ParsedBlockSubscribe build the params object with the wrong field name:

if opts.Rewards != nil {
    obj["rewards"] = opts.Rewards
}

The Solana websocket spec for blockSubscribe calls this field showRewards, not rewards. The validator silently ignores the unknown rewards key, which means setting BlockSubscribeOpts.Rewards = &false has no effect today — rewards are always populated on the wire. The original report in #208 (open since 2024-05) cites the spec and notes there is no workaround.

Note: this is not the same as the HTTP getBlock RPC, where rewards is the correct field name per its own spec — only the websocket variant differs. rpc/getBlock.go is left untouched.

Fix

  • rpc/ws/blockSubscribe.go: emit showRewards instead of rewards.
  • rpc/ws/parsedBlockSubscribe.go: same fix in the parsed variant (PR Subscribe block #203 copied the buggy name).

Tests

rpc/ws/blockSubscribe_rewards_test.go (new), using the in-tree mockWSServer to intercept the subscribe request and assert the params shape:

  • TestBlockSubscribeUsesShowRewardsField — pins that BlockSubscribe emits showRewards: false (and never rewards) when Rewards = &false.
  • TestParsedBlockSubscribeUsesShowRewardsField — same for the parsed path with Rewards = &true.
$ go test -count=1 ./rpc/ws/... ./rpc/
ok   github.com/gagliardetto/solana-go/rpc/ws   0.313s
ok   github.com/gagliardetto/solana-go/rpc      0.596s

Diff size

 rpc/ws/blockSubscribe.go               | +1 -1
 rpc/ws/parsedBlockSubscribe.go         | +1 -1
 rpc/ws/blockSubscribe_rewards_test.go  | +107   (new)

The blockSubscribe / parsedBlockSubscribe params object was emitting
`rewards` for the rewards-toggle field, but the Solana spec uses
`showRewards`. The validator silently ignored the unknown `rewards`
key, which meant Rewards=false (or true) had no effect — rewards
were always populated.

Change both BlockSubscribe and ParsedBlockSubscribe to emit
`showRewards`, matching the spec at:
https://solana.com/docs/rpc/websocket/blocksubscribe

Note: the HTTP getBlock RPC continues to use `rewards` — that name
is correct per its own spec, only the websocket variant differs.

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

ws blocksubscribe - does extract rewords

1 participant