Skip to content

Conversation

@EricGrill
Copy link

Summary

  • Fixes infinite recursion in StringOrArray.MarshalJSON by converting to underlying []string type before marshaling
  • Adds Warnings field to GetBlockChainInfoResult using StringOrArray type

Background

The StringOrArray.MarshalJSON method was calling json.Marshal(h) which caused infinite recursion because Go sees that h implements json.Marshaler and calls MarshalJSON() again.

Bitcoin Core added a warnings field to getblockchaininfo in PR #10858, and recently changed it from a string to an array in PR #29845. Using StringOrArray handles both formats.

Test plan

  • StringOrArray.MarshalJSON no longer causes stack overflow
  • GetBlockChainInfoResult can unmarshal warnings as string or array

Closes #2369
Closes #2444

🤖 Generated with Claude Code

EricGrill and others added 2 commits January 14, 2026 20:19
The MarshalJSON method was calling json.Marshal(h) where h is of type
StringOrArray. Since StringOrArray implements json.Marshaler, this
caused json.Marshal to call MarshalJSON again, resulting in infinite
recursion and a stack overflow.

Fix by converting to the underlying []string type before marshaling,
which breaks the interface lookup cycle.

Closes btcsuite#2369

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Bitcoin Core added a warnings field to getblockchaininfo in PR #10858,
and recently changed it from a string to an array in PR #29845. Add
the field using StringOrArray type to handle both formats.

This allows rpcclient to properly unmarshal getblockchaininfo responses
from all Bitcoin Core versions.

Closes btcsuite#2444

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

[bug]: type mismatch at response of 'GetBlockChainInfo' [bug]: StringOrArray.MarshalJSON triggers infinite recursion → stack-overflow panic

1 participant