Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Keefe Liu committed Dec 22, 2022
1 parent f5ce045 commit a896eaf
Show file tree
Hide file tree
Showing 22 changed files with 954 additions and 964 deletions.
12 changes: 6 additions & 6 deletions proto/cosmos/slashing/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ service Msg {
// and rewards again.
rpc Unjail(MsgUnjail) returns (MsgUnjailResponse);

// KickOut defines a method for removing an existing validator after gov proposal passes.
rpc KickOut(MsgKickOut) returns (MsgKickOutResponse);
// Impeach defines a method for removing an existing validator after gov proposal passes.
rpc Impeach(MsgImpeach) returns (MsgImpeachResponse);
}

// MsgUnjail defines the Msg/Unjail request type
Expand All @@ -32,8 +32,8 @@ message MsgUnjail {
// MsgUnjailResponse defines the Msg/Unjail response type
message MsgUnjailResponse {}

// MsgKickOut defines the Msg/Kickout request type
message MsgKickOut {
// MsgImpeach defines the Msg/Impeach request type
message MsgImpeach {
// NOTE: The validator should be removed by the gov module account after the proposal passes.
option (cosmos.msg.v1.signer) = "from";

Expand All @@ -44,5 +44,5 @@ message MsgKickOut {
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgKickOutResponse defines the Msg/KickOut response type.
message MsgKickOutResponse {}
// MsgImpeachResponse defines the Msg/Impeach response type.
message MsgImpeachResponse {}
16 changes: 6 additions & 10 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ message Validator {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
//
// For Inscription
//
// selfdel_address defines the address of the validator for self delegation.
string selfdel_address = 12 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// self_del_address defines the address of the validator for self delegation.
string self_del_address = 12 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// relayer_address defines the address of the validator's authorized relayer/operator;.
string relayer_address = 13 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// relayer_blskey defines the bls pubkey of the validator's authorized relayer/operator;
bytes relayer_blskey = 14;
// relayer_bls_key defines the bls pubkey of the validator's authorized relayer/operator;
bytes relayer_bls_key = 14;
}

// BondStatus is the status of a validator.
Expand Down Expand Up @@ -312,9 +310,7 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
//
// For Inscription
//

// min_self_delegation defines the minimum self delegation for validators.
string min_self_delegation = 7 [
(cosmos_proto.scalar) = "cosmos.Int",
Expand Down
6 changes: 2 additions & 4 deletions proto/cosmos/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ message MsgCreateValidator {
google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false];

// For Inscription
string from = 8 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string relayer_address = 9 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string relayer_blskey = 10; // The BLS pubkey for the authorized relayer
string relayer_bls_key = 10;
}

// MsgCreateValidatorResponse defines the Msg/CreateValidator response type.
Expand All @@ -88,9 +87,8 @@ message MsgEditValidator {
string min_self_delegation = 4
[(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"];

// For Inscription
string relayer_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string relayer_blskey = 6; // The BLS pubkey for the authorized relayer
string relayer_bls_key = 6; // The BLS pubkey for the authorized relayer
}

// MsgEditValidatorResponse defines the Msg/EditValidator response type.
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func NewSimApp(
&stakingKeeper, authtypes.FeeCollectorName,
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &app.AccountKeeper, &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
)
app.CrisisKeeper = crisiskeeper.NewKeeper(
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
Expand Down
3 changes: 3 additions & 0 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const (

// EthAddressLength defines a valid Ethereum compatible chain address length
EthAddressLength = 20

// BLSPubKeyLength defines a valid BLS Public key length
BLSPubKeyLength = 48
)

// cache variables
Expand Down
6 changes: 4 additions & 2 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"bufio"
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -163,8 +164,9 @@ $ %s gentx my-key-name 1000000stake \
return err
}
blsPk := args[4]
if len(blsPk) == 0 {
return errors.New("empty relayer bls pubkey")
blsPkBytes, err := hex.DecodeString(blsPk)
if err != nil || len(blsPkBytes) != sdk.BLSPubKeyLength {
return errors.New("invalid relayer bls pubkey")
}

createValCfg.Validator = validator
Expand Down
4 changes: 1 addition & 3 deletions x/slashing/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import (
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
ak types.AccountKeeper
sk types.StakingKeeper
paramspace types.ParamSubspace
}

// NewKeeper creates a slashing keeper
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper {
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, sk types.StakingKeeper, paramspace types.ParamSubspace) Keeper {
// set KeyTable if it has not already been set
if !paramspace.HasKeyTable() {
paramspace = paramspace.WithKeyTable(types.ParamKeyTable())
Expand All @@ -31,7 +30,6 @@ func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountK
return Keeper{
storeKey: key,
cdc: cdc,
ak: ak,
sk: sk,
paramspace: paramspace,
}
Expand Down
20 changes: 10 additions & 10 deletions x/slashing/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package keeper

import (
"context"
"math"
"time"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

sdk "github.com/cosmos/cosmos-sdk/types"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -47,12 +50,12 @@ func (k msgServer) Unjail(goCtx context.Context, msg *types.MsgUnjail) (*types.M
return &types.MsgUnjailResponse{}, nil
}

// KickOut defines a method for removing an existing validator after gov proposal passes.
func (k msgServer) KickOut(goCtx context.Context, msg *types.MsgKickOut) (*types.MsgKickOutResponse, error) {
// Impeach defines a method for removing an existing validator after gov proposal passes.
func (k msgServer) Impeach(goCtx context.Context, msg *types.MsgImpeach) (*types.MsgImpeachResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

signers := msg.GetSigners()
if len(signers) != 1 || !signers[0].Equals(k.ak.GetModuleAddress(gov.ModuleName)) {
if len(signers) != 1 || !signers[0].Equals(authtypes.NewModuleAddress(gov.ModuleName)) {
return nil, types.ErrSignerNotGovModule
}

Expand All @@ -78,20 +81,17 @@ func (k msgServer) KickOut(goCtx context.Context, msg *types.MsgKickOut) (*types
k.Jail(ctx, consAddr)
}

// Jail to a big enough time (Dec 31, 9999 - 23:59:59 GMT)
k.JailUntil(ctx, consAddr, time.Unix(253402300799, 0))
// Jail forever.
k.JailUntil(ctx, consAddr, time.Unix(math.MaxInt64, 0))

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeKickOut,
sdk.NewAttribute(types.AttributeKeyAddress, msg.ValidatorAddress),
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.From),
sdk.NewAttribute(types.AttributeKeyAddress, msg.ValidatorAddress),
),
})

return &types.MsgKickOutResponse{}, nil
return &types.MsgImpeachResponse{}, nil
}
2 changes: 1 addition & 1 deletion x/slashing/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgUnjail{},
&MsgKickOut{},
&MsgImpeach{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
1 change: 0 additions & 1 deletion x/slashing/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
type AccountKeeper interface {
GetAccount(ctx sdk.Context, addr sdk.AccAddress) auth.AccountI
IterateAccounts(ctx sdk.Context, process func(auth.AccountI) (stop bool))
GetModuleAddress(name string) sdk.AccAddress
}

// BankKeeper defines the expected interface needed to retrieve account balances.
Expand Down
18 changes: 8 additions & 10 deletions x/slashing/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,34 @@ func (msg MsgUnjail) ValidateBasic() error {
return nil
}

// NewMsgKickOut creates a new MsgKickOut instance
//
//nolint:interfacer
func NewMsgKickOut(valAddr sdk.ValAddress, from sdk.AccAddress) *MsgKickOut {
return &MsgKickOut{
// NewMsgImpeach creates a new MsgImpeach instance
func NewMsgImpeach(valAddr sdk.ValAddress, from sdk.AccAddress) *MsgImpeach {
return &MsgImpeach{
ValidatorAddress: valAddr.String(),
From: from.String(),
}
}

// Route implements the sdk.Msg interface.
func (msg MsgKickOut) Route() string { return RouterKey }
func (msg MsgImpeach) Route() string { return RouterKey }

// Type implements the sdk.Msg interface.
func (msg MsgKickOut) Type() string { return TypeMsgKickOut }
func (msg MsgImpeach) Type() string { return TypeMsgKickOut }

// GetSigners implements the sdk.Msg interface.
func (msg MsgKickOut) GetSigners() []sdk.AccAddress {
func (msg MsgImpeach) GetSigners() []sdk.AccAddress {
fromAddr, _ := sdk.AccAddressFromHexUnsafe(msg.From)
return []sdk.AccAddress{fromAddr}
}

// GetSignBytes implements the sdk.Msg interface.
func (msg MsgKickOut) GetSignBytes() []byte {
func (msg MsgImpeach) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}

// ValidateBasic implements the sdk.Msg interface.
func (msg MsgKickOut) ValidateBasic() error {
func (msg MsgImpeach) ValidateBasic() error {
if _, err := sdk.AccAddressFromHexUnsafe(msg.From); err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid account address: %s", err)
}
Expand Down
Loading

0 comments on commit a896eaf

Please sign in to comment.