Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update filter policy hourly #126

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks too complicated...
why not just forget about the time frequency and define the block frequency

  • 720 for gnosis
  • 300 for other networks

also, better to use constant for these numbers (no magic numbers like 5 or 12)

same effect, but easier to read.

) {
filterPolicy.reloadPolicies().catch((error) => {
console.log(`Error fetching the filter policy config for chain `, error);
return null;
Expand Down
Loading