Skip to content

Commit

Permalink
Order staleness tracking (#491)
Browse files Browse the repository at this point in the history
* Track dutchv2 order latency

* New dashboard charts
  • Loading branch information
codyborn authored Nov 27, 2024
1 parent a24e2b2 commit 3614707
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bin/stacks/dashboard-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,43 @@ export class DashboardStack extends cdk.NestedStack {
stat: 'p90',
},
},
{
height: 6,
width: 12,
y: 56,
x: 0,
type: 'metric',
properties: {
metrics: _.flatMap(SUPPORTED_CHAINS, (chainId) => [
['Uniswap', `OrderStaleness-chain-${chainId}`, 'Service', `UniswapXService`],
['.', '.', '.', `.`, { stat: 'p99' }],
['.', '.', '.', `.`, { stat: 'p50' }],
['.', '.', '.', `.`, { stat: 'Average' }],
]),
view: 'timeSeries',
region,
title: 'DutchV2 Order Staleness',
period: 300,
stat: 'p90',
},
},
{
height: 6,
width: 12,
y: 56,
x: 12,
type: 'metric',
properties: {
metrics: _.flatMap(SUPPORTED_CHAINS, (chainId) => [
['Uniswap', `StaleOrder-chain-${chainId}`, 'Service', `UniswapXService`],
]),
view: 'timeSeries',
region,
title: 'DutchV2 Stale Order Count',
period: 300,
stat: 'Sum',
},
},
{
height: 1,
width: 24,
Expand Down
1 change: 1 addition & 0 deletions lib/handlers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +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;
15 changes: 15 additions & 0 deletions lib/handlers/post-order/PostOrderBodyParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { Order } from '../../models/Order'
import { PriorityOrder } from '../../models/PriorityOrder'
import { RelayOrder } from '../../models/RelayOrder'
import { PostOrderRequestBody } from './schema'
import { metrics } from '../../util/metrics'
import { Unit } from 'aws-embedded-metrics'
import { DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC } from '../constants'

export class PostOrderBodyParser {
private readonly uniswapXParser = new UniswapXOrderParser()
Expand Down Expand Up @@ -95,6 +98,18 @@ export class PostOrderBodyParser {
): DutchV2Order {
try {
const order = CosignedV2DutchOrder.parse(encodedOrder, chainId)
// 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)

if (timeDifference > DUTCHV2_ORDER_LATENCY_THRESHOLD_SEC) {
const staleOrderMetricName = `StaleOrder-chain-${chainId.toString()}`
metrics.putMetric(staleOrderMetricName, 1, Unit.Count)
}
const staleOrderMetricName = `OrderStaleness-chain-${chainId.toString()}`
metrics.putMetric(staleOrderMetricName, timeDifference)

return new DutchV2Order(order as SDKV2DutchOrder, signature, chainId, undefined, undefined, quoteId, requestId)
} catch (err) {
this.logger.error('Unable to parse DutchV2 order', {
Expand Down

0 comments on commit 3614707

Please sign in to comment.