diff --git a/src/finalizer/index.ts b/src/finalizer/index.ts index c8c1fca53..3dcacbae8 100644 --- a/src/finalizer/index.ts +++ b/src/finalizer/index.ts @@ -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, @@ -16,6 +17,7 @@ import { import { DataworkerConfig } from "../dataworker/DataworkerConfig"; import { SpokePoolClientsByChain } from "../interfaces"; import { + CHAIN_IDs, Signer, blockExplorerLink, config, @@ -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, @@ -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. diff --git a/src/finalizer/utils/linea/l1ToL2.ts b/src/finalizer/utils/linea/l1ToL2.ts index a14658e2d..c2575ccc7 100644 --- a/src/finalizer/utils/linea/l1ToL2.ts +++ b/src/finalizer/utils/linea/l1ToL2.ts @@ -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"; @@ -24,7 +23,7 @@ export async function lineaL1ToL2Finalizer( _spokePoolClient: SpokePoolClient, l1ToL2AddressesToFinalize: string[] ): Promise { - 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(); @@ -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.