Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track staleness of v2 orders #496

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions bin/stacks/dashboard-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,43 @@ export class DashboardStack extends cdk.NestedStack {
stat: 'Sum',
},
},
{
height: 6,
width: 12,
y: 62,
x: 0,
type: 'metric',
properties: {
metrics: _.flatMap(SUPPORTED_CHAINS, (chainId) => [
['Uniswap', `NotificationOrderStaleness-chain-${chainId}`, 'Service', `UniswapXService`],
['.', '.', '.', `.`, { stat: 'p99' }],
['.', '.', '.', `.`, { stat: 'p50' }],
['.', '.', '.', `.`, { stat: 'Average' }],
]),
view: 'timeSeries',
region,
title: 'DutchV2 Notification Order Staleness',
period: 300,
stat: 'p90',
},
},
{
height: 6,
width: 12,
y: 62,
x: 12,
type: 'metric',
properties: {
metrics: _.flatMap(SUPPORTED_CHAINS, (chainId) => [
['Uniswap', `NotificationStaleOrder-chain-${chainId}`, 'Service', `UniswapXService`],
]),
view: 'timeSeries',
region,
title: 'DutchV2 Notification Stale Order Count',
period: 300,
stat: 'Sum',
},
},
{
height: 1,
width: 24,
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export const DEFAULT_MAX_OPEN_LIMIT_ORDERS = 100
export const HIGH_MAX_OPEN_ORDERS = 200

export const PRIORITY_ORDER_TARGET_BLOCK_BUFFER = 3
export const DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC = 3;
export const DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC = 20;
20 changes: 20 additions & 0 deletions lib/handlers/order-notification/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { eventRecordToOrder } from '../../util/order'
import { BatchFailureResponse, DynamoStreamLambdaHandler } from '../base/dynamo-stream-handler'
import { ContainerInjected, RequestInjected } from './injector'
import { OrderNotificationInputJoi } from './schema'
import { CosignedV2DutchOrder, OrderType } from '@uniswap/uniswapx-sdk'
import { DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC } from '../constants'
import { Unit } from 'aws-embedded-metrics'
import { ChainId } from '../../util/chain'

const WEBHOOK_TIMEOUT_MS = 500

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

// Log the decay start time difference for debugging
if (newOrder.orderType == OrderType.Dutch_V2) {
const order = CosignedV2DutchOrder.parse(newOrder.encodedOrder, newOrder.chainId)
const decayStartTime = order.info.cosignerData.decayStartTime
const currentTime = Math.floor(Date.now() / 1000) // Convert to seconds
const timeDifference = Number(decayStartTime) - currentTime

// GPA currentlys sets mainnet decay start to 24 secs into the future
if (newOrder.chainId == ChainId.MAINNET && timeDifference > DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC) {
const staleOrderMetricName = `NotificationStaleOrder-chain-${newOrder.chainId.toString()}`
codyborn marked this conversation as resolved.
Show resolved Hide resolved
metrics.putMetric(staleOrderMetricName, 1, Unit.Count)
}
const staleOrderMetricName = `NotificationOrderStaleness-chain-${newOrder.chainId.toString()}`
metrics.putMetric(staleOrderMetricName, timeDifference)
}

const registeredEndpoints = await webhookProvider.getEndpoints({
offerer: newOrder.swapper,
orderStatus: newOrder.orderStatus,
Expand Down
6 changes: 4 additions & 2 deletions lib/handlers/post-order/PostOrderBodyParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DutchV3Order } from '../../models/DutchV3Order'
import { metrics } from '../../util/metrics'
import { Unit } from 'aws-embedded-metrics'
import { DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC } from '../constants'
import { ChainId } from '../../util/chain'

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

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