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 7, 2023
1 parent f6bcca8 commit e7b3d4e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/domain/checkForAndPlaceOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
totalPollingOnChainChecks,
totalPollingRuns,
totalPollingUnexpectedErrors,
totalPollingOnChainEthersErrors,
} from "../utils/metrics";

const GPV2SETTLEMENT = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41";
Expand Down Expand Up @@ -529,6 +530,7 @@ async function _pollLegacy(
const { contract, multicall, chainId } = context;
const logPrefix = `checkForAndPlaceOrder:_pollLegacy:${orderRef}`;
const log = getLogger(logPrefix);
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 @@ -537,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,12 +577,13 @@ async function _pollLegacy(
target,
callData,
revertData: returnData,
metricLabels,
});
} catch (error: any) {
// 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
log.error(`${logPrefix} ethers/call Unexpected error`, error);
totalPollingOnChainEthersErrors.labels(...metricLabels).inc();
return {
result: PollResultCode.TRY_NEXT_BLOCK,
reason:
Expand Down
13 changes: 12 additions & 1 deletion src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SupportedChainId,
} from "@cowprotocol/cow-sdk";
import { getLogger } from "./logging";
import { totalPollingOnChainInvalidInterfaces } from "./metrics";

// Selectors that are required to be part of the contract's bytecode in order to be considered compatible
const REQUIRED_SELECTORS = [
Expand Down Expand Up @@ -196,8 +197,17 @@ export function handleOnChainCustomError(params: {
target: string;
callData: string;
revertData: string;
metricLabels: string[];
}): PollResultErrors {
const { owner, orderRef, chainId, target, callData, revertData } = params;
const {
owner,
orderRef,
chainId,
target,
callData,
revertData,
metricLabels,
} = params;
const logPrefix = `contracts:handleOnChainCustomError:${orderRef}`;

try {
Expand Down Expand Up @@ -287,6 +297,7 @@ export function handleOnChainCustomError(params: {
log.debug(
`Contract returned a non-compliant interface revert via getTradeableOrderWithSignature. Simulate: https://dashboard.tenderly.co/gp-v2/watch-tower-prod/simulator/new?network=${chainId}&contractAddress=${target}&rawFunctionInput=${callData}`
);
totalPollingOnChainInvalidInterfaces.labels(...metricLabels).inc();
return {
result: PollResultCode.DONT_TRY_AGAIN,
reason: "Order returned a non-compliant (invalid/erroneous) revert hint",
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,
};
1 change: 1 addition & 0 deletions src/utils/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe("handle on-chain custom errors", () => {
revertData: abiToSelector(
CUSTOM_ERROR_ABI_MAP[CustomErrorSelectors.SINGLE_ORDER_NOT_AUTHED]
),
metricLabels: [],
};

it("should pass a known selector correctly", () => {
Expand Down

0 comments on commit e7b3d4e

Please sign in to comment.