diff --git a/proto/centauri/keyrotation/v1beta1/genesis.proto b/proto/centauri/keyrotation/v1beta1/genesis.proto new file mode 100644 index 000000000..6ad9c1d55 --- /dev/null +++ b/proto/centauri/keyrotation/v1beta1/genesis.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package centauri.keyrotation.v1beta1; + +import "gogoproto/gogo.proto"; + +option go_package = "x/keyrotation/types"; + +// GenesisState defines the mint module's genesis state. +message GenesisState {} diff --git a/proto/centauri/keyrotation/v1beta1/rotation.proto b/proto/centauri/keyrotation/v1beta1/rotation.proto new file mode 100644 index 000000000..67eecc7ae --- /dev/null +++ b/proto/centauri/keyrotation/v1beta1/rotation.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package centauri.keyrotation.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "google/protobuf/any.proto"; + +option go_package = "x/keyrotation/types"; + +// GenesisState defines the mint module's genesis state. +message ConsPubKeyRotationHistory { + string operator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + google.protobuf.Any old_key = 2 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; + google.protobuf.Any new_key = 3 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; + uint64 block_height = 4; +} \ No newline at end of file diff --git a/proto/centauri/keyrotation/v1beta1/tx.proto b/proto/centauri/keyrotation/v1beta1/tx.proto new file mode 100644 index 000000000..eb79811d2 --- /dev/null +++ b/proto/centauri/keyrotation/v1beta1/tx.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package centauri.keyrotation.v1beta1; + +import "cosmos/msg/v1/msg.proto"; +import "amino/amino.proto"; +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "google/protobuf/any.proto"; + +option go_package = "x/keyrotation/types"; + +// Msg defines the x/keyrotation Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + // CreateValidator defines a method for creating a new validator. + rpc RotateConsPubKey(MsgRotateConsPubKey) returns (MsgRotateConsPubKeyResponse); +} + +message MsgRotateConsPubKey { + string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + google.protobuf.Any pubkey = 2 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; +} + +message MsgRotateConsPubKeyResponse { +} \ No newline at end of file diff --git a/x/keyrotation/keeper/abci.go b/x/keyrotation/keeper/abci.go new file mode 100644 index 000000000..65cc444e4 --- /dev/null +++ b/x/keyrotation/keeper/abci.go @@ -0,0 +1,10 @@ +package keeper + +import ( + abci "github.com/cometbft/cometbft/abci/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { + return nil +} diff --git a/x/keyrotation/keeper/genesis.go b/x/keyrotation/keeper/genesis.go new file mode 100644 index 000000000..ca342d49c --- /dev/null +++ b/x/keyrotation/keeper/genesis.go @@ -0,0 +1,13 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/notional-labs/composable/v6/x/keyrotation/types" +) + +func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {} + +func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + return nil +} diff --git a/x/keyrotation/keeper/keeper.go b/x/keyrotation/keeper/keeper.go new file mode 100644 index 000000000..7932d8c1f --- /dev/null +++ b/x/keyrotation/keeper/keeper.go @@ -0,0 +1,104 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/notional-labs/composable/v6/x/keyrotation/types" +) + +type Keeper struct { + storeKey storetypes.StoreKey + cdc codec.BinaryCodec + sk types.StakingKeeper + + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string +} + +func NewKeeper( + cdc codec.BinaryCodec, + key storetypes.StoreKey, + sk types.StakingKeeper, + authority string, +) Keeper { + return Keeper{ + cdc: cdc, + storeKey: key, + sk: sk, + authority: authority, + } +} + +func (k Keeper) handleMsgRotateConsPubKey(ctx sdk.Context, valAddress sdk.ValAddress, pubKey cryptotypes.PubKey) error { + var ( + validator stakingtypes.Validator + found bool + ) + // check to see if the validator not exist + if validator, found = k.sk.GetValidator(ctx, valAddress); !found { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "validator not exists") + } + + // check if pubkey is exists + if _, found := k.sk.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pubKey)); found { + return stakingtypes.ErrValidatorPubKeyExists + } + + // check if new pubkey is allowed + cp := ctx.ConsensusParams() + if cp != nil && cp.Validator != nil { + pkType := pubKey.Type() + hasKeyType := false + for _, keyType := range cp.Validator.PubKeyTypes { + if pkType == keyType { + hasKeyType = true + break + } + } + if !hasKeyType { + return errorsmod.Wrapf( + stakingtypes.ErrValidatorPubKeyTypeNotSupported, + "got: %s, expected: %s", pubKey.Type(), cp.Validator.PubKeyTypes, + ) + } + } + + // wrap pubkey to types any + newPkAny, err := codectypes.NewAnyWithValue(pubKey) + if err != nil { + return err + } + + oldPkAny := validator.ConsensusPubkey + + // replace pubkey + validator.ConsensusPubkey = newPkAny + + // NOTE: staking module do not support DeleteValidatorByConsAddr method for Validator types + // we need to record all the rotated pubkey in keyrotation store so when we can delete later + // by upgrade handler + + // set validator + k.sk.SetValidator(ctx, validator) + k.sk.SetValidatorByConsAddr(ctx, validator) + + // Set rotation history + consPubKeyRotationHistory := types.ConsPubKeyRotationHistory{ + OperatorAddress: valAddress.String(), + OldKey: oldPkAny, + NewKey: newPkAny, + BlockHeight: uint64(ctx.BlockHeight()), + } + + k.SetKeyRotationHistory(ctx, consPubKeyRotationHistory) + + return nil +} diff --git a/x/keyrotation/keeper/msg_server.go b/x/keyrotation/keeper/msg_server.go new file mode 100644 index 000000000..a697bf18b --- /dev/null +++ b/x/keyrotation/keeper/msg_server.go @@ -0,0 +1,47 @@ +package keeper + +import ( + "context" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/notional-labs/composable/v6/x/keyrotation/types" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var _ types.MsgServer = msgServer{} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{ + Keeper: keeper, + } +} + +type msgServer struct { + Keeper +} + +func (k Keeper) RotateConsPubKey(goCtx context.Context, msg *types.MsgRotateConsPubKey) (*types.MsgRotateConsPubKeyResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + if err != nil { + return nil, err + } + + // get pubkey + pk, ok := msg.Pubkey.GetCachedValue().(cryptotypes.PubKey) + if !ok { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", pk) + } + + err = k.handleMsgRotateConsPubKey(ctx, valAddr, pk) + if err != nil { + return nil, err + } + + return &types.MsgRotateConsPubKeyResponse{}, nil +} diff --git a/x/keyrotation/keeper/pubkey_rotation.go b/x/keyrotation/keeper/pubkey_rotation.go new file mode 100644 index 000000000..845187d1b --- /dev/null +++ b/x/keyrotation/keeper/pubkey_rotation.go @@ -0,0 +1,26 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/notional-labs/composable/v6/x/keyrotation/types" +) + +func (k Keeper) SetKeyRotationHistory(ctx sdk.Context, consRotationHistory types.ConsPubKeyRotationHistory) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(&consRotationHistory) + store.Set(types.GetKeyRotationHistory(consRotationHistory.OperatorAddress), bz) +} + +func (k Keeper) IterateRotationHistory(ctx sdk.Context, cb func(types.ConsPubKeyRotationHistory) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.KeyRotation) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + var rotationHistory types.ConsPubKeyRotationHistory + k.cdc.MustUnmarshal(iterator.Value(), &rotationHistory) + if cb(rotationHistory) { + break + } + } +} diff --git a/x/keyrotation/module.go b/x/keyrotation/module.go new file mode 100644 index 000000000..80c4442be --- /dev/null +++ b/x/keyrotation/module.go @@ -0,0 +1,131 @@ +package keyrotation + +import ( + "encoding/json" + "fmt" + + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/notional-labs/composable/v6/x/keyrotation/keeper" + "github.com/notional-labs/composable/v6/x/keyrotation/types" + "github.com/spf13/cobra" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic defines the basic application module used by the ibc-hooks module. +type AppModuleBasic struct{} + +// Name returns the ibc-hooks module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the ibc-hooks module's types on the given LegacyAmino codec. +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers module concrete types into protobuf Any. +func (AppModuleBasic) RegisterInterfaces(reg codectypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns default genesis state as raw bytes for the ibc +// router module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// RegisterRESTRoutes implements AppModuleBasic interface +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { +} + +// GetTxCmd implements AppModuleBasic interface +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd implements AppModuleBasic interface +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil +} + +// AppModule represents the AppModule for this module +type AppModule struct { + AppModuleBasic + keeper *keeper.Keeper +} + +// NewAppModule creates a new router module +func NewAppModule(k *keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{}, + keeper: k, + } +} + +// Name returns the capability module's name. +func (am AppModule) Name() string { + return am.AppModuleBasic.Name() +} + +// QuerierRoute implements the AppModule interface +func (AppModule) QuerierRoute() string { + return types.QuerierRoute +} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { +} + +// InitGenesis performs genesis initialization for the ibc-router module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) + return []abci.ValidatorUpdate{} +} + +// ValidateGenesis performs genesis state validation for the mint module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + // TODO: Add types.ValidateGenesis(data) + return types.ValidateGenesis(data) +} + +// ExportGenesis returns the exported genesis state as raw bytes for the ibc-router +// module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.keeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock implements the AppModule interface +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { +} + +// EndBlock implements the AppModule interface +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return am.keeper.EndBlock(ctx) +} diff --git a/x/keyrotation/types/codec.go b/x/keyrotation/types/codec.go new file mode 100644 index 000000000..63cd1b44a --- /dev/null +++ b/x/keyrotation/types/codec.go @@ -0,0 +1,45 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/types/msgservice" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterLegacyAminoCodec registers the account interfaces and concrete types on the +// provided LegacyAmino codec. These types are used for Amino JSON serialization +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgRotateConsPubKey{}, "composable/MsgAddRateLimit") +} + +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgRotateConsPubKey{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances + RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) +} diff --git a/x/keyrotation/types/expected_keepers.go b/x/keyrotation/types/expected_keepers.go new file mode 100644 index 000000000..b9073bca5 --- /dev/null +++ b/x/keyrotation/types/expected_keepers.go @@ -0,0 +1,14 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// StakingKeeper expected staking keeper +type StakingKeeper interface { + SetValidator(sdk.Context, stakingtypes.Validator) + SetValidatorByConsAddr(sdk.Context, stakingtypes.Validator) error + GetValidator(sdk.Context, sdk.ValAddress) (stakingtypes.Validator, bool) + GetValidatorByConsAddr(sdk.Context, sdk.ConsAddress) (stakingtypes.Validator, bool) +} diff --git a/x/keyrotation/types/genesis.go b/x/keyrotation/types/genesis.go new file mode 100644 index 000000000..c37da918b --- /dev/null +++ b/x/keyrotation/types/genesis.go @@ -0,0 +1,12 @@ +package types + +// DefaultGenesis returns the default Capability genesis state +func DefaultGenesisState() *GenesisState { + return &GenesisState{} +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func ValidateGenesis(data GenesisState) error { + return nil +} diff --git a/x/keyrotation/types/genesis.pb.go b/x/keyrotation/types/genesis.pb.go new file mode 100644 index 000000000..a9351b690 --- /dev/null +++ b/x/keyrotation/types/genesis.pb.go @@ -0,0 +1,267 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/keyrotation/v1beta1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// 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 + +// GenesisState defines the mint module's genesis state. +type GenesisState struct { +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_3e508c32b41452b7, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "centauri.keyrotation.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("centauri/keyrotation/v1beta1/genesis.proto", fileDescriptor_3e508c32b41452b7) +} + +var fileDescriptor_3e508c32b41452b7 = []byte{ + // 146 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0x4e, 0xcd, 0x2b, + 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0xcf, 0x4e, 0xad, 0x2c, 0xca, 0x2f, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, + 0xd3, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, + 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x81, 0xa9, 0xd5, 0x43, 0x52, 0xab, 0x07, 0x55, + 0x2b, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xa8, 0x0f, 0x62, 0x41, 0xf4, 0x28, 0xf1, 0x71, + 0xf1, 0xb8, 0x43, 0x0c, 0x09, 0x2e, 0x49, 0x2c, 0x49, 0x75, 0xd2, 0x3d, 0xf1, 0x48, 0x8e, 0xf1, + 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, + 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xe1, 0x0a, 0x14, 0x27, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, + 0xb1, 0x81, 0x4d, 0x31, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x89, 0x29, 0x11, 0x1c, 0xa7, 0x00, + 0x00, 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrIntOverflowGenesis + } + 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, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/keyrotation/types/keys.go b/x/keyrotation/types/keys.go new file mode 100644 index 000000000..1efa0c336 --- /dev/null +++ b/x/keyrotation/types/keys.go @@ -0,0 +1,22 @@ +package types + +const ( + ModuleName = "keyrotation" + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName + + RouterKey = ModuleName +) + +func KeyPrefix(p string) []byte { + return []byte(p) +} + +var ( + KeyRotation = KeyPrefix("rotation") +) + +func GetKeyRotationHistory(valAddress string) []byte { + return append(KeyRotation, []byte(valAddress)...) +} diff --git a/x/keyrotation/types/msgs.go b/x/keyrotation/types/msgs.go new file mode 100644 index 000000000..fb2c33716 --- /dev/null +++ b/x/keyrotation/types/msgs.go @@ -0,0 +1,78 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + TypeMsgRotateConsPubKey = "rotate_cons_pubkey" +) + +var ( + _ sdk.Msg = &MsgRotateConsPubKey{} +) + +func NewMsgRotateConsPubKey( + valAddr sdk.ValAddress, + pubKey cryptotypes.PubKey, +) (*MsgRotateConsPubKey, error) { + var pkAny *codectypes.Any + if pubKey != nil { + var err error + if pkAny, err = codectypes.NewAnyWithValue(pubKey); err != nil { + return nil, err + } + } + return &MsgRotateConsPubKey{ + ValidatorAddress: valAddr.String(), + Pubkey: pkAny, + }, nil +} + +// Route implements the sdk.Msg interface. +func (msg MsgRotateConsPubKey) Route() string { return RouterKey } + +// Type implements the sdk.Msg interface. +func (msg MsgRotateConsPubKey) Type() string { return TypeMsgRotateConsPubKey } + +// GetSigners implements the sdk.Msg interface. It returns the address(es) that +// must sign over msg.GetSignBytes(). +// If the validator address is not same as delegator's, then the validator must +// sign the msg as well. +func (msg MsgRotateConsPubKey) GetSigners() []sdk.AccAddress { + valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) + + valAccAddr := sdk.AccAddress(valAddr) + + return []sdk.AccAddress{valAccAddr} +} + +// GetSignBytes returns the message bytes to sign over. +func (msg MsgRotateConsPubKey) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic implements the sdk.Msg interface. +func (msg MsgRotateConsPubKey) ValidateBasic() error { + _, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + if err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) + } + + if msg.Pubkey == nil { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty pubkey") + } + + return nil +} + +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (msg MsgRotateConsPubKey) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var pubKey cryptotypes.PubKey + return unpacker.UnpackAny(msg.Pubkey, &pubKey) +} diff --git a/x/keyrotation/types/rotation.pb.go b/x/keyrotation/types/rotation.pb.go new file mode 100644 index 000000000..490899c0a --- /dev/null +++ b/x/keyrotation/types/rotation.pb.go @@ -0,0 +1,486 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/keyrotation/v1beta1/rotation.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// 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 + +// GenesisState defines the mint module's genesis state. +type ConsPubKeyRotationHistory struct { + OperatorAddress string `protobuf:"bytes,1,opt,name=operator_address,json=operatorAddress,proto3" json:"operator_address,omitempty"` + OldKey *types.Any `protobuf:"bytes,2,opt,name=old_key,json=oldKey,proto3" json:"old_key,omitempty"` + NewKey *types.Any `protobuf:"bytes,3,opt,name=new_key,json=newKey,proto3" json:"new_key,omitempty"` + BlockHeight uint64 `protobuf:"varint,4,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` +} + +func (m *ConsPubKeyRotationHistory) Reset() { *m = ConsPubKeyRotationHistory{} } +func (m *ConsPubKeyRotationHistory) String() string { return proto.CompactTextString(m) } +func (*ConsPubKeyRotationHistory) ProtoMessage() {} +func (*ConsPubKeyRotationHistory) Descriptor() ([]byte, []int) { + return fileDescriptor_68d414f3745c6381, []int{0} +} +func (m *ConsPubKeyRotationHistory) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConsPubKeyRotationHistory) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ConsPubKeyRotationHistory.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 *ConsPubKeyRotationHistory) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConsPubKeyRotationHistory.Merge(m, src) +} +func (m *ConsPubKeyRotationHistory) XXX_Size() int { + return m.Size() +} +func (m *ConsPubKeyRotationHistory) XXX_DiscardUnknown() { + xxx_messageInfo_ConsPubKeyRotationHistory.DiscardUnknown(m) +} + +var xxx_messageInfo_ConsPubKeyRotationHistory proto.InternalMessageInfo + +func (m *ConsPubKeyRotationHistory) GetOperatorAddress() string { + if m != nil { + return m.OperatorAddress + } + return "" +} + +func (m *ConsPubKeyRotationHistory) GetOldKey() *types.Any { + if m != nil { + return m.OldKey + } + return nil +} + +func (m *ConsPubKeyRotationHistory) GetNewKey() *types.Any { + if m != nil { + return m.NewKey + } + return nil +} + +func (m *ConsPubKeyRotationHistory) GetBlockHeight() uint64 { + if m != nil { + return m.BlockHeight + } + return 0 +} + +func init() { + proto.RegisterType((*ConsPubKeyRotationHistory)(nil), "centauri.keyrotation.v1beta1.ConsPubKeyRotationHistory") +} + +func init() { + proto.RegisterFile("centauri/keyrotation/v1beta1/rotation.proto", fileDescriptor_68d414f3745c6381) +} + +var fileDescriptor_68d414f3745c6381 = []byte{ + // 324 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xbd, 0x4e, 0x02, 0x41, + 0x14, 0x85, 0x19, 0x24, 0x18, 0x17, 0x13, 0x0d, 0x52, 0x2c, 0xc4, 0x6c, 0xd0, 0x8a, 0xc4, 0x30, + 0x1b, 0xf4, 0x09, 0x80, 0x42, 0x12, 0x1a, 0x83, 0x9d, 0xcd, 0x66, 0x7f, 0xae, 0xc3, 0x86, 0x75, + 0xee, 0x66, 0x66, 0x10, 0xe7, 0x2d, 0x6c, 0x7c, 0x13, 0x1f, 0xc2, 0x58, 0x11, 0x2b, 0x4b, 0x03, + 0x2f, 0x62, 0x98, 0xd9, 0x8d, 0xda, 0xda, 0xcd, 0x3d, 0xe7, 0xdc, 0xef, 0x9e, 0x64, 0x9c, 0x8b, + 0x18, 0xb8, 0x0a, 0x97, 0x22, 0xf5, 0x17, 0xa0, 0x05, 0xaa, 0x50, 0xa5, 0xc8, 0xfd, 0xc7, 0x41, + 0x04, 0x2a, 0x1c, 0xf8, 0xa5, 0x40, 0x73, 0x81, 0x0a, 0x9b, 0xa7, 0x65, 0x98, 0xfe, 0x0a, 0xd3, + 0x22, 0xdc, 0x69, 0x31, 0x64, 0x68, 0x82, 0xfe, 0xee, 0x65, 0x77, 0x3a, 0xed, 0x18, 0xe5, 0x03, + 0xca, 0xc0, 0x1a, 0x76, 0x28, 0x2d, 0x86, 0xc8, 0x32, 0xf0, 0xcd, 0x14, 0x2d, 0xef, 0xfd, 0x90, + 0x6b, 0x6b, 0x9d, 0xbf, 0x54, 0x9d, 0xf6, 0x18, 0xb9, 0xbc, 0x59, 0x46, 0x53, 0xd0, 0xb3, 0xe2, + 0xd4, 0x24, 0x95, 0x0a, 0x85, 0x6e, 0x8e, 0x9d, 0x63, 0xcc, 0x41, 0x84, 0x0a, 0x45, 0x10, 0x26, + 0x89, 0x00, 0x29, 0x5d, 0xd2, 0x25, 0xbd, 0x83, 0x91, 0xfb, 0xf1, 0xda, 0x6f, 0x15, 0x47, 0x86, + 0xd6, 0xb9, 0x55, 0x22, 0xe5, 0x6c, 0x76, 0x54, 0x6e, 0x14, 0x72, 0xf3, 0xda, 0xd9, 0xc7, 0x2c, + 0x09, 0x16, 0xa0, 0xdd, 0x6a, 0x97, 0xf4, 0x1a, 0x97, 0x2d, 0x6a, 0xfb, 0xd0, 0xb2, 0x0f, 0x1d, + 0x72, 0x3d, 0x72, 0xdf, 0x7f, 0x88, 0xb1, 0xd0, 0xb9, 0x42, 0x5a, 0x94, 0xaa, 0x63, 0x96, 0x4c, + 0x41, 0xef, 0x40, 0x1c, 0x56, 0x06, 0xb4, 0xf7, 0x3f, 0x10, 0x87, 0xd5, 0x0e, 0x74, 0xe6, 0x1c, + 0x46, 0x19, 0xc6, 0x8b, 0x60, 0x0e, 0x29, 0x9b, 0x2b, 0xb7, 0xd6, 0x25, 0xbd, 0xda, 0xac, 0x61, + 0xb4, 0x89, 0x91, 0x46, 0xfd, 0xb7, 0x8d, 0x47, 0xd6, 0x1b, 0x8f, 0x7c, 0x6d, 0x3c, 0xf2, 0xbc, + 0xf5, 0x2a, 0xeb, 0xad, 0x57, 0xf9, 0xdc, 0x7a, 0x95, 0xbb, 0x93, 0xa7, 0x3f, 0x3f, 0xa8, 0x74, + 0x0e, 0x32, 0xaa, 0x9b, 0x06, 0x57, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x92, 0x3e, 0x25, 0x1f, + 0xe6, 0x01, 0x00, 0x00, +} + +func (m *ConsPubKeyRotationHistory) 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 *ConsPubKeyRotationHistory) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConsPubKeyRotationHistory) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.BlockHeight != 0 { + i = encodeVarintRotation(dAtA, i, uint64(m.BlockHeight)) + i-- + dAtA[i] = 0x20 + } + if m.NewKey != nil { + { + size, err := m.NewKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRotation(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.OldKey != nil { + { + size, err := m.OldKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintRotation(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.OperatorAddress) > 0 { + i -= len(m.OperatorAddress) + copy(dAtA[i:], m.OperatorAddress) + i = encodeVarintRotation(dAtA, i, uint64(len(m.OperatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintRotation(dAtA []byte, offset int, v uint64) int { + offset -= sovRotation(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ConsPubKeyRotationHistory) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.OperatorAddress) + if l > 0 { + n += 1 + l + sovRotation(uint64(l)) + } + if m.OldKey != nil { + l = m.OldKey.Size() + n += 1 + l + sovRotation(uint64(l)) + } + if m.NewKey != nil { + l = m.NewKey.Size() + n += 1 + l + sovRotation(uint64(l)) + } + if m.BlockHeight != 0 { + n += 1 + sovRotation(uint64(m.BlockHeight)) + } + return n +} + +func sovRotation(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozRotation(x uint64) (n int) { + return sovRotation(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ConsPubKeyRotationHistory) 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 ErrIntOverflowRotation + } + 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: ConsPubKeyRotationHistory: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ConsPubKeyRotationHistory: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OperatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRotation + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthRotation + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthRotation + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.OperatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OldKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRotation + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRotation + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRotation + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.OldKey == nil { + m.OldKey = &types.Any{} + } + if err := m.OldKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRotation + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRotation + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthRotation + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.NewKey == nil { + m.NewKey = &types.Any{} + } + if err := m.NewKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockHeight", wireType) + } + m.BlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRotation + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipRotation(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthRotation + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipRotation(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, ErrIntOverflowRotation + } + 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, ErrIntOverflowRotation + } + 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, ErrIntOverflowRotation + } + 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, ErrInvalidLengthRotation + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupRotation + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthRotation + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthRotation = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowRotation = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupRotation = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/keyrotation/types/tx.pb.go b/x/keyrotation/types/tx.pb.go new file mode 100644 index 000000000..36dadee82 --- /dev/null +++ b/x/keyrotation/types/tx.pb.go @@ -0,0 +1,600 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: centauri/keyrotation/v1beta1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// 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 + +type MsgRotateConsPubKey struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Pubkey *types.Any `protobuf:"bytes,2,opt,name=pubkey,proto3" json:"pubkey,omitempty"` +} + +func (m *MsgRotateConsPubKey) Reset() { *m = MsgRotateConsPubKey{} } +func (m *MsgRotateConsPubKey) String() string { return proto.CompactTextString(m) } +func (*MsgRotateConsPubKey) ProtoMessage() {} +func (*MsgRotateConsPubKey) Descriptor() ([]byte, []int) { + return fileDescriptor_7b7eabc36a3a1a44, []int{0} +} +func (m *MsgRotateConsPubKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRotateConsPubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRotateConsPubKey.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 *MsgRotateConsPubKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRotateConsPubKey.Merge(m, src) +} +func (m *MsgRotateConsPubKey) XXX_Size() int { + return m.Size() +} +func (m *MsgRotateConsPubKey) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRotateConsPubKey.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRotateConsPubKey proto.InternalMessageInfo + +func (m *MsgRotateConsPubKey) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +func (m *MsgRotateConsPubKey) GetPubkey() *types.Any { + if m != nil { + return m.Pubkey + } + return nil +} + +type MsgRotateConsPubKeyResponse struct { +} + +func (m *MsgRotateConsPubKeyResponse) Reset() { *m = MsgRotateConsPubKeyResponse{} } +func (m *MsgRotateConsPubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRotateConsPubKeyResponse) ProtoMessage() {} +func (*MsgRotateConsPubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7b7eabc36a3a1a44, []int{1} +} +func (m *MsgRotateConsPubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRotateConsPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRotateConsPubKeyResponse.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 *MsgRotateConsPubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRotateConsPubKeyResponse.Merge(m, src) +} +func (m *MsgRotateConsPubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRotateConsPubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRotateConsPubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRotateConsPubKeyResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgRotateConsPubKey)(nil), "centauri.keyrotation.v1beta1.MsgRotateConsPubKey") + proto.RegisterType((*MsgRotateConsPubKeyResponse)(nil), "centauri.keyrotation.v1beta1.MsgRotateConsPubKeyResponse") +} + +func init() { + proto.RegisterFile("centauri/keyrotation/v1beta1/tx.proto", fileDescriptor_7b7eabc36a3a1a44) +} + +var fileDescriptor_7b7eabc36a3a1a44 = []byte{ + // 356 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4d, 0x4e, 0xcd, 0x2b, + 0x49, 0x2c, 0x2d, 0xca, 0xd4, 0xcf, 0x4e, 0xad, 0x2c, 0xca, 0x2f, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, + 0xd3, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0x92, 0x81, 0x29, 0xd3, 0x43, 0x52, 0xa6, 0x07, 0x55, 0x26, 0x25, 0x9e, 0x9c, 0x5f, + 0x9c, 0x9b, 0x5f, 0xac, 0x9f, 0x5b, 0x9c, 0xae, 0x5f, 0x66, 0x08, 0xa2, 0x20, 0xda, 0xa4, 0x04, + 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x54, 0x48, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, + 0xd4, 0x07, 0xb1, 0xa0, 0xa2, 0x92, 0x10, 0x13, 0xe2, 0x21, 0x12, 0x10, 0x0e, 0x4c, 0x2a, 0x3d, + 0x3f, 0x3f, 0x3d, 0x27, 0x55, 0x1f, 0xcc, 0x4b, 0x2a, 0x4d, 0xd3, 0x4f, 0xcc, 0xab, 0x84, 0x48, + 0x29, 0x2d, 0x61, 0xe4, 0x12, 0xf6, 0x2d, 0x4e, 0x0f, 0x02, 0xb9, 0x27, 0xd5, 0x39, 0x3f, 0xaf, + 0x38, 0xa0, 0x34, 0xc9, 0x3b, 0xb5, 0x52, 0xc8, 0x95, 0x4b, 0xb0, 0x2c, 0x31, 0x27, 0x33, 0x25, + 0xb1, 0x24, 0xbf, 0x28, 0x3e, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x58, 0x82, 0x51, 0x81, 0x51, + 0x83, 0xd3, 0x49, 0xe2, 0xd2, 0x16, 0x5d, 0x11, 0xa8, 0xf9, 0x8e, 0x10, 0x99, 0xe0, 0x92, 0xa2, + 0xcc, 0xbc, 0xf4, 0x20, 0x01, 0xb8, 0x16, 0xa8, 0xb8, 0x90, 0x1b, 0x17, 0x5b, 0x41, 0x69, 0x52, + 0x76, 0x6a, 0xa5, 0x04, 0x93, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x88, 0x1e, 0xc4, 0x29, 0x7a, 0x30, + 0xa7, 0xe8, 0x39, 0xe6, 0x55, 0x3a, 0x49, 0x9c, 0x42, 0x98, 0x98, 0x5c, 0x54, 0x59, 0x50, 0x92, + 0xaf, 0x07, 0x71, 0x46, 0x10, 0x54, 0xb7, 0x92, 0x2c, 0x97, 0x34, 0x16, 0x57, 0x06, 0xa5, 0x16, + 0x17, 0xe4, 0xe7, 0x15, 0xa7, 0x1a, 0xf5, 0x33, 0x72, 0x31, 0xfb, 0x16, 0xa7, 0x0b, 0x35, 0x30, + 0x72, 0x09, 0x60, 0x78, 0xc5, 0x50, 0x0f, 0x5f, 0xc8, 0xeb, 0x61, 0x31, 0x57, 0xca, 0x92, 0x64, + 0x2d, 0x30, 0xa7, 0x48, 0xb1, 0x36, 0x3c, 0xdf, 0xa0, 0xc5, 0xe8, 0xa4, 0x7b, 0xe2, 0x91, 0x1c, + 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, + 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xc2, 0x15, 0x28, 0xe9, 0xa4, 0xa4, 0xb2, 0x20, 0xb5, + 0x38, 0x89, 0x0d, 0x1c, 0x1e, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe6, 0xc8, 0xea, 0x25, + 0x4c, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // CreateValidator defines a method for creating a new validator. + RotateConsPubKey(ctx context.Context, in *MsgRotateConsPubKey, opts ...grpc.CallOption) (*MsgRotateConsPubKeyResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) RotateConsPubKey(ctx context.Context, in *MsgRotateConsPubKey, opts ...grpc.CallOption) (*MsgRotateConsPubKeyResponse, error) { + out := new(MsgRotateConsPubKeyResponse) + err := c.cc.Invoke(ctx, "/centauri.keyrotation.v1beta1.Msg/RotateConsPubKey", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // CreateValidator defines a method for creating a new validator. + RotateConsPubKey(context.Context, *MsgRotateConsPubKey) (*MsgRotateConsPubKeyResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) RotateConsPubKey(ctx context.Context, req *MsgRotateConsPubKey) (*MsgRotateConsPubKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RotateConsPubKey not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_RotateConsPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRotateConsPubKey) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RotateConsPubKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/centauri.keyrotation.v1beta1.Msg/RotateConsPubKey", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RotateConsPubKey(ctx, req.(*MsgRotateConsPubKey)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "centauri.keyrotation.v1beta1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RotateConsPubKey", + Handler: _Msg_RotateConsPubKey_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "centauri/keyrotation/v1beta1/tx.proto", +} + +func (m *MsgRotateConsPubKey) 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 *MsgRotateConsPubKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRotateConsPubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pubkey != nil { + { + size, err := m.Pubkey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRotateConsPubKeyResponse) 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 *MsgRotateConsPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRotateConsPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgRotateConsPubKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Pubkey != nil { + l = m.Pubkey.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRotateConsPubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgRotateConsPubKey) 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 ErrIntOverflowTx + } + 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: MsgRotateConsPubKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRotateConsPubKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pubkey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pubkey == nil { + m.Pubkey = &types.Any{} + } + if err := m.Pubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRotateConsPubKeyResponse) 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 ErrIntOverflowTx + } + 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: MsgRotateConsPubKeyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRotateConsPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrIntOverflowTx + } + 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, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +)