Skip to content

Commit

Permalink
hotfix: improved/fixed catchup and disbled GENESIS_CATCHUP for
Browse files Browse the repository at this point in the history
production
  • Loading branch information
FilipHarald committed Nov 27, 2024
1 parent 2aced75 commit 89972e4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion k8s/production/aztec-listener/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions services/aztec-listener/src/aztec/block_poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions services/aztec-listener/src/aztec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
5 changes: 4 additions & 1 deletion services/aztec-listener/src/aztec/network-client.ts
Original file line number Diff line number Diff line change
@@ -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";

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

Expand Down

0 comments on commit 89972e4

Please sign in to comment.