From d2b54d22f6552ca8fb45870f2c85b2f9f2769a11 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 18 Jul 2023 18:35:55 +0530 Subject: [PATCH 01/11] migrate AddrPubkeyRelation to collections --- x/slashing/keeper/keeper.go | 19 ++++++++++--------- x/slashing/migrations/v2/store_test.go | 3 ++- x/slashing/simulation/decoder_test.go | 3 ++- x/slashing/types/keys.go | 7 +------ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 31e82a73c804..4818673732de 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -34,12 +35,12 @@ type Keeper struct { func NewKeeper(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, storeService storetypes.KVStoreService, sk types.StakingKeeper, authority string) Keeper { sb := collections.NewSchemaBuilder(storeService) k := Keeper{ - storeService: storeService, - cdc: cdc, - legacyAmino: legacyAmino, - sk: sk, - authority: authority, - Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + storeService: storeService, + cdc: cdc, + legacyAmino: legacyAmino, + sk: sk, + authority: authority, + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), } schema, err := sb.Build() @@ -68,14 +69,14 @@ func (k Keeper) AddPubkey(ctx context.Context, pubkey cryptotypes.PubKey) error return err } store := k.storeService.OpenKVStore(ctx) - key := types.AddrPubkeyRelationKey(pubkey.Address()) + key := append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(pubkey.Address())...) return store.Set(key, bz) } // GetPubkey returns the pubkey from the adddress-pubkey relation func (k Keeper) GetPubkey(ctx context.Context, a cryptotypes.Address) (cryptotypes.PubKey, error) { store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.AddrPubkeyRelationKey(a)) + bz, err := store.Get(append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(a)...)) if err != nil { return nil, err } @@ -140,5 +141,5 @@ func (k Keeper) Jail(ctx context.Context, consAddr sdk.ConsAddress) error { func (k Keeper) deleteAddrPubkeyRelation(ctx context.Context, addr cryptotypes.Address) error { store := k.storeService.OpenKVStore(ctx) - return store.Delete(types.AddrPubkeyRelationKey(addr)) + return store.Delete(append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(addr)...)) } diff --git a/x/slashing/migrations/v2/store_test.go b/x/slashing/migrations/v2/store_test.go index 4b8794c42db6..3b89a8444619 100644 --- a/x/slashing/migrations/v2/store_test.go +++ b/x/slashing/migrations/v2/store_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" v1 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v1" v2 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v2" "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -46,7 +47,7 @@ func TestStoreMigration(t *testing.T) { { "AddrPubkeyRelationKey", v1.AddrPubkeyRelationKey(consAddr), - types.AddrPubkeyRelationKey(consAddr), + append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(consAddr)...), }, } diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index c63dcbbd23cc..f307849dc92a 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -36,7 +37,7 @@ func TestDecodeStore(t *testing.T) { Pairs: []kv.Pair{ {Key: types.ValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshal(&info)}, {Key: types.ValidatorMissedBlockBitmapKey(consAddr1, 6), Value: missed}, - {Key: types.AddrPubkeyRelationKey(delAddr1), Value: bz}, + {Key: append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(delAddr1)...), Value: bz}, {Key: []byte{0x99}, Value: []byte{0x99}}, // This test should panic }, } diff --git a/x/slashing/types/keys.go b/x/slashing/types/keys.go index ffd1c73650bc..ebc90d1fffc0 100644 --- a/x/slashing/types/keys.go +++ b/x/slashing/types/keys.go @@ -53,7 +53,7 @@ var ( ParamsKey = collections.NewPrefix(0) // Prefix for params key ValidatorSigningInfoKeyPrefix = []byte{0x01} // Prefix for signing info ValidatorMissedBlockBitmapKeyPrefix = []byte{0x02} // Prefix for missed block bitmap - AddrPubkeyRelationKeyPrefix = []byte{0x03} // Prefix for address-pubkey relation + AddrPubkeyRelationKeyPrefix = collections.NewPrefix(3) // Prefix for address-pubkey relation ) // ValidatorSigningInfoKey - stored by *Consensus* address (not operator address) @@ -84,8 +84,3 @@ func ValidatorMissedBlockBitmapKey(v sdk.ConsAddress, chunkIndex int64) []byte { return append(ValidatorMissedBlockBitmapPrefixKey(v), bz...) } - -// AddrPubkeyRelationKey gets pubkey relation key used to get the pubkey from the address -func AddrPubkeyRelationKey(addr []byte) []byte { - return append(AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(addr)...) -} From 8727127bbde8b4819b6aaf007b69bb5429173fc5 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 19 Jul 2023 11:14:36 +0530 Subject: [PATCH 02/11] fix lint --- x/slashing/keeper/keeper.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 4818673732de..2c2a8de723b0 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -35,12 +35,12 @@ type Keeper struct { func NewKeeper(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, storeService storetypes.KVStoreService, sk types.StakingKeeper, authority string) Keeper { sb := collections.NewSchemaBuilder(storeService) k := Keeper{ - storeService: storeService, - cdc: cdc, - legacyAmino: legacyAmino, - sk: sk, - authority: authority, - Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + storeService: storeService, + cdc: cdc, + legacyAmino: legacyAmino, + sk: sk, + authority: authority, + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), } schema, err := sb.Build() From 5b03842e5d75df5ef3d33c2ff3aec3db9a767c73 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 19 Jul 2023 16:17:15 +0530 Subject: [PATCH 03/11] delete pubkey keeper methods --- x/slashing/keeper/genesis.go | 2 +- x/slashing/keeper/hooks.go | 4 +-- x/slashing/keeper/hooks_test.go | 4 +-- x/slashing/keeper/keeper.go | 39 ++++++-------------------- x/slashing/keeper/keeper_test.go | 4 +-- x/slashing/migrations/v2/store_test.go | 3 +- x/slashing/simulation/decoder_test.go | 3 +- x/slashing/types/keys.go | 5 ++++ 8 files changed, 22 insertions(+), 42 deletions(-) diff --git a/x/slashing/keeper/genesis.go b/x/slashing/keeper/genesis.go index 60ea32eb71e9..8080d25de191 100644 --- a/x/slashing/keeper/genesis.go +++ b/x/slashing/keeper/genesis.go @@ -20,7 +20,7 @@ func (keeper Keeper) InitGenesis(ctx sdk.Context, stakingKeeper types.StakingKee panic(err) } - err = keeper.AddPubkey(ctx, consPk) + err = keeper.AddrPubkeyRelation.Set(ctx, sdk.AccAddress(validator.GetOperator()).Bytes(), consPk) if err != nil { panic(err) } diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index 8dadfb6488da..495fdaa8bad0 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -46,7 +46,7 @@ func (h Hooks) AfterValidatorBonded(ctx context.Context, consAddr sdk.ConsAddres // AfterValidatorRemoved deletes the address-pubkey relation when a validator is removed, func (h Hooks) AfterValidatorRemoved(ctx context.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress) error { - return h.k.deleteAddrPubkeyRelation(ctx, crypto.Address(consAddr)) + return h.k.AddrPubkeyRelation.Remove(ctx, crypto.Address(consAddr)) } // AfterValidatorCreated adds the address-pubkey relation when a validator is created. @@ -62,7 +62,7 @@ func (h Hooks) AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress return err } - return h.k.AddPubkey(sdkCtx, consPk) + return h.k.AddrPubkeyRelation.Set(sdkCtx, sdk.AccAddress(valAddr).Bytes(), consPk) } func (h Hooks) AfterValidatorBeginUnbonding(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { diff --git a/x/slashing/keeper/hooks_test.go b/x/slashing/keeper/hooks_test.go index 0456bcb9c170..4380835b9bee 100644 --- a/x/slashing/keeper/hooks_test.go +++ b/x/slashing/keeper/hooks_test.go @@ -31,13 +31,13 @@ func (s *KeeperTestSuite) TestAfterValidatorCreatedOrRemoved() { err = keeper.Hooks().AfterValidatorCreated(ctx, valAddr) require.NoError(err) - ePubKey, err := keeper.GetPubkey(ctx, addr.Bytes()) + ePubKey, err := keeper.AddrPubkeyRelation.Get(ctx, addr.Bytes()) require.NoError(err) require.Equal(ePubKey, pubKey) err = keeper.Hooks().AfterValidatorRemoved(ctx, sdk.ConsAddress(addr), nil) require.NoError(err) - _, err = keeper.GetPubkey(ctx, addr.Bytes()) + _, err = keeper.AddrPubkeyRelation.Get(ctx, addr.Bytes()) require.Error(err) } diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 0b89e2966234..847dd4cfa80b 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -30,6 +29,7 @@ type Keeper struct { Schema collections.Schema Params collections.Item[types.Params] ValidatorSigningInfo collections.Map[sdk.ConsAddress, types.ValidatorSigningInfo] + AddrPubkeyRelation collections.Map[[]byte, cryptotypes.PubKey] } // NewKeeper creates a slashing keeper @@ -49,6 +49,13 @@ func NewKeeper(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, storeServi sdk.ConsAddressKey, codec.CollValue[types.ValidatorSigningInfo](cdc), ), + AddrPubkeyRelation: collections.NewMap( + sb, + types.AddrPubkeyRelationKeyPrefix, + "addr_pubkey_relation", + collections.BytesKey, + codec.CollInterfaceValue[cryptotypes.PubKey](cdc), + ), } schema, err := sb.Build() @@ -70,31 +77,6 @@ func (k Keeper) Logger(ctx context.Context) log.Logger { return sdkCtx.Logger().With("module", "x/"+types.ModuleName) } -// AddPubkey sets a address-pubkey relation -func (k Keeper) AddPubkey(ctx context.Context, pubkey cryptotypes.PubKey) error { - bz, err := k.cdc.MarshalInterface(pubkey) - if err != nil { - return err - } - store := k.storeService.OpenKVStore(ctx) - key := append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(pubkey.Address())...) - return store.Set(key, bz) -} - -// GetPubkey returns the pubkey from the adddress-pubkey relation -func (k Keeper) GetPubkey(ctx context.Context, a cryptotypes.Address) (cryptotypes.PubKey, error) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(a)...)) - if err != nil { - return nil, err - } - if bz == nil { - return nil, fmt.Errorf("address %s not found", sdk.ConsAddress(a)) - } - var pk cryptotypes.PubKey - return pk, k.cdc.UnmarshalInterface(bz, &pk) -} - // Slash attempts to slash a validator. The slash is delegated to the staking // module to make the necessary validator changes. It specifies no intraction reason. func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, fraction sdkmath.LegacyDec, power, distributionHeight int64) error { @@ -146,8 +128,3 @@ func (k Keeper) Jail(ctx context.Context, consAddr sdk.ConsAddress) error { ) return nil } - -func (k Keeper) deleteAddrPubkeyRelation(ctx context.Context, addr cryptotypes.Address) error { - store := k.storeService.OpenKVStore(ctx) - return store.Delete(append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(addr)...)) -} diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index ac8a6d441d86..f81abf4cbe78 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -72,9 +72,9 @@ func (s *KeeperTestSuite) TestPubkey() { require := s.Require() _, pubKey, addr := testdata.KeyTestPubAddr() - require.NoError(keeper.AddPubkey(ctx, pubKey)) + require.NoError(keeper.AddrPubkeyRelation.Set(ctx, addr.Bytes(), pubKey)) - expectedPubKey, err := keeper.GetPubkey(ctx, addr.Bytes()) + expectedPubKey, err := keeper.AddrPubkeyRelation.Get(ctx, addr.Bytes()) require.NoError(err) require.Equal(pubKey, expectedPubKey) } diff --git a/x/slashing/migrations/v2/store_test.go b/x/slashing/migrations/v2/store_test.go index 3b89a8444619..4b8794c42db6 100644 --- a/x/slashing/migrations/v2/store_test.go +++ b/x/slashing/migrations/v2/store_test.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" v1 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v1" v2 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v2" "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -47,7 +46,7 @@ func TestStoreMigration(t *testing.T) { { "AddrPubkeyRelationKey", v1.AddrPubkeyRelationKey(consAddr), - append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(consAddr)...), + types.AddrPubkeyRelationKey(consAddr), }, } diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index f307849dc92a..c63dcbbd23cc 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -37,7 +36,7 @@ func TestDecodeStore(t *testing.T) { Pairs: []kv.Pair{ {Key: types.ValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshal(&info)}, {Key: types.ValidatorMissedBlockBitmapKey(consAddr1, 6), Value: missed}, - {Key: append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(delAddr1)...), Value: bz}, + {Key: types.AddrPubkeyRelationKey(delAddr1), Value: bz}, {Key: []byte{0x99}, Value: []byte{0x99}}, // This test should panic }, } diff --git a/x/slashing/types/keys.go b/x/slashing/types/keys.go index 3894777d933b..83217e26e37a 100644 --- a/x/slashing/types/keys.go +++ b/x/slashing/types/keys.go @@ -74,3 +74,8 @@ func ValidatorMissedBlockBitmapKey(v sdk.ConsAddress, chunkIndex int64) []byte { return append(ValidatorMissedBlockBitmapPrefixKey(v), bz...) } + +// AddrPubkeyRelationKey gets pubkey relation key used to get the pubkey from the address +func AddrPubkeyRelationKey(addr []byte) []byte { + return append(AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(addr)...) +} From e299158770e736aeecd671d21543dca5a9be2c93 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 19 Jul 2023 16:20:10 +0530 Subject: [PATCH 04/11] add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b2c31a4a966..d48c6bb5336e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/slashing) [17044](https://github.com/cosmos/cosmos-sdk/pull/17044) Use collections for `AddrPubkeyRelation`: + * remove `Keeper`: `AddPubkey`, `GetPubkey`, `deleteAddrPubkeyRelation` * (x/slashing) [17023](https://github.com/cosmos/cosmos-sdk/pull/17023) Use collections for `ValidatorSigningInfo`: * remove `Keeper`: `SetValidatorSigningInfo`, `GetValidatorSigningInfo`, `IterateValidatorSigningInfos` * (x/staking) [#17026](https://github.com/cosmos/cosmos-sdk/pull/17026) Use collections for `LastTotalPower`: From ed0ea74d79279e161abc4f00ea8292c50d448b38 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 19 Jul 2023 16:43:19 +0530 Subject: [PATCH 05/11] more changes --- CHANGELOG.md | 2 +- x/slashing/keeper/genesis.go | 2 +- x/slashing/keeper/hooks.go | 2 +- x/slashing/keeper/hooks_test.go | 4 ++-- x/slashing/keeper/keeper.go | 11 +++++++++++ x/slashing/keeper/keeper_test.go | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d48c6bb5336e..6e1fb1eb24da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,7 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes * (x/slashing) [17044](https://github.com/cosmos/cosmos-sdk/pull/17044) Use collections for `AddrPubkeyRelation`: - * remove `Keeper`: `AddPubkey`, `GetPubkey`, `deleteAddrPubkeyRelation` + * remove `Keeper`: `deleteAddrPubkeyRelation` * (x/slashing) [17023](https://github.com/cosmos/cosmos-sdk/pull/17023) Use collections for `ValidatorSigningInfo`: * remove `Keeper`: `SetValidatorSigningInfo`, `GetValidatorSigningInfo`, `IterateValidatorSigningInfos` * (x/staking) [#17026](https://github.com/cosmos/cosmos-sdk/pull/17026) Use collections for `LastTotalPower`: diff --git a/x/slashing/keeper/genesis.go b/x/slashing/keeper/genesis.go index 8080d25de191..60ea32eb71e9 100644 --- a/x/slashing/keeper/genesis.go +++ b/x/slashing/keeper/genesis.go @@ -20,7 +20,7 @@ func (keeper Keeper) InitGenesis(ctx sdk.Context, stakingKeeper types.StakingKee panic(err) } - err = keeper.AddrPubkeyRelation.Set(ctx, sdk.AccAddress(validator.GetOperator()).Bytes(), consPk) + err = keeper.AddPubkey(ctx, consPk) if err != nil { panic(err) } diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index 495fdaa8bad0..da181c12a31c 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -62,7 +62,7 @@ func (h Hooks) AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress return err } - return h.k.AddrPubkeyRelation.Set(sdkCtx, sdk.AccAddress(valAddr).Bytes(), consPk) + return h.k.AddPubkey(sdkCtx, consPk) } func (h Hooks) AfterValidatorBeginUnbonding(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { diff --git a/x/slashing/keeper/hooks_test.go b/x/slashing/keeper/hooks_test.go index 4380835b9bee..0456bcb9c170 100644 --- a/x/slashing/keeper/hooks_test.go +++ b/x/slashing/keeper/hooks_test.go @@ -31,13 +31,13 @@ func (s *KeeperTestSuite) TestAfterValidatorCreatedOrRemoved() { err = keeper.Hooks().AfterValidatorCreated(ctx, valAddr) require.NoError(err) - ePubKey, err := keeper.AddrPubkeyRelation.Get(ctx, addr.Bytes()) + ePubKey, err := keeper.GetPubkey(ctx, addr.Bytes()) require.NoError(err) require.Equal(ePubKey, pubKey) err = keeper.Hooks().AfterValidatorRemoved(ctx, sdk.ConsAddress(addr), nil) require.NoError(err) - _, err = keeper.AddrPubkeyRelation.Get(ctx, addr.Bytes()) + _, err = keeper.GetPubkey(ctx, addr.Bytes()) require.Error(err) } diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 847dd4cfa80b..3f002b77cc75 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -77,6 +77,17 @@ func (k Keeper) Logger(ctx context.Context) log.Logger { return sdkCtx.Logger().With("module", "x/"+types.ModuleName) } +// AddPubkey sets a address-pubkey relation +func (k Keeper) AddPubkey(ctx context.Context, pubkey cryptotypes.PubKey) error { + key := types.AddrPubkeyRelationKey(pubkey.Address()) + return k.AddrPubkeyRelation.Set(ctx, key, pubkey) +} + +// GetPubkey returns the pubkey from the adddress-pubkey relation +func (k Keeper) GetPubkey(ctx context.Context, a cryptotypes.Address) (cryptotypes.PubKey, error) { + return k.AddrPubkeyRelation.Get(ctx, types.AddrPubkeyRelationKey(a)) +} + // Slash attempts to slash a validator. The slash is delegated to the staking // module to make the necessary validator changes. It specifies no intraction reason. func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, fraction sdkmath.LegacyDec, power, distributionHeight int64) error { diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index f81abf4cbe78..ac8a6d441d86 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -72,9 +72,9 @@ func (s *KeeperTestSuite) TestPubkey() { require := s.Require() _, pubKey, addr := testdata.KeyTestPubAddr() - require.NoError(keeper.AddrPubkeyRelation.Set(ctx, addr.Bytes(), pubKey)) + require.NoError(keeper.AddPubkey(ctx, pubKey)) - expectedPubKey, err := keeper.AddrPubkeyRelation.Get(ctx, addr.Bytes()) + expectedPubKey, err := keeper.GetPubkey(ctx, addr.Bytes()) require.NoError(err) require.Equal(pubKey, expectedPubKey) } From a97cfc5edad4bf7b08c6ca6e3ce8fd2f427b7f3c Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Wed, 19 Jul 2023 16:49:08 +0530 Subject: [PATCH 06/11] fix tests and add changes accordingly --- CHANGELOG.md | 3 +-- x/slashing/keeper/hooks.go | 2 +- x/slashing/keeper/keeper.go | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e1fb1eb24da..42d8c229b8c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,8 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (x/slashing) [17044](https://github.com/cosmos/cosmos-sdk/pull/17044) Use collections for `AddrPubkeyRelation`: - * remove `Keeper`: `deleteAddrPubkeyRelation` +* (x/slashing) [17044](https://github.com/cosmos/cosmos-sdk/pull/17044) Use collections for `AddrPubkeyRelation` * (x/slashing) [17023](https://github.com/cosmos/cosmos-sdk/pull/17023) Use collections for `ValidatorSigningInfo`: * remove `Keeper`: `SetValidatorSigningInfo`, `GetValidatorSigningInfo`, `IterateValidatorSigningInfos` * (x/staking) [#17026](https://github.com/cosmos/cosmos-sdk/pull/17026) Use collections for `LastTotalPower`: diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index da181c12a31c..8dadfb6488da 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -46,7 +46,7 @@ func (h Hooks) AfterValidatorBonded(ctx context.Context, consAddr sdk.ConsAddres // AfterValidatorRemoved deletes the address-pubkey relation when a validator is removed, func (h Hooks) AfterValidatorRemoved(ctx context.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress) error { - return h.k.AddrPubkeyRelation.Remove(ctx, crypto.Address(consAddr)) + return h.k.deleteAddrPubkeyRelation(ctx, crypto.Address(consAddr)) } // AfterValidatorCreated adds the address-pubkey relation when a validator is created. diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 3f002b77cc75..31000b91e19c 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -139,3 +139,7 @@ func (k Keeper) Jail(ctx context.Context, consAddr sdk.ConsAddress) error { ) return nil } + +func (k Keeper) deleteAddrPubkeyRelation(ctx context.Context, addr cryptotypes.Address) error { + return k.AddrPubkeyRelation.Remove(ctx, types.AddrPubkeyRelationKey(addr)) +} From cf9ca314ba07d54eb1450d761ccef64cf8a80b61 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 7 Aug 2023 17:01:28 +0530 Subject: [PATCH 07/11] more changes --- CHANGELOG.md | 3 ++- x/slashing/keeper/keeper.go | 9 ++++----- x/slashing/migrations/v2/store_test.go | 7 ++++++- x/slashing/simulation/decoder_test.go | 3 ++- x/slashing/types/keys.go | 5 ----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b41f29989d0..86be55184190 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,7 +63,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (x/slashing) [17044](https://github.com/cosmos/cosmos-sdk/pull/17044) Use collections for `AddrPubkeyRelation` +* (x/slashing) [17044](https://github.com/cosmos/cosmos-sdk/pull/17044) Use collections for `AddrPubkeyRelation`: + * remove from `types`: `AddrPubkeyRelationKey` * (x/staking) [#17256](https://github.com/cosmos/cosmos-sdk/pull/17256) Use collections for `UnbondingID`. * (x/staking) [#17260](https://github.com/cosmos/cosmos-sdk/pull/17260) Use collections for `ValidatorByConsAddr`: * remove from `types`: `GetValidatorByConsAddrKey` diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 95f0935cfffb..0b703d4198d6 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -53,7 +53,7 @@ func NewKeeper(cdc codec.BinaryCodec, legacyAmino *codec.LegacyAmino, storeServi sb, types.AddrPubkeyRelationKeyPrefix, "addr_pubkey_relation", - collections.BytesKey, + sdk.LengthPrefixedBytesKey, // sdk.LengthPrefixedBytesKey is needed to retain state compatibility codec.CollInterfaceValue[cryptotypes.PubKey](cdc), ), } @@ -79,13 +79,12 @@ func (k Keeper) Logger(ctx context.Context) log.Logger { // AddPubkey sets a address-pubkey relation func (k Keeper) AddPubkey(ctx context.Context, pubkey cryptotypes.PubKey) error { - key := types.AddrPubkeyRelationKey(pubkey.Address()) - return k.AddrPubkeyRelation.Set(ctx, key, pubkey) + return k.AddrPubkeyRelation.Set(ctx, pubkey.Address(), pubkey) } // GetPubkey returns the pubkey from the adddress-pubkey relation func (k Keeper) GetPubkey(ctx context.Context, a cryptotypes.Address) (cryptotypes.PubKey, error) { - return k.AddrPubkeyRelation.Get(ctx, types.AddrPubkeyRelationKey(a)) + return k.AddrPubkeyRelation.Get(ctx, a) } // Slash attempts to slash a validator. The slash is delegated to the staking @@ -141,5 +140,5 @@ func (k Keeper) Jail(ctx context.Context, consAddr sdk.ConsAddress) error { } func (k Keeper) deleteAddrPubkeyRelation(ctx context.Context, addr cryptotypes.Address) error { - return k.AddrPubkeyRelation.Remove(ctx, types.AddrPubkeyRelationKey(addr)) + return k.AddrPubkeyRelation.Remove(ctx, addr) } diff --git a/x/slashing/migrations/v2/store_test.go b/x/slashing/migrations/v2/store_test.go index 4b8794c42db6..26fcba9910e9 100644 --- a/x/slashing/migrations/v2/store_test.go +++ b/x/slashing/migrations/v2/store_test.go @@ -12,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" v1 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v1" v2 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v2" "github.com/cosmos/cosmos-sdk/x/slashing/types" @@ -46,7 +47,7 @@ func TestStoreMigration(t *testing.T) { { "AddrPubkeyRelationKey", v1.AddrPubkeyRelationKey(consAddr), - types.AddrPubkeyRelationKey(consAddr), + addrPubkeyRelationKey(consAddr), }, } @@ -75,3 +76,7 @@ func TestStoreMigration(t *testing.T) { }) } } + +func addrPubkeyRelationKey(addr []byte) []byte { + return append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(addr)...) +} diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index c63dcbbd23cc..f307849dc92a 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -36,7 +37,7 @@ func TestDecodeStore(t *testing.T) { Pairs: []kv.Pair{ {Key: types.ValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshal(&info)}, {Key: types.ValidatorMissedBlockBitmapKey(consAddr1, 6), Value: missed}, - {Key: types.AddrPubkeyRelationKey(delAddr1), Value: bz}, + {Key: append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(delAddr1)...), Value: bz}, {Key: []byte{0x99}, Value: []byte{0x99}}, // This test should panic }, } diff --git a/x/slashing/types/keys.go b/x/slashing/types/keys.go index 83217e26e37a..3894777d933b 100644 --- a/x/slashing/types/keys.go +++ b/x/slashing/types/keys.go @@ -74,8 +74,3 @@ func ValidatorMissedBlockBitmapKey(v sdk.ConsAddress, chunkIndex int64) []byte { return append(ValidatorMissedBlockBitmapPrefixKey(v), bz...) } - -// AddrPubkeyRelationKey gets pubkey relation key used to get the pubkey from the address -func AddrPubkeyRelationKey(addr []byte) []byte { - return append(AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(addr)...) -} From fdff427df4865e51c147c3dccd00e15ea5d0fc6c Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Mon, 7 Aug 2023 17:04:25 +0530 Subject: [PATCH 08/11] cleanup --- x/slashing/keeper/hooks.go | 2 +- x/slashing/keeper/keeper.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index 8dadfb6488da..da181c12a31c 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -46,7 +46,7 @@ func (h Hooks) AfterValidatorBonded(ctx context.Context, consAddr sdk.ConsAddres // AfterValidatorRemoved deletes the address-pubkey relation when a validator is removed, func (h Hooks) AfterValidatorRemoved(ctx context.Context, consAddr sdk.ConsAddress, _ sdk.ValAddress) error { - return h.k.deleteAddrPubkeyRelation(ctx, crypto.Address(consAddr)) + return h.k.AddrPubkeyRelation.Remove(ctx, crypto.Address(consAddr)) } // AfterValidatorCreated adds the address-pubkey relation when a validator is created. diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 0b703d4198d6..6d93c731c44e 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -138,7 +138,3 @@ func (k Keeper) Jail(ctx context.Context, consAddr sdk.ConsAddress) error { ) return nil } - -func (k Keeper) deleteAddrPubkeyRelation(ctx context.Context, addr cryptotypes.Address) error { - return k.AddrPubkeyRelation.Remove(ctx, addr) -} From f14cf391252d8f0da15782ed17fd4b909e4047d9 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Tue, 8 Aug 2023 14:01:12 +0530 Subject: [PATCH 09/11] remove AddPubKey from keeper --- CHANGELOG.md | 1 + tests/integration/evidence/keeper/infraction_test.go | 2 +- tests/integration/slashing/keeper/keeper_test.go | 6 +++--- x/slashing/keeper/genesis.go | 2 +- x/slashing/keeper/hooks.go | 3 +-- x/slashing/keeper/keeper.go | 5 ----- x/slashing/keeper/keeper_test.go | 2 +- 7 files changed, 8 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e724f6bfab25..39e709e06d39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/slashing) [17044](https://github.com/cosmos/cosmos-sdk/pull/17044) Use collections for `AddrPubkeyRelation`: * remove from `types`: `AddrPubkeyRelationKey` + * remove from `Keeper`: `AddPubkey` * (x/staking) [#17256](https://github.com/cosmos/cosmos-sdk/pull/17256) Use collections for `UnbondingID`. * (x/staking) [#17260](https://github.com/cosmos/cosmos-sdk/pull/17260) Use collections for `ValidatorByConsAddr`: * remove from `types`: `GetValidatorByConsAddrKey` diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index f716cf4f0101..5968d716cb2b 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -192,7 +192,7 @@ func TestHandleDoubleSign(t *testing.T) { assert.NilError(t, err) assert.DeepEqual(t, selfDelegation, val.GetBondedTokens()) - assert.NilError(t, f.slashingKeeper.AddPubkey(f.sdkCtx, valpubkey)) + assert.NilError(t, f.slashingKeeper.AddrPubkeyRelation.Set(f.sdkCtx, valpubkey.Address(), valpubkey)) info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.sdkCtx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0)) err = f.slashingKeeper.ValidatorSigningInfo.Set(f.sdkCtx, sdk.ConsAddress(valpubkey.Address()), info) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index fae0ff2f58f6..866b66b30e63 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -233,7 +233,7 @@ func TestHandleNewValidator(t *testing.T) { assert.NilError(t, err) f.ctx = f.ctx.WithBlockHeight(signedBlocksWindow + 1) - assert.NilError(t, f.slashingKeeper.AddPubkey(f.ctx, pks[0])) + assert.NilError(t, f.slashingKeeper.AddrPubkeyRelation.Set(f.ctx, pks[0].Address(), pks[0])) info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(valpubkey.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0)) assert.NilError(t, f.slashingKeeper.ValidatorSigningInfo.Set(f.ctx, sdk.ConsAddress(valpubkey.Address()), info)) @@ -287,7 +287,7 @@ func TestHandleAlreadyJailed(t *testing.T) { power := int64(100) tstaking := stakingtestutil.NewHelper(t, f.ctx, f.stakingKeeper) - err := f.slashingKeeper.AddPubkey(f.ctx, pks[0]) + err := f.slashingKeeper.AddrPubkeyRelation.Set(f.ctx, pks[0].Address(), pks[0]) assert.NilError(t, err) info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(val.Address()), f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0)) @@ -362,7 +362,7 @@ func TestValidatorDippingInAndOut(t *testing.T) { tstaking := stakingtestutil.NewHelper(t, f.ctx, f.stakingKeeper) valAddr := sdk.ValAddress(addr) - assert.NilError(t, f.slashingKeeper.AddPubkey(f.ctx, pks[0])) + assert.NilError(t, f.slashingKeeper.AddrPubkeyRelation.Set(f.ctx, pks[0].Address(), pks[0])) info := slashingtypes.NewValidatorSigningInfo(consAddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0)) assert.NilError(t, f.slashingKeeper.ValidatorSigningInfo.Set(f.ctx, consAddr, info)) diff --git a/x/slashing/keeper/genesis.go b/x/slashing/keeper/genesis.go index 60ea32eb71e9..71ac3fccae09 100644 --- a/x/slashing/keeper/genesis.go +++ b/x/slashing/keeper/genesis.go @@ -20,7 +20,7 @@ func (keeper Keeper) InitGenesis(ctx sdk.Context, stakingKeeper types.StakingKee panic(err) } - err = keeper.AddPubkey(ctx, consPk) + err = keeper.AddrPubkeyRelation.Set(ctx, consPk.Address(), consPk) if err != nil { panic(err) } diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index da181c12a31c..595ffbf78d72 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -51,7 +51,6 @@ func (h Hooks) AfterValidatorRemoved(ctx context.Context, consAddr sdk.ConsAddre // AfterValidatorCreated adds the address-pubkey relation when a validator is created. func (h Hooks) AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress) error { - sdkCtx := sdk.UnwrapSDKContext(ctx) validator, err := h.k.sk.Validator(ctx, valAddr) if err != nil { return err @@ -62,7 +61,7 @@ func (h Hooks) AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress return err } - return h.k.AddPubkey(sdkCtx, consPk) + return h.k.AddrPubkeyRelation.Set(ctx, consPk.Address(), consPk) } func (h Hooks) AfterValidatorBeginUnbonding(_ context.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error { diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go index 6d93c731c44e..f963d61c38f9 100644 --- a/x/slashing/keeper/keeper.go +++ b/x/slashing/keeper/keeper.go @@ -77,11 +77,6 @@ func (k Keeper) Logger(ctx context.Context) log.Logger { return sdkCtx.Logger().With("module", "x/"+types.ModuleName) } -// AddPubkey sets a address-pubkey relation -func (k Keeper) AddPubkey(ctx context.Context, pubkey cryptotypes.PubKey) error { - return k.AddrPubkeyRelation.Set(ctx, pubkey.Address(), pubkey) -} - // GetPubkey returns the pubkey from the adddress-pubkey relation func (k Keeper) GetPubkey(ctx context.Context, a cryptotypes.Address) (cryptotypes.PubKey, error) { return k.AddrPubkeyRelation.Get(ctx, a) diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index 65e6eaaa2ed6..e6ea23a78fab 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -74,7 +74,7 @@ func (s *KeeperTestSuite) TestPubkey() { require := s.Require() _, pubKey, addr := testdata.KeyTestPubAddr() - require.NoError(keeper.AddPubkey(ctx, pubKey)) + require.NoError(keeper.AddrPubkeyRelation.Set(ctx, pubKey.Address(), pubKey)) expectedPubKey, err := keeper.GetPubkey(ctx, addr.Bytes()) require.NoError(err) From 9645181324480081b912ce44b05f5a1823f3df90 Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 10 Aug 2023 11:35:40 +0530 Subject: [PATCH 10/11] remove unnecessary decoder test case --- x/slashing/simulation/decoder_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index f307849dc92a..86d5825a3782 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/kv" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/slashing" @@ -30,14 +29,11 @@ func TestDecodeStore(t *testing.T) { info := types.NewValidatorSigningInfo(consAddr1, 0, 1, time.Now().UTC(), false, 0) missed := []byte{1} // we want to display the bytes for simulation diffs - bz, err := cdc.MarshalInterface(delPk1) - require.NoError(t, err) kvPairs := kv.Pairs{ Pairs: []kv.Pair{ {Key: types.ValidatorSigningInfoKey(consAddr1), Value: cdc.MustMarshal(&info)}, {Key: types.ValidatorMissedBlockBitmapKey(consAddr1, 6), Value: missed}, - {Key: append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(delAddr1)...), Value: bz}, {Key: []byte{0x99}, Value: []byte{0x99}}, // This test should panic }, } @@ -49,7 +45,6 @@ func TestDecodeStore(t *testing.T) { }{ {"ValidatorSigningInfo", fmt.Sprintf("%v\n%v", info, info), false}, {"ValidatorMissedBlockBitArray", fmt.Sprintf("missedA: %v\nmissedB: %v\n", missed, missed), false}, - {"AddrPubkeyRelation", fmt.Sprintf("PubKeyA: %s\nPubKeyB: %s", delPk1, delPk1), false}, {"other", "", true}, } for i, tt := range tests { From 96b3afeb5b4d87faa6bfd1a2c1f6f0bd848a205c Mon Sep 17 00:00:00 2001 From: likhita-809 Date: Thu, 10 Aug 2023 11:53:17 +0530 Subject: [PATCH 11/11] fix lint --- x/slashing/simulation/decoder_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/slashing/simulation/decoder_test.go b/x/slashing/simulation/decoder_test.go index 86d5825a3782..dc98a2d1eeda 100644 --- a/x/slashing/simulation/decoder_test.go +++ b/x/slashing/simulation/decoder_test.go @@ -18,7 +18,6 @@ import ( var ( delPk1 = ed25519.GenPrivKey().PubKey() - delAddr1 = sdk.AccAddress(delPk1.Address()) consAddr1 = sdk.ConsAddress(delPk1.Address().Bytes()) )