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(finalizer): Inject addresses into L1ToL2 finalizer #1335

Merged
merged 19 commits into from
Mar 21, 2024
Merged
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
30 changes: 30 additions & 0 deletions src/finalizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getAddress } from "ethers/lib/utils";
import { groupBy, uniq } from "lodash";
import { AugmentedTransaction, HubPoolClient, MultiCallerClient, TransactionClient } from "../clients";
import {
CONTRACT_ADDRESSES,
Clients,
FINALIZER_TOKENBRIDGE_LOOKBACK,
Multicall2Call,
Expand All @@ -16,6 +17,7 @@ import {
import { DataworkerConfig } from "../dataworker/DataworkerConfig";
import { SpokePoolClientsByChain } from "../interfaces";
import {
CHAIN_IDs,
Signer,
blockExplorerLink,
config,
Expand Down Expand Up @@ -72,6 +74,17 @@ const chainFinalizerOverrides: { [chainId: number]: ChainFinalizer[] } = {
59140: [lineaL2ToL1Finalizer],
};

function enrichL1ToL2AddressesToFinalize(l1ToL2AddressesToFinalize: string[], addressesToEnsure: string[]): string[] {
const resultingAddresses = l1ToL2AddressesToFinalize.slice().map(getAddress);
for (const address of addressesToEnsure) {
const checksummedAddress = getAddress(address);
if (!resultingAddresses.includes(checksummedAddress)) {
resultingAddresses.push(checksummedAddress);
}
}
return resultingAddresses;
}

export async function finalize(
logger: winston.Logger,
hubSigner: Signer,
Expand Down Expand Up @@ -109,6 +122,23 @@ export async function finalize(

const network = getNetworkName(chainId);

// For certain chains we always want to track certain addresses for finalization:
// LineaL1ToL2: Always track HubPool, AtomicDepositor, LineaSpokePool. HubPool sends messages and tokens to the
// SpokePool, while the relayer rebalances ETH via the AtomicDepositor
if (chainId === hubChainId) {
if (chainId !== CHAIN_IDs.MAINNET) {
logger.warn({
at: "Finalizer",
message: "Testnet Finalizer: skipping finalizations where from or to address is set to AtomicDepositor",
});
}
l1ToL2AddressesToFinalize = enrichL1ToL2AddressesToFinalize(l1ToL2AddressesToFinalize, [
hubPoolClient.hubPool.address,
spokePoolClients[hubChainId === CHAIN_IDs.MAINNET ? CHAIN_IDs.LINEA : CHAIN_IDs.LINEA_GOERLI].spokePool.address,
CONTRACT_ADDRESSES[hubChainId]?.atomicDepositor?.address,
]);
}

// We can subloop through the finalizers for each chain, and then execute the finalizer. For now, the
// main reason for this is related to CCTP finalizations. We want to run the CCTP finalizer AND the
// normal finalizer for each chain. This is going to cause an overlap of finalization attempts on USDC.
Expand Down
9 changes: 1 addition & 8 deletions src/finalizer/utils/linea/l1ToL2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { utils as sdkUtils } from "@across-protocol/sdk-v2";
import { OnChainMessageStatus } from "@consensys/linea-sdk";
import { Contract } from "ethers";
import { getAddress } from "ethers/lib/utils";
import { groupBy } from "lodash";
import { HubPoolClient, SpokePoolClient } from "../../../clients";
import { CHAIN_MAX_BLOCK_LOOKBACK, CONTRACT_ADDRESSES } from "../../../common";
Expand All @@ -24,7 +23,7 @@ export async function lineaL1ToL2Finalizer(
_spokePoolClient: SpokePoolClient,
l1ToL2AddressesToFinalize: string[]
): Promise<FinalizerPromise> {
const [l1ChainId, hubPoolAddress] = [hubPoolClient.chainId, hubPoolClient.hubPool.address];
const [l1ChainId] = [hubPoolClient.chainId, hubPoolClient.hubPool.address];
const l2ChainId = l1ChainId === 1 ? 59144 : 59140;
const lineaSdk = initLineaSdk(l1ChainId, l2ChainId);
const l2MessageServiceContract = lineaSdk.getL2Contract();
Expand All @@ -40,12 +39,6 @@ export async function lineaL1ToL2Finalizer(
hubPoolClient.hubPool.provider
);

// We always want to make sure that the l1ToL2AddressesToFinalize array contains
// the HubPool address, so we can finalize any pending messages sent from the HubPool.
if (!l1ToL2AddressesToFinalize.includes(getAddress(hubPoolAddress))) {
l1ToL2AddressesToFinalize.push(hubPoolAddress);
}

// Optimize block range for querying Linea's MessageSent events on L1.
// We want to conservatively query for events that are between 0 and 24 hours old
// because Linea L1->L2 messages are claimable after ~20 mins.
Expand Down
Loading