Skip to content

Commit a0aa103

Browse files
committed
logs for debugging
1 parent d0b6d51 commit a0aa103

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

protocol/streaming/grpc/client/client.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"fmt"
45
"sync"
56

67
"cosmossdk.io/log"
@@ -87,6 +88,11 @@ func (c *GrpcClient) GetOrderbookSnapshot(pairId uint32) *LocalOrderbook {
8788
// Write method for stream orderbook updates.
8889
func (c *GrpcClient) Update(updates *clobtypes.StreamOrderbookUpdatesResponse) {
8990
for _, update := range updates.GetUpdates() {
91+
c.Logger.Info(
92+
fmt.Sprintf("Received stream update for callback %+v", update.ExecMode),
93+
"blockHeight",
94+
update.BlockHeight,
95+
)
9096
if orderUpdate := update.GetOrderbookUpdate(); orderUpdate != nil {
9197
c.ProcessOrderbookUpdate(orderUpdate)
9298
}
@@ -106,18 +112,30 @@ func (c *GrpcClient) ProcessOrderbookUpdate(orderUpdate *clobtypes.StreamOrderbo
106112
for _, update := range orderUpdate.Updates {
107113
if orderPlace := update.GetOrderPlace(); orderPlace != nil {
108114
order := orderPlace.GetOrder()
115+
c.Logger.Info(
116+
"place order recieved",
117+
"orderId", IndexerOrderIdToOrderId(order.OrderId).String(),
118+
)
109119
orderbook := c.GetOrderbook(order.OrderId.ClobPairId)
110120
orderbook.AddOrder(*order)
111121
}
112122

113123
if orderRemove := update.GetOrderRemove(); orderRemove != nil {
114124
orderId := orderRemove.RemovedOrderId
125+
c.Logger.Info(
126+
"remove order recieved",
127+
"orderId", IndexerOrderIdToOrderId(*orderId).String(),
128+
)
115129
orderbook := c.GetOrderbook(orderId.ClobPairId)
116130
orderbook.RemoveOrder(*orderId)
117131
}
118132

119133
if orderUpdate := update.GetOrderUpdate(); orderUpdate != nil {
120134
orderId := orderUpdate.OrderId
135+
c.Logger.Info(
136+
"update order recieved",
137+
"orderId", IndexerOrderIdToOrderId(*orderId).String(),
138+
)
121139
orderbook := c.GetOrderbook(orderId.ClobPairId)
122140
orderbook.SetOrderFillAmount(orderId, orderUpdate.TotalFilledQuantums)
123141
}
@@ -145,6 +163,9 @@ func (c *GrpcClient) ProcessMatchPerpetualLiquidation(
145163
orderMap map[clobtypes.OrderId]clobtypes.Order,
146164
fillAmountMap map[clobtypes.OrderId]uint64,
147165
) {
166+
c.Logger.Info(
167+
"liquidation order recieved",
168+
)
148169
localOrderbook := c.Orderbook[perpLiquidation.ClobPairId]
149170
for _, fill := range perpLiquidation.GetFills() {
150171
makerOrder := orderMap[fill.MakerOrderId]
@@ -158,6 +179,9 @@ func (c *GrpcClient) ProcessMatchOrders(
158179
orderMap map[clobtypes.OrderId]clobtypes.Order,
159180
fillAmountMap map[clobtypes.OrderId]uint64,
160181
) {
182+
c.Logger.Info(
183+
"match order recieved",
184+
)
161185
takerOrderId := matchOrders.TakerOrderId
162186
clobPairId := takerOrderId.GetClobPairId()
163187
localOrderbook := c.Orderbook[clobPairId]
@@ -287,6 +311,11 @@ func (l *LocalOrderbook) SetOrderFillAmount(
287311
l.Lock()
288312
defer l.Unlock()
289313

314+
l.Logger.Info(
315+
fmt.Sprintf("local fill set to %+v", fillAmount),
316+
"orderId", IndexerOrderIdToOrderId(*orderId).String(),
317+
)
318+
290319
if fillAmount == 0 {
291320
delete(l.FillAmounts, *orderId)
292321
} else {

protocol/x/clob/abci.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,16 @@ func PrepareCheckState(
162162
log.LocalValidatorOperationsQueue, types.GetInternalOperationsQueueTextString(localValidatorOperationsQueue),
163163
)
164164

165+
log.InfoLog(ctx,
166+
"removing all operations from local opqueue",
167+
)
168+
165169
keeper.MemClob.RemoveAndClearOperationsQueue(ctx, localValidatorOperationsQueue)
166170

171+
log.InfoLog(ctx,
172+
"purging state from local opqueue",
173+
)
174+
167175
// 2. Purge invalid state from the memclob.
168176
offchainUpdates := types.NewOffchainUpdates()
169177
offchainUpdates = keeper.MemClob.PurgeInvalidMemclobState(
@@ -175,6 +183,10 @@ func PrepareCheckState(
175183
offchainUpdates,
176184
)
177185

186+
log.InfoLog(ctx,
187+
"place stateful order placements",
188+
)
189+
178190
// 3. Place all stateful order placements included in the last block on the memclob.
179191
// Note telemetry is measured outside of the function call because `PlaceStatefulOrdersFromLastBlock`
180192
// is called within `PlaceConditionalOrdersTriggeredInLastBlock`.
@@ -204,6 +216,10 @@ func PrepareCheckState(
204216
offchainUpdates,
205217
)
206218

219+
log.InfoLog(ctx,
220+
"replay local validator operations",
221+
)
222+
207223
// 5. Replay the local validator’s operations onto the book.
208224
replayUpdates := keeper.MemClob.ReplayOperations(
209225
ctx,

protocol/x/clob/keeper/grpc_stream_orderbook.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,12 @@ func (k Keeper) CompareMemclobOrderbookWithLocalOrderbook(
220220
localOrderbookFillAmount := localOrderbook.FillAmounts[indexerOrderId]
221221

222222
if orderFillAmount != localOrderbookFillAmount {
223+
order := localOrderbook.OrderIdToOrder[v1.OrderIdToIndexerOrderId(orderId)]
223224
logger.Error(
224225
"Fill Amount Mismatch",
225226
"orderId", orderId.String(),
227+
"time_in_force", order.TimeInForce,
228+
"order_flags", order.OrderId.OrderFlags,
226229
"state_fill_amt", orderFillAmount,
227230
"local_fill_amt", localOrderbookFillAmount,
228231
)

protocol/x/clob/keeper/order_state.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keeper
33
import (
44
"bytes"
55
"encoding/binary"
6+
"fmt"
67

78
"cosmossdk.io/store/prefix"
89
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -93,6 +94,12 @@ func (k Keeper) SetOrderFillAmount(
9394
orderId.ToStateKey(),
9495
orderFillStateBytes,
9596
)
97+
98+
log.InfoLog(
99+
ctx,
100+
fmt.Sprintf("real fill set to %+v", fillAmount),
101+
"orderId", orderId.String(),
102+
)
96103
}
97104

98105
// GetOrderFillAmount returns the total `fillAmount` and `prunableBlockHeight` from the memStore.
@@ -277,6 +284,12 @@ func (k Keeper) RemoveOrderFillAmount(ctx sdk.Context, orderId types.OrderId) {
277284
)
278285
memStore.Delete(orderId.ToStateKey())
279286

287+
log.InfoLog(
288+
ctx,
289+
"real fill set to 0 (remove)",
290+
"orderId", orderId.String(),
291+
)
292+
280293
// If grpc stream is on, zero out the fill amount.
281294
if k.GetGrpcStreamingManager().Enabled() {
282295
allUpdates := types.NewOffchainUpdates()

0 commit comments

Comments
 (0)