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 40 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ 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.
* `ValidatorSlashEvents` is now a struct with `slashevents `.
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
* `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
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,23 @@ 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
# When running this command you will have to update the proto files with third_party imports instead of what is copied
@curl $(tendermint)/abci/types/types.proto > $(tmabci)
@curl $(tendermint)/libs/kv/types.proto > $(tmkv)
@curl $(tendermint)/crypto/merkle/merkle.proto > $(tmmerkle)
@sed 's@package types;@package abci;@' $(tmabci) > protobuf/abci.proto
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
@curl $(tendermint)/version/version.go | grep -F -eTMCoreSem -eABCISemVer > version.txt

.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
2 changes: 1 addition & 1 deletion simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewards(ctx, val.GetOperator())
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps.Rewards...)
app.DistrKeeper.SetFeePool(ctx, feePool)

app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
Expand Down
29 changes: 22 additions & 7 deletions x/crisis/internal/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
)

// Register concrete types on codec codec
type Codec struct {
codec.Marshaler

// Keep reference to the amino codec to allow backwards compatibility along
// with type, and interface registration.
amino *codec.Codec
}

func NewCodec(amino *codec.Codec) *Codec {
return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino}
}

// ----------------------------------------------------------------------------

// RegisterCodec registers all the necessary crisis module concrete types and
// interfaces with the provided codec reference.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant", nil)
}

// generic sealed codec to be used throughout module
var ModuleCdc *codec.Codec
// ModuleCdc defines a crisis module global Amino codec.
var ModuleCdc *Codec

func init() {
ModuleCdc = codec.New()
RegisterCodec(ModuleCdc)
codec.RegisterCrypto(ModuleCdc)
ModuleCdc.Seal()
ModuleCdc = NewCodec(codec.New())
RegisterCodec(ModuleCdc.amino)
codec.RegisterCrypto(ModuleCdc.amino)
ModuleCdc.amino.Seal()
}
7 changes: 0 additions & 7 deletions x/crisis/internal/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// MsgVerifyInvariant - message struct to verify a particular invariance
type MsgVerifyInvariant struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
InvariantModuleName string `json:"invariant_module_name" yaml:"invariant_module_name"`
InvariantRoute string `json:"invariant_route" yaml:"invariant_route"`
}

// ensure Msg interface compliance at compile time
var _ sdk.Msg = &MsgVerifyInvariant{}

Expand Down
Loading