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

proto: migrate x/distr to use hybrid codec #5610

Merged
merged 54 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
dec703b
Migrate staking types to proto
alexanderbez Feb 1, 2020
31311cb
Use int32 for validator status
alexanderbez Feb 3, 2020
0d2938b
Update staking types
alexanderbez Feb 3, 2020
60dc367
Add benchmarks for bech32 pubkey funcs
alexanderbez Feb 3, 2020
f0f6f50
Update BondStatus type alias to int32
alexanderbez Feb 3, 2020
c268a9e
Remove PubKey proto type
alexanderbez Feb 3, 2020
95edc79
Fix unit test
alexanderbez Feb 3, 2020
46be4b4
Update staking keeper
alexanderbez Feb 3, 2020
7503396
Fix staking keeper tests
alexanderbez Feb 3, 2020
97ac0b5
Update query client
alexanderbez Feb 3, 2020
8e84801
Update staking genesis and app_test
alexanderbez Feb 3, 2020
c35939a
Update staking handler
alexanderbez Feb 4, 2020
febaae8
Use Int64Value instead of IntProto
alexanderbez Feb 4, 2020
5b83d9b
Updates tests and APIs
alexanderbez Feb 4, 2020
0a904f1
Fix iteration
alexanderbez Feb 4, 2020
1ee4527
proto: move distr over to proto
tac0turtle Feb 4, 2020
7fb0d34
proto: some more types to proto
tac0turtle Feb 4, 2020
6dc3dd9
fix protolinting
tac0turtle Feb 4, 2020
2450409
Linting
alexanderbez Feb 4, 2020
1ce8248
minor reading, will wait on staking pr to be merged
tac0turtle Feb 4, 2020
97148e2
Fix linting
alexanderbez Feb 4, 2020
da9d51f
Merge branch 'master' into bez/5444-staking-proto-enc
alexanderbez Feb 4, 2020
11a0d8b
Add changelog entry
alexanderbez Feb 4, 2020
db45cfc
Update changelog entry
alexanderbez Feb 4, 2020
c5a7baa
Merge branch 'master' into bez/5444-staking-proto-enc
alexanderbez Feb 4, 2020
6140d37
Merge branch 'bez/5444-staking-proto-enc' into proto/distr
tac0turtle Feb 5, 2020
d0b2786
referencing types
tac0turtle Feb 5, 2020
c68058d
change some types to proto
tac0turtle Feb 5, 2020
37bc9c4
make it build, kinda
tac0turtle Feb 5, 2020
8c2431a
its alive
tac0turtle Feb 6, 2020
bdf9455
fix tests
tac0turtle Feb 6, 2020
ccc799c
move slashevents to proto
tac0turtle Feb 6, 2020
59d8427
bump buf to 0.7
tac0turtle Feb 6, 2020
728ac20
remove here
tac0turtle Feb 6, 2020
677a8f1
Merge branch 'master' into proto/distr
tac0turtle Feb 7, 2020
77b6f1f
add applevelcodec
tac0turtle Feb 7, 2020
41426fa
add make cmd for tendermint proto files update
tac0turtle Feb 7, 2020
789a03d
fix spacing
tac0turtle Feb 7, 2020
a2346d3
add changelog
tac0turtle Feb 7, 2020
3019263
Merge branch 'master' into proto/distr
tac0turtle Feb 7, 2020
fcbe7c3
Fix x/crisis linting
alexanderbez Feb 7, 2020
28591b3
Verify and cleanup proto types
alexanderbez Feb 7, 2020
230829b
Update CHANGELOG.md
alexanderbez Feb 10, 2020
7f2140d
Update x/distribution/keeper/delegation.go
alexanderbez Feb 10, 2020
cad3caf
Update x/distribution/keeper/invariants.go
alexanderbez Feb 10, 2020
7a5ebff
Merge branch 'master' into proto/distr
alexanderbez Feb 10, 2020
ebe0140
Review suggestions/linting
alexanderbez Feb 10, 2020
69f965a
Review suggestions/linting
alexanderbez Feb 10, 2020
d680eac
change json tag of height
tac0turtle Feb 11, 2020
1988305
revet query.go changes
tac0turtle Feb 11, 2020
45159b8
Merge branch 'master' into proto/distr
tac0turtle Feb 11, 2020
0d71b3b
add sed command to third_party tendermint cmds
tac0turtle Feb 11, 2020
6cd4103
Update changelog entry
alexanderbez Feb 11, 2020
970562d
Merge branch 'master' into proto/distr
alexanderbez Feb 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ for JSON encoding.
* Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`.
* The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type
provided is specified by `ModuleCdc`.
* (distr) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffer for state
serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino
for JSON encoding.
* `ValidatorHistoricalRewards.ReferenceCount` is now of types `uint32` instead of `uint16`.
* `ValidatorSlashEvents` is now a struct with `slashevents`.
* `ValidatorOutstandingRewards` is now a struct with `rewards`.
* `ValidatorAccumulatedCommission` is now a struct with `commission`.
* The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type
provided is specified by `ModuleCdc`.

### Improvements

Expand Down
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,25 @@ proto-lint:
proto-check-breaking:
@buf check breaking --against-input '.git#branch=master'

.PHONY: proto-all proto-gen proto-lint proto-check-breaking
# Origin
# TODO: Update to the version of Tendermint that is being used in go.mod
version_branch = v0.33.0
tendermint = https://raw.githubusercontent.com/tendermint/tendermint/$(version_branch)

# Outputs
tmkv = third_party/proto/tendermint/libs/kv/types.proto
tmmerkle = third_party/proto/tendermint/crypto/merkle/merkle.proto
tmabci = third_party/proto/tendermint/abci/types/types.proto

# You *only* need to run this to rebuild protobufs from the tendermint source
proto-update-tendermint:
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
@curl $(tendermint)/abci/types/types.proto > $(tmabci)
sed -i '' '8,9 s|github.com/tendermint|third_party/proto|g' $(tmabci)
sed -i '' '7 s|github.com/gogo/protobuf|third_party/proto|' $(tmabci)
@curl $(tendermint)/libs/kv/types.proto > $(tmkv)
sed -i '' 's|github.com/gogo/protobuf|third_party/proto|' $(tmkv)
@curl $(tendermint)/crypto/merkle/merkle.proto > $(tmmerkle)
sed -i '' '7 s|github.com/gogo/protobuf|third_party/proto|' $(tmmerkle)


.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-update-tendermint
2 changes: 1 addition & 1 deletion contrib/devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ UNAME_M ?= $(shell uname -m)
GOPATH ?= $(shell $(GO) env GOPATH)
GITHUBDIR := $(GOPATH)$(FS)src$(FS)github.com

BUF_VERSION ?= 0.4.0
BUF_VERSION ?= 0.7.0

TOOLS_DESTDIR ?= $(GOPATH)/bin
STATIK = $(TOOLS_DESTDIR)/statik
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func NewSimApp(
app.SupplyKeeper, auth.FeeCollectorName,
)
app.DistrKeeper = distr.NewKeeper(
app.cdc, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper,
appCodec.Distribution, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(),
)
app.SlashingKeeper = slashing.NewKeeper(
Expand Down
9 changes: 6 additions & 3 deletions simapp/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/staking"
)

Expand All @@ -12,15 +13,17 @@ import (
type AppCodec struct {
amino *codec.Codec

Staking *staking.Codec
Staking *staking.Codec
Distribution *distr.Codec
}

func NewAppCodec() *AppCodec {
amino := MakeCodec()

return &AppCodec{
amino: amino,
Staking: staking.NewCodec(amino),
amino: amino,
Staking: staking.NewCodec(amino),
Distribution: distr.NewCodec(amino),
}
}

Expand Down
3 changes: 1 addition & 2 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str

// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {

// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewards(ctx, val.GetOperator())
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)
Expand Down
126 changes: 60 additions & 66 deletions third_party/proto/tendermint/abci/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.goproto_registration) = true;

// Generate tests
option (gogoproto.populate_all) = true;
option (gogoproto.equal_all) = true;
Expand All @@ -43,9 +42,12 @@ message Request {
}
}

message RequestEcho { string message = 1; }
message RequestEcho {
string message = 1;
}

message RequestFlush {}
message RequestFlush {
}

message RequestInfo {
string version = 1;
Expand All @@ -60,11 +62,10 @@ message RequestSetOption {
}

message RequestInitChain {
google.protobuf.Timestamp time = 1
Copy link
Member Author

Choose a reason for hiding this comment

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

fixed a lot of these here: tendermint/tendermint#4386 this will be in the next release. The release will be coming in the coming days

[ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ];
google.protobuf.Timestamp time = 1 [(gogoproto.nullable)=false, (gogoproto.stdtime)=true];
string chain_id = 2;
ConsensusParams consensus_params = 3;
repeated ValidatorUpdate validators = 4 [ (gogoproto.nullable) = false ];
repeated ValidatorUpdate validators = 4 [(gogoproto.nullable)=false];
bytes app_state_bytes = 5;
}

Expand All @@ -77,9 +78,9 @@ message RequestQuery {

message RequestBeginBlock {
bytes hash = 1;
Header header = 2 [ (gogoproto.nullable) = false ];
LastCommitInfo last_commit_info = 3 [ (gogoproto.nullable) = false ];
repeated Evidence byzantine_validators = 4 [ (gogoproto.nullable) = false ];
Header header = 2 [(gogoproto.nullable)=false];
LastCommitInfo last_commit_info = 3 [(gogoproto.nullable)=false];
repeated Evidence byzantine_validators = 4 [(gogoproto.nullable)=false];
}

enum CheckTxType {
Expand All @@ -92,11 +93,16 @@ message RequestCheckTx {
CheckTxType type = 2;
}

message RequestDeliverTx { bytes tx = 1; }
message RequestDeliverTx {
bytes tx = 1;
}

message RequestEndBlock { int64 height = 1; }
message RequestEndBlock {
int64 height = 1;
}

message RequestCommit {}
message RequestCommit {
}

//----------------------------------------
// Response types
Expand All @@ -119,11 +125,16 @@ message Response {
}

// nondeterministic
message ResponseException { string error = 1; }
message ResponseException {
string error = 1;
}

message ResponseEcho { string message = 1; }
message ResponseEcho {
string message = 1;
}

message ResponseFlush {}
message ResponseFlush {
}

message ResponseInfo {
string data = 1;
Expand All @@ -145,13 +156,13 @@ message ResponseSetOption {

message ResponseInitChain {
ConsensusParams consensus_params = 1;
repeated ValidatorUpdate validators = 2 [ (gogoproto.nullable) = false ];
repeated ValidatorUpdate validators = 2 [(gogoproto.nullable)=false];
}

message ResponseQuery {
uint32 code = 1;
// bytes data = 2; // use "value" instead.
string log = 3; // nondeterministic
string log = 3; // nondeterministic
string info = 4; // nondeterministic
int64 index = 5;
bytes key = 6;
Expand All @@ -162,48 +173,35 @@ message ResponseQuery {
}

message ResponseBeginBlock {
repeated Event events = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "events,omitempty"
];
repeated Event events = 1 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"];
}

message ResponseCheckTx {
uint32 code = 1;
bytes data = 2;
string log = 3; // nondeterministic
string log = 3; // nondeterministic
string info = 4; // nondeterministic
int64 gas_wanted = 5;
int64 gas_wanted = 5;
int64 gas_used = 6;
repeated Event events = 7 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "events,omitempty"
];
repeated Event events = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"];
string codespace = 8;
}

message ResponseDeliverTx {
uint32 code = 1;
bytes data = 2;
string log = 3; // nondeterministic
string log = 3; // nondeterministic
string info = 4; // nondeterministic
int64 gas_wanted = 5;
int64 gas_used = 6;
repeated Event events = 7 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "events,omitempty"
];
repeated Event events = 7 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"];
string codespace = 8;
}

message ResponseEndBlock {
repeated ValidatorUpdate validator_updates = 1
[ (gogoproto.nullable) = false ];
repeated ValidatorUpdate validator_updates = 1 [(gogoproto.nullable)=false];
ConsensusParams consensus_param_updates = 2;
repeated Event events = 3 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "events,omitempty"
];
repeated Event events = 3 [(gogoproto.nullable)=false, (gogoproto.jsontag)="events,omitempty"];
}

message ResponseCommit {
Expand Down Expand Up @@ -233,51 +231,47 @@ message BlockParams {
message EvidenceParams {
// Note: must be greater than 0
int64 max_age_num_blocks = 1;
google.protobuf.Duration max_age_duration = 2
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
google.protobuf.Duration max_age_duration = 2 [(gogoproto.nullable)=false, (gogoproto.stdduration)=true];
}

// ValidatorParams contains limits on validators.
message ValidatorParams { repeated string pub_key_types = 1; }
message ValidatorParams {
repeated string pub_key_types = 1;
}

message LastCommitInfo {
int32 round = 1;
repeated VoteInfo votes = 2 [ (gogoproto.nullable) = false ];
repeated VoteInfo votes = 2 [(gogoproto.nullable)=false];
}

message Event {
string type = 1;
repeated tendermint.libs.kv.Pair attributes = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "attributes,omitempty"
];
repeated tendermint.libs.kv.Pair attributes = 2 [(gogoproto.nullable)=false, (gogoproto.jsontag)="attributes,omitempty"];
}

//----------------------------------------
// Blockchain Types

message Header {
// basic block info
Version version = 1 [ (gogoproto.nullable) = false ];
string chain_id = 2 [ (gogoproto.customname) = "ChainID" ];
Version version = 1 [(gogoproto.nullable)=false];
string chain_id = 2 [(gogoproto.customname)="ChainID"];
int64 height = 3;
google.protobuf.Timestamp time = 4
[ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ];
google.protobuf.Timestamp time = 4 [(gogoproto.nullable)=false, (gogoproto.stdtime)=true];

// prev block info
BlockID last_block_id = 5 [ (gogoproto.nullable) = false ];
BlockID last_block_id = 5 [(gogoproto.nullable)=false];

// hashes of block data
bytes last_commit_hash = 6; // commit from validators from the last block
bytes data_hash = 7; // transactions

// hashes from the app output from the prev block
bytes validators_hash = 8; // validators for the current block
bytes next_validators_hash = 9; // validators for the next block
bytes consensus_hash = 10; // consensus params for current block
bytes app_hash = 11; // state after txs from the previous block
bytes last_results_hash =
12; // root hash of all results from the txs from the previous block
bytes validators_hash = 8; // validators for the current block
bytes next_validators_hash = 9; // validators for the next block
bytes consensus_hash = 10; // consensus params for current block
bytes app_hash = 11; // state after txs from the previous block
bytes last_results_hash = 12;// root hash of all results from the txs from the previous block

// consensus info
bytes evidence_hash = 13; // evidence included in the block
Expand All @@ -289,9 +283,10 @@ message Version {
uint64 App = 2;
}


message BlockID {
bytes hash = 1;
PartSetHeader parts_header = 2 [ (gogoproto.nullable) = false ];
PartSetHeader parts_header = 2 [(gogoproto.nullable)=false];
}

message PartSetHeader {
Expand All @@ -302,41 +297,40 @@ message PartSetHeader {
// Validator
message Validator {
bytes address = 1;
// PubKey pub_key = 2 [(gogoproto.nullable)=false];
//PubKey pub_key = 2 [(gogoproto.nullable)=false];
int64 power = 3;
}

// ValidatorUpdate
message ValidatorUpdate {
PubKey pub_key = 1 [ (gogoproto.nullable) = false ];
PubKey pub_key = 1 [(gogoproto.nullable)=false];
int64 power = 2;
}

// VoteInfo
message VoteInfo {
Validator validator = 1 [ (gogoproto.nullable) = false ];
Validator validator = 1 [(gogoproto.nullable)=false];
bool signed_last_block = 2;
}

message PubKey {
string type = 1;
bytes data = 2;
bytes data = 2;
}

message Evidence {
string type = 1;
Validator validator = 2 [ (gogoproto.nullable) = false ];
Validator validator = 2 [(gogoproto.nullable)=false];
int64 height = 3;
google.protobuf.Timestamp time = 4
[ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ];
google.protobuf.Timestamp time = 4 [(gogoproto.nullable)=false, (gogoproto.stdtime)=true];
int64 total_voting_power = 5;
}

//----------------------------------------
// Service Definition

service ABCIApplication {
rpc Echo(RequestEcho) returns (ResponseEcho);
rpc Echo(RequestEcho) returns (ResponseEcho) ;
rpc Flush(RequestFlush) returns (ResponseFlush);
rpc Info(RequestInfo) returns (ResponseInfo);
rpc SetOption(RequestSetOption) returns (ResponseSetOption);
Expand Down
Loading