Skip to content

chore: Mark all potential chainId runtime errors #1089

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dijanin-brat
Copy link
Contributor

Mark all potential chainId runtime errors so we can fix them easier later.

@dijanin-brat dijanin-brat self-assigned this Jun 19, 2025
Copy link
Contributor

@pxrl pxrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dijanin-brat. There seem to be a few ways we can mitigate most/all of these, though I'd love to find a way to ensure the caller is protected against this scenario without having to remember to check it manually.

Comment on lines 794 to 795
// @TODO This can throw an runtime error if chainId is wrong.
return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicholaspai For this case, do we want to specify in the UMIP that we revert to mainnet time in case that a destination SpokePool deployment is not available? That would permit us to handle this pretty gracefully.

Perhaps something like this:

Suggested change
// @TODO This can throw an runtime error if chainId is wrong.
return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
const [, endTimestamp] = bundleBlockTimestamps[deposit.destinationChainId] ?? bundleBlockTimestamps[this.hubChainId];
return deposit.fillDeadline < endTimestamp;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +816 to 817
// Because of this check, there is a good chance that _getFillStatusForDeposit will not throw an error.
.filter((chainId) => !_isChainDisabled(chainId) && spokePoolClients[chainId] !== undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think _isChainDisabled() will end up throwing because it assumes it's supplied with a valid chainId. So we might consider updating _isChainDisabled or isChainDisabled to first verify that the chain exists in the ConfigStoreClient (CHAIN_ID_INDICES) first, and if not, to return false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably err on adding an assert() to _isChainDisabled(), so we can explicitly specify that the error is: unsupported chainId (${chainId}).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, if the chain is not supported, we will throw this error anyway

if (indexForChain === -1) { throw new Error(Could not find chain ${chain} in chain ID list ${chainIdListForBundleEvaluationBlockNumbers}); }

I don't see the point of assert there bcs of this.

Comment on lines +1422 to 1426
// @TODO The function getBlockRangeForChain can throw an error if chainId is wrong.
// Look at getBlockRangeForChain implementation.
const destinationBlockRange = getBlockRangeForChain(blockRangesForChains, destinationChainId, chainIds);

// Only look for deposits that were mined before this bundle and that are newly expired.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here (and below) we use the bundle end block to resolve a timestamp, and then compare that against the fillDeadline. So if we are OK to fall back to the mainnet bundle timestamp then we might be able to replay that here. It looks like it'd require a little bit of refactoring, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be done in separate PR as well like this one #1089 (comment)

Comment on lines 793 to 796
return deposit.fillDeadline < bundleBlockTimestamps[deposit.destinationChainId][1];
const [, endTimestamp] =
bundleBlockTimestamps[deposit.destinationChainId] ?? bundleBlockTimestamps[this.clients.hubPoolClient.chainId];
return deposit.fillDeadline < endTimestamp;
Copy link
Contributor

@pxrl pxrl Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dijanin-brat OK to split this one out into a separate PR? It requires protocol clarification so we can't change it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1562,8 +1574,9 @@ export class BundleDataClient {
const unknownReasonInvalidFills: FillWithBlock[] = [];

bundleInvalidFillsV3.forEach((fill) => {
// @TODO This can throw an runtime error if chainId is wrong.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be OK to drop this now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants