-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): Add checks to oracle ABCI test (#1724)
* add checks to oracle abci test
- Loading branch information
Showing
7 changed files
with
132 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// PruneAllPrices deletes all historic prices, medians, and median deviations | ||
// outside pruning period determined by the stamp period multiplied by the maximum stamps. | ||
func (k *Keeper) PruneAllPrices(ctx sdk.Context) { | ||
params := k.GetParams(ctx) | ||
blockHeight := uint64(ctx.BlockHeight()) | ||
|
||
if k.IsPeriodLastBlock(ctx, params.HistoricStampPeriod) { | ||
pruneHistoricPeriod := params.HistoricStampPeriod * params.MaximumPriceStamps | ||
if pruneHistoricPeriod < blockHeight { | ||
k.PruneHistoricPricesBeforeBlock(ctx, blockHeight-pruneHistoricPeriod) | ||
} | ||
|
||
if k.IsPeriodLastBlock(ctx, params.MedianStampPeriod) { | ||
pruneMedianPeriod := params.MedianStampPeriod * params.MaximumMedianStamps | ||
if pruneMedianPeriod < blockHeight { | ||
k.PruneMediansBeforeBlock(ctx, blockHeight-pruneMedianPeriod) | ||
k.PruneMedianDeviationsBeforeBlock(ctx, blockHeight-pruneMedianPeriod) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// IsPeriodLastBlock returns true if we are at the last block of the period | ||
func (k *Keeper) IsPeriodLastBlock(ctx sdk.Context, blocksPerPeriod uint64) bool { | ||
return (uint64(ctx.BlockHeight())+1)%blocksPerPeriod == 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters