-
Notifications
You must be signed in to change notification settings - Fork 35
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
fix: less time intensive slashing migration #580
Changes from all commits
0f8e195
9f5b3a8
a01af63
d71baef
93f4773
402c93e
845c554
4017084
cce4edd
836192e
f14e950
f815ac8
fbf64e6
e60b723
a670d98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ | |
* (slashing) [#543](https://github.com/osmosis-labs/cosmos-sdk/pull/543) Make slashing not write sign info every block | ||
* (authz) [#513](https://github.com/osmosis-labs/cosmos-sdk/pull/513) Limit expired authz grant pruning to 200 per block | ||
* (gov) [#514](https://github.com/osmosis-labs/cosmos-sdk/pull/514) Let gov hooks return an error | ||
* (slashing) [#580](https://github.com/osmosis-labs/cosmos-sdk/pull/580) Less time intensive slashing migration | ||
|
||
## [State Compatible] | ||
|
||
Comment on lines
44
to
50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The term "CacheKV speedups" might be more accurately described as "CacheKV performance improvements" to clearly convey the nature of the changes. - * (store) [#525](https://github.com/osmosis-labs/cosmos-sdk/pull/525) CacheKV speedups
+ * (store) [#525](https://github.com/osmosis-labs/cosmos-sdk/pull/525) CacheKV performance improvements
The term "Removal of regex usage on denom validation" could be more descriptive. Suggesting: "Improve denom validation by removing regex usage". - * (coin) [#570](https://github.com/osmosis-labs/cosmos-sdk/pull/570) Removal of regex usage on denom validation
+ * (coin) [#570](https://github.com/osmosis-labs/cosmos-sdk/pull/570) Improve denom validation by removing regex usage
The entry "Bumps IAVL v1 version for bug fixes" could be reworded for clarity and consistency with other entries. Suggestion: "Update IAVL v1 version to include bug fixes". - * (store) [#575](https://github.com/osmosis-labs/cosmos-sdk/pull/575) Bumps IAVL v1 version for bug fixes
+ * (store) [#575](https://github.com/osmosis-labs/cosmos-sdk/pull/575) Update IAVL v1 version to include bug fixes
The phrase "Speedup to UnmarshalBalanceCompat" could be improved for clarity. Suggestion: "Enhance performance of UnmarshalBalanceCompat". - * (x/bank) [#547](https://github.com/osmosis-labs/cosmos-sdk/pull/547) Speedup to UnmarshalBalanceCompat
+ * (x/bank) [#547](https://github.com/osmosis-labs/cosmos-sdk/pull/547) Enhance performance of UnmarshalBalanceCompat
The entry "Fix IAVL db grow issue" could be more descriptive. Suggestion: "Address IAVL database growth issue". - * (store) [#537](https://github.com/osmosis-labs/cosmos-sdk/pull/537) Fix IAVL db grow issue
+ * (store) [#537](https://github.com/osmosis-labs/cosmos-sdk/pull/537) Address IAVL database growth issue
The term "Speedup to UnmarshalBalanceCompat" could be rephrased for better clarity. Suggestion: "Enhance UnmarshalBalanceCompat performance". - * (x/bank) [#546](https://github.com/osmosis-labs/cosmos-sdk/pull/546) Speedup to UnmarshalBalanceCompat
+ * (x/bank) [#546](https://github.com/osmosis-labs/cosmos-sdk/pull/546) Enhance UnmarshalBalanceCompat performance
The entry "Add - * (client/rpc) [#17274](https://github.com/cosmos/cosmos-sdk/pull/17274) Add `QueryEventForTxCmd` cmd to subscribe and wait event for transaction by hash.
+ * (client/rpc) [#17274](https://github.com/cosmos/cosmos-sdk/pull/17274) Introduce `QueryEventForTxCmd` command for event subscription and waiting based on transaction hash.
The phrase "Add - * (x/gov) [#17387](https://github.com/cosmos/cosmos-sdk/pull/17387) Add `MsgSubmitProposal` `SetMsgs` method.
+ * (x/gov) [#17387](https://github.com/cosmos/cosmos-sdk/pull/17387) Introduce `SetMsgs` method in `MsgSubmitProposal`.
The entry "Emit - * (x/gov) [#17354](https://github.com/cosmos/cosmos-sdk/issues/17354) Emit `VoterAddr` in `proposal_vote` event.
+ * (x/gov) [#17354](https://github.com/cosmos/cosmos-sdk/issues/17354) Include `VoterAddr` in the `proposal_vote` event.
The phrase "Add - * (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Add `MigrateHandler` to allow reuse migrate genesis related function.
+ * (x/genutil) [#17296](https://github.com/cosmos/cosmos-sdk/pull/17296) Introduce `MigrateHandler` for reusable migration of genesis-related functions.
The phrase "Properly allow to combine depinject-enabled modules and non-depinject-enabled modules in app v2." could be rephrased for clarity. Suggestion: "Enable seamless integration of depinject-enabled and non-depinject-enabled modules in app v2." - * (runtime) [#17284](https://github.com/cosmos/cosmos-sdk/pull/17284) Properly allow to combine depinject-enabled modules and non-depinject-enabled modules in app v2.
+ * (runtime) [#17284](https://github.com/cosmos/cosmos-sdk/pull/17284) Enable seamless integration of depinject-enabled and non-depinject-enabled modules in app v2.
The phrase "Do not try validate - * (x/gov,x/group) [#17220](https://github.com/cosmos/cosmos-sdk/pull/17220) Do not try validate `msgURL` as web URL in `draft-proposal` command.
+ * (x/gov,x/group) [#17220](https://github.com/cosmos/cosmos-sdk/pull/17220) Avoid validating `msgURL` as a web URL in the `draft-proposal` command.
The phrase "Improve - * (cli) [#16856](https://github.com/cosmos/cosmos-sdk/pull/16856) Improve `simd prune` UX by using the app default home directory and set pruning method as first variable argument (defaults to default).
+ * (cli) [#16856](https://github.com/cosmos/cosmos-sdk/pull/16856) Enhance `simd prune` user experience by utilizing the app's default home directory and setting the pruning method as the primary variable argument.
The phrase "Add circuit breaker setter in baseapp." could be rephrased for clarity. Suggestion: "Introduce circuit breaker setter functionality in BaseApp." - * (baseapp) [#16290](https://github.com/cosmos/cosmos-sdk/pull/16290) Add circuit breaker setter in baseapp.
+ * (baseapp) [#16290](https://github.com/cosmos/cosmos-sdk/pull/16290) Introduce circuit breaker setter functionality in BaseApp.
The phrase "Add - * (tx) [#15992](https://github.com/cosmos/cosmos-sdk/pull/15992) Add `WithExtensionOptions` in tx Factory to allow `SetExtensionOptions` with given extension options.
+ * (tx) [#15992](https://github.com/cosmos/cosmos-sdk/pull/15992) Introduce `WithExtensionOptions` in the transaction Factory to enable setting extension options.
The phrase "Make - * (baseapp) [#16407](https://github.com/cosmos/cosmos-sdk/pull/16407) Make `DefaultProposalHandler.ProcessProposalHandler` return a ProcessProposal NoOp when using none or a NoOp mempool.
+ * (baseapp) [#16407](https://github.com/cosmos/cosmos-sdk/pull/16407) Ensure `DefaultProposalHandler.ProcessProposalHandler` returns a NoOp for ProcessProposal when using a NoOp or empty mempool.
The phrase "Use - * (server) [#15984](https://github.com/cosmos/cosmos-sdk/pull/15984) Use `cosmossdk.io/log` package for logging instead of CometBFT logger.
+ * (server) [#15984](https://github.com/cosmos/cosmos-sdk/pull/15984) Adopt `cosmossdk.io/log` for logging, replacing the CometBFT logger.
The phrase "Update simulation to allow non-EOA accounts to stake." could be rephrased for clarity. Suggestion: "Modify simulation to enable staking for non-EOA accounts." - * (x/staking) [#16068](https://github.com/osmosis-labs/cosmos-sdk/pull/16068) Update simulation to allow non-EOA accounts to stake.
+ * (x/staking) [#16068](https://github.com/osmosis-labs/cosmos-sdk/pull/16068) Modify simulation to enable staking for non-EOA accounts.
The phrase "Rename interface - * (types) [#16145](https://github.com/cosmos/cosmos-sdk/pull/16145) Rename interface `ExtensionOptionI` back to `TxExtensionOptionI` to avoid breaking change.
+ * (types) [#16145](https://github.com/cosmos/cosmos-sdk/pull/16145) Revert interface name from `ExtensionOptionI` to `TxExtensionOptionI` to prevent breaking changes.
The phrase "Add - * (baseapp) [#16193](https://github.com/cosmos/cosmos-sdk/pull/16193) Add `Close` method to `BaseApp` for custom app to cleanup resource in graceful shutdown.
+ * (baseapp) [#16193](https://github.com/cosmos/cosmos-sdk/pull/16193) Introduce `Close` method in `BaseApp` for resource cleanup during graceful shutdown of custom apps.
The phrase "Do not override some Comet config is purposely set differently in - * (server) [#16395](https://github.com/cosmos/cosmos-sdk/pull/16395) Do not override some Comet config is purposely set differently in `InterceptConfigsPreRunHandler`.
+ * (server) [#16395](https://github.com/cosmos/cosmos-sdk/pull/16395) Avoid overriding specific Comet configurations that are intentionally set differently in `InterceptConfigsPreRunHandler`.
The phrase "Fix StateSync Restore by excluding memory store." could be rephrased for clarity. Suggestion: "Correct StateSync restoration process by excluding the memory store." - * (store) [#16449](https://github.com/cosmos/cosmos-sdk/pull/16449) Fix StateSync Restore by excluding memory store.
+ * (store) [#16449](https://github.com/cosmos/cosmos-sdk/pull/16449) Correct StateSync restoration process by excluding the memory store.
The phrase "Allow any addresses in - * (cli) [#16312](https://github.com/cosmos/cosmos-sdk/pull/16312) Allow any addresses in `client.ValidatePromptAddress`.
+ * (cli) [#16312](https://github.com/cosmos/cosmos-sdk/pull/16312) Enable validation for all addresses in `client.ValidatePromptAddress`. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ import ( | |
"github.com/cosmos/cosmos-sdk/x/slashing/types" | ||
) | ||
|
||
var deprecatedBitArrayPruneLimitPerBlock = 2000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be convinced to lower this, but I would rather have the one time payment of deleting every block frontloaded at time of upgrade rather than slight degradation for a very long time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would agree with this |
||
|
||
// BeginBlocker check for infraction evidence or downtime of validators | ||
// on every begin block | ||
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { | ||
|
@@ -23,4 +25,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) | |
for _, voteInfo := range req.LastCommitInfo.GetVotes() { | ||
k.HandleValidatorSignatureWithParams(ctx, params, voteInfo.Validator.Address, voteInfo.Validator.Power, voteInfo.SignedLastBlock) | ||
} | ||
|
||
// If there are still entries for the deprecated MissedBlockBitArray, delete them up until we hit the per block limit | ||
k.DeleteDeprecatedValidatorMissedBlockBitArray(ctx, deprecatedBitArrayPruneLimitPerBlock) | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"github.com/cosmos/cosmos-sdk/codec" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v4 "github.com/cosmos/cosmos-sdk/x/slashing/migrations/v4" | ||
"github.com/cosmos/cosmos-sdk/x/slashing/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
@@ -115,3 +116,44 @@ func (k Keeper) deleteAddrPubkeyRelation(ctx sdk.Context, addr cryptotypes.Addre | |
store := ctx.KVStore(k.storeKey) | ||
store.Delete(types.AddrPubkeyRelationKey(addr)) | ||
} | ||
|
||
func (k Keeper) DeleteDeprecatedValidatorMissedBlockBitArray(ctx sdk.Context, iterationLimit int) { | ||
store := ctx.KVStore(k.storeKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going between using store vs using params a few times. I thought params was the best at first since we already call getParams in the BeginBlocker, but it felt kind of awkward. |
||
if store.Get(types.IsPruningKey) == nil { | ||
return | ||
} | ||
|
||
// Iterate over all the validator signing infos and delete the deprecated missed block bit arrays | ||
valSignInfoIter := sdk.KVStorePrefixIterator(store, types.ValidatorSigningInfoKeyPrefix) | ||
defer valSignInfoIter.Close() | ||
|
||
iterationCounter := 0 | ||
for ; valSignInfoIter.Valid(); valSignInfoIter.Next() { | ||
address := types.ValidatorSigningInfoAddress(valSignInfoIter.Key()) | ||
|
||
// Creat anonymous function to scope defer statement | ||
func() { | ||
iter := storetypes.KVStorePrefixIterator(store, v4.DeprecatedValidatorMissedBlockBitArrayPrefixKey(address)) | ||
defer iter.Close() | ||
|
||
for ; iter.Valid(); iter.Next() { | ||
store.Delete(iter.Key()) | ||
iterationCounter++ | ||
if iterationCounter >= iterationLimit { | ||
break | ||
} | ||
} | ||
}() | ||
|
||
if iterationCounter >= iterationLimit { | ||
break | ||
} | ||
} | ||
|
||
ctx.Logger().Info("Deleted deprecated missed block bit arrays", "count", iterationCounter) | ||
|
||
// If we have deleted all the deprecated missed block bit arrays, we can delete the pruning key (set to nil) | ||
if iterationCounter == 0 { | ||
store.Delete(types.IsPruningKey) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,13 @@ import ( | |
const MissedBlockBitmapChunkSize = 1024 // 2^10 bits | ||
|
||
var ( | ||
ValidatorSigningInfoKeyPrefix = []byte{0x01} | ||
validatorMissedBlockBitArrayKeyPrefix = []byte{0x02} | ||
ValidatorSigningInfoKeyPrefix = []byte{0x01} | ||
deprecatedValidatorMissedBlockBitArrayKeyPrefix = []byte{0x02} | ||
|
||
// NOTE: sdk v0.50 uses the same key prefix for both deprecated and new missed block bitmaps. | ||
// We needed to use a new key, because we are skipping deletion of all old keys at upgrade time | ||
// due to how long this would bring the chain down. We use 0x10 here to prevent overlap with any future keys. | ||
validatorMissedBlockBitMapKeyPrefix = []byte{0x10} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set to 0x10 to prevent overlap if more keys are introduced in the next sdk release we upgrade to |
||
) | ||
|
||
func ValidatorSigningInfoKey(v sdk.ConsAddress) []byte { | ||
|
@@ -27,18 +32,18 @@ func ValidatorSigningInfoAddress(key []byte) (v sdk.ConsAddress) { | |
return sdk.ConsAddress(addr) | ||
} | ||
|
||
func validatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte { | ||
return append(validatorMissedBlockBitArrayKeyPrefix, address.MustLengthPrefix(v.Bytes())...) | ||
func DeprecatedValidatorMissedBlockBitArrayPrefixKey(v sdk.ConsAddress) []byte { | ||
return append(deprecatedValidatorMissedBlockBitArrayKeyPrefix, address.MustLengthPrefix(v.Bytes())...) | ||
} | ||
|
||
func ValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte { | ||
func DeprecatedValidatorMissedBlockBitArrayKey(v sdk.ConsAddress, i int64) []byte { | ||
b := make([]byte, 8) | ||
binary.LittleEndian.PutUint64(b, uint64(i)) | ||
return append(validatorMissedBlockBitArrayPrefixKey(v), b...) | ||
return append(DeprecatedValidatorMissedBlockBitArrayPrefixKey(v), b...) | ||
} | ||
|
||
func validatorMissedBlockBitmapPrefixKey(v sdk.ConsAddress) []byte { | ||
return append(validatorMissedBlockBitArrayKeyPrefix, address.MustLengthPrefix(v.Bytes())...) | ||
return append(validatorMissedBlockBitMapKeyPrefix, address.MustLengthPrefix(v.Bytes())...) | ||
} | ||
|
||
func ValidatorMissedBlockBitmapKey(v sdk.ConsAddress, chunkIndex int64) []byte { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrase "Make slashing not write sign info every block" could be rephrased for clarity. Suggestion: "Optimize slashing by reducing sign info writes".
Committable suggestion