Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(LineaFinalizer): Force RPC calls through custom provider #1931

Merged
merged 20 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor
nicholaspai committed Nov 26, 2024
commit bad866eec0bbbdca864bb56246f586f57706fdb4
26 changes: 1 addition & 25 deletions src/finalizer/utils/linea/common.ts
Original file line number Diff line number Diff line change
@@ -96,38 +96,14 @@ export function makeGetMessagesWithStatusByTxHash(
};
}

// Temporary re-implementations of the SDK's various `getMessageStatus` functions that allow us to use
// Temporary re-implementation of the SDK's `L1ClaimingService.getMessageStatus` functions that allow us to use
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
// our custom provider, with retry and caching logic, to get around the SDK's hardcoded logic to query events
// from 0 to "latest" which will not work on all RPC's.
export async function getL1ToL2MessageStatusUsingCustomProvider(
messageService: L2MessageServiceContract,
messageHash: string,
l2Provider: ethers.providers.Provider
): Promise<OnChainMessageStatus> {
const l2Contract = new Contract(messageService.contract.address, messageService.contract.interface, l2Provider);
const status: BigNumber = await l2Contract.inboxL1L2MessageStatus(messageHash);
switch (status.toString()) {
case "0":
return OnChainMessageStatus.UNKNOWN;
case "1":
return OnChainMessageStatus.CLAIMABLE;
case "2":
return OnChainMessageStatus.CLAIMED;
}
}
async function getL2L1MessageStatusUsingCustomProvider(
messageService: L1ClaimingService,
messageHash: string,
l1Provider: ethers.providers.Provider,
l1SearchConfig: EventSearchConfig
): Promise<OnChainMessageStatus> {
return await getMessageStatusUsingMessageHash(messageHash, messageService, l1Provider, l1SearchConfig);
}
async function getMessageStatusUsingMessageHash(
messageHash: string,
messageService: L1ClaimingService,
l1Provider: ethers.providers.Provider,
l1SearchConfig: EventSearchConfig
): Promise<OnChainMessageStatus> {
const l1Contract = new Contract(
messageService.l1Contract.contract.address,
24 changes: 22 additions & 2 deletions src/finalizer/utils/linea/l1ToL2.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
import { utils as sdkUtils } from "@across-protocol/sdk";
import { OnChainMessageStatus } from "@consensys/linea-sdk";
import { L2MessageServiceContract } from "@consensys/linea-sdk/dist/lib/contracts";
import { Contract } from "ethers";
import { groupBy } from "lodash";
import { HubPoolClient, SpokePoolClient } from "../../../clients";
import { CHAIN_MAX_BLOCK_LOOKBACK, CONTRACT_ADDRESSES } from "../../../common";
import { EventSearchConfig, Signer, convertFromWei, winston, CHAIN_IDs } from "../../../utils";
import { EventSearchConfig, Signer, convertFromWei, winston, CHAIN_IDs, ethers, BigNumber } from "../../../utils";
import { CrossChainMessage, FinalizerPromise } from "../../types";
import {
determineMessageType,
findMessageFromTokenBridge,
findMessageFromUsdcBridge,
findMessageSentEvents,
getBlockRangeByHoursOffsets,
getL1ToL2MessageStatusUsingCustomProvider,
initLineaSdk,
} from "./common";

// Temporary re-implementation of the SDK's `L2MessageServiceContract.getMessageStatus` functions that allow us to use
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
// our custom provider, with retry and caching logic, to get around the SDK's hardcoded logic to query events
// from 0 to "latest" which will not work on all RPC's.
async function getL1ToL2MessageStatusUsingCustomProvider(
messageService: L2MessageServiceContract,
messageHash: string,
l2Provider: ethers.providers.Provider
): Promise<OnChainMessageStatus> {
const l2Contract = new Contract(messageService.contract.address, messageService.contract.interface, l2Provider);
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
const status: BigNumber = await l2Contract.inboxL1L2MessageStatus(messageHash);
switch (status.toString()) {
nicholaspai marked this conversation as resolved.
Show resolved Hide resolved
case "0":
return OnChainMessageStatus.UNKNOWN;
case "1":
return OnChainMessageStatus.CLAIMABLE;
case "2":
return OnChainMessageStatus.CLAIMED;
}
}

export async function lineaL1ToL2Finalizer(
logger: winston.Logger,
signer: Signer,