(cherry picked from commit f124cb71aec67a2a48ad550b9f1afa3d861cdeaf) Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
This commit is contained in:
parent
121ae53499
commit
12fae01a25
|
@ -25,6 +25,8 @@ message MsgUpdateParams {
|
||||||
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||||
|
|
||||||
// params defines the x/consensus_params parameters to update.
|
// params defines the x/consensus_params parameters to update.
|
||||||
|
// VersionsParams is not included in this Msg because it is tracked
|
||||||
|
// separarately in x/upgrade.
|
||||||
//
|
//
|
||||||
// NOTE: All parameters must be supplied.
|
// NOTE: All parameters must be supplied.
|
||||||
tendermint.types.BlockParams block = 2;
|
tendermint.types.BlockParams block = 2;
|
||||||
|
|
|
@ -14,8 +14,8 @@ type (
|
||||||
Get(ctx sdk.Context, key []byte, ptr interface{})
|
Get(ctx sdk.Context, key []byte, ptr interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConsensusParamSetter defines the interface fulfilled by BaseApp
|
// ConsensusParamSetter defines the interface fulfilled by BaseApp's
|
||||||
// which allows setting its appVersion field.
|
// ParamStore which allows setting its appVersion field.
|
||||||
ConsensusParamSetter interface {
|
ConsensusParamSetter interface {
|
||||||
Get(ctx sdk.Context) (*tmproto.ConsensusParams, error)
|
Get(ctx sdk.Context) (*tmproto.ConsensusParams, error)
|
||||||
Has(ctx sdk.Context) bool
|
Has(ctx sdk.Context) bool
|
||||||
|
|
|
@ -31,7 +31,7 @@ func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParam
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
consensusParams := req.ToProtoConsensusParams()
|
consensusParams := req.ToProtoConsensusParams()
|
||||||
if err := types.Validate(tmtypes.ConsensusParamsFromProto(consensusParams)); err != nil {
|
if err := tmtypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
|
||||||
expErrMsg: "block.MaxBytes must be greater than 0. Got -10",
|
expErrMsg: "block.MaxBytes must be greater than 0. Got -10",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid authority",
|
name: "invalid authority",
|
||||||
input: &types.MsgUpdateParams{
|
input: &types.MsgUpdateParams{
|
||||||
Authority: "invalid",
|
Authority: "invalid",
|
||||||
Block: defaultConsensusParams.Block,
|
Block: defaultConsensusParams.Block,
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConsensusVersion defines the current x/bank module consensus version.
|
// ConsensusVersion defines the current x/consensus module consensus version.
|
||||||
const ConsensusVersion = 1
|
const ConsensusVersion = 1
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -42,7 +42,9 @@ type AppModuleBasic struct {
|
||||||
func (AppModuleBasic) Name() string { return types.ModuleName }
|
func (AppModuleBasic) Name() string { return types.ModuleName }
|
||||||
|
|
||||||
// RegisterLegacyAminoCodec registers the consensus_param module's types on the LegacyAmino codec.
|
// RegisterLegacyAminoCodec registers the consensus_param module's types on the LegacyAmino codec.
|
||||||
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||||
|
types.RegisterLegacyAminoCodec(cdc)
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultGenesis returns default genesis state as raw bytes for the consensus_param
|
// DefaultGenesis returns default genesis state as raw bytes for the consensus_param
|
||||||
// module.
|
// module.
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec/legacy"
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
|
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||||
|
@ -14,3 +20,26 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||||
|
|
||||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterLegacyAminoCodec registers the necessary x/consensus 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, &MsgUpdateParams{}, "cosmos-sdk/x/consensus/MsgUpdateParams")
|
||||||
|
}
|
||||||
|
|
||||||
|
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 MsgUpdate instances
|
||||||
|
RegisterLegacyAminoCodec(authzcodec.Amino)
|
||||||
|
RegisterLegacyAminoCodec(govcodec.Amino)
|
||||||
|
RegisterLegacyAminoCodec(groupcodec.Amino)
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// bank message types
|
// bank message types
|
||||||
|
@ -12,7 +13,7 @@ const (
|
||||||
TypeMsgUpdateParams = "update_params"
|
TypeMsgUpdateParams = "update_params"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sdk.Msg = &MsgUpdateParams{}
|
var _ legacytx.LegacyMsg = &MsgUpdateParams{}
|
||||||
|
|
||||||
// GetSigners returns the signer addresses that are expected to sign the result
|
// GetSigners returns the signer addresses that are expected to sign the result
|
||||||
// of GetSignBytes.
|
// of GetSignBytes.
|
||||||
|
@ -24,13 +25,21 @@ func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
|
||||||
// GetSignBytes returns the raw bytes for a MsgUpdateParams message that
|
// GetSignBytes returns the raw bytes for a MsgUpdateParams message that
|
||||||
// the expected signer needs to sign.
|
// the expected signer needs to sign.
|
||||||
func (msg MsgUpdateParams) GetSignBytes() []byte {
|
func (msg MsgUpdateParams) GetSignBytes() []byte {
|
||||||
return []byte{}
|
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg MsgUpdateParams) Route() string {
|
||||||
|
return sdk.MsgTypeURL(&msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg MsgUpdateParams) Type() string {
|
||||||
|
return sdk.MsgTypeURL(&msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateBasic performs basic MsgUpdateParams message validation.
|
// ValidateBasic performs basic MsgUpdateParams message validation.
|
||||||
func (msg MsgUpdateParams) ValidateBasic() error {
|
func (msg MsgUpdateParams) ValidateBasic() error {
|
||||||
params := tmtypes.ConsensusParamsFromProto(msg.ToProtoConsensusParams())
|
params := tmtypes.ConsensusParamsFromProto(msg.ToProtoConsensusParams())
|
||||||
return Validate(params)
|
return params.ValidateBasic()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg MsgUpdateParams) ToProtoConsensusParams() tmproto.ConsensusParams {
|
func (msg MsgUpdateParams) ToProtoConsensusParams() tmproto.ConsensusParams {
|
||||||
|
@ -47,6 +56,6 @@ func (msg MsgUpdateParams) ToProtoConsensusParams() tmproto.ConsensusParams {
|
||||||
Validator: &tmproto.ValidatorParams{
|
Validator: &tmproto.ValidatorParams{
|
||||||
PubKeyTypes: msg.Validator.PubKeyTypes,
|
PubKeyTypes: msg.Validator.PubKeyTypes,
|
||||||
},
|
},
|
||||||
Version: tmtypes.DefaultConsensusParams().ToProto().Version,
|
Version: tmtypes.DefaultConsensusParams().ToProto().Version, // Version is stored in x/upgrade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Validate performs basic validation of ConsensusParams returning an error upon
|
|
||||||
// failure.
|
|
||||||
func Validate(p tmtypes.ConsensusParams) error {
|
|
||||||
return p.ValidateBasic()
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Sentinel errors for the x/consensus module.
|
|
||||||
var (
|
|
||||||
ErrUnauthorized = sdkerrors.Register(ModuleName, 2, "unauthorized action")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Events
|
|
||||||
const (
|
|
||||||
EventTypeUpdateParam = "update_param"
|
|
||||||
|
|
||||||
AttributeKeyParamUpdater = "param_updater"
|
|
||||||
)
|
|
Loading…
Reference in New Issue