Skip to content

Commit e8ce475

Browse files
committed
fix: prioritize EVM chains when resolving chainId collisions
ChainId can have collisions across chain families (e.g., both Ethereum and Aptos have chainId=1). Updated resolveToInternalId to collect all matches and prioritize EVM chains, since by-chain-id endpoints are typically used for EVM chain IDs. This fixes the issue where /lanes/by-chain-id/1/43114 was incorrectly resolving to Aptos instead of Ethereum.
1 parent 739c343 commit e8ce475

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/lib/ccip/services/lane-data.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,20 +590,40 @@ export class LaneDataService {
590590
}
591591

592592
// Search through chains to find matching chain_id or selector
593-
for (const [internalId, chainConfig] of Object.entries(chainsReferenceData)) {
594-
if (inputKeyType === "chainId") {
595-
// Try to match by numeric chain ID
593+
if (inputKeyType === "chainId") {
594+
// Collect all matching chains (chainId can have collisions across chain families)
595+
const matches: Array<{ internalId: string; chainType: ChainType; chainFamily: ChainFamily }> = []
596+
597+
for (const [internalId] of Object.entries(chainsReferenceData)) {
596598
try {
597599
const supportedChain = directoryToSupportedChain(internalId)
598600
const chainId = getChainId(supportedChain)
599601
if (chainId && chainId.toString() === identifier) {
600-
return internalId
602+
const { chainType, chainFamily } = getChainTypeAndFamily(supportedChain)
603+
matches.push({ internalId, chainType, chainFamily })
601604
}
602605
} catch {
603606
// Skip chains that can't be resolved
604607
}
605-
} else if (inputKeyType === "selector") {
606-
// Match by selector
608+
}
609+
610+
if (matches.length === 0) {
611+
return null
612+
}
613+
614+
// Prioritize EVM chains since by-chain-id is typically used for EVM chain IDs
615+
const evmMatch = matches.find((m) => m.chainFamily === "evm")
616+
if (evmMatch) {
617+
return evmMatch.internalId
618+
}
619+
620+
// Fall back to first match if no EVM chain found
621+
return matches[0].internalId
622+
}
623+
624+
// For selector, there should be no collisions
625+
for (const [internalId, chainConfig] of Object.entries(chainsReferenceData)) {
626+
if (inputKeyType === "selector") {
607627
if (chainConfig.chainSelector === identifier) {
608628
return internalId
609629
}

0 commit comments

Comments
 (0)