Skip to content

Commit

Permalink
hotfix: make aztec-listener recover from restarted chain
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipHarald committed Oct 11, 2024
1 parent 2700e06 commit f3c9799
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions services/aztec-listener/src/aztec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
AZTEC_GENESIS_CATCHUP,
AZTEC_LISTEN_FOR_BLOCKS,
} from "../constants.js";
import { getHeight as getLatestProcessedHeight } from "../database/latestProcessedHeight.controller.js";
import {
getHeight as getLatestProcessedHeight,
storeHeight,
} from "../database/latestProcessedHeight.controller.js";
import { logger } from "../logger.js";
import {
getLatestHeight,
Expand Down Expand Up @@ -33,14 +36,21 @@ export const init = async () => {
}, backOffOptions);
logger.info(`AZTEC: initialized: ${JSON.stringify(nodeInfo)}`);

const latestProcessedHeight = await getLatestProcessedHeight();
const pollFromHeight = latestProcessedHeight
const latestProcessedHeight = (await getLatestProcessedHeight()) ?? 0;
const chainHeight = await getLatestHeight();
const isOffSync = chainHeight < latestProcessedHeight;
if (isOffSync) {
logger.warn(
`🤡 AZTEC: chain height is ${chainHeight} but we've processed up to ${latestProcessedHeight}`
);
await storeHeight(0);
}
const pollFromHeight = !isOffSync && latestProcessedHeight
? latestProcessedHeight + 1
: await getLatestHeight();
: chainHeight;
if (AZTEC_GENESIS_CATCHUP)
await startCatchup({ from: 1, to: pollFromHeight });
if (AZTEC_LISTEN_FOR_BLOCKS)
startPolling({ fromHeight: pollFromHeight });
if (AZTEC_LISTEN_FOR_BLOCKS) startPolling({ fromHeight: pollFromHeight });

return {
id: "AZTEC",
Expand Down

0 comments on commit f3c9799

Please sign in to comment.