Skip to content

Commit

Permalink
chore: metrics todo
Browse files Browse the repository at this point in the history
  • Loading branch information
mfw78 committed Oct 6, 2023
1 parent 565ff63 commit f78a02c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/domain/checkForAndPlaceOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ import {
import { ChainContext } from "./chainContext";
import {
pollingOnChainDurationSeconds,
totalPollingOnChainInvalidInterfaces,
totalActiveOrders,
totalActiveOwners,
totalOrderBookDiscreteOrders,
totalOrderBookErrors,
totalPollingOnChainChecks,
totalPollingRuns,
totalPollingUnexpectedErrors,
totalPollingOnChainEthersErrors,
} from "../utils/metrics";

const GPV2SETTLEMENT = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41";
Expand Down Expand Up @@ -527,7 +529,8 @@ async function _pollLegacy(
offchainInput: string,
orderRef: string
): Promise<PollResult> {
const { contract, multicall } = context;
const { contract, multicall, chainId } = context;
const { handler } = conditionalOrder.params;
// as we going to use multicall, with `aggregate3Value`, there is no need to do any simulation as the
// calls are guaranteed to pass, and will return the results, or the reversion within the ABI-encoded data.
// By not using `populateTransaction`, we avoid an `eth_estimateGas` RPC call.
Expand All @@ -536,6 +539,8 @@ async function _pollLegacy(
"getTradeableOrderWithSignature",
[owner, conditionalOrder.params, offchainInput, proof]
);
const id = ConditionalOrderSDK.leafToId(conditionalOrder.params);
const metricLabels = [chainId.toString(), owner, handler, id];

try {
const lowLevelCall = await multicall.callStatic.aggregate3Value([
Expand Down Expand Up @@ -573,7 +578,8 @@ async function _pollLegacy(
orderRef,
context,
to,
data
data,
metricLabels
);
}
}
Expand All @@ -584,7 +590,8 @@ function _handleGetTradableOrderWithSignatureCall(
orderRef: string,
context: ChainContext,
to: string,
data: string
data: string,
metricLabels: string[]
): PollResultErrors {
const logPrefix = `checkForAndPlaceOrder:_handleGetTradableOrderCall:${orderRef}`;
const log = getLogger(logPrefix);
Expand Down Expand Up @@ -636,7 +643,6 @@ function _handleGetTradableOrderWithSignatureCall(
result: PollResultCode.DONT_TRY_AGAIN,
reason: `${selector}: The safe has swap guard enabled`,
};
// TODO: Add metrics to track this
case "ORDER_NOT_VALID":
case "POLL_TRY_NEXT_BLOCK":
// OrderNotValid: With the revised custom errors, `OrderNotValid` is generally returned when elements
Expand Down Expand Up @@ -684,10 +690,10 @@ function _handleGetTradableOrderWithSignatureCall(
} catch (err: any) {
// Any errors thrown here can _ONLY_ come from non-compliant interfaces (ie. bad revert ABI encoding).
// We log the error, and return a DONT_TRY_AGAIN result.
// TODO: Add metrics to track this
log.error(
`Contract returned non-interface compliant revert via getTradeableOrderWithSignature. Simulate: https://dashboard.tenderly.co/gp-v2/watch-tower-prod/simulator/new?network=${chainId}&contractAddress=${to}&rawFunctionInput=${data}`
);
totalPollingOnChainInvalidInterfaces.labels(...metricLabels).inc();
return {
result: PollResultCode.DONT_TRY_AGAIN,
reason:
Expand All @@ -698,9 +704,9 @@ function _handleGetTradableOrderWithSignatureCall(
}

log.error(`${logPrefix} ethers/call Unexpected error`, error);
totalPollingOnChainEthersErrors.labels(...metricLabels).inc();
// We can only get here from some provider / ethers failure. As the contract hasn't had it's say
// we will defer to try again.
// TODO: Add metrics to track this
return {
result: PollResultCode.TRY_NEXT_BLOCK,
reason:
Expand Down
14 changes: 14 additions & 0 deletions src/utils/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ const pollingOnChainDurationSeconds = new client.Histogram({
labelNames: ["chain_id", "handler", "owner", "id"],
});

const totalPollingOnChainInvalidInterfaces = new client.Counter({
name: "watch_tower_polling_onchain_invalid_interface_total",
help: "Total number of invalid on-chain hint interface",
labelNames: ["chain_id", "handler", "owner", "id"],
});

const totalPollingOnChainEthersErrors = new client.Counter({
name: "watch_tower_polling_onchain_ethers_errors_total",
help: "Total number of ethers on-chain hint errors",
labelNames: ["chain_id", "handler", "owner", "id"],
});

const totalPollingUnexpectedErrors = new client.Counter({
name: "watch_tower_polling_unexpected_errors_total",
help: "Total number of unexpected polling errors",
Expand All @@ -132,6 +144,8 @@ export {
totalOrderBookErrors,
totalPollingRuns,
totalPollingOnChainChecks,
totalPollingOnChainInvalidInterfaces,
totalPollingOnChainEthersErrors,
pollingOnChainDurationSeconds,
totalPollingUnexpectedErrors,
};

0 comments on commit f78a02c

Please sign in to comment.