-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat(WIP) : rotate operator key #15494
Closed
Closed
Changes from 13 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
8f6299f
proto
atheeshp 5f978d8
make proto-gen
atheeshp a468a05
proto
atheeshp e2161b5
proto-gen
atheeshp 8dfd0bb
proto
atheeshp 7ec7cac
proto-gen
atheeshp 8fed09a
WIP: operator key
atheeshp cff75c6
mocks
atheeshp bcda6c4
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/rotate_op…
atheeshp eb47ea3
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/rotate_op…
atheeshp 85ab4ad
proto
atheeshp ed7e3ed
proto-gen
atheeshp 239a358
set waiting period for operator key rotation
atheeshp 9cf2bda
add delegations by validator index
atheeshp 445b722
refactor: add delegations by validator index
atheeshp 9b3c8b4
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp cc1c2ce
nits
atheeshp 71aabc2
update validator delegations query with index
atheeshp b99b5e8
remove unnecessory tests
atheeshp dc60199
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp d6a4a0c
fix tests
atheeshp 76bc044
remove unnecessary test
atheeshp 6656c62
remove test code
atheeshp faa45dc
refactor
atheeshp f96a4b3
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp d3f0412
review changes
atheeshp 213ea9a
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp 58aa3ba
review changes
atheeshp b03ad16
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp 4a1ad7f
register migration
atheeshp 64349dd
review changes
atheeshp 7062b56
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp 697ee7b
keys
atheeshp a04740a
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp 07ea2e5
review changes
atheeshp d07bc41
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/delegatio…
atheeshp 8308684
review changes
atheeshp d655db3
review changes
atheeshp 727e273
review changes
atheeshp d5f5fea
fix lint
atheeshp 9ada08c
fix lint
atheeshp c058798
error handling
atheeshp cc2ee23
Merge branch 'main' into ap/delegations-by-validator
atheeshp 0a70b08
Merge branch 'main' into ap/delegations-by-validator
atheeshp c3a2c41
review changes
atheeshp 45a84e9
Merge branch 'ap/delegations-by-validator' of github.com:cosmos/cosmo…
atheeshp be5d46e
Merge branch 'ap/delegations-by-validator' of github.com:cosmos/cosmo…
atheeshp fed64cc
add key updations
atheeshp 30aa0f1
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/rotate_op…
atheeshp 2596e00
updations
atheeshp 066e672
proto-gen
atheeshp d316acf
fix
atheeshp 43ea5dd
Merge branch 'main' of github.com:cosmos/cosmos-sdk into ap/rotate_op…
atheeshp 590d0ca
Merge branch 'ap/rotate_oper_key' of github.com:cosmos/cosmos-sdk int…
atheeshp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
storetypes "cosmossdk.io/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
func (k Keeper) GetValidatorOperatorKeyRotationsHistory(ctx sdk.Context, | ||
valAddr sdk.ValAddress) []types.OperatorKeyRotationRecord { | ||
|
||
var historyObjs []types.OperatorKeyRotationRecord | ||
store := ctx.KVStore(k.storeKey) | ||
|
||
iterator := storetypes.KVStorePrefixIterator(store, | ||
append([]byte(types.ValidatorOperatorKeyRotationRecordKey), valAddr...)) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
var history types.OperatorKeyRotationRecord | ||
|
||
k.cdc.MustUnmarshal(iterator.Value(), &history) | ||
historyObjs = append(historyObjs, history) | ||
} | ||
return historyObjs | ||
} | ||
|
||
func (k Keeper) SetOperatorKeyRotationRecord(ctx sdk.Context, curValAddr, newValAddr sdk.ValAddress, height int64) error { | ||
historyObj := types.OperatorKeyRotationRecord{ | ||
OperatorAddress: newValAddr.String(), | ||
OldOperatorAddress: curValAddr.String(), | ||
Height: uint64(ctx.BlockHeight()), | ||
} | ||
|
||
store := ctx.KVStore(k.storeKey) | ||
key := types.GetOperKeyRotationHistoryKey(newValAddr, uint64(height)) | ||
bz, err := k.cdc.Marshal(&historyObj) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
store.Set(key, bz) | ||
k.SetVORQueue(ctx, ctx.BlockTime(), newValAddr) | ||
k.SetVORIndex(ctx, newValAddr) | ||
|
||
return nil | ||
} | ||
|
||
func (k Keeper) GetVORQueue(ctx sdk.Context, ts time.Time) types.RotatedOperatorAddresses { | ||
var valAddrs types.RotatedOperatorAddresses | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.GetOperatorRotationTimeKey(ts) | ||
bz := store.Get(key) | ||
if bz == nil { | ||
return valAddrs | ||
} | ||
k.cdc.MustUnmarshal(bz, &valAddrs) | ||
return valAddrs | ||
} | ||
|
||
func (k Keeper) SetVORQueue(ctx sdk.Context, ts time.Time, valAddr sdk.ValAddress) { | ||
operKeys := k.GetVORQueue(ctx, ts) | ||
operKeys.Addresses = append(operKeys.Addresses, valAddr.String()) | ||
key := types.GetOperatorRotationTimeKey(ts) | ||
store := ctx.KVStore(k.storeKey) | ||
bz := k.cdc.MustMarshal(&operKeys) | ||
store.Set(key, bz) | ||
} | ||
|
||
func (k Keeper) SetVORIndex(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.GetVORIndexKey(valAddr) | ||
store.Set(key, []byte{}) | ||
} | ||
|
||
func (k Keeper) GetVORIndex(ctx sdk.Context, valAddr sdk.ValAddress) bool { | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.GetVORIndexKey(valAddr) | ||
bz := store.Get(key) | ||
return bz != nil | ||
} | ||
|
||
func (k Keeper) UpdateAllMaturedVORRotatedKeys(ctx sdk.Context, maturedTime time.Time) { | ||
maturedRotatedValAddrs := k.GetAllMaturedRotatedKeys(ctx, maturedTime) | ||
for _, valAddrStr := range maturedRotatedValAddrs { | ||
valAddr, err := sdk.ValAddressFromBech32(valAddrStr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
k.deleteVORIndexKey(ctx, valAddr) | ||
} | ||
} | ||
|
||
func (k Keeper) GetAllMaturedRotatedKeys(ctx sdk.Context, matureTime time.Time) []string { | ||
store := ctx.KVStore(k.storeKey) | ||
var ValAddresses []string | ||
prefixIterator := storetypes.KVStorePrefixIterator(store, storetypes.InclusiveEndBytes(types.GetOperatorRotationTimeKey(matureTime))) | ||
|
||
for ; prefixIterator.Valid(); prefixIterator.Next() { | ||
var operKey types.RotatedOperatorAddresses | ||
k.cdc.MustUnmarshal(prefixIterator.Value(), &operKey) | ||
ValAddresses = append(ValAddresses, operKey.Addresses...) | ||
store.Delete(prefixIterator.Key()) | ||
} | ||
|
||
return ValAddresses | ||
} | ||
|
||
func (k Keeper) deleteVORIndexKey(ctx sdk.Context, valAddr sdk.ValAddress) { | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.GetVORIndexKey(valAddr) | ||
store.Delete(key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods