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

Migrate x/staking to Protobuf #5600

Merged
merged 26 commits into from
Feb 6, 2020
Merged

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Feb 1, 2020

Migrate x/staking to protocol buffer encoding:

  • Update third_party/ to include Tendermint dependencies
  • Update BondStatus from byte to int32
  • Update params to use int32 instead of int16
  • Use string to represent validator public key
  • Remove a lot of JSON/YAML encoding cruft for the Validator type

Components that still use Amino:

  • Client (CLI/REST) for JSON
  • Genesis state for JSON
  • Message signing
  • Querier

ref: #5444


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)

@alexanderbez alexanderbez added C:x/staking WIP T: State Machine Breaking State machine breaking changes (impacts consensus). labels Feb 1, 2020
x/staking/keeper/query_utils.go Outdated Show resolved Hide resolved
x/staking/types/delegation.go Outdated Show resolved Hide resolved
@alexanderbez alexanderbez added R4R and removed WIP labels Feb 4, 2020
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

@@ -9,6 +9,7 @@ require (
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
github.com/golang/protobuf v1.3.2
Copy link
Member

@aaronc aaronc Feb 5, 2020

Choose a reason for hiding this comment

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

Why is golang/protobuf required? This likely means there's a directive needed to make a golang/protobuf type point to a gogo/protobuf type.

Copy link
Contributor Author

@alexanderbez alexanderbez Feb 5, 2020

Choose a reason for hiding this comment

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

Because of our dependency on

import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

e.g.

message Commission {
  option (gogoproto.equal) = true;
  option (gogoproto.goproto_stringer) = false;

  // ...
  google.protobuf.Timestamp update_time = 2 [
    (gogoproto.nullable) = false,
    (gogoproto.stdtime) = true,
    (gogoproto.moretags) = "yaml:\"update_time\""
  ];
}

In addition, gogo proto itself depends on google/protobuf. Does gogo proto itself provide these? If so, what advantage is there with one over the other?

Copy link
Member

Choose a reason for hiding this comment

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

You need this in protocgen.sh:

protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/gogo/protobuf/protobuf --{binary}_out=\
Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:. \
myproto.proto

See https://github.com/gogo/protobuf#more-speed-and-more-generated-code

simapp/app.go Outdated
@@ -180,7 +180,7 @@ func NewSimApp(
app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
)
stakingKeeper := staking.NewKeeper(
app.cdc, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
staking.ModuleCdc, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
Copy link
Member

Choose a reason for hiding this comment

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

Why is the ModuleCdc being used here? I thought we were trying to deprecate those anyway, and wouldn't the app codec necessarily include everything ModuleCdc has?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, eventually in the app constructor we will pass a singular codec that fulfills all the module interfaces. However, we can't really do this until we wrap up all the modules.

I suppose I can start that groundwork here (singular codec) 👍 .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've created AppCodec. Please review. Is this in line with what you had in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, makes sense from what I've seen so far.

@@ -77,7 +77,12 @@ $ %s query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhff
return fmt.Errorf("no validator found with address %s", addr)
}

return cliCtx.PrintOutput(types.MustUnmarshalValidator(cdc, res))
validator, err := types.UnmarshalValidator(types.ModuleCdc, res)
Copy link
Member

Choose a reason for hiding this comment

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

Is the idea here to more generally move away from panicking? I think that makes sense esp for CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, we should never panic in client code. There are remnants of Must* and I've been migrating that as I go.

I would totally appreciate it if you do the same in your PRs 👍

Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -180,7 +172,7 @@ func NewSimApp(
app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
)
stakingKeeper := staking.NewKeeper(
app.cdc, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
appCodec.Staking, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
Copy link
Member

Choose a reason for hiding this comment

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

Okay, I get it now. Would keepers also receive a Marshaler instance? Would AppCodec include Marshaler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would keepers also receive a Marshaler instance?

Yes! Unless they need a custom interface like x/auth that needs to know how to decode its custom types.

@codecov
Copy link

codecov bot commented Feb 6, 2020

Codecov Report

Merging #5600 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5600      +/-   ##
==========================================
- Coverage   44.54%   44.54%   -0.01%     
==========================================
  Files         324      324              
  Lines       24670    24672       +2     
==========================================
  Hits        10990    10990              
- Misses      12623    12625       +2     
  Partials     1057     1057
Impacted Files Coverage Δ
client/context/query.go 1.86% <0%> (-0.04%) ⬇️

@tac0turtle
Copy link
Member

do we want to generate the .pb_test.go files when we generate the files, would help with not killing codecov

@aaronc
Copy link
Member

aaronc commented Feb 6, 2020

do we want to generate the .pb_test.go files when we generate the files, would help with not killing codecov

Sounds like a good idea. I can enable it globally in the cosmos-proto shim. For now we can use testgen_all.

@tac0turtle
Copy link
Member

tac0turtle commented Feb 6, 2020

we would have to enable populate_all along side it. might be better to just ignore *.pb.go files. unless people want it

@alexanderbez alexanderbez merged commit 53bf227 into master Feb 6, 2020
@alexanderbez alexanderbez deleted the bez/5444-staking-proto-enc branch February 6, 2020 19:21
@alexanderbez alexanderbez mentioned this pull request Feb 11, 2020
28 tasks
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/staking T: State Machine Breaking State machine breaking changes (impacts consensus).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants