diff --git a/CHANGELOG.md b/CHANGELOG.md index 34c617d89f9c..5804dbb319d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,11 @@ 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`. +* (x/slashing) [\#5627](https://github.com/cosmos/cosmos-sdk/pull/5627) Migrate the `x/slashing` module to use Protocol Buffers 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 + provided is specified by `ModuleCdc`. * (x/distribution) [\#5610](https://github.com/cosmos/cosmos-sdk/pull/5610) Migrate the `x/distribution` module to use Protocol Buffers for state serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino for JSON encoding. diff --git a/simapp/app.go b/simapp/app.go index e1d646f7c978..56f5513e2d2b 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -184,7 +184,7 @@ func NewSimApp( app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) app.SlashingKeeper = slashing.NewKeeper( - app.cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], + appCodec, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], ) app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, diff --git a/types/proto.go b/types/proto.go index e4cdbdc511c0..b6978c1eb9a5 100644 --- a/types/proto.go +++ b/types/proto.go @@ -1,7 +1,7 @@ package types import ( - _ "github.com/gogo/protobuf/gogoproto" // nolint + _ "github.com/gogo/protobuf/gogoproto" // nolint _ "github.com/regen-network/cosmos-proto" // nolint ) diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index a6a14c885b3d..c1b0f62fffb4 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/alias.go b/x/slashing/alias.go index 38d556a6e492..9ebdd29edf35 100644 --- a/x/slashing/alias.go +++ b/x/slashing/alias.go @@ -3,8 +3,8 @@ package slashing // nolint import ( - "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) const ( diff --git a/x/slashing/client/cli/query.go b/x/slashing/client/cli/query.go index 71f404230758..c661b589f1d0 100644 --- a/x/slashing/client/cli/query.go +++ b/x/slashing/client/cli/query.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetQueryCmd returns the cli query commands for this module @@ -68,7 +68,11 @@ $ query slashing signing-info cosmosvalconspub1zcjduepqfhvwcmt7p06fvdge } var signingInfo types.ValidatorSigningInfo - cdc.MustUnmarshalBinaryLengthPrefixed(res, &signingInfo) + signingInfo, err = types.UnmarshalValSigningInfo(types.ModuleCdc, res) + if err != nil { + return err + } + return cliCtx.PrintOutput(signingInfo) }, } diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index 117e216a957a..4233d5c7a072 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetTxCmd returns the transaction commands for this module diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 751fe648dc45..2d3d9bfab798 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 1257b8e105a5..9498ea8ba5ff 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -10,7 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/slashing/genesis.go b/x/slashing/genesis.go index 8b959c8a0bac..a5d2eb0f1350 100644 --- a/x/slashing/genesis.go +++ b/x/slashing/genesis.go @@ -2,7 +2,7 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking/exported" ) diff --git a/x/slashing/handler.go b/x/slashing/handler.go index fe4ef7cb7c2e..629a92dde29e 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -3,7 +3,7 @@ package slashing import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // NewHandler creates an sdk.Handler for all the slashing type messages diff --git a/x/slashing/handler_test.go b/x/slashing/handler_test.go index c168f8052ffb..abd5e52559fd 100644 --- a/x/slashing/handler_test.go +++ b/x/slashing/handler_test.go @@ -11,8 +11,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/internal/types/codec.go b/x/slashing/internal/types/codec.go deleted file mode 100644 index 34790d54d630..000000000000 --- a/x/slashing/internal/types/codec.go +++ /dev/null @@ -1,20 +0,0 @@ -package types - -import ( - "github.com/cosmos/cosmos-sdk/codec" -) - -// RegisterCodec registers concrete types on codec -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) -} - -// ModuleCdc defines the module codec -var ModuleCdc *codec.Codec - -func init() { - ModuleCdc = codec.New() - RegisterCodec(ModuleCdc) - codec.RegisterCrypto(ModuleCdc) - ModuleCdc.Seal() -} diff --git a/x/slashing/internal/keeper/hooks.go b/x/slashing/keeper/hooks.go similarity index 97% rename from x/slashing/internal/keeper/hooks.go rename to x/slashing/keeper/hooks.go index a8ef6e093e15..e6374a87f990 100644 --- a/x/slashing/internal/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func (k Keeper) AfterValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) { diff --git a/x/slashing/internal/keeper/infractions.go b/x/slashing/keeper/infractions.go similarity index 98% rename from x/slashing/internal/keeper/infractions.go rename to x/slashing/keeper/infractions.go index a10b6f945b3a..a8e349b75be8 100644 --- a/x/slashing/internal/keeper/infractions.go +++ b/x/slashing/keeper/infractions.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // HandleValidatorSignature handles a validator signature, must be called once per validator per block. diff --git a/x/slashing/internal/keeper/keeper.go b/x/slashing/keeper/keeper.go similarity index 77% rename from x/slashing/internal/keeper/keeper.go rename to x/slashing/keeper/keeper.go index e725519314d1..43f21a516edb 100644 --- a/x/slashing/internal/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -3,24 +3,26 @@ package keeper import ( "fmt" + gogotypes "github.com/gogo/protobuf/types" + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Keeper of the slashing store type Keeper struct { storeKey sdk.StoreKey - cdc *codec.Codec + cdc codec.Marshaler sk types.StakingKeeper paramspace types.ParamSubspace } // NewKeeper creates a slashing keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { +func NewKeeper(cdc codec.Marshaler, key sdk.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper { return Keeper{ storeKey: key, cdc: cdc, @@ -37,18 +39,31 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // AddPubkey sets a address-pubkey relation func (k Keeper) AddPubkey(ctx sdk.Context, pubkey crypto.PubKey) { addr := pubkey.Address() - k.setAddrPubkeyRelation(ctx, addr, pubkey) + + pkStr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubkey) + if err != nil { + panic(fmt.Errorf("error while setting address-pubkey relation: %s", addr)) + } + + k.setAddrPubkeyRelation(ctx, addr, pkStr) } // GetPubkey returns the pubkey from the adddress-pubkey relation func (k Keeper) GetPubkey(ctx sdk.Context, address crypto.Address) (crypto.PubKey, error) { store := ctx.KVStore(k.storeKey) - var pubkey crypto.PubKey + + 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)) } - return pubkey, nil + + pkStr, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pubkey.Value) + if err != nil { + return pkStr, err + } + + return pkStr, nil } // Slash attempts to slash a validator. The slash is delegated to the staking @@ -79,9 +94,10 @@ func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) { k.sk.Jail(ctx, consAddr) } -func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey crypto.PubKey) { +func (k Keeper) setAddrPubkeyRelation(ctx sdk.Context, addr crypto.Address, pubkey string) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(pubkey) + + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.StringValue{Value: pubkey}) store.Set(types.GetAddrPubkeyRelationKey(addr), bz) } diff --git a/x/slashing/internal/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go similarity index 99% rename from x/slashing/internal/keeper/keeper_test.go rename to x/slashing/keeper/keeper_test.go index fdf50a261e27..4f4f555bbffc 100644 --- a/x/slashing/internal/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" ) diff --git a/x/slashing/internal/keeper/params.go b/x/slashing/keeper/params.go similarity index 96% rename from x/slashing/internal/keeper/params.go rename to x/slashing/keeper/params.go index 82fe991cccc1..8ece97a687ad 100644 --- a/x/slashing/internal/keeper/params.go +++ b/x/slashing/keeper/params.go @@ -4,7 +4,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // SignedBlocksWindow - sliding window for downtime slashing diff --git a/x/slashing/internal/keeper/querier.go b/x/slashing/keeper/querier.go similarity index 97% rename from x/slashing/internal/keeper/querier.go rename to x/slashing/keeper/querier.go index 11b365e1ee1b..1eab719a63f7 100644 --- a/x/slashing/internal/keeper/querier.go +++ b/x/slashing/keeper/querier.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // NewQuerier creates a new querier for slashing clients. diff --git a/x/slashing/internal/keeper/querier_test.go b/x/slashing/keeper/querier_test.go similarity index 92% rename from x/slashing/internal/keeper/querier_test.go rename to x/slashing/keeper/querier_test.go index ea4095dc61b1..fd924bc8e823 100644 --- a/x/slashing/internal/keeper/querier_test.go +++ b/x/slashing/keeper/querier_test.go @@ -7,7 +7,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func TestNewQuerier(t *testing.T) { diff --git a/x/slashing/internal/keeper/signing_info.go b/x/slashing/keeper/signing_info.go similarity index 91% rename from x/slashing/internal/keeper/signing_info.go rename to x/slashing/keeper/signing_info.go index 1162c258f35a..0e1a82c62fa2 100644 --- a/x/slashing/internal/keeper/signing_info.go +++ b/x/slashing/keeper/signing_info.go @@ -3,8 +3,10 @@ package keeper import ( "time" + gogotypes "github.com/gogo/protobuf/types" + sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // GetValidatorSigningInfo retruns the ValidatorSigningInfo for a specific validator @@ -31,7 +33,7 @@ func (k Keeper) HasValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddres // SetValidatorSigningInfo sets the validator signing info to a consensus address key func (k Keeper) SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info types.ValidatorSigningInfo) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(info) + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&info) store.Set(types.GetValidatorSigningInfoKey(address), bz) } @@ -53,16 +55,17 @@ func (k Keeper) IterateValidatorSigningInfos(ctx sdk.Context, } // GetValidatorMissedBlockBitArray gets the bit for the missed blocks array -func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (missed bool) { +func (k Keeper) GetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) bool { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetValidatorMissedBlockBitArrayKey(address, index)) + var missed gogotypes.BoolValue if bz == nil { // lazy: treat empty key as not missed - missed = false - return + return false } k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) - return + + return missed.Value } // IterateValidatorMissedBlockBitArray iterates over the signed blocks window @@ -74,13 +77,14 @@ func (k Keeper) IterateValidatorMissedBlockBitArray(ctx sdk.Context, index := int64(0) // Array may be sparse for ; index < k.SignedBlocksWindow(ctx); index++ { - var missed bool + var missed gogotypes.BoolValue bz := store.Get(types.GetValidatorMissedBlockBitArrayKey(address, index)) if bz == nil { continue } + k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &missed) - if handler(index, missed) { + if handler(index, missed.Value) { break } } @@ -128,7 +132,7 @@ func (k Keeper) IsTombstoned(ctx sdk.Context, consAddr sdk.ConsAddress) bool { // missed a block in the current window func (k Keeper) SetValidatorMissedBlockBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, missed bool) { store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshalBinaryLengthPrefixed(missed) + bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.BoolValue{Value: missed}) store.Set(types.GetValidatorMissedBlockBitArrayKey(address, index), bz) } diff --git a/x/slashing/internal/keeper/signing_info_test.go b/x/slashing/keeper/signing_info_test.go similarity index 97% rename from x/slashing/internal/keeper/signing_info_test.go rename to x/slashing/keeper/signing_info_test.go index 7d9e7c56e526..ac8c5075276f 100644 --- a/x/slashing/internal/keeper/signing_info_test.go +++ b/x/slashing/keeper/signing_info_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) func TestGetSetValidatorSigningInfo(t *testing.T) { diff --git a/x/slashing/internal/keeper/test_common.go b/x/slashing/keeper/test_common.go similarity index 98% rename from x/slashing/internal/keeper/test_common.go rename to x/slashing/keeper/test_common.go index ca388dd24d18..6fa24149f5ef 100644 --- a/x/slashing/internal/keeper/test_common.go +++ b/x/slashing/keeper/test_common.go @@ -24,7 +24,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/params/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/supply" ) @@ -124,7 +124,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee } paramstore := paramsKeeper.Subspace(types.DefaultParamspace) - keeper := NewKeeper(cdc, keySlashing, &sk, paramstore) + keeper := NewKeeper(types.ModuleCdc, keySlashing, &sk, paramstore) keeper.SetParams(ctx, defaults) sk.SetHooks(keeper.Hooks()) diff --git a/x/slashing/internal/keeper/unjail.go b/x/slashing/keeper/unjail.go similarity index 95% rename from x/slashing/internal/keeper/unjail.go rename to x/slashing/keeper/unjail.go index 51fda4855382..cf57c1e71c4a 100644 --- a/x/slashing/internal/keeper/unjail.go +++ b/x/slashing/keeper/unjail.go @@ -2,7 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Unjail calls the staking Unjail function to unjail a validator if the diff --git a/x/slashing/module.go b/x/slashing/module.go index 3e4c0b7a99e8..b404b8c4ecde 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -17,8 +17,8 @@ import ( sim "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" "github.com/cosmos/cosmos-sdk/x/slashing/client/rest" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" "github.com/cosmos/cosmos-sdk/x/slashing/simulation" + "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) diff --git a/x/slashing/simulation/decoder.go b/x/slashing/simulation/decoder.go index 9aea5f701b15..48a12705a780 100644 --- a/x/slashing/simulation/decoder.go +++ b/x/slashing/simulation/decoder.go @@ -4,12 +4,13 @@ import ( "bytes" "fmt" + gogotypes "github.com/gogo/protobuf/types" "github.com/tendermint/tendermint/crypto" tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // DecodeStore unmarshals the KVPair's Value to the corresponding slashing type @@ -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 diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index acd3be67c62f..522bff74750d 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + gogotypes "github.com/gogo/protobuf/types" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" @@ -12,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // nolint:deadcode,unused,varcheck @@ -36,11 +38,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}}, } @@ -50,7 +52,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", ""}, } diff --git a/x/slashing/simulation/genesis.go b/x/slashing/simulation/genesis.go index a26a626642b7..d9dae7cd3d7b 100644 --- a/x/slashing/simulation/genesis.go +++ b/x/slashing/simulation/genesis.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) // Simulation parameter constants diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 8b7124609c09..c0f0b94554f6 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -10,8 +10,8 @@ import ( simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) diff --git a/x/slashing/simulation/params.go b/x/slashing/simulation/params.go index 6679928d8fc4..72048f2264bd 100644 --- a/x/slashing/simulation/params.go +++ b/x/slashing/simulation/params.go @@ -7,7 +7,7 @@ import ( "math/rand" "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/internal/types" + "github.com/cosmos/cosmos-sdk/x/slashing/types" ) const ( diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go new file mode 100644 index 000000000000..04114f1465a1 --- /dev/null +++ b/x/slashing/types/codec.go @@ -0,0 +1,28 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" +) + +// RegisterCodec registers concrete types on codec +func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) +} + +var ( + amino = codec.New() + + // ModuleCdc references the global x/slashing module codec. Note, the codec + // should ONLY be used in certain instances of tests and for JSON encoding as Amino + // is still used for that purpose. + // + // The actual codec used for serialization should be provided to x/slashing and + // defined at the application level. + ModuleCdc = codec.NewHybridCodec(amino) +) + +func init() { + RegisterCodec(amino) + codec.RegisterCrypto(amino) + amino.Seal() +} diff --git a/x/slashing/internal/types/errors.go b/x/slashing/types/errors.go similarity index 100% rename from x/slashing/internal/types/errors.go rename to x/slashing/types/errors.go diff --git a/x/slashing/internal/types/events.go b/x/slashing/types/events.go similarity index 100% rename from x/slashing/internal/types/events.go rename to x/slashing/types/events.go diff --git a/x/slashing/internal/types/expected_keepers.go b/x/slashing/types/expected_keepers.go similarity index 100% rename from x/slashing/internal/types/expected_keepers.go rename to x/slashing/types/expected_keepers.go diff --git a/x/slashing/internal/types/genesis.go b/x/slashing/types/genesis.go similarity index 100% rename from x/slashing/internal/types/genesis.go rename to x/slashing/types/genesis.go diff --git a/x/slashing/internal/types/keys.go b/x/slashing/types/keys.go similarity index 100% rename from x/slashing/internal/types/keys.go rename to x/slashing/types/keys.go diff --git a/x/slashing/internal/types/msg.go b/x/slashing/types/msg.go similarity index 83% rename from x/slashing/internal/types/msg.go rename to x/slashing/types/msg.go index b2ccdce173ba..a9798615f6ad 100644 --- a/x/slashing/internal/types/msg.go +++ b/x/slashing/types/msg.go @@ -7,11 +7,6 @@ import ( // verify interface at compile time var _ sdk.Msg = &MsgUnjail{} -// MsgUnjail - struct for unjailing jailed validator -type MsgUnjail struct { - ValidatorAddr sdk.ValAddress `json:"address" yaml:"address"` // address of the validator operator -} - // NewMsgUnjail creates a new MsgUnjail instance func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { return MsgUnjail{ @@ -37,5 +32,6 @@ func (msg MsgUnjail) ValidateBasic() error { if msg.ValidatorAddr.Empty() { return ErrBadValidatorAddr } + return nil } diff --git a/x/slashing/internal/types/msg_test.go b/x/slashing/types/msg_test.go similarity index 100% rename from x/slashing/internal/types/msg_test.go rename to x/slashing/types/msg_test.go diff --git a/x/slashing/internal/types/params.go b/x/slashing/types/params.go similarity index 100% rename from x/slashing/internal/types/params.go rename to x/slashing/types/params.go diff --git a/x/slashing/internal/types/querier.go b/x/slashing/types/querier.go similarity index 100% rename from x/slashing/internal/types/querier.go rename to x/slashing/types/querier.go diff --git a/x/slashing/internal/types/signing_info.go b/x/slashing/types/signing_info.go similarity index 50% rename from x/slashing/internal/types/signing_info.go rename to x/slashing/types/signing_info.go index 431658c2241a..315cac792c56 100644 --- a/x/slashing/internal/types/signing_info.go +++ b/x/slashing/types/signing_info.go @@ -4,19 +4,11 @@ import ( "fmt" "time" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) -// ValidatorSigningInfo defines the signing info for a validator -type ValidatorSigningInfo struct { - Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address - StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed - IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array - JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until - Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set) - MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time) -} - // NewValidatorSigningInfo creates a new ValidatorSigningInfo instance func NewValidatorSigningInfo( condAddr sdk.ConsAddress, startHeight, indexOffset int64, @@ -45,3 +37,9 @@ func (i ValidatorSigningInfo) String() string { i.Address, i.StartHeight, i.IndexOffset, i.JailedUntil, i.Tombstoned, i.MissedBlocksCounter) } + +// unmarshal a validator signing info from a store value +func UnmarshalValSigningInfo(cdc codec.Marshaler, value []byte) (signingInfo ValidatorSigningInfo, err error) { + err = cdc.UnmarshalBinaryLengthPrefixed(value, &signingInfo) + return signingInfo, err +} diff --git a/x/slashing/types/types.pb.go b/x/slashing/types/types.pb.go new file mode 100644 index 000000000000..82791e7bcdcd --- /dev/null +++ b/x/slashing/types/types.pb.go @@ -0,0 +1,761 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/slashing/internal/types/types.proto + +package types + +import ( + bytes "bytes" + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/golang/protobuf/ptypes/timestamp" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgUnjail - struct for unjailing jailed validator +type MsgUnjail struct { + ValidatorAddr github_com_cosmos_cosmos_sdk_types.ValAddress `protobuf:"bytes,1,opt,name=validator_addr,json=validatorAddr,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ValAddress" json:"address" yaml:"address"` +} + +func (m *MsgUnjail) Reset() { *m = MsgUnjail{} } +func (m *MsgUnjail) String() string { return proto.CompactTextString(m) } +func (*MsgUnjail) ProtoMessage() {} +func (*MsgUnjail) Descriptor() ([]byte, []int) { + return fileDescriptor_2b882c3b0cdd6f57, []int{0} +} +func (m *MsgUnjail) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUnjail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUnjail.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUnjail) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUnjail.Merge(m, src) +} +func (m *MsgUnjail) XXX_Size() int { + return m.Size() +} +func (m *MsgUnjail) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUnjail.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUnjail proto.InternalMessageInfo + +func (m *MsgUnjail) GetValidatorAddr() github_com_cosmos_cosmos_sdk_types.ValAddress { + if m != nil { + return m.ValidatorAddr + } + return nil +} + +// ValidatorSigningInfo defines the signing info for a validator +type ValidatorSigningInfo struct { + Address github_com_cosmos_cosmos_sdk_types.ConsAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.ConsAddress" json:"address,omitempty"` + StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty" yaml:"start_height"` + IndexOffset int64 `protobuf:"varint,3,opt,name=index_offset,json=indexOffset,proto3" json:"index_offset,omitempty" yaml:"index_offset"` + JailedUntil time.Time `protobuf:"bytes,4,opt,name=jailed_until,json=jailedUntil,proto3,stdtime" json:"jailed_until" yaml:"jailed_until"` + Tombstoned bool `protobuf:"varint,5,opt,name=tombstoned,proto3" json:"tombstoned,omitempty"` + MissedBlocksCounter int64 `protobuf:"varint,6,opt,name=missed_blocks_counter,json=missedBlocksCounter,proto3" json:"missed_blocks_counter,omitempty" yaml:"missed_blocks_counter"` +} + +func (m *ValidatorSigningInfo) Reset() { *m = ValidatorSigningInfo{} } +func (*ValidatorSigningInfo) ProtoMessage() {} +func (*ValidatorSigningInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_2b882c3b0cdd6f57, []int{1} +} +func (m *ValidatorSigningInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSigningInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSigningInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorSigningInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSigningInfo.Merge(m, src) +} +func (m *ValidatorSigningInfo) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSigningInfo) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSigningInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSigningInfo proto.InternalMessageInfo + +func (m *ValidatorSigningInfo) GetAddress() github_com_cosmos_cosmos_sdk_types.ConsAddress { + if m != nil { + return m.Address + } + return nil +} + +func (m *ValidatorSigningInfo) GetStartHeight() int64 { + if m != nil { + return m.StartHeight + } + return 0 +} + +func (m *ValidatorSigningInfo) GetIndexOffset() int64 { + if m != nil { + return m.IndexOffset + } + return 0 +} + +func (m *ValidatorSigningInfo) GetJailedUntil() time.Time { + if m != nil { + return m.JailedUntil + } + return time.Time{} +} + +func (m *ValidatorSigningInfo) GetTombstoned() bool { + if m != nil { + return m.Tombstoned + } + return false +} + +func (m *ValidatorSigningInfo) GetMissedBlocksCounter() int64 { + if m != nil { + return m.MissedBlocksCounter + } + return 0 +} + +func init() { + proto.RegisterType((*MsgUnjail)(nil), "cosmos_sdk.x.slashing.v1.MsgUnjail") + proto.RegisterType((*ValidatorSigningInfo)(nil), "cosmos_sdk.x.slashing.v1.ValidatorSigningInfo") +} + +func init() { + proto.RegisterFile("x/slashing/internal/types/types.proto", fileDescriptor_2b882c3b0cdd6f57) +} + +var fileDescriptor_2b882c3b0cdd6f57 = []byte{ + // 491 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3f, 0x6f, 0xd3, 0x4e, + 0x18, 0xc7, 0x73, 0xbf, 0xfc, 0x5a, 0xca, 0x25, 0x74, 0x70, 0x41, 0x58, 0x11, 0xf2, 0x59, 0x96, + 0x40, 0x59, 0x6a, 0x8b, 0xb2, 0x65, 0xc3, 0x5d, 0x40, 0xe2, 0x8f, 0x64, 0xda, 0x0e, 0x0c, 0x58, + 0xe7, 0xdc, 0xe5, 0x7c, 0xc4, 0xbe, 0x8b, 0x7c, 0xe7, 0x2a, 0x59, 0x79, 0x05, 0x1d, 0x19, 0xfb, + 0x42, 0x78, 0x01, 0x1d, 0x3b, 0x32, 0x19, 0x94, 0x2c, 0x88, 0x31, 0x63, 0x27, 0x64, 0x5f, 0x4c, + 0x23, 0xc4, 0xc0, 0x92, 0xf8, 0xfb, 0xb9, 0xe7, 0xfb, 0x7c, 0xef, 0xf1, 0x63, 0xf8, 0x78, 0x1e, + 0xa8, 0x0c, 0xab, 0x94, 0x0b, 0x16, 0x70, 0xa1, 0x69, 0x21, 0x70, 0x16, 0xe8, 0xc5, 0x8c, 0x2a, + 0xf3, 0xeb, 0xcf, 0x0a, 0xa9, 0xa5, 0x65, 0x8f, 0xa5, 0xca, 0xa5, 0x8a, 0x15, 0x99, 0xfa, 0x73, + 0xbf, 0x75, 0xf8, 0xe7, 0x4f, 0x07, 0x4f, 0x74, 0xca, 0x0b, 0x12, 0xcf, 0x70, 0xa1, 0x17, 0x41, + 0x53, 0x1c, 0x30, 0xc9, 0xe4, 0xed, 0x93, 0xe9, 0x30, 0x40, 0x4c, 0x4a, 0x96, 0x51, 0x53, 0x92, + 0x94, 0x93, 0x40, 0xf3, 0x9c, 0x2a, 0x8d, 0xf3, 0x99, 0x29, 0xf0, 0x3e, 0x01, 0x78, 0xf7, 0xb5, + 0x62, 0xa7, 0xe2, 0x23, 0xe6, 0x99, 0x55, 0xc2, 0xfd, 0x73, 0x9c, 0x71, 0x82, 0xb5, 0x2c, 0x62, + 0x4c, 0x48, 0x61, 0x03, 0x17, 0x0c, 0xfb, 0xe1, 0x9b, 0x9f, 0x15, 0xba, 0x53, 0x6b, 0xaa, 0xd4, + 0xba, 0x42, 0xfb, 0x0b, 0x9c, 0x67, 0x23, 0x6f, 0x03, 0xbc, 0x9b, 0x0a, 0x1d, 0x32, 0xae, 0xd3, + 0x32, 0xf1, 0xc7, 0x32, 0x0f, 0xcc, 0xa5, 0x37, 0x7f, 0x87, 0x8a, 0x4c, 0x37, 0x33, 0x9d, 0xe1, + 0xec, 0xb9, 0x71, 0x44, 0xf7, 0x7e, 0xa7, 0xd4, 0xc4, 0xfb, 0xd2, 0x85, 0xf7, 0xcf, 0x5a, 0xf2, + 0x8e, 0x33, 0xc1, 0x05, 0x7b, 0x29, 0x26, 0xd2, 0x7a, 0x05, 0xdb, 0xd4, 0xcd, 0x45, 0x8e, 0x6e, + 0x2a, 0xe4, 0xff, 0x43, 0xd6, 0xb1, 0x14, 0xaa, 0x0d, 0x6b, 0x5b, 0x58, 0x23, 0xd8, 0x57, 0x1a, + 0x17, 0x3a, 0x4e, 0x29, 0x67, 0xa9, 0xb6, 0xff, 0x73, 0xc1, 0xb0, 0x1b, 0x3e, 0x5c, 0x57, 0xe8, + 0xc0, 0x0c, 0xb4, 0x7d, 0xea, 0x45, 0xbd, 0x46, 0xbe, 0x68, 0x54, 0xed, 0xe5, 0x82, 0xd0, 0x79, + 0x2c, 0x27, 0x13, 0x45, 0xb5, 0xdd, 0xfd, 0xd3, 0xbb, 0x7d, 0xea, 0x45, 0xbd, 0x46, 0xbe, 0x6d, + 0x94, 0xf5, 0x01, 0xf6, 0xeb, 0xb7, 0x4b, 0x49, 0x5c, 0x0a, 0xcd, 0x33, 0xfb, 0x7f, 0x17, 0x0c, + 0x7b, 0x47, 0x03, 0xdf, 0xec, 0xc6, 0x6f, 0x77, 0xe3, 0x9f, 0xb4, 0xbb, 0x09, 0xd1, 0x55, 0x85, + 0x3a, 0xb7, 0xbd, 0xb7, 0xdd, 0xde, 0xc5, 0x37, 0x04, 0xa2, 0x9e, 0x41, 0xa7, 0x35, 0xb1, 0x1c, + 0x08, 0xb5, 0xcc, 0x13, 0xa5, 0xa5, 0xa0, 0xc4, 0xde, 0x71, 0xc1, 0x70, 0x2f, 0xda, 0x22, 0xd6, + 0x09, 0x7c, 0x90, 0x73, 0xa5, 0x28, 0x89, 0x93, 0x4c, 0x8e, 0xa7, 0x2a, 0x1e, 0xcb, 0xb2, 0xfe, + 0xe8, 0xec, 0xdd, 0x66, 0x08, 0x77, 0x5d, 0xa1, 0x47, 0x26, 0xe8, 0xaf, 0x65, 0x5e, 0x74, 0x60, + 0x78, 0xd8, 0xe0, 0x63, 0x43, 0x47, 0x7b, 0x9f, 0x2f, 0x51, 0xe7, 0xc7, 0x25, 0x02, 0x21, 0xba, + 0x5a, 0x3a, 0xe0, 0x7a, 0xe9, 0x80, 0xef, 0x4b, 0x07, 0x5c, 0xac, 0x9c, 0xce, 0xf5, 0xca, 0xe9, + 0x7c, 0x5d, 0x39, 0x9d, 0xf7, 0x3b, 0xcd, 0x36, 0x92, 0xdd, 0x66, 0xc4, 0x67, 0xbf, 0x02, 0x00, + 0x00, 0xff, 0xff, 0x61, 0xf4, 0xaf, 0xf7, 0xf7, 0x02, 0x00, 0x00, +} + +func (this *ValidatorSigningInfo) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ValidatorSigningInfo) + if !ok { + that2, ok := that.(ValidatorSigningInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !bytes.Equal(this.Address, that1.Address) { + return false + } + if this.StartHeight != that1.StartHeight { + return false + } + if this.IndexOffset != that1.IndexOffset { + return false + } + if !this.JailedUntil.Equal(that1.JailedUntil) { + return false + } + if this.Tombstoned != that1.Tombstoned { + return false + } + if this.MissedBlocksCounter != that1.MissedBlocksCounter { + return false + } + return true +} +func (m *MsgUnjail) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUnjail) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ValidatorAddr) > 0 { + i -= len(m.ValidatorAddr) + copy(dAtA[i:], m.ValidatorAddr) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ValidatorAddr))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ValidatorSigningInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorSigningInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSigningInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MissedBlocksCounter != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.MissedBlocksCounter)) + i-- + dAtA[i] = 0x30 + } + if m.Tombstoned { + i-- + if m.Tombstoned { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.JailedUntil, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.JailedUntil):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTypes(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x22 + if m.IndexOffset != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.IndexOffset)) + i-- + dAtA[i] = 0x18 + } + if m.StartHeight != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.StartHeight)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUnjail) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddr) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ValidatorSigningInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.StartHeight != 0 { + n += 1 + sovTypes(uint64(m.StartHeight)) + } + if m.IndexOffset != 0 { + n += 1 + sovTypes(uint64(m.IndexOffset)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.JailedUntil) + n += 1 + l + sovTypes(uint64(l)) + if m.Tombstoned { + n += 2 + } + if m.MissedBlocksCounter != 0 { + n += 1 + sovTypes(uint64(m.MissedBlocksCounter)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUnjail) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUnjail: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUnjail: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddr", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddr = append(m.ValidatorAddr[:0], dAtA[iNdEx:postIndex]...) + if m.ValidatorAddr == nil { + m.ValidatorAddr = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSigningInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorSigningInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSigningInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = append(m.Address[:0], dAtA[iNdEx:postIndex]...) + if m.Address == nil { + m.Address = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartHeight", wireType) + } + m.StartHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IndexOffset", wireType) + } + m.IndexOffset = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.IndexOffset |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field JailedUntil", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.JailedUntil, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Tombstoned", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Tombstoned = bool(v != 0) + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MissedBlocksCounter", wireType) + } + m.MissedBlocksCounter = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MissedBlocksCounter |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/slashing/types/types.proto b/x/slashing/types/types.proto new file mode 100644 index 000000000000..9aafe07c3bf3 --- /dev/null +++ b/x/slashing/types/types.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; +package cosmos_sdk.x.slashing.v1; + +option go_package = "github.com/cosmos/cosmos-sdk/x/slashing/types"; + +import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +// MsgUnjail - struct for unjailing jailed validator +message MsgUnjail { + bytes validator_addr = 1 [ + (gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress", + (gogoproto.moretags) = "yaml:\"address\"", + (gogoproto.jsontag) = "address" + ]; +} + +// ValidatorSigningInfo defines the signing info for a validator +message ValidatorSigningInfo { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + bytes address = 1 [ + (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.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) +} \ No newline at end of file