From 49776d019c28d81a2380748303e33ba48f14e5d0 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Sat, 13 Apr 2024 10:02:40 +0900 Subject: [PATCH] Delete TWAP deprecated pruning handler (#8033) --- app/upgrades/v24/upgrades.go | 2 +- app/upgrades/v24/upgrades_test.go | 8 ++++---- app/upgrades/v25/upgrades.go | 2 ++ x/twap/logic.go | 6 ------ x/twap/store.go | 14 ++++---------- x/twap/types/keys.go | 3 ++- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/app/upgrades/v24/upgrades.go b/app/upgrades/v24/upgrades.go index ced75182d44..c3e72780d9b 100644 --- a/app/upgrades/v24/upgrades.go +++ b/app/upgrades/v24/upgrades.go @@ -53,7 +53,7 @@ func CreateUpgradeHandler( // Now that the TWAP keys are refactored, we can delete all time indexed TWAPs // since we only need the pool indexed TWAPs. We set the is pruning store value to true // and spread the pruning time across multiple blocks to avoid a single block taking too long. - keepers.TwapKeeper.SetDeprecatedHistoricalTWAPsIsPruning(ctx) + // keepers.TwapKeeper.SetDeprecatedHistoricalTWAPsIsPruning(ctx) // Set the new min value for distribution for the incentives module. // https://www.mintscan.io/osmosis/proposals/733 diff --git a/app/upgrades/v24/upgrades_test.go b/app/upgrades/v24/upgrades_test.go index 6389eaff0f9..324850dea4d 100644 --- a/app/upgrades/v24/upgrades_test.go +++ b/app/upgrades/v24/upgrades_test.go @@ -207,10 +207,10 @@ func (s *UpgradeTestSuite) TestUpgrade() { s.App.EndBlocker(s.Ctx, abci.RequestEndBlock{}) // Since the prune limit was 1, 1 TWAP record indexed by time should be completely removed, leaving one more. - twapRecords, err = osmoutils.GatherValuesFromStorePrefix(store, []byte(HistoricalTWAPTimeIndexPrefix), types.ParseTwapFromBz) - s.Require().NoError(err) - s.Require().Len(twapRecords, 1) - s.Require().Equal(twapRecord2, twapRecords[0]) + // twapRecords, err = osmoutils.GatherValuesFromStorePrefix(store, []byte(HistoricalTWAPTimeIndexPrefix), types.ParseTwapFromBz) + // s.Require().NoError(err) + // s.Require().Len(twapRecords, 1) + // s.Require().Equal(twapRecord2, twapRecords[0]) // TWAP records indexed by pool ID should be untouched. twapRecords, err = s.App.TwapKeeper.GetAllHistoricalPoolIndexedTWAPsForPoolId(s.Ctx, twapRecord1.PoolId) diff --git a/app/upgrades/v25/upgrades.go b/app/upgrades/v25/upgrades.go index 3bab234007e..2674ddd6425 100644 --- a/app/upgrades/v25/upgrades.go +++ b/app/upgrades/v25/upgrades.go @@ -23,6 +23,8 @@ func CreateUpgradeHandler( return nil, err } + keepers.TwapKeeper.DeleteDeprecatedHistoricalTWAPsIsPruning(ctx) + return migrations, nil } } diff --git a/x/twap/logic.go b/x/twap/logic.go index 160f61ac729..e8575a61e2e 100644 --- a/x/twap/logic.go +++ b/x/twap/logic.go @@ -123,12 +123,6 @@ func (k Keeper) EndBlock(ctx sdk.Context) { ctx.Logger().Error("Error pruning old twaps at the end block", err) } } - - // If we still have more deprecated historical twaps to prune, then we prune up to the per block limit. - // TODO: Can remove this in the v25 upgrade or after. - if k.IsDeprecatedHistoricalTWAPsPruning(ctx) { - k.DeleteHistoricalTimeIndexedTWAPs(ctx) - } } // updateRecords updates all records for a given pool id. diff --git a/x/twap/store.go b/x/twap/store.go index 5432d48e545..db1f18d8273 100644 --- a/x/twap/store.go +++ b/x/twap/store.go @@ -295,16 +295,10 @@ func (k Keeper) DeleteHistoricalTimeIndexedTWAPs(ctx sdk.Context) { } } -// IsDeprecatedHistoricalTWAPsPruning returns whether the deprecated historical twaps are being pruned. -func (k Keeper) IsDeprecatedHistoricalTWAPsPruning(ctx sdk.Context) bool { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.DeprecatedHistoricalTWAPsIsPruningKey) - return bz != nil -} - -// SetDeprecatedHistoricalTWAPsIsPruning sets the state entry that determines if we are still +// DeleteDeprecatedHistoricalTWAPsIsPruning the state entry that determines if we are still // executing pruning logic in the end blocker. -func (k Keeper) SetDeprecatedHistoricalTWAPsIsPruning(ctx sdk.Context) { +// TODO: Remove this in v26 +func (k Keeper) DeleteDeprecatedHistoricalTWAPsIsPruning(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - store.Set(types.DeprecatedHistoricalTWAPsIsPruningKey, sentinelExistsValue) + store.Delete(types.DeprecatedHistoricalTWAPsIsPruningKey) } diff --git a/x/twap/types/keys.go b/x/twap/types/keys.go index 86e540aa50c..d20f3cdac64 100644 --- a/x/twap/types/keys.go +++ b/x/twap/types/keys.go @@ -26,7 +26,8 @@ const ( ) var ( - PruningStateKey = []byte{0x01} + PruningStateKey = []byte{0x01} + // TODO: Delete in v26 DeprecatedHistoricalTWAPsIsPruningKey = []byte{0x02} mostRecentTWAPsNoSeparator = "recent_twap" historicalTWAPPoolIndexNoSeparator = "historical_pool_index"