Skip to content

Commit

Permalink
fix(finalizer): polygon (#1538)
Browse files Browse the repository at this point in the history
* fix(finalizer): polygon

* improve(finalizer): Filter USDC from arbitrum and op stack finalizers (#1539)

* fix(Finalizer): Dedup transaction hash list when creating list of transactions to query for CCTP l2->l1 transactions

We’re not de-duping the set of txn receipts to query for CCTP l2 to l1 deposits, but we do this in the l1 to l2 direciton.

What’s unique for L2 to L1 is we look for SpokePool.TokensBridged() events but we forget there might be multiple of these in the same block

* improve(finalizer): Increase margin of error for finalizer to cover for multiple day downtime

Currently the finalizer is optimized for run-time speed and tries to look over as short of an event search window as possible.

However, this provides very little margin for error in case the finalizer goes down for multiple days.

* Update l2ToL1.ts

* add arbitrum/optimism filters

* Update l2ToL1.ts

* Update arbitrum.ts

---------

Co-authored-by: nicholaspai <[email protected]>
  • Loading branch information
james-a-morris and nicholaspai authored May 20, 2024
1 parent 13ec536 commit 2af75df
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 30 deletions.
29 changes: 19 additions & 10 deletions src/finalizer/utils/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
getRedisCache,
getBlockForTimestamp,
getL1TokenInfo,
compareAddressesSimple,
TOKEN_SYMBOLS_MAP,
} from "../../utils";
import { TokensBridged } from "../../interfaces";
import { HubPoolClient, SpokePoolClient } from "../../clients";
Expand Down Expand Up @@ -139,17 +141,24 @@ async function getAllMessageStatuses(
// This is important for bridge transactions containing multiple events.
const logIndexesForMessage = getUniqueLogIndex(tokensBridged);
return (
await Promise.all(
tokensBridged.map((e, i) => getMessageOutboxStatusAndProof(logger, e, mainnetSigner, logIndexesForMessage[i]))
(
await Promise.all(
tokensBridged.map((e, i) => getMessageOutboxStatusAndProof(logger, e, mainnetSigner, logIndexesForMessage[i]))
)
)
)
.map((result, i) => {
return {
...result,
info: tokensBridged[i],
};
})
.filter((result) => result.message !== undefined);
.map((result, i) => {
return {
...result,
info: tokensBridged[i],
};
})
// USDC withdrawals for Arbitrum should be finalized via the CCTP Finalizer.
.filter(
(result) =>
result.message !== undefined &&
!compareAddressesSimple(result.info.l2TokenAddress, TOKEN_SYMBOLS_MAP["_USDC"].addresses[CHAIN_ID])
)
);
}

async function getMessageOutboxStatusAndProof(
Expand Down
4 changes: 1 addition & 3 deletions src/finalizer/utils/linea/l1ToL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export async function lineaL1ToL2Finalizer(
);

// 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.
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l1ChainId, 24, 0);
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l1ChainId, 24 * 7, 0);
logger.debug({
at: "Finalizer#LineaL1ToL2Finalizer",
message: "Linea MessageSent event filter",
Expand Down
5 changes: 2 additions & 3 deletions src/finalizer/utils/linea/l2ToL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ export async function lineaL2ToL1Finalizer(
const getMessagesWithStatusByTxHash = makeGetMessagesWithStatusByTxHash(l2Contract, l1ClaimingService);

// Optimize block range for querying relevant source events on L2.
// We want to conservatively query for events that are between 8 and 72 hours old
// because Linea L2->L1 messages are claimable after 6 - 32 hours
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l2ChainId, 72, 8);
// Linea L2->L1 messages are claimable after 6 - 32 hours
const { fromBlock, toBlock } = await getBlockRangeByHoursOffsets(l2ChainId, 24 * 8, 6);
logger.debug({
at: "Finalizer#LineaL2ToL1Finalizer",
message: "Linea TokensBridged event filter",
Expand Down
40 changes: 26 additions & 14 deletions src/finalizer/utils/opStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { HubPoolClient, SpokePoolClient } from "../../clients";
import { TokensBridged } from "../../interfaces";
import {
BigNumber,
CHAIN_IDs,
chainIsOPStack,
compareAddressesSimple,
convertFromWei,
getBlockForTimestamp,
getCachedProvider,
Expand All @@ -16,6 +18,7 @@ import {
getUniqueLogIndex,
groupObjectCountsByProp,
Signer,
TOKEN_SYMBOLS_MAP,
winston,
} from "../../utils";
import { Multicall2Call } from "../../common";
Expand Down Expand Up @@ -129,22 +132,31 @@ async function getCrossChainMessages(
const logIndexesForMessage = getUniqueLogIndex(tokensBridged);

return (
await Promise.all(
tokensBridged.map(
async (l2Event, i) =>
(
await crossChainMessenger.getMessagesByTransaction(l2Event.transactionHash, {
direction: optimismSDK.MessageDirection.L2_TO_L1,
})
)[logIndexesForMessage[i]]
(
await Promise.all(
tokensBridged.map(
async (l2Event, i) =>
(
await crossChainMessenger.getMessagesByTransaction(l2Event.transactionHash, {
direction: optimismSDK.MessageDirection.L2_TO_L1,
})
)[logIndexesForMessage[i]]
)
)
)
).map((message, i) => {
return {
message,
event: tokensBridged[i],
};
});
.map((message, i) => {
return {
message,
event: tokensBridged[i],
};
})
// USDC withdrawals for Base and Optimism should be finalized via the CCTP Finalizer.
.filter(
(e) =>
!compareAddressesSimple(e.event.l2TokenAddress, TOKEN_SYMBOLS_MAP["_USDC"].addresses[_chainId]) ||
!(_chainId === CHAIN_IDs.BASE || _chainId === CHAIN_IDs.OPTIMISM)
)
);
}

async function getMessageStatuses(
Expand Down
8 changes: 8 additions & 0 deletions src/finalizer/utils/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
getRedisCache,
getBlockForTimestamp,
getL1TokenInfo,
compareAddressesSimple,
TOKEN_SYMBOLS_MAP,
} from "../../utils";
import { EthersError, TokensBridged } from "../../interfaces";
import { HubPoolClient, SpokePoolClient } from "../../clients";
Expand Down Expand Up @@ -110,6 +112,12 @@ async function getFinalizableTransactions(
const exitStatus = await Promise.all(
checkpointedTokensBridged.map(async (_, i) => {
const payload = payloads[i];
const { chainId, l2TokenAddress } = tokensBridged[i];

if (compareAddressesSimple(l2TokenAddress, TOKEN_SYMBOLS_MAP._USDC.addresses[chainId])) {
return { status: "NON_CANONICAL_BRIDGE" };
}

try {
// If we can estimate gas for exit transaction call, then we can exit the burn tx, otherwise its likely
// been processed. Note this will capture mislabel some exit txns that fail for other reasons as "exit
Expand Down

0 comments on commit 2af75df

Please sign in to comment.