From a2826ac00f06fc53f48bc98e77d25851df726284 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sun, 7 Jul 2024 19:49:17 +0800 Subject: [PATCH 01/13] change val's consensus pubkey --- x/distribution/keeper/hooks.go | 5 ++++ x/slashing/internal/keeper/hooks.go | 14 ++++++++++ x/slashing/internal/keeper/infractions.go | 3 ++- x/staking/alias.go | 1 + x/staking/client/cli/tx.go | 23 ++++++++++++----- x/staking/handler.go | 31 +++++++++++++++++------ x/staking/keeper/hooks.go | 7 +++++ x/staking/keeper/test_common.go | 6 +++-- x/staking/keeper/val_state_change.go | 10 ++++++++ x/staking/keeper/validator.go | 30 ++++++++++++++++++++++ x/staking/types/errors.go | 16 ++++++++++-- x/staking/types/expected_keepers.go | 2 ++ x/staking/types/hooks.go | 7 +++++ x/staking/types/keys.go | 7 ++++- x/staking/types/msg.go | 8 +++--- 15 files changed, 147 insertions(+), 23 deletions(-) diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index 4b144966f1..57705fa8c8 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/okex/exchain/libs/cosmos-sdk/types" + "github.com/okex/exchain/libs/tendermint/crypto" "github.com/okex/exchain/x/distribution/types" stakingtypes "github.com/okex/exchain/x/staking/types" @@ -23,6 +24,10 @@ func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) { h.k.initializeValidator(ctx, val) } +func (h Hooks) AfterValidatorPubkeyChanged(ctx sdk.Context, oldAddress sdk.ConsAddress, newAddress sdk.ConsAddress, newPubkey crypto.PubKey) { + +} + // AfterValidatorRemoved cleans up for after validator is removed func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) { if h.k.CheckDistributionProposalValid(ctx) { diff --git a/x/slashing/internal/keeper/hooks.go b/x/slashing/internal/keeper/hooks.go index fbbe6f3b37..289db2af3b 100644 --- a/x/slashing/internal/keeper/hooks.go +++ b/x/slashing/internal/keeper/hooks.go @@ -40,6 +40,17 @@ func (k Keeper) AfterValidatorRemoved(ctx sdk.Context, address sdk.ConsAddress) k.modifyValidatorStatus(ctx, address, types.Destroyed) } +func (k Keeper) AfterValidatorPubkeyChanged(ctx sdk.Context, oldAddress sdk.ConsAddress, newAddress sdk.ConsAddress, newPubkey crypto.PubKey) { + k.deleteAddrPubkeyRelation(ctx, crypto.Address(oldAddress)) + signingInfo, found := k.GetValidatorSigningInfo(ctx, oldAddress) + k.modifyValidatorStatus(ctx, oldAddress, types.Destroyed) + + k.AddPubkey(ctx, newPubkey) + if found { + k.SetValidatorSigningInfo(ctx, newAddress, signingInfo) + } +} + func (k Keeper) AfterValidatorDestroyed(ctx sdk.Context, valAddr sdk.ValAddress) { validator := k.sk.Validator(ctx, valAddr) if validator != nil { @@ -76,6 +87,9 @@ func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) { h.k.AfterValidatorCreated(ctx, valAddr) } +func (h Hooks) AfterValidatorPubkeyChanged(ctx sdk.Context, oldAddress sdk.ConsAddress, newAddress sdk.ConsAddress, newPubkey crypto.PubKey) { + h.k.AfterValidatorPubkeyChanged(ctx, oldAddress, newAddress, newPubkey) +} func (h Hooks) AfterValidatorDestroyed(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) { h.k.AfterValidatorDestroyed(ctx, valAddr) } diff --git a/x/slashing/internal/keeper/infractions.go b/x/slashing/internal/keeper/infractions.go index 52cd6c4ed2..3fdb565a16 100644 --- a/x/slashing/internal/keeper/infractions.go +++ b/x/slashing/internal/keeper/infractions.go @@ -17,7 +17,8 @@ func (k Keeper) HandleValidatorSignature(ctx sdk.Context, addr crypto.Address, p // fetch the validator public key consAddr := sdk.ConsAddress(addr) if _, err := k.GetPubkey(ctx, addr); err != nil { - panic(fmt.Sprintf("Validator consensus-address %s not found", consAddr)) + // ignore this panic, now we can change the validator's pub key + //panic(fmt.Sprintf("Validator consensus-address %s not found", consAddr)) } // fetch signing info diff --git a/x/staking/alias.go b/x/staking/alias.go index 8d1e9bf0ff..d7480ed93c 100644 --- a/x/staking/alias.go +++ b/x/staking/alias.go @@ -31,6 +31,7 @@ var ( RegisterCodec = types.RegisterCodec NewCommission = types.NewCommission ErrNoValidatorFound = types.ErrNoValidatorFound + ErrPubkeyEqual = types.ErrPubkeyEqual ErrValidatorOwnerExists = types.ErrValidatorOwnerExists ErrValidatorPubKeyExists = types.ErrValidatorPubKeyExists ErrValidatorPubKeyTypeNotSupported = types.ErrValidatorPubKeyTypeNotSupported diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 10fd940bd5..f3fe5c5cf1 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -106,6 +106,16 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { Details: viper.GetString(FlagDetails), } + pkStr := viper.GetString(FlagPubKey) + var pk crypto.PubKey = nil + var err error + if pkStr != "" { + pk, err = types.GetConsPubKeyBech32(pkStr) + if err != nil { + return err + } + } + // TODO: recover the msd modification later //var newMinSelfDelegation *sdk.Int // @@ -122,7 +132,7 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { //} // //msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation) - msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description) + msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, pk) // build and sign the transaction, then broadcast to Tendermint return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) @@ -130,6 +140,7 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { } cmd.Flags().AddFlagSet(fsDescriptionEdit) + cmd.Flags().String(FlagPubKey, "", "The Bech32 encoded PubKey of the validator") //cmd.Flags().AddFlagSet(fsCommissionUpdate) return cmd @@ -138,11 +149,11 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { //__________________________________________________________ var ( -//defaultTokens = sdk.TokensFromConsensusPower(100) -//defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom -//defaultCommissionRate = "0.1" -//defaultCommissionMaxRate = "0.2" -//defaultCommissionMaxChangeRate = "0.01" +// defaultTokens = sdk.TokensFromConsensusPower(100) +// defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom +// defaultCommissionRate = "0.1" +// defaultCommissionMaxRate = "0.2" +// defaultCommissionMaxChangeRate = "0.01" ) // CreateValidatorMsgHelpers returns the flagset, particular flags, and a description of defaults diff --git a/x/staking/handler.go b/x/staking/handler.go index 8ef4229f97..d2a49309a7 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -165,15 +165,30 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe return nil, ErrNoValidatorFound(msg.ValidatorAddress.String()) } - // replace all editable fields (clients should autofill existing values) - description, err := validator.Description.UpdateDescription(msg.Description) - if err != nil { - return nil, err - } - - validator.Description = description + if msg.Description != (Description{}) { + // replace all editable fields (clients should autofill existing values) + description, err := validator.Description.UpdateDescription(msg.Description) + if err != nil { + return nil, err + } - k.SetValidator(ctx, validator) + validator.Description = description + k.SetValidator(ctx, validator) + } + if msg.PubKey != nil && len(msg.PubKey.Bytes()) != 0 { + if validator.ConsPubKey.Equals(msg.PubKey) { + return nil, ErrPubkeyEqual(msg.PubKey.Address().String()) + } + k.SetChangePubkey(ctx, validator.OperatorAddress, validator.GetConsPubKey()) + oldConsAddr := validator.GetConsAddr() + + validator.ConsPubKey = msg.PubKey + newConsAddr := validator.GetConsAddr() + k.SetValidator(ctx, validator) + k.SetValidatorByConsAddr(ctx, validator) + k.DeleteValidatorByConsAddr(ctx, oldConsAddr) + k.AfterValidatorPubkeyChanged(ctx, oldConsAddr, newConsAddr, msg.PubKey) + } ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent(types.EventTypeEditValidator, diff --git a/x/staking/keeper/hooks.go b/x/staking/keeper/hooks.go index 55a157ccdd..d379b79288 100644 --- a/x/staking/keeper/hooks.go +++ b/x/staking/keeper/hooks.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/okex/exchain/libs/cosmos-sdk/types" + "github.com/okex/exchain/libs/tendermint/crypto" "github.com/okex/exchain/x/staking/types" ) @@ -15,6 +16,12 @@ func (k Keeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) { } } +func (k Keeper) AfterValidatorPubkeyChanged(ctx sdk.Context, oldAddress sdk.ConsAddress, newAddress sdk.ConsAddress, newPubkey crypto.PubKey) { + if k.hooks != nil { + k.hooks.AfterValidatorPubkeyChanged(ctx, oldAddress, newAddress, newPubkey) + } +} + // BeforeValidatorModified - call hook if registered func (k Keeper) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) { if k.hooks != nil { diff --git a/x/staking/keeper/test_common.go b/x/staking/keeper/test_common.go index be234bbaaa..03123ab3de 100644 --- a/x/staking/keeper/test_common.go +++ b/x/staking/keeper/test_common.go @@ -315,8 +315,10 @@ func SimpleCheckValidator(t *testing.T, ctx sdk.Context, stkKeeper Keeper, vaAdd // mockDistributionKeeper is supported to test Hooks type mockDistributionKeeper struct{} -func (dk mockDistributionKeeper) Hooks() types.StakingHooks { return dk } -func (dk mockDistributionKeeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {} +func (dk mockDistributionKeeper) Hooks() types.StakingHooks { return dk } +func (dk mockDistributionKeeper) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {} +func (dk mockDistributionKeeper) AfterValidatorPubkeyChanged(ctx sdk.Context, oldAddress sdk.ConsAddress, newAddress sdk.ConsAddress, newPubkey crypto.PubKey) { +} func (dk mockDistributionKeeper) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) {} func (dk mockDistributionKeeper) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) { } diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index 337e919429..5f9ae391b1 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -76,6 +76,16 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab k.SetLastValidatorPower(ctx, valAddr, newPower) } + // change val node key + if pk, found := k.GetChangePubkey(ctx, validator.OperatorAddress); found { + oldVal := types.Validator{ConsPubKey: pk} + // delete old pubkey + updates = append(updates, oldVal.ABCIValidatorUpdateZero()) + // add new pubkey + updates = append(updates, validator.ABCIValidatorUpdateByShares()) + k.DeleteChangePubkey(ctx, validator.OperatorAddress) + } + // validator still in the validator set, so delete from the copy delete(last, valAddrBytes) diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index 3945043ad4..0042f566e9 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -3,6 +3,8 @@ package keeper import ( "bytes" "fmt" + "github.com/okex/exchain/libs/tendermint/crypto" + cryptoAmino "github.com/okex/exchain/libs/tendermint/crypto/encoding/amino" "time" sdk "github.com/okex/exchain/libs/cosmos-sdk/types" @@ -54,6 +56,29 @@ func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) { store.Set(types.GetValidatorKey(validator.OperatorAddress), bz) } +func (k Keeper) SetChangePubkey(ctx sdk.Context, addr sdk.ValAddress, pubkey crypto.PubKey) { + store := ctx.KVStore(k.storeKey) + store.Set(types.GetValidatorChangePubkeyKey(addr), pubkey.Bytes()) +} + +func (k Keeper) DeleteChangePubkey(ctx sdk.Context, addr sdk.ValAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetValidatorChangePubkeyKey(addr)) +} + +func (k Keeper) GetChangePubkey(ctx sdk.Context, addr sdk.ValAddress) (pubkey crypto.PubKey, found bool) { + store := ctx.KVStore(k.storeKey) + value := store.Get(types.GetValidatorChangePubkeyKey(addr)) + if value == nil { + return nil, false + } + pk, err := cryptoAmino.PubKeyFromBytes(value) + if err != nil { + panic(err) + } + return pk, true +} + // SetValidatorByConsAddr sets the operator address with the key of validator consensus pubkey func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validator) { store := ctx.KVStore(k.storeKey) @@ -61,6 +86,11 @@ func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validato store.Set(types.GetValidatorByConsAddrKey(consAddr), validator.OperatorAddress) } +func (k Keeper) DeleteValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetValidatorByConsAddrKey(consAddr)) +} + // SetValidatorByPowerIndex sets the power index key of an unjailed validator func (k Keeper) SetValidatorByPowerIndex(ctx sdk.Context, validator types.Validator) { // jailed validators are not kept in the power index diff --git a/x/staking/types/errors.go b/x/staking/types/errors.go index e9ccfd8724..ce51d77fd3 100644 --- a/x/staking/types/errors.go +++ b/x/staking/types/errors.go @@ -58,17 +58,29 @@ const ( CodeNoDelegatorExisted uint32 = 67044 CodeTargetValsDuplicate uint32 = 67045 CodeAlreadyBound uint32 = 67046 + + CodePubkeyEqual uint32 = 67047 + CodeDescriptionAndPubkeyIsEmpty uint32 = 67048 ) var ( - ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 144, "invalid historical info") - ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 145, "no historical info found") + ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 144, "invalid historical info") + ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 145, "no historical info found") ) + // ErrNoValidatorFound returns an error when a validator doesn't exist func ErrNoValidatorFound(valAddr string) sdk.EnvelopedErr { return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeNoValidatorFound, fmt.Sprintf("validator %s does not exist", valAddr))} } +func ErrPubkeyEqual(pubkey string) sdk.EnvelopedErr { + return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodePubkeyEqual, fmt.Sprintf("validator pubkey %s does exist", pubkey))} +} + +func ErrDescriptionAndPubkeyIsEmpty() sdk.Error { + return sdkerrors.New(DefaultCodespace, CodeDescriptionAndPubkeyIsEmpty, "empty description and pubkey") +} + // ErrInvalidDelegation returns an error when the delegation is invalid func ErrInvalidDelegation(delegator string) sdk.EnvelopedErr { return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeInvalidDelegation, diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 781a0e5afb..82aaec3ce4 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( sdk "github.com/okex/exchain/libs/cosmos-sdk/types" authexported "github.com/okex/exchain/libs/cosmos-sdk/x/auth/exported" supplyexported "github.com/okex/exchain/libs/cosmos-sdk/x/supply/exported" + "github.com/okex/exchain/libs/tendermint/crypto" stakingexported "github.com/okex/exchain/x/staking/exported" ) @@ -74,6 +75,7 @@ type ValidatorSet interface { type StakingHooks interface { // Must be called when a validator is created AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) + AfterValidatorPubkeyChanged(ctx sdk.Context, oldAddress sdk.ConsAddress, newAddress sdk.ConsAddress, newPubkey crypto.PubKey) // Must be called when a validator's state changes BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) // Must be called when a validator is deleted diff --git a/x/staking/types/hooks.go b/x/staking/types/hooks.go index c2170d7e10..14a6af1866 100644 --- a/x/staking/types/hooks.go +++ b/x/staking/types/hooks.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/okex/exchain/libs/cosmos-sdk/types" + "github.com/okex/exchain/libs/tendermint/crypto" ) // MultiStakingHooks combines multiple staking hooks, all hook functions are run in array sequence @@ -20,6 +21,12 @@ func (h MultiStakingHooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.Va } } +func (h MultiStakingHooks) AfterValidatorPubkeyChanged(ctx sdk.Context, oldAddress sdk.ConsAddress, newAddress sdk.ConsAddress, newPubkey crypto.PubKey) { + for i := range h { + h[i].AfterValidatorPubkeyChanged(ctx, oldAddress, newAddress, newPubkey) + } +} + // BeforeValidatorModified handles the hooks before the validator modified func (h MultiStakingHooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) { for i := range h { diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index 71b71f7c8b..ab6605d181 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -30,7 +30,7 @@ const ( RouterKey = ModuleName ) -//nolint +// nolint var ( // Keys for store prefixes // Last* values are constant during a block. @@ -40,6 +40,7 @@ var ( ValidatorsKey = []byte{0x21} // prefix for each key to a validator ValidatorsByConsAddrKey = []byte{0x22} // prefix for each key to a validator index, by pubkey ValidatorsByPowerIndexKey = []byte{0x23} // prefix for each key to a validator index, sorted by power + ValChangePubkeyKey = []byte{0x24} ValidatorQueueKey = []byte{0x43} // prefix for the timestamps in validator queue @@ -67,6 +68,10 @@ func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte { return append(ValidatorsByConsAddrKey, addr.Bytes()...) } +func GetValidatorChangePubkeyKey(operatorAddr sdk.ValAddress) []byte { + return append(ValChangePubkeyKey, operatorAddr.Bytes()...) +} + // AddressFromLastValidatorPowerKey gets the validator operator address from LastValidatorPowerKey func AddressFromLastValidatorPowerKey(key []byte) []byte { return key[1:] // remove prefix bytes diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index d458fbfc91..8c2071764a 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -132,13 +132,15 @@ func (msg MsgCreateValidator) ValidateBasic() error { type MsgEditValidator struct { Description ValidatorAddress sdk.ValAddress `json:"address" yaml:"address"` + PubKey crypto.PubKey `json:"pubkey" yaml:"pubkey"` } // NewMsgEditValidator creates a msg of edit-validator -func NewMsgEditValidator(valAddr sdk.ValAddress, description Description) MsgEditValidator { +func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, pubKey crypto.PubKey) MsgEditValidator { return MsgEditValidator{ Description: description, ValidatorAddress: valAddr, + PubKey: pubKey, } } @@ -161,8 +163,8 @@ func (msg MsgEditValidator) ValidateBasic() error { return ErrNilValidatorAddr() } - if msg.Description == (Description{}) { - return ErrNilValidatorAddr() + if msg.Description == (Description{}) && (msg.PubKey == nil || len(msg.PubKey.Bytes()) == 0) { + return ErrDescriptionAndPubkeyIsEmpty() } return nil From 1eecee4b0113491199be82670c879123fc1f316f Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sun, 7 Jul 2024 20:38:49 +0800 Subject: [PATCH 02/13] fix UT --- x/staking/types/msg_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index ea5f8fb939..53cab5fe62 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -119,7 +119,7 @@ func TestMsgEditValidator(t *testing.T) { for _, tc := range tests { description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details) - msg := NewMsgEditValidator(tc.validatorAddr, description) + msg := NewMsgEditValidator(tc.validatorAddr, description, nil) if tc.expectPass { require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) checkMsg(t, msg, "edit_validator") From 88f69a813f04f04c1e12f4ef642e62462a00c4f1 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Sun, 7 Jul 2024 20:50:37 +0800 Subject: [PATCH 03/13] fix UT --- x/staking/handler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 36a9b4a14f..7bdaae4755 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -175,7 +175,7 @@ func TestEditValidatorDecreaseMinSelfDelegation(t *testing.T) { SharesFromDefaultMSD, false) // edit validator - msgEditValidator := NewMsgEditValidator(validatorAddr, Description{Moniker: "moniker"}) + msgEditValidator := NewMsgEditValidator(validatorAddr, Description{Moniker: "moniker"}, nil) require.Nil(t, msgEditValidator.ValidateBasic()) // no one could change msd From b9d1ed883c5cec6eaceda3f5fa3242a27c3855ea Mon Sep 17 00:00:00 2001 From: ylsGit Date: Tue, 9 Jul 2024 09:50:49 +0800 Subject: [PATCH 04/13] check pubkey when change it --- x/staking/handler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/x/staking/handler.go b/x/staking/handler.go index d2a49309a7..cf8b15862a 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -179,6 +179,16 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe if validator.ConsPubKey.Equals(msg.PubKey) { return nil, ErrPubkeyEqual(msg.PubKey.Address().String()) } + if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(msg.PubKey)); found { + return nil, ErrValidatorPubKeyExists() + } + if ctx.ConsensusParams() != nil { + tmPubKey := tmtypes.TM2PB.PubKey(msg.PubKey) + if !StringInSlice(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) { + return nil, ErrValidatorPubKeyTypeNotSupported(tmPubKey.Type, + ctx.ConsensusParams().Validator.PubKeyTypes) + } + } k.SetChangePubkey(ctx, validator.OperatorAddress, validator.GetConsPubKey()) oldConsAddr := validator.GetConsAddr() From 557f03849d28204d1242d8b0fbd6122a7acbb6a9 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Tue, 9 Jul 2024 16:21:48 +0800 Subject: [PATCH 05/13] add milstone height 'Jupiter' --- Makefile | 6 +++++- app/app_test.go | 2 +- libs/cosmos-sdk/simapp/helpers/test_helpers.go | 2 +- libs/cosmos-sdk/x/auth/ante/ante_test.go | 2 +- libs/cosmos-sdk/x/auth/ante/sigverify_test.go | 4 ++-- .../cosmos-sdk/x/auth/client/cli/tx_multisign.go | 2 +- libs/cosmos-sdk/x/auth/client/cli/tx_sign.go | 2 +- libs/cosmos-sdk/x/auth/types/stdsignmsg.go | 2 +- libs/cosmos-sdk/x/auth/types/stdtx.go | 12 +++++++++--- libs/cosmos-sdk/x/auth/types/stdtx_test.go | 2 +- libs/cosmos-sdk/x/auth/types/test_common.go | 4 ++-- libs/cosmos-sdk/x/mock/app.go | 2 +- libs/tendermint/types/milestone.go | 16 ++++++++++++++++ x/evm/watcher/tx_test.go | 2 +- 14 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 524c32954f..a492ef7a6d 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ Venus4Height=0 Venus5Height=0 EarthHeight=0 MarsHeight=0 +JupiterHeight=0 LINK_STATICALLY = false cgo_flags= @@ -53,6 +54,7 @@ ifeq ($(MAKECMDGOALS),mainnet) Venus3Height=15277000 Venus5Height=17849000 EarthHeight=18735000 + JupiterHeight=0 WITH_ROCKSDB=true else ifeq ($(MAKECMDGOALS),testnet) @@ -65,6 +67,7 @@ else ifeq ($(MAKECMDGOALS),testnet) EarthHeight=17364500 Venus4Height=17531500 Venus5Height=18861500 + JupiterHeight=0 WITH_ROCKSDB=true endif @@ -120,7 +123,8 @@ ldflags = -X $(GithubTop)/okex/exchain/libs/cosmos-sdk/version.Version=$(Version -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_VENUS4_HEIGHT=$(Venus4Height) \ -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_VENUS5_HEIGHT=$(Venus5Height) \ -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_EARTH_HEIGHT=$(EarthHeight) \ - -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_MARS_HEIGHT=$(MarsHeight) + -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_MARS_HEIGHT=$(MarsHeight) \ + -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_JUPITER_NAME=$(JupiterHeight) ifeq ($(WITH_ROCKSDB),true) diff --git a/app/app_test.go b/app/app_test.go index 898301b443..1b51ee9e2c 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -324,7 +324,7 @@ func (suite *FakeBlockTxTestSuite) TestFakeBlockTx() { func newTestStdTx(msgs []cosmossdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee auth.StdFee, memo string) cosmossdk.Tx { sigs := make([]authtypes.StdSignature, len(privs)) for i, priv := range privs { - sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo)) + sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo, 0)) if err != nil { panic(err) } diff --git a/libs/cosmos-sdk/simapp/helpers/test_helpers.go b/libs/cosmos-sdk/simapp/helpers/test_helpers.go index 28340b2d7c..beaa82c05d 100644 --- a/libs/cosmos-sdk/simapp/helpers/test_helpers.go +++ b/libs/cosmos-sdk/simapp/helpers/test_helpers.go @@ -34,7 +34,7 @@ func GenTx(msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums for i, p := range priv { // use a empty chainID for ease of testing - sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo)) + sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo, 0)) if err != nil { panic(err) } diff --git a/libs/cosmos-sdk/x/auth/ante/ante_test.go b/libs/cosmos-sdk/x/auth/ante/ante_test.go index b8f6e29efa..2cc062cf57 100644 --- a/libs/cosmos-sdk/x/auth/ante/ante_test.go +++ b/libs/cosmos-sdk/x/auth/ante/ante_test.go @@ -511,7 +511,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { for _, cs := range cases { tx := types.NewTestTxWithSignBytes( msgs, privs, accnums, seqs, fee, - types.StdSignBytes(cs.chainID, cs.accnum, cs.seq, cs.fee, cs.msgs, ""), + types.StdSignBytes(cs.chainID, cs.accnum, cs.seq, cs.fee, cs.msgs, "", 0), "", ) checkInvalidTx(t, anteHandler, ctx, tx, false, cs.err) diff --git a/libs/cosmos-sdk/x/auth/ante/sigverify_test.go b/libs/cosmos-sdk/x/auth/ante/sigverify_test.go index 005086c7e0..5310c8833c 100644 --- a/libs/cosmos-sdk/x/auth/ante/sigverify_test.go +++ b/libs/cosmos-sdk/x/auth/ante/sigverify_test.go @@ -2,8 +2,8 @@ package ante_test import ( "fmt" - "github.com/stretchr/testify/assert" "github.com/spf13/viper" + "github.com/stretchr/testify/assert" "testing" "github.com/okex/exchain/libs/tendermint/crypto" @@ -431,7 +431,7 @@ func TestVerifySig(t *testing.T) { } func NewSig(ctx sdk.Context, msgs []sdk.Msg, priv crypto.PrivKey, accNum uint64, seq uint64, fee types.StdFee) []types.StdSignature { - signBytes := types.StdSignBytes(ctx.ChainID(), accNum, seq, fee, msgs, "") + signBytes := types.StdSignBytes(ctx.ChainID(), accNum, seq, fee, msgs, "", 0) sig, err := priv.Sign(signBytes) if err != nil { panic(err) diff --git a/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go b/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go index d136c1739a..f8577ada51 100644 --- a/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go +++ b/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go @@ -104,7 +104,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) // Validate each signature sigBytes := types.StdSignBytes( txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(), - stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), + stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), 0, ) if ok := stdSig.PubKey.VerifyBytes(sigBytes, stdSig.Signature); !ok { return fmt.Errorf("couldn't verify signature") diff --git a/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go b/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go index df74497994..6fcf878a6b 100644 --- a/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go +++ b/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go @@ -232,7 +232,7 @@ func printAndValidateSigs( sigBytes := types.StdSignBytes( chainID, acc.GetAccountNumber(), acc.GetSequence(), - stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), + stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), 0, ) if ok := sig.VerifyBytes(sigBytes, sig.Signature); !ok { diff --git a/libs/cosmos-sdk/x/auth/types/stdsignmsg.go b/libs/cosmos-sdk/x/auth/types/stdsignmsg.go index fa98e96278..711418b6cc 100644 --- a/libs/cosmos-sdk/x/auth/types/stdsignmsg.go +++ b/libs/cosmos-sdk/x/auth/types/stdsignmsg.go @@ -18,5 +18,5 @@ type StdSignMsg struct { // get message bytes func (msg StdSignMsg) Bytes() []byte { - return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo) + return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo, 0) } diff --git a/libs/cosmos-sdk/x/auth/types/stdtx.go b/libs/cosmos-sdk/x/auth/types/stdtx.go index a0bdd0f36d..9bbdf26a8b 100644 --- a/libs/cosmos-sdk/x/auth/types/stdtx.go +++ b/libs/cosmos-sdk/x/auth/types/stdtx.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "math/big" + "strings" ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" @@ -14,6 +15,7 @@ import ( "github.com/okex/exchain/libs/tendermint/crypto" cryptoamino "github.com/okex/exchain/libs/tendermint/crypto/encoding/amino" "github.com/okex/exchain/libs/tendermint/crypto/multisig" + tmtypes "github.com/okex/exchain/libs/tendermint/types" "github.com/tendermint/go-amino" yaml "gopkg.in/yaml.v2" ) @@ -236,7 +238,7 @@ func (tx *StdTx) GetSignBytes(ctx sdk.Context, index int, acc exported.Account) } return StdSignBytes( - chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo, + chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo, ctx.BlockHeight(), ) } @@ -434,10 +436,14 @@ type StdSignDoc struct { } // StdSignBytes returns the bytes to sign for a transaction. -func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string) []byte { +func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string, height int64) []byte { msgsBytes := make([]json.RawMessage, 0, len(msgs)) for _, msg := range msgs { - msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes())) + msgByte := json.RawMessage(msg.GetSignBytes()) + if height > 0 && !tmtypes.HigherThanJupiter(height) && msg.Type() == "edit_validator" { + msgByte = []byte(strings.ReplaceAll(string(msgByte), `,"pubkey":null`, "")) + } + msgsBytes = append(msgsBytes, msgByte) } bz, err := ModuleCdc.MarshalJSON(StdSignDoc{ AccountNumber: accnum, diff --git a/libs/cosmos-sdk/x/auth/types/stdtx_test.go b/libs/cosmos-sdk/x/auth/types/stdtx_test.go index ca437717fb..e0065f43d2 100644 --- a/libs/cosmos-sdk/x/auth/types/stdtx_test.go +++ b/libs/cosmos-sdk/x/auth/types/stdtx_test.go @@ -126,7 +126,7 @@ func TestStdSignBytes(t *testing.T) { }, } for i, tc := range tests { - got := string(StdSignBytes(tc.args.chainID, tc.args.accnum, tc.args.sequence, tc.args.fee, tc.args.msgs, tc.args.memo)) + got := string(StdSignBytes(tc.args.chainID, tc.args.accnum, tc.args.sequence, tc.args.fee, tc.args.msgs, tc.args.memo, 0)) require.Equal(t, tc.want, got, "Got unexpected result on test case i: %d", i) } } diff --git a/libs/cosmos-sdk/x/auth/types/test_common.go b/libs/cosmos-sdk/x/auth/types/test_common.go index 78684b99dd..f6fe0b9760 100644 --- a/libs/cosmos-sdk/x/auth/types/test_common.go +++ b/libs/cosmos-sdk/x/auth/types/test_common.go @@ -35,7 +35,7 @@ func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { - signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "") + signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "", 0) sig, err := priv.Sign(signBytes) if err != nil { @@ -52,7 +52,7 @@ func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { - signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo) + signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo, 0) sig, err := priv.Sign(signBytes) if err != nil { diff --git a/libs/cosmos-sdk/x/mock/app.go b/libs/cosmos-sdk/x/mock/app.go index 1b2c31d8d0..45add77260 100644 --- a/libs/cosmos-sdk/x/mock/app.go +++ b/libs/cosmos-sdk/x/mock/app.go @@ -228,7 +228,7 @@ func GenTx(msgs []sdk.Msg, accnums []uint64, seq []uint64, priv ...crypto.PrivKe memo := "testmemotestmemo" for i, p := range priv { - sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo)) + sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo, 0)) if err != nil { panic(err) } diff --git a/libs/tendermint/types/milestone.go b/libs/tendermint/types/milestone.go index 9daabf89e5..096c62089a 100644 --- a/libs/tendermint/types/milestone.go +++ b/libs/tendermint/types/milestone.go @@ -48,6 +48,9 @@ var ( MILESTONE_VENUS7_NAME = "venus7" milestoneVenus7Height int64 = 0 + MILESTONE_JUPITER_NAME string + milestoneJupiterHeight int64 + // note: it stores the earlies height of the node,and it is used by cli nodePruneHeight int64 @@ -88,6 +91,7 @@ func init() { milestoneEarthHeight = string2number(MILESTONE_EARTH_HEIGHT) milestoneVenus4Height = string2number(MILESTONE_VENUS4_HEIGHT) milestoneVenus5Height = string2number(MILESTONE_VENUS5_HEIGHT) + milestoneJupiterHeight = string2number(MILESTONE_JUPITER_NAME) }) } @@ -142,6 +146,18 @@ func HigherThanMars(height int64) bool { return height > milestoneMarsHeight } +// change val's pubkey +func HigherThanJupiter(height int64) bool { + if milestoneJupiterHeight == 0 { + return false + } + return height > milestoneJupiterHeight +} + +func GetJupiterHeight() int64 { + return milestoneJupiterHeight +} + // GetMilestoneVenusHeight returns milestoneVenusHeight func GetMilestoneVenusHeight() int64 { return milestoneVenusHeight diff --git a/x/evm/watcher/tx_test.go b/x/evm/watcher/tx_test.go index f68cd97e4b..c24add2a8d 100644 --- a/x/evm/watcher/tx_test.go +++ b/x/evm/watcher/tx_test.go @@ -256,7 +256,7 @@ func (suite *TxTestSuite) TestRecordTxAndFailedReceipt() { func newTestStdTx(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee auth.StdFee, memo string) sdk.Tx { sigs := make([]authtypes.StdSignature, len(privs)) for i, priv := range privs { - sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo)) + sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo, 0)) if err != nil { panic(err) } From 27fed1cff7b72e03d979cecc9fcbeadbb232a369 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Tue, 9 Jul 2024 17:40:42 +0800 Subject: [PATCH 06/13] revert StdSignBytes --- app/app_test.go | 2 +- libs/cosmos-sdk/simapp/helpers/test_helpers.go | 2 +- libs/cosmos-sdk/x/auth/ante/ante_test.go | 2 +- libs/cosmos-sdk/x/auth/ante/sigverify_test.go | 2 +- libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go | 2 +- libs/cosmos-sdk/x/auth/client/cli/tx_sign.go | 2 +- libs/cosmos-sdk/x/auth/types/stdsignmsg.go | 2 +- libs/cosmos-sdk/x/auth/types/stdtx.go | 15 ++++----------- libs/cosmos-sdk/x/auth/types/stdtx_test.go | 2 +- libs/cosmos-sdk/x/auth/types/test_common.go | 4 ++-- libs/cosmos-sdk/x/mock/app.go | 2 +- x/evm/watcher/tx_test.go | 2 +- 12 files changed, 16 insertions(+), 23 deletions(-) diff --git a/app/app_test.go b/app/app_test.go index 1b51ee9e2c..898301b443 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -324,7 +324,7 @@ func (suite *FakeBlockTxTestSuite) TestFakeBlockTx() { func newTestStdTx(msgs []cosmossdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee auth.StdFee, memo string) cosmossdk.Tx { sigs := make([]authtypes.StdSignature, len(privs)) for i, priv := range privs { - sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo, 0)) + sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo)) if err != nil { panic(err) } diff --git a/libs/cosmos-sdk/simapp/helpers/test_helpers.go b/libs/cosmos-sdk/simapp/helpers/test_helpers.go index beaa82c05d..28340b2d7c 100644 --- a/libs/cosmos-sdk/simapp/helpers/test_helpers.go +++ b/libs/cosmos-sdk/simapp/helpers/test_helpers.go @@ -34,7 +34,7 @@ func GenTx(msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accnums for i, p := range priv { // use a empty chainID for ease of testing - sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo, 0)) + sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo)) if err != nil { panic(err) } diff --git a/libs/cosmos-sdk/x/auth/ante/ante_test.go b/libs/cosmos-sdk/x/auth/ante/ante_test.go index 2cc062cf57..b8f6e29efa 100644 --- a/libs/cosmos-sdk/x/auth/ante/ante_test.go +++ b/libs/cosmos-sdk/x/auth/ante/ante_test.go @@ -511,7 +511,7 @@ func TestAnteHandlerBadSignBytes(t *testing.T) { for _, cs := range cases { tx := types.NewTestTxWithSignBytes( msgs, privs, accnums, seqs, fee, - types.StdSignBytes(cs.chainID, cs.accnum, cs.seq, cs.fee, cs.msgs, "", 0), + types.StdSignBytes(cs.chainID, cs.accnum, cs.seq, cs.fee, cs.msgs, ""), "", ) checkInvalidTx(t, anteHandler, ctx, tx, false, cs.err) diff --git a/libs/cosmos-sdk/x/auth/ante/sigverify_test.go b/libs/cosmos-sdk/x/auth/ante/sigverify_test.go index 5310c8833c..d7247f83d2 100644 --- a/libs/cosmos-sdk/x/auth/ante/sigverify_test.go +++ b/libs/cosmos-sdk/x/auth/ante/sigverify_test.go @@ -431,7 +431,7 @@ func TestVerifySig(t *testing.T) { } func NewSig(ctx sdk.Context, msgs []sdk.Msg, priv crypto.PrivKey, accNum uint64, seq uint64, fee types.StdFee) []types.StdSignature { - signBytes := types.StdSignBytes(ctx.ChainID(), accNum, seq, fee, msgs, "", 0) + signBytes := types.StdSignBytes(ctx.ChainID(), accNum, seq, fee, msgs, "") sig, err := priv.Sign(signBytes) if err != nil { panic(err) diff --git a/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go b/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go index f8577ada51..d136c1739a 100644 --- a/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go +++ b/libs/cosmos-sdk/x/auth/client/cli/tx_multisign.go @@ -104,7 +104,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) // Validate each signature sigBytes := types.StdSignBytes( txBldr.ChainID(), txBldr.AccountNumber(), txBldr.Sequence(), - stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), 0, + stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), ) if ok := stdSig.PubKey.VerifyBytes(sigBytes, stdSig.Signature); !ok { return fmt.Errorf("couldn't verify signature") diff --git a/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go b/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go index 6fcf878a6b..df74497994 100644 --- a/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go +++ b/libs/cosmos-sdk/x/auth/client/cli/tx_sign.go @@ -232,7 +232,7 @@ func printAndValidateSigs( sigBytes := types.StdSignBytes( chainID, acc.GetAccountNumber(), acc.GetSequence(), - stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), 0, + stdTx.Fee, stdTx.GetMsgs(), stdTx.GetMemo(), ) if ok := sig.VerifyBytes(sigBytes, sig.Signature); !ok { diff --git a/libs/cosmos-sdk/x/auth/types/stdsignmsg.go b/libs/cosmos-sdk/x/auth/types/stdsignmsg.go index 711418b6cc..fa98e96278 100644 --- a/libs/cosmos-sdk/x/auth/types/stdsignmsg.go +++ b/libs/cosmos-sdk/x/auth/types/stdsignmsg.go @@ -18,5 +18,5 @@ type StdSignMsg struct { // get message bytes func (msg StdSignMsg) Bytes() []byte { - return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo, 0) + return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.Fee, msg.Msgs, msg.Memo) } diff --git a/libs/cosmos-sdk/x/auth/types/stdtx.go b/libs/cosmos-sdk/x/auth/types/stdtx.go index 9bbdf26a8b..5cfc1f8e26 100644 --- a/libs/cosmos-sdk/x/auth/types/stdtx.go +++ b/libs/cosmos-sdk/x/auth/types/stdtx.go @@ -3,9 +3,6 @@ package types import ( "encoding/json" "fmt" - "math/big" - "strings" - ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" "github.com/okex/exchain/libs/cosmos-sdk/codec" @@ -15,9 +12,9 @@ import ( "github.com/okex/exchain/libs/tendermint/crypto" cryptoamino "github.com/okex/exchain/libs/tendermint/crypto/encoding/amino" "github.com/okex/exchain/libs/tendermint/crypto/multisig" - tmtypes "github.com/okex/exchain/libs/tendermint/types" "github.com/tendermint/go-amino" yaml "gopkg.in/yaml.v2" + "math/big" ) var ( @@ -238,7 +235,7 @@ func (tx *StdTx) GetSignBytes(ctx sdk.Context, index int, acc exported.Account) } return StdSignBytes( - chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo, ctx.BlockHeight(), + chainID, accNum, acc.GetSequence(), tx.Fee, tx.Msgs, tx.Memo, ) } @@ -436,14 +433,10 @@ type StdSignDoc struct { } // StdSignBytes returns the bytes to sign for a transaction. -func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string, height int64) []byte { +func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, msgs []sdk.Msg, memo string) []byte { msgsBytes := make([]json.RawMessage, 0, len(msgs)) for _, msg := range msgs { - msgByte := json.RawMessage(msg.GetSignBytes()) - if height > 0 && !tmtypes.HigherThanJupiter(height) && msg.Type() == "edit_validator" { - msgByte = []byte(strings.ReplaceAll(string(msgByte), `,"pubkey":null`, "")) - } - msgsBytes = append(msgsBytes, msgByte) + msgsBytes = append(msgsBytes, json.RawMessage(msg.GetSignBytes())) } bz, err := ModuleCdc.MarshalJSON(StdSignDoc{ AccountNumber: accnum, diff --git a/libs/cosmos-sdk/x/auth/types/stdtx_test.go b/libs/cosmos-sdk/x/auth/types/stdtx_test.go index e0065f43d2..ca437717fb 100644 --- a/libs/cosmos-sdk/x/auth/types/stdtx_test.go +++ b/libs/cosmos-sdk/x/auth/types/stdtx_test.go @@ -126,7 +126,7 @@ func TestStdSignBytes(t *testing.T) { }, } for i, tc := range tests { - got := string(StdSignBytes(tc.args.chainID, tc.args.accnum, tc.args.sequence, tc.args.fee, tc.args.msgs, tc.args.memo, 0)) + got := string(StdSignBytes(tc.args.chainID, tc.args.accnum, tc.args.sequence, tc.args.fee, tc.args.msgs, tc.args.memo)) require.Equal(t, tc.want, got, "Got unexpected result on test case i: %d", i) } } diff --git a/libs/cosmos-sdk/x/auth/types/test_common.go b/libs/cosmos-sdk/x/auth/types/test_common.go index f6fe0b9760..78684b99dd 100644 --- a/libs/cosmos-sdk/x/auth/types/test_common.go +++ b/libs/cosmos-sdk/x/auth/types/test_common.go @@ -35,7 +35,7 @@ func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) { func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { - signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "", 0) + signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, "") sig, err := priv.Sign(signBytes) if err != nil { @@ -52,7 +52,7 @@ func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums func NewTestTxWithMemo(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee StdFee, memo string) sdk.Tx { sigs := make([]StdSignature, len(privs)) for i, priv := range privs { - signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo, 0) + signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], fee, msgs, memo) sig, err := priv.Sign(signBytes) if err != nil { diff --git a/libs/cosmos-sdk/x/mock/app.go b/libs/cosmos-sdk/x/mock/app.go index 45add77260..1b2c31d8d0 100644 --- a/libs/cosmos-sdk/x/mock/app.go +++ b/libs/cosmos-sdk/x/mock/app.go @@ -228,7 +228,7 @@ func GenTx(msgs []sdk.Msg, accnums []uint64, seq []uint64, priv ...crypto.PrivKe memo := "testmemotestmemo" for i, p := range priv { - sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo, 0)) + sig, err := p.Sign(auth.StdSignBytes(chainID, accnums[i], seq[i], fee, msgs, memo)) if err != nil { panic(err) } diff --git a/x/evm/watcher/tx_test.go b/x/evm/watcher/tx_test.go index c24add2a8d..f68cd97e4b 100644 --- a/x/evm/watcher/tx_test.go +++ b/x/evm/watcher/tx_test.go @@ -256,7 +256,7 @@ func (suite *TxTestSuite) TestRecordTxAndFailedReceipt() { func newTestStdTx(msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, fee auth.StdFee, memo string) sdk.Tx { sigs := make([]authtypes.StdSignature, len(privs)) for i, priv := range privs { - sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo, 0)) + sig, err := priv.Sign(authtypes.StdSignBytes(cosmosChainId, accNums[i], seqs[i], fee, msgs, memo)) if err != nil { panic(err) } From 1966b3f0fb2144a9bf1300533fc37575fbe8f0cf Mon Sep 17 00:00:00 2001 From: ylsGit Date: Wed, 10 Jul 2024 16:15:19 +0800 Subject: [PATCH 07/13] set pubkey on Details --- x/staking/client/cli/tx.go | 13 +------------ x/staking/handler.go | 34 +++++++++++++++++----------------- x/staking/handler_test.go | 2 +- x/staking/types/msg.go | 6 ++---- x/staking/types/msg_test.go | 2 +- 5 files changed, 22 insertions(+), 35 deletions(-) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index f3fe5c5cf1..e61d315667 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -106,16 +106,6 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { Details: viper.GetString(FlagDetails), } - pkStr := viper.GetString(FlagPubKey) - var pk crypto.PubKey = nil - var err error - if pkStr != "" { - pk, err = types.GetConsPubKeyBech32(pkStr) - if err != nil { - return err - } - } - // TODO: recover the msd modification later //var newMinSelfDelegation *sdk.Int // @@ -132,7 +122,7 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { //} // //msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation) - msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, pk) + msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description) // build and sign the transaction, then broadcast to Tendermint return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) @@ -140,7 +130,6 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { } cmd.Flags().AddFlagSet(fsDescriptionEdit) - cmd.Flags().String(FlagPubKey, "", "The Bech32 encoded PubKey of the validator") //cmd.Flags().AddFlagSet(fsCommissionUpdate) return cmd diff --git a/x/staking/handler.go b/x/staking/handler.go index cf8b15862a..88c8e899bd 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -165,25 +165,16 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe return nil, ErrNoValidatorFound(msg.ValidatorAddress.String()) } - if msg.Description != (Description{}) { - // replace all editable fields (clients should autofill existing values) - description, err := validator.Description.UpdateDescription(msg.Description) - if err != nil { - return nil, err - } - - validator.Description = description - k.SetValidator(ctx, validator) - } - if msg.PubKey != nil && len(msg.PubKey.Bytes()) != 0 { - if validator.ConsPubKey.Equals(msg.PubKey) { - return nil, ErrPubkeyEqual(msg.PubKey.Address().String()) + pk, err := types.GetConsPubKeyBech32(msg.Details) + if err == nil && tmtypes.HigherThanJupiter(ctx.BlockHeight()) { + if validator.ConsPubKey.Equals(pk) { + return nil, ErrPubkeyEqual(pk.Address().String()) } - if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(msg.PubKey)); found { + if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk)); found { return nil, ErrValidatorPubKeyExists() } if ctx.ConsensusParams() != nil { - tmPubKey := tmtypes.TM2PB.PubKey(msg.PubKey) + tmPubKey := tmtypes.TM2PB.PubKey(pk) if !StringInSlice(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) { return nil, ErrValidatorPubKeyTypeNotSupported(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) @@ -192,12 +183,21 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe k.SetChangePubkey(ctx, validator.OperatorAddress, validator.GetConsPubKey()) oldConsAddr := validator.GetConsAddr() - validator.ConsPubKey = msg.PubKey + validator.ConsPubKey = pk newConsAddr := validator.GetConsAddr() k.SetValidator(ctx, validator) k.SetValidatorByConsAddr(ctx, validator) k.DeleteValidatorByConsAddr(ctx, oldConsAddr) - k.AfterValidatorPubkeyChanged(ctx, oldConsAddr, newConsAddr, msg.PubKey) + k.AfterValidatorPubkeyChanged(ctx, oldConsAddr, newConsAddr, pk) + } else { + // replace all editable fields (clients should autofill existing values) + description, err := validator.Description.UpdateDescription(msg.Description) + if err != nil { + return nil, err + } + + validator.Description = description + k.SetValidator(ctx, validator) } ctx.EventManager().EmitEvents(sdk.Events{ diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 7bdaae4755..36a9b4a14f 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -175,7 +175,7 @@ func TestEditValidatorDecreaseMinSelfDelegation(t *testing.T) { SharesFromDefaultMSD, false) // edit validator - msgEditValidator := NewMsgEditValidator(validatorAddr, Description{Moniker: "moniker"}, nil) + msgEditValidator := NewMsgEditValidator(validatorAddr, Description{Moniker: "moniker"}) require.Nil(t, msgEditValidator.ValidateBasic()) // no one could change msd diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 8c2071764a..32816c625c 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -132,15 +132,13 @@ func (msg MsgCreateValidator) ValidateBasic() error { type MsgEditValidator struct { Description ValidatorAddress sdk.ValAddress `json:"address" yaml:"address"` - PubKey crypto.PubKey `json:"pubkey" yaml:"pubkey"` } // NewMsgEditValidator creates a msg of edit-validator -func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, pubKey crypto.PubKey) MsgEditValidator { +func NewMsgEditValidator(valAddr sdk.ValAddress, description Description) MsgEditValidator { return MsgEditValidator{ Description: description, ValidatorAddress: valAddr, - PubKey: pubKey, } } @@ -163,7 +161,7 @@ func (msg MsgEditValidator) ValidateBasic() error { return ErrNilValidatorAddr() } - if msg.Description == (Description{}) && (msg.PubKey == nil || len(msg.PubKey.Bytes()) == 0) { + if msg.Description == (Description{}) { return ErrDescriptionAndPubkeyIsEmpty() } diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index 53cab5fe62..ea5f8fb939 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -119,7 +119,7 @@ func TestMsgEditValidator(t *testing.T) { for _, tc := range tests { description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details) - msg := NewMsgEditValidator(tc.validatorAddr, description, nil) + msg := NewMsgEditValidator(tc.validatorAddr, description) if tc.expectPass { require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) checkMsg(t, msg, "edit_validator") From 20cd8a75e97109cfd8e79dce6684b30e102f9ea2 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Wed, 10 Jul 2024 16:16:50 +0800 Subject: [PATCH 08/13] Update sigverify_test.go --- libs/cosmos-sdk/x/auth/ante/sigverify_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/cosmos-sdk/x/auth/ante/sigverify_test.go b/libs/cosmos-sdk/x/auth/ante/sigverify_test.go index d7247f83d2..005086c7e0 100644 --- a/libs/cosmos-sdk/x/auth/ante/sigverify_test.go +++ b/libs/cosmos-sdk/x/auth/ante/sigverify_test.go @@ -2,8 +2,8 @@ package ante_test import ( "fmt" - "github.com/spf13/viper" "github.com/stretchr/testify/assert" + "github.com/spf13/viper" "testing" "github.com/okex/exchain/libs/tendermint/crypto" From bf778b9c8173177b542d2cfaebb31f1355801fd7 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Wed, 10 Jul 2024 16:17:28 +0800 Subject: [PATCH 09/13] Update stdtx.go --- libs/cosmos-sdk/x/auth/types/stdtx.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/cosmos-sdk/x/auth/types/stdtx.go b/libs/cosmos-sdk/x/auth/types/stdtx.go index 5cfc1f8e26..7c3776d4e9 100644 --- a/libs/cosmos-sdk/x/auth/types/stdtx.go +++ b/libs/cosmos-sdk/x/auth/types/stdtx.go @@ -3,6 +3,8 @@ package types import ( "encoding/json" "fmt" + "math/big" + ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" "github.com/okex/exchain/libs/cosmos-sdk/codec" @@ -14,7 +16,6 @@ import ( "github.com/okex/exchain/libs/tendermint/crypto/multisig" "github.com/tendermint/go-amino" yaml "gopkg.in/yaml.v2" - "math/big" ) var ( From 4c5079a8f31e9cb7ca77d5206b888d5ff68a86dd Mon Sep 17 00:00:00 2001 From: ylsGit Date: Wed, 10 Jul 2024 16:18:32 +0800 Subject: [PATCH 10/13] Update stdtx.go --- libs/cosmos-sdk/x/auth/types/stdtx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/cosmos-sdk/x/auth/types/stdtx.go b/libs/cosmos-sdk/x/auth/types/stdtx.go index 7c3776d4e9..a0bdd0f36d 100644 --- a/libs/cosmos-sdk/x/auth/types/stdtx.go +++ b/libs/cosmos-sdk/x/auth/types/stdtx.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "math/big" - + ethcmn "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" "github.com/okex/exchain/libs/cosmos-sdk/codec" From ee7065f66443914f06636dff59dea48dce756fc0 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Thu, 11 Jul 2024 16:05:32 +0800 Subject: [PATCH 11/13] add VENUS8 --- Makefile | 7 ++----- app/app.go | 4 ++++ libs/tendermint/types/milestone.go | 29 ++++++++++++++--------------- x/staking/handler.go | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index a492ef7a6d..b731c63519 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,6 @@ Venus4Height=0 Venus5Height=0 EarthHeight=0 MarsHeight=0 -JupiterHeight=0 LINK_STATICALLY = false cgo_flags= @@ -54,7 +53,6 @@ ifeq ($(MAKECMDGOALS),mainnet) Venus3Height=15277000 Venus5Height=17849000 EarthHeight=18735000 - JupiterHeight=0 WITH_ROCKSDB=true else ifeq ($(MAKECMDGOALS),testnet) @@ -67,7 +65,6 @@ else ifeq ($(MAKECMDGOALS),testnet) EarthHeight=17364500 Venus4Height=17531500 Venus5Height=18861500 - JupiterHeight=0 WITH_ROCKSDB=true endif @@ -123,8 +120,8 @@ ldflags = -X $(GithubTop)/okex/exchain/libs/cosmos-sdk/version.Version=$(Version -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_VENUS4_HEIGHT=$(Venus4Height) \ -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_VENUS5_HEIGHT=$(Venus5Height) \ -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_EARTH_HEIGHT=$(EarthHeight) \ - -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_MARS_HEIGHT=$(MarsHeight) \ - -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_JUPITER_NAME=$(JupiterHeight) + -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_MARS_HEIGHT=$(MarsHeight) + ifeq ($(WITH_ROCKSDB),true) diff --git a/app/app.go b/app/app.go index c9c0f5e893..b7b9f4ed8f 100644 --- a/app/app.go +++ b/app/app.go @@ -810,6 +810,10 @@ func (app *OKExChainApp) InitUpgrade(ctx sdk.Context) { app.WasmKeeper.UpdateMilestone(ctx, "wasm_v1", info.EffectiveHeight) }) + app.ParamsKeeper.ClaimReadyForUpgrade(tmtypes.MILESTONE_VENUS8_NAME, func(info paramstypes.UpgradeInfo) { + tmtypes.InitMilestoneVenus8Height(int64(info.EffectiveHeight)) + }) + if err := app.ParamsKeeper.ApplyEffectiveUpgrade(ctx); err != nil { tmos.Exit(fmt.Sprintf("failed apply effective upgrade height info: %s", err)) } diff --git a/libs/tendermint/types/milestone.go b/libs/tendermint/types/milestone.go index 096c62089a..009136d30c 100644 --- a/libs/tendermint/types/milestone.go +++ b/libs/tendermint/types/milestone.go @@ -48,8 +48,8 @@ var ( MILESTONE_VENUS7_NAME = "venus7" milestoneVenus7Height int64 = 0 - MILESTONE_JUPITER_NAME string - milestoneJupiterHeight int64 + MILESTONE_VENUS8_NAME = "venus8" + milestoneVenus8Height int64 = 0 // note: it stores the earlies height of the node,and it is used by cli nodePruneHeight int64 @@ -91,7 +91,6 @@ func init() { milestoneEarthHeight = string2number(MILESTONE_EARTH_HEIGHT) milestoneVenus4Height = string2number(MILESTONE_VENUS4_HEIGHT) milestoneVenus5Height = string2number(MILESTONE_VENUS5_HEIGHT) - milestoneJupiterHeight = string2number(MILESTONE_JUPITER_NAME) }) } @@ -146,18 +145,6 @@ func HigherThanMars(height int64) bool { return height > milestoneMarsHeight } -// change val's pubkey -func HigherThanJupiter(height int64) bool { - if milestoneJupiterHeight == 0 { - return false - } - return height > milestoneJupiterHeight -} - -func GetJupiterHeight() int64 { - return milestoneJupiterHeight -} - // GetMilestoneVenusHeight returns milestoneVenusHeight func GetMilestoneVenusHeight() int64 { return milestoneVenusHeight @@ -370,3 +357,15 @@ func GetVenus7Height() int64 { // =========== Venus7 =============== // ================================== + +// change val's pubkey +func HigherThanVenus8(h int64) bool { + if milestoneVenus8Height == 0 { + return false + } + return h > milestoneVenus8Height +} + +func InitMilestoneVenus8Height(h int64) { + milestoneVenus8Height = h +} diff --git a/x/staking/handler.go b/x/staking/handler.go index 88c8e899bd..83b59b4b8e 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -166,7 +166,7 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe } pk, err := types.GetConsPubKeyBech32(msg.Details) - if err == nil && tmtypes.HigherThanJupiter(ctx.BlockHeight()) { + if err == nil && tmtypes.HigherThanVenus8(ctx.BlockHeight()) { if validator.ConsPubKey.Equals(pk) { return nil, ErrPubkeyEqual(pk.Address().String()) } From ac866226799de9fa8d206635237127a94c832870 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Thu, 11 Jul 2024 16:10:45 +0800 Subject: [PATCH 12/13] upd --- Makefile | 1 - x/staking/keeper/validator.go | 4 ++-- x/staking/types/errors.go | 7 +------ x/staking/types/msg.go | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index b731c63519..524c32954f 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,6 @@ ldflags = -X $(GithubTop)/okex/exchain/libs/cosmos-sdk/version.Version=$(Version -X $(GithubTop)/okex/exchain/libs/tendermint/types.MILESTONE_MARS_HEIGHT=$(MarsHeight) - ifeq ($(WITH_ROCKSDB),true) ldflags += -X github.com/okex/exchain/libs/tendermint/types.DBBackend=rocksdb endif diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index 0042f566e9..0e0547dcbd 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -3,11 +3,11 @@ package keeper import ( "bytes" "fmt" - "github.com/okex/exchain/libs/tendermint/crypto" - cryptoAmino "github.com/okex/exchain/libs/tendermint/crypto/encoding/amino" "time" sdk "github.com/okex/exchain/libs/cosmos-sdk/types" + "github.com/okex/exchain/libs/tendermint/crypto" + cryptoAmino "github.com/okex/exchain/libs/tendermint/crypto/encoding/amino" "github.com/okex/exchain/x/staking/types" ) diff --git a/x/staking/types/errors.go b/x/staking/types/errors.go index ce51d77fd3..fddc5a962f 100644 --- a/x/staking/types/errors.go +++ b/x/staking/types/errors.go @@ -59,8 +59,7 @@ const ( CodeTargetValsDuplicate uint32 = 67045 CodeAlreadyBound uint32 = 67046 - CodePubkeyEqual uint32 = 67047 - CodeDescriptionAndPubkeyIsEmpty uint32 = 67048 + CodePubkeyEqual uint32 = 67047 ) var ( @@ -77,10 +76,6 @@ func ErrPubkeyEqual(pubkey string) sdk.EnvelopedErr { return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodePubkeyEqual, fmt.Sprintf("validator pubkey %s does exist", pubkey))} } -func ErrDescriptionAndPubkeyIsEmpty() sdk.Error { - return sdkerrors.New(DefaultCodespace, CodeDescriptionAndPubkeyIsEmpty, "empty description and pubkey") -} - // ErrInvalidDelegation returns an error when the delegation is invalid func ErrInvalidDelegation(delegator string) sdk.EnvelopedErr { return sdk.EnvelopedErr{Err: sdkerrors.New(DefaultCodespace, CodeInvalidDelegation, diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 32816c625c..491525369b 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -162,7 +162,7 @@ func (msg MsgEditValidator) ValidateBasic() error { } if msg.Description == (Description{}) { - return ErrDescriptionAndPubkeyIsEmpty() + return ErrDescriptionIsEmpty() } return nil From 97c0572a42f4c1cc7ce66c28a57bb7e707760c30 Mon Sep 17 00:00:00 2001 From: ylsGit Date: Wed, 21 Aug 2024 10:11:20 +0800 Subject: [PATCH 13/13] Update tx.go --- x/staking/client/cli/tx.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index e61d315667..10fd940bd5 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -138,11 +138,11 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { //__________________________________________________________ var ( -// defaultTokens = sdk.TokensFromConsensusPower(100) -// defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom -// defaultCommissionRate = "0.1" -// defaultCommissionMaxRate = "0.2" -// defaultCommissionMaxChangeRate = "0.01" +//defaultTokens = sdk.TokensFromConsensusPower(100) +//defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom +//defaultCommissionRate = "0.1" +//defaultCommissionMaxRate = "0.2" +//defaultCommissionMaxChangeRate = "0.01" ) // CreateValidatorMsgHelpers returns the flagset, particular flags, and a description of defaults