-
-
Notifications
You must be signed in to change notification settings - Fork 12
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: Synchronize position deletion in PositionsByPoolId #151
Fix: Synchronize position deletion in PositionsByPoolId #151
Conversation
@@ -85,6 +85,14 @@ func (k Keeper) RemovePosition(ctx context.Context, id uint64) { | |||
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) | |||
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.PositionKey)) | |||
store.Delete(GetPositionIDBytes(id)) | |||
|
|||
// Remove from PositionsByPoolId | |||
position, found := k.GetPosition(ctx, id) |
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.
If this function is executed after store.Delete(GetPositionIDBytes(id))
, it would always return [Empty], false
.
Shouldn't it be like below?
func (k Keeper) RemovePosition(ctx context.Context, id uint64) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.PositionKey))
store.Delete(GetPositionIDBytes(id))
k.RemovePositionsByPool(ctx, id)
k.RemovePositionsByAddress(ctx, id)
}
// Remove PositionBy Pool
func RemovePositionsByPool(...) {
store = prefix.NewStore(storeAdapter, types.PositionByPoolPrefix(poolId))
iterator := storetypes.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
id := sdk.BigEndianToUint64(iterator.Value())
store.Delete(iterator.Value())
}
}
// Remove PositionsByAddress
func RemovePositionsByAddress(...) {
// Do similar things
}
Thank you for submitting a Pull Request, I appreciate it! |
Thanks for the feedback, can you review the changes again? |
Thank you for revision! |
@kimurayu45z Thankyou :) |
Contact me in Discord of Sunrise server. |
Overview
fix #143
This PR addresses an issue where the
Delete
method did not synchronize the deleted position in thePositionsByPoolId
store.Changes Made:
RemovePosition
method in thestore_position.go
file to ensure that when a position is deleted from the main store, it is also removed from the correspondingPositionsByPoolId
store.PoolId
of the deleted position and delete the position from the pool-specific store.Impact:
This change ensures that the state of the positions is consistent across all relevant stores, preventing potential issues with data integrity when querying positions by pool ID after deletions.