Skip to content

Commit

Permalink
chore: update filter policy hourly (#126)
Browse files Browse the repository at this point in the history
# Description

Update the filter policy every hour

# Changes

- [x] Set frequency at which to update the filter policy
  • Loading branch information
mfw78 authored Jan 10, 2024
1 parent 52833c9 commit 17f934a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/domain/chainContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 17f934a

Please sign in to comment.