Skip to content
Open
Show file tree
Hide file tree
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
101 changes: 57 additions & 44 deletions packages/indexer/src/data-indexing/service/CctpFinalizerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RepeatableTask } from "../../generics";
import { DataSource, entities } from "@repo/indexer-database";
import { CHAIN_IDs } from "@across-protocol/constants";
import { PubSubService } from "../../pubsub/service";
import { Config } from "../../parseEnv";
import { Config, CctpFinalizerMode } from "../../parseEnv";
import {
fetchAttestationsForTxn,
getCctpDestinationChainFromDomain,
Expand Down Expand Up @@ -33,9 +33,10 @@ export class CctpFinalizerServiceManager {
this.logger,
this.postgres,
this.pubSubService,
this.config,
);
await this.lighterFinalizerService.start(CCTP_FINALIZER_DELAY_SECONDS);
if (!this.config.enableCctpFinalizer) {
if (this.config.cctpFinalizerMode === CctpFinalizerMode.Off) {
this.logger.warn({
at: "Indexer#CctpFinalizerServiceManager#start",
message: "CCTP finalizer is disabled",
Expand All @@ -48,7 +49,9 @@ export class CctpFinalizerServiceManager {
this.logger,
this.postgres,
this.pubSubService,
this.config,
);
// Start the service if we are not in 'off' mode (implied by the early return above)
await this.service.start(CCTP_FINALIZER_DELAY_SECONDS);
} catch (error) {
this.logger.error({
Expand All @@ -74,6 +77,7 @@ class LighterCctpFinalizerService extends RepeatableTask {
logger: winston.Logger,
private readonly postgres: DataSource,
private readonly pubSubService: PubSubService,
private readonly config: Config,
) {
super(logger, "lighter-cctp-finalizer-service");
}
Expand Down Expand Up @@ -214,27 +218,32 @@ class LighterCctpFinalizerService extends RepeatableTask {
{ chainId, blockNumber: burnEvent.blockNumber, transactionHash },
)
.execute();
this.logger.debug({
at: "LighterCctpFinalizerService#publishBurnEvent",
message: "Publishing burn event to pubsub",
chainId,
transactionHash,
minFinalityThreshold,
blockTimestamp,
attestationTimeSeconds,
elapsedSeconds,
});
const destinationChainId = getCctpDestinationChainFromDomain(
burnEvent.destinationDomain,
);
await this.pubSubService.publishCctpFinalizerMessage(
transactionHash,
Number(chainId),
message,
attestation,
destinationChainId,
signature,
);

if (this.config.cctpFinalizerMode === CctpFinalizerMode.Full) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mode is attesation-only here

this.logger.debug({
at: "LighterCctpFinalizerService#publishBurnEvent",
message: "Publishing burn event to pubsub",
chainId,
transactionHash,
minFinalityThreshold,
blockTimestamp,
attestationTimeSeconds,
elapsedSeconds,
});

const destinationChainId = getCctpDestinationChainFromDomain(
burnEvent.destinationDomain,
);

await this.pubSubService.publishCctpFinalizerMessage(
transactionHash,
Number(chainId),
message,
attestation,
destinationChainId,
signature,
);
}

const jobValues: {
attestation: string;
Expand Down Expand Up @@ -278,6 +287,7 @@ class CctpFinalizerService extends RepeatableTask {
logger: winston.Logger,
private readonly postgres: DataSource,
private readonly pubSubService: PubSubService,
private readonly config: Config,
) {
super(logger, "cctp-finalizer-service");
}
Expand Down Expand Up @@ -426,27 +436,30 @@ class CctpFinalizerService extends RepeatableTask {
{ chainId, blockNumber: burnEvent.blockNumber, transactionHash },
)
.execute();
this.logger.debug({
at: "CctpFinalizerService#publishBurnEvent",
message: "Publishing burn event to pubsub",
chainId,
transactionHash,
minFinalityThreshold,
blockTimestamp,
attestationTimeSeconds,
elapsedSeconds,
});
const destinationChainId = getCctpDestinationChainFromDomain(
burnEvent.destinationDomain,
);
await this.pubSubService.publishCctpFinalizerMessage(
transactionHash,
Number(chainId),
message,
attestation,
destinationChainId,
signature,
);

if (this.config.cctpFinalizerMode === CctpFinalizerMode.Full) {
this.logger.debug({
at: "CctpFinalizerService#publishBurnEvent",
message: "Publishing burn event to pubsub",
chainId,
transactionHash,
minFinalityThreshold,
blockTimestamp,
attestationTimeSeconds,
elapsedSeconds,
});
const destinationChainId = getCctpDestinationChainFromDomain(
burnEvent.destinationDomain,
);
await this.pubSubService.publishCctpFinalizerMessage(
transactionHash,
Number(chainId),
message,
attestation,
destinationChainId,
signature,
);
}

const jobValues: {
attestation: string;
Expand Down
28 changes: 28 additions & 0 deletions packages/indexer/src/parseEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type Config = {
enableBundleBuilder: boolean;
cctpIndexerChainIds: number[];
enableCctpFinalizer: boolean;
cctpFinalizerMode: CctpFinalizerMode;
pubSubCctpFinalizerTopic: string;
pubSubGcpProjectId: string;
enableOftIndexer: boolean;
Expand Down Expand Up @@ -69,6 +70,12 @@ export type RetryProviderConfig = {

export type Env = Record<string, string | undefined>;

export enum CctpFinalizerMode {
Off = "off",
Full = "full",
FetchAttestationOnly = "fetch-attestation-only",
}

export function parseRedisConfig(env: Env): RedisConfig {
const { REDIS_HOST, REDIS_PORT } = env;
assert(REDIS_HOST, "requires REDIS_HOST");
Expand Down Expand Up @@ -232,6 +239,26 @@ export function envToConfig(env: Env): Config {
const enableCctpFinalizer = env.ENABLE_CCTP_FINALIZER
? env.ENABLE_CCTP_FINALIZER === "true"
: false;
Comment on lines 239 to 241
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we good to remove this?

let cctpFinalizerMode: CctpFinalizerMode = CctpFinalizerMode.Off;

if (env.CCTP_FINALIZER_MODE) {
if (
env.CCTP_FINALIZER_MODE === "full" ||
env.CCTP_FINALIZER_MODE === "fetch-attestation-only" ||
env.CCTP_FINALIZER_MODE === "off"
) {
cctpFinalizerMode = env.CCTP_FINALIZER_MODE as CctpFinalizerMode;
} else {
throw new Error(
`Invalid CCTP_FINALIZER_MODE: ${env.CCTP_FINALIZER_MODE}. Must be one of 'off', 'full', 'fetch-attestation-only'`,
);
}
} else if (env.ENABLE_CCTP_FINALIZER) {
cctpFinalizerMode =
env.ENABLE_CCTP_FINALIZER === "true"
? CctpFinalizerMode.Full
: CctpFinalizerMode.Off;
}
Comment on lines +256 to +261
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove the support for ENABLE_CCTP_FINALIZER env entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not removing the support for ENABLE_CCTP_FINALIZER, the variable still exists. If ENABLE_CCTP_FINALIZER is false then the mode is going to be off if it is true and the mode is not set then the mode is set to full

const pubSubCctpFinalizerTopic = env.PUBSUB_CCTP_FINALIZER_TOPIC ?? "";
const pubSubGcpProjectId = env.PUBSUB_GCP_PROJECT_ID ?? "";
const enableBundleIncludedEventsService =
Expand Down Expand Up @@ -293,6 +320,7 @@ export function envToConfig(env: Env): Config {
cctpIndexerChainIds,
enableOftIndexer,
enableCctpFinalizer,
cctpFinalizerMode,
pubSubCctpFinalizerTopic,
pubSubGcpProjectId,
webhookConfig,
Expand Down