From 55ad7e14147168a995b3321a712c43d12b1ad893 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 13 Apr 2023 00:13:39 +0200 Subject: [PATCH 1/3] remove bech32 from evidence --- simapp/app.go | 2 +- x/evidence/keeper/keeper.go | 5 ++++- x/evidence/keeper/keeper_test.go | 2 ++ x/evidence/keeper/msg_server.go | 2 +- x/evidence/module.go | 4 +++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 0f0416547dad..3c1bbd414aa8 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -370,7 +370,7 @@ func NewSimApp( // create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( - appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper, + appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper, app.AccountKeeper.GetAddressCodec(), ) // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper diff --git a/x/evidence/keeper/keeper.go b/x/evidence/keeper/keeper.go index dc0d091a5c25..bd992e7ff56f 100644 --- a/x/evidence/keeper/keeper.go +++ b/x/evidence/keeper/keeper.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "cosmossdk.io/core/address" "cosmossdk.io/log" "cosmossdk.io/x/evidence/exported" "cosmossdk.io/x/evidence/types" @@ -26,18 +27,20 @@ type Keeper struct { router types.Router stakingKeeper types.StakingKeeper slashingKeeper types.SlashingKeeper + addressCodec address.Codec } // NewKeeper creates a new Keeper object. func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, stakingKeeper types.StakingKeeper, - slashingKeeper types.SlashingKeeper, + slashingKeeper types.SlashingKeeper, ac address.Codec, ) *Keeper { return &Keeper{ cdc: cdc, storeKey: storeKey, stakingKeeper: stakingKeeper, slashingKeeper: slashingKeeper, + addressCodec: ac, } } diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index ff8de64f5bc7..b155d659deee 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -17,6 +17,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil" @@ -101,6 +102,7 @@ func (suite *KeeperTestSuite) SetupTest() { key, stakingKeeper, slashingKeeper, + address.NewBech32Codec("cosmos"), ) suite.stakingKeeper = stakingKeeper diff --git a/x/evidence/keeper/msg_server.go b/x/evidence/keeper/msg_server.go index f9a3296e43b4..9862bbf6b953 100644 --- a/x/evidence/keeper/msg_server.go +++ b/x/evidence/keeper/msg_server.go @@ -24,7 +24,7 @@ var _ types.MsgServer = msgServer{} // SubmitEvidence implements the MsgServer.SubmitEvidence method. func (ms msgServer) SubmitEvidence(goCtx context.Context, msg *types.MsgSubmitEvidence) (*types.MsgSubmitEvidenceResponse, error) { - if _, err := sdk.AccAddressFromBech32(msg.Submitter); err != nil { + if _, err := ms.addressCodec.StringToBytes(msg.Submitter); err != nil { return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid submitter address: %s", err) } diff --git a/x/evidence/module.go b/x/evidence/module.go index 5632450294b0..a0c4c6fbbf59 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" modulev1 "cosmossdk.io/api/cosmos/evidence/module/v1" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" @@ -207,6 +208,7 @@ type ModuleInputs struct { StakingKeeper types.StakingKeeper SlashingKeeper types.SlashingKeeper + AddressCodec address.Codec } type ModuleOutputs struct { @@ -217,7 +219,7 @@ type ModuleOutputs struct { } func ProvideModule(in ModuleInputs) ModuleOutputs { - k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper) + k := keeper.NewKeeper(in.Cdc, in.Key, in.StakingKeeper, in.SlashingKeeper, in.AddressCodec) m := NewAppModule(*k) return ModuleOutputs{EvidenceKeeper: *k, Module: m} From b0ec7a307f4b76e29180e0853228e14ae9cc0f71 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 13 Apr 2023 00:17:47 +0200 Subject: [PATCH 2/3] fix tests --- x/evidence/keeper/msg_server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/evidence/keeper/msg_server_test.go b/x/evidence/keeper/msg_server_test.go index 2e5a29c21647..055d1b863976 100644 --- a/x/evidence/keeper/msg_server_test.go +++ b/x/evidence/keeper/msg_server_test.go @@ -42,7 +42,7 @@ func (s *KeeperTestSuite) TestSubmitEvidence() { name: "invalid address", req: &types.MsgSubmitEvidence{}, expErr: true, - expErrMsg: "invalid submitter address: empty address string is not allowed: invalid address", + expErrMsg: "invalid submitter address: decoding bech32 failed: invalid bech32 string length 0", }, { name: "missing evidence", From c2e4c2f0fea29ec599fd725579789d968287212f Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 13 Apr 2023 10:11:31 +0200 Subject: [PATCH 3/3] changelog --- x/evidence/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/evidence/CHANGELOG.md b/x/evidence/CHANGELOG.md index c54edf89ad3f..7c37c9aee7d5 100644 --- a/x/evidence/CHANGELOG.md +++ b/x/evidence/CHANGELOG.md @@ -29,3 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) The `x/evidence` module is extracted to have a separate go.mod file which allows it be a standalone module. * (keeper) [#15420](https://github.com/cosmos/cosmos-sdk/pull/15420) Move `BeginBlocker` to the keeper folder & make HandleEquivocation private + +### API Breaking Changes + +* (keeper) [#15825](https://github.com/cosmos/cosmos-sdk/pull/15825) Evidence constructor now requires an `address.Codec` (`import "cosmossdk.io/core/address"`)