Skip to content

Commit

Permalink
feat: handle error loading filter config
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Nov 20, 2023
1 parent 6daa261 commit e1ae9ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
19 changes: 14 additions & 5 deletions src/domain/chainContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import {
reorgDepth,
reorgsTotal,
} from "../utils/metrics";
import { FilterPolicy, fetchPolicy } from "../utils/policy";
import {
FilterPolicy,
fetchPolicy as fetchFilterPolicyConfig,
} from "../utils/policy";

const WATCHDOG_FREQUENCY = 5 * 1000; // 5 seconds

Expand Down Expand Up @@ -446,10 +449,16 @@ async function processBlock(
block.number.toString()
);

// Update filter policy
const policy = await fetchPolicy(chainId);
filterPolicy.setHandlers(policy.handlers);
filterPolicy.setOwners(policy.owners);
// Get the latest filter policy
const policyConfig = await fetchFilterPolicyConfig(chainId).catch((error) => {
console.log(`Error fetching the filter policy config for chain `, error);
return null;
});

if (policyConfig) {
filterPolicy.setHandlers(policyConfig.handlers);
filterPolicy.setOwners(policyConfig.owners);
}

// Transaction watcher for adding new contracts
let hasErrors = false;
Expand Down
5 changes: 3 additions & 2 deletions src/domain/checkForAndPlaceOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export async function checkForAndPlaceOrder(
owner,
conditionalOrderParams: conditionalOrder.params,
});

switch (filterResult) {
case FilterAction.DROP:
log.debug(
Expand All @@ -142,9 +143,9 @@ export async function checkForAndPlaceOrder(
ordersPendingDelete.push(conditionalOrder);

continue;
case FilterAction.IGNORE:
case FilterAction.SKIP:
log.debug(
"Skipping conditional order. Reason: AcceptPolicy: IGNORE",
"Skipping conditional order. Reason: AcceptPolicy: SKIP",
conditionalOrder.params
);
continue;
Expand Down
8 changes: 3 additions & 5 deletions src/utils/policy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import fetch from "node-fetch";

import { ConditionalOrderParams, SupportedChainId } from "@cowprotocol/cow-sdk";

export enum FilterAction {
DROP,
IGNORE,
ACCEPT,
DROP = "DROP",
SKIP = "SKIP",
ACCEPT = "ACCEPT",
}

export interface FilterParams {
Expand Down

0 comments on commit e1ae9ce

Please sign in to comment.