From 17f934a69413fb4a07da1e621e40c0b3eb5c60b3 Mon Sep 17 00:00:00 2001 From: mfw78 <53399572+mfw78@users.noreply.github.com> Date: Wed, 10 Jan 2024 20:19:05 +0000 Subject: [PATCH] chore: update filter policy hourly (#126) # Description Update the filter policy every hour # Changes - [x] Set frequency at which to update the filter policy --- src/domain/chainContext.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/domain/chainContext.ts b/src/domain/chainContext.ts index 452051f..2309159 100644 --- a/src/domain/chainContext.ts +++ b/src/domain/chainContext.ts @@ -37,6 +37,7 @@ import { FilterPolicy } from "../utils/filterPolicy"; const WATCHDOG_FREQUENCY = 5 * 1000; // 5 seconds const MULTICALL3 = "0xcA11bde05977b3631167028862bE2a173976CA11"; +const FILTER_FREQUENCY_SECS = 60 * 60; // 1 hour export const SDK_BACKOFF_NUM_OF_ATTEMPTS = 5; @@ -469,8 +470,15 @@ async function processBlock( block.number.toString() ); - // Get the latest filter policy - if (filterPolicy) { + // Refresh the policy every hour + // NOTE: This is a temporary solution until we have a better way to update the filter policy + const blocksPerFilterFrequency = + FILTER_FREQUENCY_SECS / + (context.chainId === SupportedChainId.GNOSIS_CHAIN ? 5 : 12); // 5 seconds for gnosis, 12 seconds for mainnet + if ( + filterPolicy && + block.number % (FILTER_FREQUENCY_SECS / blocksPerFilterFrequency) == 0 + ) { filterPolicy.reloadPolicies().catch((error) => { console.log(`Error fetching the filter policy config for chain `, error); return null;