Skip to content

Commit 4133dc2

Browse files
refactor(x/staking)!: rename NewToOldConsKeyMap to ConsKeyToValidatorIdentifierMap (#20696)
1 parent 6d2f6ff commit 4133dc2

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

x/staking/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ ValidatorConsensusKeyRotationRecordIndexKey:`104 | valAddr | format(time) -> Pro
280280

281281
OldToNewConsKeyMap:`105 | byte(oldConsKey) -> byte(newConsKey)`
282282

283-
NewToOldConsKeyMap:`106 | byte(newConsKey) -> byte(oldConsKey)`
283+
ConsKeyToValidatorIdentifierMap:`106 | byte(newConsKey) -> byte(initialConsKey)`
284284

285285
`ConsPubKeyRotationHistory` is used for querying the rotations of a validator
286286

@@ -292,7 +292,7 @@ A `ConsPubKeyRotationHistory` object is created every time a consensus pubkey ro
292292

293293
An entry is added in `OldToNewConsKeyMap` collection for every rotation (Note: this is to handle the evidences when submitted with old cons key).
294294

295-
An entry is added in `NewToOldConsKeyMap` collection for every rotation, this entry is to block the rotation if the validator is rotating to the cons key which is involved in the history.
295+
An entry is added in `ConsKeyToValidatorIdentifierMap` collection for every rotation, this entry is to block the rotation if the validator is rotating to the cons key which is involved in the history.
296296

297297
To prevent the spam:
298298

x/staking/keeper/cons_pubkey.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,18 @@ func (k Keeper) updateToNewPubkey(ctx context.Context, val types.Validator, oldP
109109
return err
110110
}
111111

112-
// sets a map: newConsKey -> oldConsKey
113-
if err := k.setNewToOldConsKeyMap(ctx, sdk.ConsAddress(oldPk.Address()), sdk.ConsAddress(newPk.Address())); err != nil {
112+
// sets a map: newConsKey -> initialConsKey
113+
if err := k.setConsKeyToValidatorIdentifierMap(ctx, sdk.ConsAddress(oldPk.Address()), sdk.ConsAddress(newPk.Address())); err != nil {
114114
return err
115115
}
116116

117117
return k.Hooks().AfterConsensusPubKeyUpdate(ctx, oldPk, newPk, fee)
118118
}
119119

120-
// setNewToOldConsKeyMap adds an entry in the state with the current consKey to the initial consKey of the validator.
120+
// setConsKeyToValidatorIdentifierMap adds an entry in the state with the current consKey to the initial consKey of the validator.
121121
// it tries to find the oldPk if there is a entry already present in the state
122-
func (k Keeper) setNewToOldConsKeyMap(ctx context.Context, oldPk, newPk sdk.ConsAddress) error {
123-
pk, err := k.NewToOldConsKeyMap.Get(ctx, oldPk)
122+
func (k Keeper) setConsKeyToValidatorIdentifierMap(ctx context.Context, oldPk, newPk sdk.ConsAddress) error {
123+
pk, err := k.ConsKeyToValidatorIdentifierMap.Get(ctx, oldPk)
124124
if err != nil && !errors.Is(err, collections.ErrNotFound) {
125125
return err
126126
}
@@ -129,13 +129,13 @@ func (k Keeper) setNewToOldConsKeyMap(ctx context.Context, oldPk, newPk sdk.Cons
129129
oldPk = pk
130130
}
131131

132-
return k.NewToOldConsKeyMap.Set(ctx, newPk, oldPk)
132+
return k.ConsKeyToValidatorIdentifierMap.Set(ctx, newPk, oldPk)
133133
}
134134

135135
// ValidatorIdentifier maps the new cons key to previous cons key (which is the address before the rotation).
136136
// (that is: newConsKey -> oldConsKey)
137137
func (k Keeper) ValidatorIdentifier(ctx context.Context, newPk sdk.ConsAddress) (sdk.ConsAddress, error) {
138-
pk, err := k.NewToOldConsKeyMap.Get(ctx, newPk)
138+
pk, err := k.ConsKeyToValidatorIdentifierMap.Get(ctx, newPk)
139139
if err != nil && !errors.Is(err, collections.ErrNotFound) {
140140
return nil, err
141141
}

x/staking/keeper/keeper.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ type Keeper struct {
122122
ValidatorConsensusKeyRotationRecordIndexKey collections.KeySet[collections.Pair[[]byte, time.Time]]
123123
// ValidatorConsensusKeyRotationRecordQueue: this key is used to set the unbonding period time on each rotation
124124
ValidatorConsensusKeyRotationRecordQueue collections.Map[time.Time, types.ValAddrsOfRotatedConsKeys]
125-
// NewToOldConsKeyMap: prefix for rotated old cons address to new cons address
126-
NewToOldConsKeyMap collections.Map[[]byte, []byte]
127-
// OldToNewConsKeyMap: prefix for rotated new cons address to old cons address
125+
// ConsKeyToValidatorIdentifierMap: maps the new cons key to the initial cons key
126+
ConsKeyToValidatorIdentifierMap collections.Map[[]byte, []byte]
127+
// OldToNewConsKeyMap: maps the old cons key to the new cons key
128128
OldToNewConsKeyMap collections.Map[[]byte, []byte]
129129
// ValidatorConsPubKeyRotationHistory: consPubkey rotation history by validator
130130
// A index is being added with key `BlockConsPubKeyRotationHistory`: consPubkey rotation history by height
@@ -280,8 +280,8 @@ func NewKeeper(
280280
),
281281

282282
// key format is: 105 | consAddr
283-
NewToOldConsKeyMap: collections.NewMap(
284-
sb, types.NewToOldConsKeyMap,
283+
ConsKeyToValidatorIdentifierMap: collections.NewMap(
284+
sb, types.ConsKeyToValidatorIdentifierMapPrefix,
285285
"new_to_old_cons_key_map",
286286
collections.BytesKey,
287287
collections.BytesValue,

x/staking/keeper/msg_server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ func (k msgServer) RotateConsPubKey(ctx context.Context, msg *types.MsgRotateCon
650650
}
651651

652652
// check cons key is already present in the key rotation history.
653-
rotatedTo, err := k.NewToOldConsKeyMap.Get(ctx, pk.Address())
653+
rotatedTo, err := k.ConsKeyToValidatorIdentifierMap.Get(ctx, pk.Address())
654654
if err != nil && !errors.Is(err, collections.ErrNotFound) {
655655
return nil, err
656656
}

x/staking/types/keys.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var (
6666
BlockConsPubKeyRotationHistoryKey = collections.NewPrefix(102) // prefix for consPubkey rotation history by height
6767
ValidatorConsensusKeyRotationRecordQueueKey = collections.NewPrefix(103) // this key is used to set the unbonding period time on each rotation
6868
ValidatorConsensusKeyRotationRecordIndexKey = collections.NewPrefix(104) // this key is used to restrict the validator next rotation within waiting (unbonding) period
69-
NewToOldConsKeyMap = collections.NewPrefix(105) // prefix for rotated cons address to new cons address
69+
ConsKeyToValidatorIdentifierMapPrefix = collections.NewPrefix(105) // prefix for rotated cons address to new cons address
7070
OldToNewConsKeyMap = collections.NewPrefix(106) // prefix for rotated cons address to new cons address
7171
)
7272

0 commit comments

Comments
 (0)