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

Regen Network/Slashing protobuf #5627

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
76757e0
Add protobuf def
anilcse Feb 7, 2020
a0eaa7a
Add proto msg type for MsgUnJail
anilcse Feb 7, 2020
0c6ca19
gofmt
anilcse Feb 7, 2020
ab7fc9e
Merge pull request #21 from regen-network/vw/slashing_protobuf_migration
anilcse Feb 7, 2020
fbf33e8
Merge branch 'master' of github.com:cosmos/cosmos-sdk into vw/slashin…
anilcse Feb 7, 2020
e8617dc
Remove ModuleCodec
anilcse Feb 7, 2020
3b7110b
Merge branch 'regen-network/slashing_protobuf' of github.com:regen-ne…
anilcse Feb 7, 2020
89b5834
Add changelog
anilcse Feb 11, 2020
1cb8cc8
Fix naming
anilcse Feb 11, 2020
2909f11
Fix undefined errors
anilcse Feb 11, 2020
c9ddfbd
Add ValidatorSigningInfo protobuf implementation
anilcse Feb 11, 2020
d286da4
Revert unnecessary codec migration
anilcse Feb 11, 2020
c601f08
Add protobuf def
anilcse Feb 7, 2020
af6b876
Add proto msg type for MsgUnJail
anilcse Feb 7, 2020
5fb7442
gofmt
anilcse Feb 7, 2020
25f7f97
Remove ModuleCodec
anilcse Feb 7, 2020
12111ae
Add changelog
anilcse Feb 11, 2020
af95b29
Fix naming
anilcse Feb 11, 2020
ba3ee92
Fix undefined errors
anilcse Feb 11, 2020
d90bb3e
Add ValidatorSigningInfo protobuf implementation
anilcse Feb 11, 2020
2ca862f
Revert unnecessary codec migration
anilcse Feb 11, 2020
5395ce8
Merge branch 'regen-network/slashing_protobuf' of github.com:regen-ne…
anilcse Feb 11, 2020
21b9cba
Add ValidatorSigningInfo proto codec
anilcse Feb 11, 2020
5a5fd73
Fix keeper init in tests
anilcse Feb 11, 2020
bdd9368
Add TODO
anilcse Feb 11, 2020
525ad52
Fix signing-info migration
anilcse Feb 11, 2020
c6bb9ae
Change query to use protobuf codec
anilcse Feb 11, 2020
486e7a1
Fix unjail testscript
anilcse Feb 11, 2020
d035a18
Fix go-imports
anilcse Feb 11, 2020
5130ecd
Merge branch 'master' of github.com:cosmos/cosmos-sdk into regen-netw…
anilcse Feb 11, 2020
bb6d8c8
Migrate all slashing queries to use protobuf
anilcse Feb 11, 2020
3dac3b6
Fix typecast
anilcse Feb 11, 2020
6d62019
Fix gofmt
anilcse Feb 11, 2020
ef7cb62
Gofmt
anilcse Feb 11, 2020
9ce0db2
Use protobuf types
anilcse Feb 12, 2020
ae47cb7
Revert
anilcse Feb 12, 2020
30673c0
Revert query params
anilcse Feb 12, 2020
1480c46
Revert query, tx
anilcse Feb 12, 2020
606dd29
Fix lint issue
anilcse Feb 12, 2020
07815e1
Update changelog
anilcse Feb 12, 2020
247af97
Fix lint issues
anilcse Feb 12, 2020
4628a98
Fix lint issues
anilcse Feb 12, 2020
24addfa
Merge pull request #24 from regen-network/regen-network/slashing_prot…
anilcse Feb 12, 2020
b111389
Removed new line
sahith-narahari Feb 12, 2020
e870c7b
Merge pull request #25 from regen-network/anil/fix_slashing_simulatio…
anilcse Feb 12, 2020
e3897cf
Fix golint
anilcse Feb 12, 2020
8fbc455
Fix use json and yaml tags the same as before
anilcse Feb 12, 2020
32aa41b
Merge branch 'regen-network/slashing_protobuf' of github.com:regen-ne…
anilcse Feb 12, 2020
cd0b99d
Merge pull request #26 from regen-network/regen-network/slashing_prot…
anilcse Feb 12, 2020
fb1a0da
Merge branch 'master' of github.com:cosmos/cosmos-sdk into regen-netw…
anilcse Feb 12, 2020
33bc104
Merge branch 'regen-network/slashing_protobuf' of github.com:regen-ne…
anilcse Feb 12, 2020
750e613
Fix gofmt
anilcse Feb 12, 2020
53b45e0
Merge branch 'master' of github.com:cosmos/cosmos-sdk into regen-netw…
anilcse Feb 16, 2020
5b9cc9f
Gofmt
anilcse Feb 16, 2020
ae52ace
Fix test-sim-import-export issue
anilcse Feb 16, 2020
28e2556
Fix gofmt
anilcse Feb 16, 2020
7e34c0c
Merge branch 'master' into regen-network/slashing_protobuf
anilcse Feb 16, 2020
e68f3f0
- Rebase to cosmos:master
anilcse Feb 18, 2020
4360aee
Fix typo
anilcse Feb 18, 2020
04ff0b5
Merge branch 'master' of github.com:cosmos/cosmos-sdk into regen-netw…
anilcse Feb 18, 2020
85b3a20
Revert str conv
anilcse Feb 18, 2020
47c5fb5
Fix gofmt
anilcse Feb 18, 2020
65b5622
Merge branch 'master' into regen-network/slashing_protobuf
anilcse Feb 18, 2020
9e7b6ed
Fix review changes
anilcse Feb 19, 2020
a836c0e
Merge branch 'master' of github.com:cosmos/cosmos-sdk into regen-netw…
anilcse Feb 19, 2020
db992df
Remove unused codec alias
anilcse Feb 19, 2020
73271ff
Merge branch 'regen-network/slashing_protobuf' of github.com:regen-ne…
anilcse Feb 19, 2020
e5f10e1
Revert
anilcse Feb 19, 2020
4c5e070
fix import
anilcse Feb 19, 2020
44559dd
Merge branch 'master' of github.com:cosmos/cosmos-sdk into regen-netw…
anilcse Feb 19, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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`.
* (slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffer for state
* (x/slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` 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.
* The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type
Expand Down
2 changes: 1 addition & 1 deletion simapp/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type AppCodec struct {
amino *codec.Codec

Params *params.Codec
Staking *staking.Codec
Slashing *slashing.Codec
Copy link
Member

Choose a reason for hiding this comment

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

I do think we should have something more generic when modules don't actually do anything special with their codec. What do you think @alexanderbez ?

Copy link
Member

Choose a reason for hiding this comment

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

this file should be removed as the new design does not contain this struct. you can see here: https://github.com/cosmos/cosmos-sdk/blob/08502d6d98bff3872916f8b69cde2d255351d3fb/simapp/codec/codec.go

Staking *staking.Codec
Distribution *distr.Codec
}

Expand Down
1 change: 0 additions & 1 deletion x/slashing/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ $ <appcli> query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge

var signingInfo types.ValidatorSigningInfo
signingInfo, err = types.UnmarshalValSigningInfo(types.ModuleCdc, res)

if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions x/slashing/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func signingInfoHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}

params := types.NewQuerySigningInfoParams(sdk.ConsAddress(pk.Address()))
bz, err := params.Marshal()

bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down Expand Up @@ -78,11 +78,10 @@ func signingInfoHandlerListFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

params := types.NewQuerySigningInfosParams(int32(page), int32(limit))
bz, err := params.Marshal()

params := types.NewQuerySigningInfosParams(page, limit)
bz, err := cliCtx.Codec.MarshalJSON(params)
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

Expand Down
3 changes: 0 additions & 3 deletions x/slashing/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func (k Keeper) AddPubkey(ctx sdk.Context, pubkey crypto.PubKey) {
addr := pubkey.Address()

pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubkey)

if err != nil {
panic(fmt.Errorf("error while setting address-pubkey relation: %s", addr))
}
Expand All @@ -55,13 +54,11 @@ func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKe

var pubkey gogotypes.StringValue
err := k.cdc.UnmarshalBinaryLengthPrefixed(store.Get(types.GetAddrPubkeyRelationKey(address)), &pubkey)

if err != nil {
return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(address))
}

pkStr, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pubkey.Value)

if err != nil {
return pkStr, err
}
Expand Down
3 changes: 1 addition & 2 deletions x/slashing/internal/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Codec struct {
codec.Marshaler
// Keep reference to the amino codec to allow backwards compatibility along
// with type, and interface registration.

amino *codec.Codec
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
amino *codec.Codec
amino *codec.Codec

}

Expand All @@ -24,8 +25,6 @@ var ModuleCdc *Codec

func init() {
ModuleCdc = NewCodec(codec.New())
Copy link
Contributor

Choose a reason for hiding this comment

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

clean/remove comments

//ModuleCdc = codec.New()
RegisterCodec(ModuleCdc.amino)
//codec.RegisterCrypto(ModuleCdc)
ModuleCdc.amino.Seal()
}
2 changes: 1 addition & 1 deletion x/slashing/internal/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (msg MsgUnjail) GetSignBytes() []byte {

// ValidateBasic validity check for the AnteHandler
func (msg MsgUnjail) ValidateBasic() error {
if len(msg.ValidatorAddr) < 1 { //if empty
if msg.ValidatorAddr.Empty() {
return ErrBadValidatorAddr
}

Expand Down
2 changes: 1 addition & 1 deletion x/slashing/internal/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestMsgUnjailGetSignBytes(t *testing.T) {
bytes := msg.GetSignBytes()
require.Equal(
t,
`{"type":"cosmos-sdk/MsgUnjail","value":{"validator_addr":"cosmosvaloper1v93xxeqhg9nn6"}}`,
`{"type":"cosmos-sdk/MsgUnjail","value":{"address":"cosmosvaloper1v93xxeqhg9nn6"}}`,
string(bytes),
)
}
72 changes: 36 additions & 36 deletions x/slashing/internal/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions x/slashing/internal/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import "google/protobuf/timestamp.proto";
message MsgUnjail {
bytes validator_addr = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
(gogoproto.moretags) = "yaml:\"validator_address\""
(gogoproto.moretags) = "yaml:\"address\"",
(gogoproto.jsontag) = "address"
];
}

Expand All @@ -20,13 +21,15 @@ message ValidatorSigningInfo {
option (gogoproto.goproto_stringer) = false;

bytes address = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress",
(gogoproto.moretags) = "yaml:\"address\"" // validator consensus address
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress" // validator consensus address
];
int64 start_height = 2 [(gogoproto.moretags) = "yaml:\"start_height\""]; // height at which validator was first a candidate OR was unjailed
int64 index_offset = 3 [(gogoproto.moretags) = "yaml:\"index_offset\""]; // index offset into signed block bit array
google.protobuf.Timestamp jailed_until = 4 [(gogoproto.stdtime) = true,
(gogoproto.nullable) = false]; // timestamp validator cannot be unjailed until
bool tombstoned = 5 [(gogoproto.moretags) = "yaml:\"tombstoned\""]; // whether or not a validator has been tombstoned (killed out of validator set)
google.protobuf.Timestamp jailed_until = 4 [
(gogoproto.moretags) = "yaml:\"jailed_until\"",
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false
]; // timestamp validator cannot be unjailed until
bool tombstoned = 5; // whether or not a validator has been tombstoned (killed out of validator set)
int64 missed_blocks_counter = 6 [(gogoproto.moretags) = "yaml:\"missed_blocks_counter\""]; // missed blocks counter (to avoid scanning the array every time)
}
5 changes: 3 additions & 2 deletions x/slashing/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"

gogotypes "github.com/gogo/protobuf/types"
"github.com/tendermint/tendermint/crypto"
tmkv "github.com/tendermint/tendermint/libs/kv"

Expand All @@ -22,10 +23,10 @@ func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string {
return fmt.Sprintf("%v\n%v", infoA, infoB)

case bytes.Equal(kvA.Key[:1], types.ValidatorMissedBlockBitArrayKey):
var missedA, missedB bool
var missedA, missedB gogotypes.BoolValue
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &missedA)
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &missedB)
return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA, missedB)
return fmt.Sprintf("missedA: %v\nmissedB: %v", missedA.Value, missedB.Value)

case bytes.Equal(kvA.Key[:1], types.AddrPubkeyRelationKey):
var pubKeyA, pubKeyB crypto.PubKey
Expand Down
7 changes: 4 additions & 3 deletions x/slashing/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simulation

import (
"fmt"
gogotypes "github.com/gogo/protobuf/types"
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
"testing"
"time"

Expand Down Expand Up @@ -36,11 +37,11 @@ func TestDecodeStore(t *testing.T) {

info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0)
bechPK := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, delPk1)
missed := true
missed := gogotypes.BoolValue{Value: true}

kvPairs := tmkv.Pairs{
tmkv.Pair{Key: types.GetValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(info)},
tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(missed)},
tmkv.Pair{Key: types.GetValidatorMissedBlockBitArrayKey(consAddr1, 6), Value: cdc.MustMarshalBinaryLengthPrefixed(&missed)},
tmkv.Pair{Key: types.GetAddrPubkeyRelationKey(delAddr1), Value: cdc.MustMarshalBinaryLengthPrefixed(delPk1)},
tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}},
}
Expand All @@ -50,7 +51,7 @@ func TestDecodeStore(t *testing.T) {
expectedLog string
}{
{"ValidatorSigningInfo", fmt.Sprintf("%v\n%v", info, info)},
{"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed, missed)},
{"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v", missed.Value, missed.Value)},
{"AddrPubkeyRelation", fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", bechPK, bechPK)},
{"other", ""},
}
Expand Down