refactor(x/staking)!: rename NewToOldConsKeyMap to ConsKeyToValidatorIdentifierMap (#20696)
This commit is contained in:
+2
-2
@@ -280,7 +280,7 @@ ValidatorConsensusKeyRotationRecordIndexKey:`104 | valAddr | format(time) -> Pro
|
||||
|
||||
OldToNewConsKeyMap:`105 | byte(oldConsKey) -> byte(newConsKey)`
|
||||
|
||||
NewToOldConsKeyMap:`106 | byte(newConsKey) -> byte(oldConsKey)`
|
||||
ConsKeyToValidatorIdentifierMap:`106 | byte(newConsKey) -> byte(initialConsKey)`
|
||||
|
||||
`ConsPubKeyRotationHistory` is used for querying the rotations of a validator
|
||||
|
||||
@@ -292,7 +292,7 @@ A `ConsPubKeyRotationHistory` object is created every time a consensus pubkey ro
|
||||
|
||||
An entry is added in `OldToNewConsKeyMap` collection for every rotation (Note: this is to handle the evidences when submitted with old cons key).
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
To prevent the spam:
|
||||
|
||||
|
||||
@@ -109,18 +109,18 @@ func (k Keeper) updateToNewPubkey(ctx context.Context, val types.Validator, oldP
|
||||
return err
|
||||
}
|
||||
|
||||
// sets a map: newConsKey -> oldConsKey
|
||||
if err := k.setNewToOldConsKeyMap(ctx, sdk.ConsAddress(oldPk.Address()), sdk.ConsAddress(newPk.Address())); err != nil {
|
||||
// sets a map: newConsKey -> initialConsKey
|
||||
if err := k.setConsKeyToValidatorIdentifierMap(ctx, sdk.ConsAddress(oldPk.Address()), sdk.ConsAddress(newPk.Address())); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.Hooks().AfterConsensusPubKeyUpdate(ctx, oldPk, newPk, fee)
|
||||
}
|
||||
|
||||
// setNewToOldConsKeyMap adds an entry in the state with the current consKey to the initial consKey of the validator.
|
||||
// setConsKeyToValidatorIdentifierMap adds an entry in the state with the current consKey to the initial consKey of the validator.
|
||||
// it tries to find the oldPk if there is a entry already present in the state
|
||||
func (k Keeper) setNewToOldConsKeyMap(ctx context.Context, oldPk, newPk sdk.ConsAddress) error {
|
||||
pk, err := k.NewToOldConsKeyMap.Get(ctx, oldPk)
|
||||
func (k Keeper) setConsKeyToValidatorIdentifierMap(ctx context.Context, oldPk, newPk sdk.ConsAddress) error {
|
||||
pk, err := k.ConsKeyToValidatorIdentifierMap.Get(ctx, oldPk)
|
||||
if err != nil && !errors.Is(err, collections.ErrNotFound) {
|
||||
return err
|
||||
}
|
||||
@@ -129,13 +129,13 @@ func (k Keeper) setNewToOldConsKeyMap(ctx context.Context, oldPk, newPk sdk.Cons
|
||||
oldPk = pk
|
||||
}
|
||||
|
||||
return k.NewToOldConsKeyMap.Set(ctx, newPk, oldPk)
|
||||
return k.ConsKeyToValidatorIdentifierMap.Set(ctx, newPk, oldPk)
|
||||
}
|
||||
|
||||
// ValidatorIdentifier maps the new cons key to previous cons key (which is the address before the rotation).
|
||||
// (that is: newConsKey -> oldConsKey)
|
||||
func (k Keeper) ValidatorIdentifier(ctx context.Context, newPk sdk.ConsAddress) (sdk.ConsAddress, error) {
|
||||
pk, err := k.NewToOldConsKeyMap.Get(ctx, newPk)
|
||||
pk, err := k.ConsKeyToValidatorIdentifierMap.Get(ctx, newPk)
|
||||
if err != nil && !errors.Is(err, collections.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -122,9 +122,9 @@ type Keeper struct {
|
||||
ValidatorConsensusKeyRotationRecordIndexKey collections.KeySet[collections.Pair[[]byte, time.Time]]
|
||||
// ValidatorConsensusKeyRotationRecordQueue: this key is used to set the unbonding period time on each rotation
|
||||
ValidatorConsensusKeyRotationRecordQueue collections.Map[time.Time, types.ValAddrsOfRotatedConsKeys]
|
||||
// NewToOldConsKeyMap: prefix for rotated old cons address to new cons address
|
||||
NewToOldConsKeyMap collections.Map[[]byte, []byte]
|
||||
// OldToNewConsKeyMap: prefix for rotated new cons address to old cons address
|
||||
// ConsKeyToValidatorIdentifierMap: maps the new cons key to the initial cons key
|
||||
ConsKeyToValidatorIdentifierMap collections.Map[[]byte, []byte]
|
||||
// OldToNewConsKeyMap: maps the old cons key to the new cons key
|
||||
OldToNewConsKeyMap collections.Map[[]byte, []byte]
|
||||
// ValidatorConsPubKeyRotationHistory: consPubkey rotation history by validator
|
||||
// A index is being added with key `BlockConsPubKeyRotationHistory`: consPubkey rotation history by height
|
||||
@@ -280,8 +280,8 @@ func NewKeeper(
|
||||
),
|
||||
|
||||
// key format is: 105 | consAddr
|
||||
NewToOldConsKeyMap: collections.NewMap(
|
||||
sb, types.NewToOldConsKeyMap,
|
||||
ConsKeyToValidatorIdentifierMap: collections.NewMap(
|
||||
sb, types.ConsKeyToValidatorIdentifierMapPrefix,
|
||||
"new_to_old_cons_key_map",
|
||||
collections.BytesKey,
|
||||
collections.BytesValue,
|
||||
|
||||
@@ -650,7 +650,7 @@ func (k msgServer) RotateConsPubKey(ctx context.Context, msg *types.MsgRotateCon
|
||||
}
|
||||
|
||||
// check cons key is already present in the key rotation history.
|
||||
rotatedTo, err := k.NewToOldConsKeyMap.Get(ctx, pk.Address())
|
||||
rotatedTo, err := k.ConsKeyToValidatorIdentifierMap.Get(ctx, pk.Address())
|
||||
if err != nil && !errors.Is(err, collections.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ var (
|
||||
BlockConsPubKeyRotationHistoryKey = collections.NewPrefix(102) // prefix for consPubkey rotation history by height
|
||||
ValidatorConsensusKeyRotationRecordQueueKey = collections.NewPrefix(103) // this key is used to set the unbonding period time on each rotation
|
||||
ValidatorConsensusKeyRotationRecordIndexKey = collections.NewPrefix(104) // this key is used to restrict the validator next rotation within waiting (unbonding) period
|
||||
NewToOldConsKeyMap = collections.NewPrefix(105) // prefix for rotated cons address to new cons address
|
||||
ConsKeyToValidatorIdentifierMapPrefix = collections.NewPrefix(105) // prefix for rotated cons address to new cons address
|
||||
OldToNewConsKeyMap = collections.NewPrefix(106) // prefix for rotated cons address to new cons address
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user