Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/slashing): migrate AddrPubkeyRelation to collections #17044

Merged
merged 22 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d2b54d2
migrate AddrPubkeyRelation to collections
likhita-809 Jul 18, 2023
8727127
fix lint
likhita-809 Jul 19, 2023
0e280bc
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 19, 2023
0fbe189
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 19, 2023
bffec87
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 19, 2023
5b03842
delete pubkey keeper methods
likhita-809 Jul 19, 2023
e299158
add changelog
likhita-809 Jul 19, 2023
ed0ea74
more changes
likhita-809 Jul 19, 2023
a97cfc5
fix tests and add changes accordingly
likhita-809 Jul 19, 2023
fa86f1f
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 19, 2023
fdbc914
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jul 20, 2023
35680bb
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 7, 2023
cf9ca31
more changes
likhita-809 Aug 7, 2023
fdff427
cleanup
likhita-809 Aug 7, 2023
0f40cb0
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 8, 2023
f14cf39
remove AddPubKey from keeper
likhita-809 Aug 8, 2023
b7f34d0
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 9, 2023
6bc1056
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 9, 2023
8901084
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 9, 2023
9645181
remove unnecessary decoder test case
likhita-809 Aug 10, 2023
9864c8e
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Aug 10, 2023
96b3afe
fix lint
likhita-809 Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions x/slashing/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -76,14 +77,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
}
Expand Down Expand Up @@ -148,5 +149,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)...))
}
3 changes: 2 additions & 1 deletion x/slashing/migrations/v2/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -46,7 +47,7 @@ func TestStoreMigration(t *testing.T) {
{
"AddrPubkeyRelationKey",
v1.AddrPubkeyRelationKey(consAddr),
types.AddrPubkeyRelationKey(consAddr),
append(types.AddrPubkeyRelationKeyPrefix, address.MustLengthPrefix(consAddr)...),
},
}

Expand Down
3 changes: 2 additions & 1 deletion x/slashing/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
{Key: []byte{0x99}, Value: []byte{0x99}}, // This test should panic
},
}
Expand Down
7 changes: 1 addition & 6 deletions x/slashing/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (
ParamsKey = collections.NewPrefix(0) // Prefix for params key
ValidatorSigningInfoKeyPrefix = collections.NewPrefix(1) // 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)
Expand All @@ -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)...)
}