-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) 👍 .
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 Report
@@ 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
|
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 |
we would have to enable populate_all along side it. might be better to just ignore *.pb.go files. unless people want it |
Migrate
x/staking
to protocol buffer encoding:third_party/
to include Tendermint dependenciesBondStatus
frombyte
toint32
int32
instead ofint16
string
to represent validator public keyValidator
typeComponents that still use Amino:
ref: #5444
For contributor use:
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerFor admin use:
WIP
,R4R
,docs
, etc)