Skip to content

Commit ad7e432

Browse files
committed
Revert "Fix extreme slow oracle twap query (#2148)"
This reverts commit 946aedb.
1 parent 4475882 commit ad7e432

File tree

4 files changed

+5
-25
lines changed

4 files changed

+5
-25
lines changed

evmrpc/setup_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ func generateTxData() {
652652
Data: []byte("synthetic"),
653653
ChainID: chainId,
654654
})
655-
debugTraceTxBuilder, debugTraceEthTx := buildTx(ethtypes.DynamicFeeTx{
655+
debugTraceTxBuilder, _ := buildTx(ethtypes.DynamicFeeTx{
656656
Nonce: 0,
657657
GasFeeCap: big.NewInt(1000000000),
658658
Gas: 200000,
@@ -725,10 +725,6 @@ func generateTxData() {
725725
}); err != nil {
726726
panic(err)
727727
}
728-
_ = EVMKeeper.MockReceipt(Ctx, debugTraceEthTx.Hash(), &types.Receipt{
729-
BlockNumber: 103,
730-
EffectiveGasPrice: 1000000,
731-
})
732728
seiAddr, err := sdk.AccAddressFromHex(common.Bytes2Hex([]byte("seiAddr")))
733729
if err != nil {
734730
panic(err)

x/oracle/keeper/keeper.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,9 @@ func (k Keeper) IteratePriceSnapshots(ctx sdk.Context, handler func(snapshot typ
451451
}
452452
}
453453

454-
func (k Keeper) IteratePriceSnapshotsReverse(ctx sdk.Context, keyPrefix []byte, handler func(snapshot types.PriceSnapshot) (stop bool)) {
454+
func (k Keeper) IteratePriceSnapshotsReverse(ctx sdk.Context, handler func(snapshot types.PriceSnapshot) (stop bool)) {
455455
store := ctx.KVStore(k.storeKey)
456-
iterator := sdk.KVStoreReversePrefixIterator(store, keyPrefix)
456+
iterator := sdk.KVStoreReversePrefixIterator(store, types.PriceSnapshotKey)
457457
defer iterator.Close()
458458

459459
for ; iterator.Valid(); iterator.Next() {
@@ -488,8 +488,7 @@ func (k Keeper) CalculateTwaps(ctx sdk.Context, lookbackSeconds uint64) (types.O
488488
return false
489489
})
490490

491-
keyPrefix := types.GetPriceSnapshotKeyForIteration(uint64(currentTime), uint64(currentTime)-lookbackSeconds)
492-
k.IteratePriceSnapshotsReverse(ctx, keyPrefix, func(snapshot types.PriceSnapshot) (stop bool) {
491+
k.IteratePriceSnapshotsReverse(ctx, func(snapshot types.PriceSnapshot) (stop bool) {
493492
stop = false
494493
snapshotTimestamp := snapshot.SnapshotTimestamp
495494
if currentTime-int64(lookbackSeconds) > snapshotTimestamp {

x/oracle/keeper/keeper_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,7 @@ func TestPriceSnapshotAdd(t *testing.T) {
521521

522522
// test iterate reverse
523523
expectedTimestampsReverse := []int64{3660, 100, 50}
524-
prefix := types.GetPriceSnapshotKeyForIteration(uint64(input.Ctx.BlockTime().Unix()), 0)
525-
input.OracleKeeper.IteratePriceSnapshotsReverse(input.Ctx, prefix, func(snapshot types.PriceSnapshot) (stop bool) {
524+
input.OracleKeeper.IteratePriceSnapshotsReverse(input.Ctx, func(snapshot types.PriceSnapshot) (stop bool) {
526525
// assert that all the timestamps are correct
527526
require.Equal(t, expectedTimestampsReverse[0], snapshot.SnapshotTimestamp)
528527
expectedTimestampsReverse = expectedTimestampsReverse[1:]

x/oracle/types/keys.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,3 @@ func GetKeyForTimestamp(timestamp uint64) []byte {
9393
func GetPriceSnapshotKey(timestamp uint64) []byte {
9494
return append(PriceSnapshotKey, GetKeyForTimestamp(timestamp)...)
9595
}
96-
97-
func GetPriceSnapshotKeyForIteration(timestampA uint64, timestampB uint64) []byte {
98-
var result []byte
99-
keyA := GetKeyForTimestamp(timestampA)
100-
keyB := GetKeyForTimestamp(timestampB)
101-
for i := 0; i < 8; i++ {
102-
if keyA[i] == keyB[i] {
103-
result = append(result, keyA[i])
104-
} else {
105-
break
106-
}
107-
}
108-
return append(PriceSnapshotKey, result...)
109-
}

0 commit comments

Comments
 (0)