Skip to content

Commit

Permalink
Merge branch 'master' into validate-running-balances-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai authored Feb 7, 2025
2 parents cc7460f + dce068f commit 89255b8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/finalizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export async function finalize(
hubSigner,
hubPoolClient,
client,
spokePoolClients[hubChainId],
l1ToL2AddressesToFinalize
);

Expand Down
4 changes: 3 additions & 1 deletion src/finalizer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export interface ChainFinalizer {
logger: winston.Logger,
signer: Signer,
hubPoolClient: HubPoolClient,
spokePoolClient: SpokePoolClient,
l2SpokePoolClient: SpokePoolClient,
// The following types are only used in L1->L2 finalizers currently and can be omitted in L2->L1 finalizers.
l1SpokePoolClient: SpokePoolClient,
l1ToL2AddressesToFinalize: string[]
): Promise<FinalizerPromise>;
}
37 changes: 23 additions & 14 deletions src/finalizer/utils/cctp/l1ToL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,47 @@ export async function cctpL1toL2Finalizer(
logger: winston.Logger,
_signer: Signer,
hubPoolClient: HubPoolClient,
spokePoolClient: SpokePoolClient,
l2SpokePoolClient: SpokePoolClient,
l1SpokePoolClient: SpokePoolClient,
l1ToL2AddressesToFinalize: string[]
): Promise<FinalizerPromise> {
const cctpMessageReceiverDetails = CONTRACT_ADDRESSES[spokePoolClient.chainId].cctpMessageTransmitter;
const cctpMessageReceiverDetails = CONTRACT_ADDRESSES[l2SpokePoolClient.chainId].cctpMessageTransmitter;
const contract = new ethers.Contract(
cctpMessageReceiverDetails.address,
cctpMessageReceiverDetails.abi,
spokePoolClient.spokePool.provider
l2SpokePoolClient.spokePool.provider
);
const decodedMessages = await resolveRelatedTxnReceipts(
l1ToL2AddressesToFinalize,
hubPoolClient.chainId,
spokePoolClient.chainId,
hubPoolClient
l2SpokePoolClient.chainId,
l1SpokePoolClient
);
const unprocessedMessages = decodedMessages.filter((message) => message.status === "ready");
const statusesGrouped = groupObjectCountsByProp(
decodedMessages,
(message: { status: CCTPMessageStatus }) => message.status
);
logger.debug({
at: `Finalizer#CCTPL1ToL2Finalizer:${spokePoolClient.chainId}`,
message: `Detected ${unprocessedMessages.length} ready to finalize messages for CCTP L1 to ${spokePoolClient.chainId}`,
at: `Finalizer#CCTPL1ToL2Finalizer:${l2SpokePoolClient.chainId}`,
message: `Detected ${unprocessedMessages.length} ready to finalize messages for CCTP L1 to ${l2SpokePoolClient.chainId}`,
statusesGrouped,
});

return {
crossChainMessages: await generateDepositData(unprocessedMessages, hubPoolClient.chainId, spokePoolClient.chainId),
crossChainMessages: await generateDepositData(
unprocessedMessages,
hubPoolClient.chainId,
l2SpokePoolClient.chainId
),
callData: await generateMultiCallData(contract, unprocessedMessages),
};
}

async function findRelevantTxnReceiptsForCCTPDeposits(
currentChainId: number,
addressesToSearch: string[],
hubPoolClient: HubPoolClient
l1SpokePoolClient: SpokePoolClient
): Promise<TransactionReceipt[]> {
const provider = getCachedProvider(currentChainId);
const tokenMessengerContract = new Contract(
Expand All @@ -74,9 +79,9 @@ async function findRelevantTxnReceiptsForCCTPDeposits(
addressesToSearch // All depositors that we are monitoring for
);
const searchConfig: EventSearchConfig = {
fromBlock: hubPoolClient.eventSearchConfig.fromBlock,
toBlock: hubPoolClient.eventSearchConfig.toBlock,
maxBlockLookBack: hubPoolClient.eventSearchConfig.maxBlockLookBack,
fromBlock: l1SpokePoolClient.eventSearchConfig.fromBlock,
toBlock: l1SpokePoolClient.latestBlockSearched,
maxBlockLookBack: l1SpokePoolClient.eventSearchConfig.maxBlockLookBack,
};
const events = await paginatedEventQuery(tokenMessengerContract, eventFilter, searchConfig);
const receipts = await Promise.all(events.map((event) => provider.getTransactionReceipt(event.transactionHash)));
Expand All @@ -88,9 +93,13 @@ async function resolveRelatedTxnReceipts(
addressesToSearch: string[],
currentChainId: number,
targetDestinationChainId: number,
hubPoolClient: HubPoolClient
l1SpokePoolClient: SpokePoolClient
): Promise<DecodedCCTPMessage[]> {
const allReceipts = await findRelevantTxnReceiptsForCCTPDeposits(currentChainId, addressesToSearch, hubPoolClient);
const allReceipts = await findRelevantTxnReceiptsForCCTPDeposits(
currentChainId,
addressesToSearch,
l1SpokePoolClient
);
return resolveCCTPRelatedTxns(allReceipts, currentChainId, targetDestinationChainId);
}

Expand Down
24 changes: 7 additions & 17 deletions src/finalizer/utils/linea/l1ToL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { OnChainMessageStatus } from "@consensys/linea-sdk";
import { Contract } from "ethers";
import { groupBy } from "lodash";
import { HubPoolClient, SpokePoolClient } from "../../../clients";
import { CHAIN_MAX_BLOCK_LOOKBACK, CONTRACT_ADDRESSES } from "../../../common";
import { CONTRACT_ADDRESSES } from "../../../common";
import { EventSearchConfig, Signer, convertFromWei, winston, CHAIN_IDs, ethers, BigNumber } from "../../../utils";
import { CrossChainMessage, FinalizerPromise } from "../../types";
import {
determineMessageType,
findMessageFromTokenBridge,
findMessageFromUsdcBridge,
findMessageSentEvents,
getBlockRangeByHoursOffsets,
getL1MessageServiceContractFromL1ClaimingService,
initLineaSdk,
} from "./common";
Expand Down Expand Up @@ -39,8 +38,8 @@ export async function lineaL1ToL2Finalizer(
logger: winston.Logger,
signer: Signer,
hubPoolClient: HubPoolClient,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_spokePoolClient: SpokePoolClient,
l2SpokePoolClient: SpokePoolClient,
l1SpokePoolClient: SpokePoolClient,
l1ToL2AddressesToFinalize: string[]
): Promise<FinalizerPromise> {
const [l1ChainId] = [hubPoolClient.chainId, hubPoolClient.hubPool.address];
Expand All @@ -62,19 +61,10 @@ export async function lineaL1ToL2Finalizer(
hubPoolClient.hubPool.provider
);

// Optimize block range for querying Linea's MessageSent events on L1.
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l1ChainId, 24 * 7, 0);
logger.debug({
at: "Finalizer#LineaL1ToL2Finalizer",
message: "Linea MessageSent event filter",
fromBlock,
toBlock,
});

const searchConfig: EventSearchConfig = {
fromBlock,
toBlock,
maxBlockLookBack: CHAIN_MAX_BLOCK_LOOKBACK[l1ChainId] || 10_000,
fromBlock: l1SpokePoolClient.eventSearchConfig.fromBlock,
toBlock: l1SpokePoolClient.latestBlockSearched,
maxBlockLookBack: l1SpokePoolClient.eventSearchConfig.maxBlockLookBack,
};

const [wethAndRelayEvents, tokenBridgeEvents, usdcBridgeEvents] = await Promise.all([
Expand All @@ -100,7 +90,7 @@ export async function lineaL1ToL2Finalizer(
const messageStatus = await getL1ToL2MessageStatusUsingCustomProvider(
l2MessageServiceContract,
_messageHash,
_spokePoolClient.spokePool.provider
l2SpokePoolClient.spokePool.provider
);
return {
messageSender: _from,
Expand Down

0 comments on commit 89255b8

Please sign in to comment.