Skip to content

Commit 431d5f8

Browse files
committed
adjust nonce generation logic
1 parent b6a462e commit 431d5f8

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

x/dlc/keeper/price.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
package keeper
22

33
import (
4+
sdkmath "cosmossdk.io/math"
45
sdk "github.com/cosmos/cosmos-sdk/types"
6+
57
"github.com/sideprotocol/side/x/dlc/types"
68
)
79

810
// GetPrice gets the current price for the specified pair
9-
func (k Keeper) GetPrice(ctx sdk.Context, pair string) uint64 {
11+
func (k Keeper) GetPrice(ctx sdk.Context, pair string) sdkmath.Int {
1012
store := ctx.KVStore(k.storeKey)
1113

1214
bz := store.Get(types.PriceKey(pair))
13-
return sdk.BigEndianToUint64(bz)
15+
price, ok := sdkmath.NewIntFromString(string(bz))
16+
if !ok {
17+
price = sdkmath.ZeroInt()
18+
}
19+
20+
return price
1421
}
1522

1623
// SetPrice sets the price for the specified pair
17-
func (k Keeper) SetPrice(ctx sdk.Context, pair string, price uint64) {
24+
func (k Keeper) SetPrice(ctx sdk.Context, pair string, price string) {
1825
store := ctx.KVStore(k.storeKey)
1926

20-
store.Set(types.PriceKey(pair), sdk.Uint64ToBigEndian(price))
27+
store.Set(types.PriceKey(pair), []byte(price))
2128
}

x/dlc/keeper/queries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ func (k Keeper) Price(goCtx context.Context, req *types.QueryPriceRequest) (*typ
128128

129129
ctx := sdk.UnwrapSDKContext(goCtx)
130130

131-
return &types.QueryPriceResponse{Price: uint64(k.GetPrice(ctx, req.Symbol))}, nil
131+
return &types.QueryPriceResponse{Price: k.GetPrice(ctx, req.Symbol).Uint64()}, nil
132132
}

x/dlc/module/abci.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@ func generateNonces(ctx sdk.Context, k keeper.Keeper) {
105105
selectedOracleId := ctx.BlockHeight() % int64(len(oracles))
106106
oracle := oracles[selectedOracleId]
107107

108-
// check nonce index
108+
// get nonce index and params
109109
nonceIndex := k.GetNonceIndex(ctx, oracle.Id)
110-
if nonceIndex >= uint64(k.GetNonceQueueSize(ctx)) {
110+
nonceQueueSize := uint64(k.GetNonceQueueSize(ctx))
111+
112+
// check if nonces need to be generated
113+
currentPrice := k.GetPrice(ctx, "BTC-USD")
114+
currentEventPrice := k.GetCurrentEventPrice(ctx, "BTC-USD")
115+
if currentEventPrice > 0 && currentEventPrice >= currentPrice.Int64() && nonceIndex >= nonceQueueSize {
111116
return
112117
}
113118

x/lending/keeper/msg_server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ func (m msgServer) SubmitPrice(goCtx context.Context, msg *types.MsgSubmitPrice)
2121
}
2222

2323
ctx := sdk.UnwrapSDKContext(goCtx)
24+
2425
m.SetPrice(ctx, msg.Price)
26+
m.dlcKeeper.SetPrice(ctx, "BTC-USD", msg.Price)
2527

2628
return &types.MsgSubmitPriceResponse{}, nil
2729
}

x/lending/types/expected_keepers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type DLCKeeper interface {
6262
GetAgency(ctx sdk.Context, id uint64) *dlctypes.Agency
6363

6464
TriggerEvent(ctx sdk.Context, id uint64)
65+
66+
SetPrice(ctx sdk.Context, pair string, price string)
6567
}
6668

6769
// BtcBridgeKeeper defines the expected BtcBridge keeper interface

0 commit comments

Comments
 (0)