feat: add binary codec with backward-compatible migration#5419
Open
martinconic wants to merge 2 commits intomasterfrom
Open
feat: add binary codec with backward-compatible migration#5419martinconic wants to merge 2 commits intomasterfrom
martinconic wants to merge 2 commits intomasterfrom
Conversation
acud
requested changes
Apr 2, 2026
| t.Parallel() | ||
|
|
||
| val := big.NewInt(555000) | ||
| legacyData, err := val.GobEncode() |
Contributor
There was a problem hiding this comment.
why not test full circle the MarshalBinary part too?
| if len(data) == 0 { | ||
| return nil | ||
| } | ||
| if i.Int == nil { |
Contributor
There was a problem hiding this comment.
i think this should always be true
| } | ||
| if data[0] == '"' { | ||
| // quoted decimal string: e.g. "123" — from bigint.BigInt JSON marshaling | ||
| return json.Unmarshal(data, i) |
Contributor
There was a problem hiding this comment.
we are straight away adding technical debt with this. the state store supports migrations. why not just migrate the balance values all at once and get it over with?
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.
Checklist
Description
MarshalBinary/UnmarshalBinarytobigint.BigInt, using compactGob encoding instead of the JSON fallback that
*big.Intpreviouslytriggered in the statestore
store.Put/store.Getcalls inaccountingandchequebook(totalIssued) to usebigint.BigIntexplicitlycode stored
*big.Intas an unquoted JSON decimal (e.g.123);UnmarshalBinarynow handles all three on-disk formats —Gob (new), unquoted decimal (old
*big.Int), quoted string (oldbigint.BigIntJSON)Why
The statestore serializes values via
encoding.BinaryMarshalerifavailable, otherwise falls back to
json.Marshal. Since*big.Intdoesnot implement
BinaryMarshaler, balance values were previously stored asunquoted JSON numbers. This change introduces a proper binary codec that
is ~2x more compact for large integers and decouples balance storage from
JSON encoding, while remaining fully backward compatible with existing
stored data.
Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):
AI Disclosure