From 89972e4dbc388a3285fed06290a48127b000f619 Mon Sep 17 00:00:00 2001 From: filip Date: Wed, 27 Nov 2024 13:56:42 +0100 Subject: [PATCH] hotfix: improved/fixed catchup and disbled GENESIS_CATCHUP for production --- k8s/production/aztec-listener/deployment.yaml | 2 +- services/aztec-listener/src/aztec/block_poller.ts | 4 ++-- services/aztec-listener/src/aztec/index.ts | 4 ++-- services/aztec-listener/src/aztec/network-client.ts | 5 ++++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/k8s/production/aztec-listener/deployment.yaml b/k8s/production/aztec-listener/deployment.yaml index 6ceffc5d..7b95dbe7 100644 --- a/k8s/production/aztec-listener/deployment.yaml +++ b/k8s/production/aztec-listener/deployment.yaml @@ -67,7 +67,7 @@ spec: name: global key: CHICMOZ_AZTEC_RPC - name: AZTEC_GENESIS_CATCHUP - value: "true" + value: "false" - name: IGNORE_PROCESSED_HEIGHT value: "false" - name: AZTEC_LISTEN_FOR_BLOCKS diff --git a/services/aztec-listener/src/aztec/block_poller.ts b/services/aztec-listener/src/aztec/block_poller.ts index c0faef22..6c9cce0e 100644 --- a/services/aztec-listener/src/aztec/block_poller.ts +++ b/services/aztec-listener/src/aztec/block_poller.ts @@ -62,9 +62,9 @@ const fetchAndPublishLatestBlockReoccurring = async () => { }; const catchUpOnMissedBlocks = async (from: number, to: number) => { - if (from - to > MAX_BATCH_SIZE_FETCH_MISSED_BLOCKS) { + if (to - from > MAX_BATCH_SIZE_FETCH_MISSED_BLOCKS) { logger.error( - `[fetchAndPublishLatestBlockReoccurring]: more than ${MAX_BATCH_SIZE_FETCH_MISSED_BLOCKS} blocks missed, skipping catchup...` + `[fetchAndPublishLatestBlockReoccurring]: more than ${MAX_BATCH_SIZE_FETCH_MISSED_BLOCKS} blocks missed from ${from} to ${to}, skipping catchup...` ); } else { logger.info( diff --git a/services/aztec-listener/src/aztec/index.ts b/services/aztec-listener/src/aztec/index.ts index 25773cb8..401f099c 100644 --- a/services/aztec-listener/src/aztec/index.ts +++ b/services/aztec-listener/src/aztec/index.ts @@ -41,12 +41,12 @@ export const init = async () => { ); await storeHeight(0); } + if (AZTEC_GENESIS_CATCHUP) + await startCatchup({ from: 1, to: chainHeight }); const pollFromHeight = !isOffSync && latestProcessedHeight ? latestProcessedHeight + 1 : chainHeight; - if (AZTEC_GENESIS_CATCHUP) - await startCatchup({ from: 1, to: pollFromHeight }); if (AZTEC_LISTEN_FOR_BLOCKS) startPollingBlocks({ fromHeight: pollFromHeight }); diff --git a/services/aztec-listener/src/aztec/network-client.ts b/services/aztec-listener/src/aztec/network-client.ts index 8a517c22..d10dce5b 100644 --- a/services/aztec-listener/src/aztec/network-client.ts +++ b/services/aztec-listener/src/aztec/network-client.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { createAztecNodeClient, AztecNode, NodeInfo } from "@aztec/aztec.js"; -import { AZTEC_RPC_URL, NODE_ENV } from "../constants.js"; +import { AZTEC_RPC_URL, MAX_BATCH_SIZE_FETCH_MISSED_BLOCKS, NODE_ENV } from "../constants.js"; import { logger } from "../logger.js"; import { IBackOffOptions, backOff } from "exponential-backoff"; @@ -99,13 +99,16 @@ export const getBlock = async (height: number) => callNodeFunction("getBlock", [height]); export const getBlocks = async (fromHeight: number, toHeight: number) => { + if (toHeight - fromHeight > MAX_BATCH_SIZE_FETCH_MISSED_BLOCKS) throw new Error("Too many blocks to fetch"); const blocks = []; for (let i = fromHeight; i < toHeight; i++) { if (NODE_ENV === "development") await new Promise((r) => setTimeout(r, 500)); + else await new Promise((r) => setTimeout(r, 200)); const block = await getBlock(i); blocks.push(block); } + return blocks; };