Skip to content

Commit 749357b

Browse files
authored
Track staleness of v2 orders (#496)
1 parent d9903a1 commit 749357b

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

bin/stacks/dashboard-stack.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,43 @@ export class DashboardStack extends cdk.NestedStack {
468468
stat: 'Sum',
469469
},
470470
},
471+
{
472+
height: 6,
473+
width: 12,
474+
y: 62,
475+
x: 0,
476+
type: 'metric',
477+
properties: {
478+
metrics: _.flatMap(SUPPORTED_CHAINS, (chainId) => [
479+
['Uniswap', `NotificationOrderStaleness-chain-${chainId}`, 'Service', `UniswapXService`],
480+
['.', '.', '.', `.`, { stat: 'p99' }],
481+
['.', '.', '.', `.`, { stat: 'p50' }],
482+
['.', '.', '.', `.`, { stat: 'Average' }],
483+
]),
484+
view: 'timeSeries',
485+
region,
486+
title: 'DutchV2 Notification Order Staleness',
487+
period: 300,
488+
stat: 'p90',
489+
},
490+
},
491+
{
492+
height: 6,
493+
width: 12,
494+
y: 62,
495+
x: 12,
496+
type: 'metric',
497+
properties: {
498+
metrics: _.flatMap(SUPPORTED_CHAINS, (chainId) => [
499+
['Uniswap', `NotificationStaleOrder-chain-${chainId}`, 'Service', `UniswapXService`],
500+
]),
501+
view: 'timeSeries',
502+
region,
503+
title: 'DutchV2 Notification Stale Order Count',
504+
period: 300,
505+
stat: 'Sum',
506+
},
507+
},
471508
{
472509
height: 1,
473510
width: 24,

lib/handlers/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ export const DEFAULT_MAX_OPEN_LIMIT_ORDERS = 100
1313
export const HIGH_MAX_OPEN_ORDERS = 200
1414

1515
export const PRIORITY_ORDER_TARGET_BLOCK_BUFFER = 3
16-
export const DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC = 3;
16+
export const DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC = 20;

lib/handlers/order-notification/handler.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { eventRecordToOrder } from '../../util/order'
55
import { BatchFailureResponse, DynamoStreamLambdaHandler } from '../base/dynamo-stream-handler'
66
import { ContainerInjected, RequestInjected } from './injector'
77
import { OrderNotificationInputJoi } from './schema'
8+
import { CosignedV2DutchOrder, OrderType } from '@uniswap/uniswapx-sdk'
9+
import { DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC } from '../constants'
10+
import { Unit } from 'aws-embedded-metrics'
11+
import { ChainId } from '../../util/chain'
812

913
const WEBHOOK_TIMEOUT_MS = 500
1014

@@ -23,6 +27,22 @@ export class OrderNotificationHandler extends DynamoStreamLambdaHandler<Containe
2327
try {
2428
const newOrder = eventRecordToOrder(record)
2529

30+
// Log the decay start time difference for debugging
31+
if (newOrder.orderType == OrderType.Dutch_V2) {
32+
const order = CosignedV2DutchOrder.parse(newOrder.encodedOrder, newOrder.chainId)
33+
const decayStartTime = order.info.cosignerData.decayStartTime
34+
const currentTime = Math.floor(Date.now() / 1000) // Convert to seconds
35+
const timeDifference = Number(decayStartTime) - currentTime
36+
37+
// GPA currentlys sets mainnet decay start to 24 secs into the future
38+
if (newOrder.chainId == ChainId.MAINNET && timeDifference > DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC) {
39+
const staleOrderMetricName = `NotificationStaleOrder-chain-${newOrder.chainId.toString()}`
40+
metrics.putMetric(staleOrderMetricName, 1, Unit.Count)
41+
}
42+
const staleOrderMetricName = `NotificationOrderStaleness-chain-${newOrder.chainId.toString()}`
43+
metrics.putMetric(staleOrderMetricName, timeDifference)
44+
}
45+
2646
const registeredEndpoints = await webhookProvider.getEndpoints({
2747
offerer: newOrder.swapper,
2848
orderStatus: newOrder.orderStatus,

lib/handlers/post-order/PostOrderBodyParser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { DutchV3Order } from '../../models/DutchV3Order'
2323
import { metrics } from '../../util/metrics'
2424
import { Unit } from 'aws-embedded-metrics'
2525
import { DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC } from '../constants'
26+
import { ChainId } from '../../util/chain'
2627

2728
export class PostOrderBodyParser {
2829
private readonly uniswapXParser = new UniswapXOrderParser()
@@ -106,9 +107,10 @@ export class PostOrderBodyParser {
106107
// Log the decay start time difference for debugging
107108
const decayStartTime = order.info.cosignerData.decayStartTime
108109
const currentTime = Math.floor(Date.now() / 1000) // Convert to seconds
109-
const timeDifference = currentTime - Number(decayStartTime)
110+
const timeDifference = Number(decayStartTime) - currentTime
110111

111-
if (timeDifference > DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC) {
112+
// GPA currentlys sets mainnet decay start to 24 secs into the future
113+
if (chainId == ChainId.MAINNET && timeDifference > DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC) {
112114
const staleOrderMetricName = `StaleOrder-chain-${chainId.toString()}`
113115
metrics.putMetric(staleOrderMetricName, 1, Unit.Count)
114116
}

0 commit comments

Comments
 (0)