-
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 13 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 |
---|---|---|
|
@@ -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,43 @@ 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 | ||
} | ||
|
||
valSignInfoIter := sdk.KVStorePrefixIterator(store, types.ValidatorSigningInfoKeyPrefix) | ||
defer valSignInfoIter.Close() | ||
|
||
iterationCounter := 0 | ||
for ; valSignInfoIter.Valid(); valSignInfoIter.Next() { | ||
address := types.ValidatorSigningInfoAddress(valSignInfoIter.Key()) | ||
|
||
// created 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 | ||
} | ||
} | ||
}() | ||
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. Using anon func due to nested defers |
||
|
||
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 (setting 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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree with this