Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favor bare binary-marshalling over length prefixed-marshalling #5799

Merged
merged 34 commits into from
Mar 13, 2020

Conversation

jgimeno
Copy link
Contributor

@jgimeno jgimeno commented Mar 12, 2020

Closes: #5748

Description


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Mar 12, 2020

Codecov Report

Merging #5799 into master will not change coverage by %.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #5799   +/-   ##
=======================================
  Coverage   36.03%   36.03%           
=======================================
  Files         342      342           
  Lines       34782    34782           
=======================================
  Hits        12534    12534           
  Misses      20998    20998           
  Partials     1250     1250           

@jgimeno jgimeno added the T: State Machine Breaking State machine breaking changes (impacts consensus). label Mar 13, 2020
@jgimeno jgimeno marked this pull request as ready for review March 13, 2020 16:43
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @jgimeno ☕️

Might be worth it to have another quick sign off from @cwgoes or @ValarDragon :)

CHANGELOG.md Outdated Show resolved Hide resolved
@alexanderbez alexanderbez added A:automerge Automatically merge PR once all prerequisites pass. C:Encoding labels Mar 13, 2020
Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -148,6 +148,7 @@ Buffers for state serialization instead of Amino.
to define their own concrete `MsgSubmitProposal` types.
* The module now accepts a `Codec` interface which extends the `codec.Marshaler` interface by
requiring a concrete codec to know how to serialize `Proposal` types.
* (codec) [\#5799](https://github.com/cosmos/cosmos-sdk/pull/5799) Now we favor the use of MarshalBinaryBare instead of LengthPrefixed in all cases that is not needed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* (codec) [\#5799](https://github.com/cosmos/cosmos-sdk/pull/5799) Now we favor the use of MarshalBinaryBare instead of LengthPrefixed in all cases that is not needed.
* (codec) [\#5799](https://github.com/cosmos/cosmos-sdk/pull/5799) Now we favor the use of `(Un)MarshalBinaryBare` instead of `(Un)MarshalBinaryLengthPrefixed` in all cases that are not needed.

@mergify mergify bot merged commit 2e42f9c into master Mar 13, 2020
@mergify mergify bot deleted the jonathan/5748-marshal-unmashal-binare-bare branch March 13, 2020 19:58
@alessio
Copy link
Contributor

alessio commented Mar 14, 2020

This brings a potentially massive ABI breaking change for clients, and as such it should be mentioned in the CHANGELOG. @jgimeno gaia's build is broken due to this PR, feel free to poke me when you spare some time, I'm happy to provide assistance and try to fix it together

@alexanderbez
Copy link
Contributor

alexanderbez commented Mar 15, 2020

How so? I think the proper message was added to changelog. For any client dealing with raw amino binary encoding, the given entry should be clear enough.

That being said, @jgimeno can you update Gaia to the SDK's latest master by any chance?

@alessio
Copy link
Contributor

alessio commented Mar 15, 2020

Whether a change introduces ABI/client breakages can be determined with a simple test: do gaia cli_tests require change? If the answer yes, then clients will receive a different response than they used to and the changeset breaks ABI.

Don't get me wrong, the CHANGELOG line per se` looks good to me, I'm arguing that this change should be mentioned among the breaking ones as well so that clients will be informed.

@alexanderbez
Copy link
Contributor

do gaia cli_tests require change? If the answer yes, then clients will receive a different response than they used to and the changeset breaks ABI.

Not necessarily. CLI/REST work in JSON, not binary. The test suite could easily fail if we're doing manual binary encoding/decoding, which I 100% bet is the case.

@jgimeno
Copy link
Contributor Author

jgimeno commented Mar 16, 2020

Yeah, there were only 2 cases that checked manually the encoding of a transaction.

The other failure were due to the changes we did for the proposal json encoding for amounts.

cosmos/gaia#323

@alessio
Copy link
Contributor

alessio commented Mar 16, 2020

Whether an interface is part of a program's ABI or API does not depend on encoding. It has nothing to do with encoding. Any interface between two binary programs is an ABI, e.g. HTTP server and client such as gaiacli rest-server and an HTTP REST-ful client. When an endpoint's JSON response's schema changes, that is an ABI breakage by definition - regardless of the encoding.
The other end just sees a different schema and may not be able to interpret it without external intervention, such as recompilation.
Same goes for command line programs. Their expected inputs and produced outputs are the ABI, why? Because on the other end there may be (quite certainly there are) automated clients that pilot the execution of the binary by supplying input and parsing outputs. If expected inputs or outputs schemas change, then the clients would quite surely require external intervention, such as recompilation.

@alexanderbez
Copy link
Contributor

Right, I get that. I'm still not following you on what broke here WRT to ABI. We went from length-prefixing to non-length-prefixing. Clients in this model are only the servers (apps) which will understand how to talk to each other. Older clients won't and that is precisely what was stated in the changelog.

@@ -124,7 +124,7 @@ func (kb baseKeybase) DecodeSignature(info Info, msg []byte) (sig []byte, pub tm
return nil, nil, err
}

if err := CryptoCdc.UnmarshalBinaryLengthPrefixed([]byte(signed), sig); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @jgimeno, I skimmed through and didn't realize you also updated the Keybase. The Keybase should not be updated because than that will break existing local wallets. Let's undo these.

@@ -337,12 +337,12 @@ func (i multiInfo) GetPath() (*hd.BIP44Params, error) {

// encoding info
func marshalInfo(i Info) []byte {
return CryptoCdc.MustMarshalBinaryLengthPrefixed(i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// decoding info
func unmarshalInfo(bz []byte) (info Info, err error) {
err = CryptoCdc.UnmarshalBinaryLengthPrefixed(bz, &info)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alessio alessio changed the title Favor marshal unmashal binare bare Favor bare binary-marshalling over length prefixed-marshalling Oct 1, 2020
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* change abci file to use BinaryBare

* change all calls to EncodeLengthPrefixed to BinaryBare in distribution keeper store.

* change all calls to EncodeLengthPrefixed to BinaryBare in mint keeper store.

* change all calls to EncodeLengthPrefixed to BinaryBare in auth keeper store.

* change all calls to EncodeLengthPrefixed to BinaryBare in distribution keeper store.

* change all calls to EncodeLengthPrefixed to BinaryBare in staking keeper store.

* change all calls to EncodeLengthPrefixed to BinaryBare in staking keeper store.

* change all calls to EncodeLengthPrefixed to BinaryBare in gov keeper store.

* change all calls to EncodeLengthPrefixed to BinaryBare in slashing keeper store.

* update decoder test

* migrate decoder

* migrate gov simulation decoder

* migrate baseapp_test

* refactor QuerySubspace

* refactor coedc std codec

* migrate keybase

* migrate iavl store

* migrate root multi

* migrate ante basic

* migrate tx type to bare

* migrate auth client

* update auth types

* update decoder

* migrate supply decoder

* migrate stake encoding

* migrate staking simulation

* migrate genutil

* migrate simapp test helpers

* migrate docs

* upgrade changelog

* Update CHANGELOG.md

Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:Encoding T: State Machine Breaking State machine breaking changes (impacts consensus).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Favor Marshal/Unmarshal BinaryBare over Length-Prefixing
4 participants