Skip to content

Commit

Permalink
Delete TWAP deprecated pruning handler (#8033)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored Apr 13, 2024
1 parent 7b599d5 commit 49776d0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/upgrades/v24/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/upgrades/v24/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v25/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func CreateUpgradeHandler(
return nil, err
}

keepers.TwapKeeper.DeleteDeprecatedHistoricalTWAPsIsPruning(ctx)

return migrations, nil
}
}
6 changes: 0 additions & 6 deletions x/twap/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 4 additions & 10 deletions x/twap/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion x/twap/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 49776d0

Please sign in to comment.