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(LineaFinalizer): Force RPC calls through custom provider #1931

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

nicholaspai
Copy link
Member

The functions that we use in the Linea SDK make event queries from block 0 to "latest" by default which means that some of our RPC's can't be used with the Finalizer. Additionally, we're missing out our custom provider retry and caching logic.

This PR removes all instances of making RPC calls via the Linea SDK's provider and replace with making the same call through our custom Provider.

The latest Linea SDK code looks like it'll support injecting custom providers but its not released yet on NPM. So this code should be removed eventually once a later SDK version is released.

The functions that we use in the Linea SDK make event queries from block 0 to "latest" by default which means that some of our RPC's can't be used with the Finalizer. Additionally, we're missing out our custom provider retry and caching logic.

This PR removes all instances of making RPC calls via the Linea SDK's provider and replace with making the same call through our custom Provider.

The latest [Linea SDK](https://github.com/Consensys/linea-monorepo/blob/3fbe660683a318b6fa1b63ec518f948791536352/sdk/src/sdk/LineaSDK.ts#L56) code looks like it'll support injecting custom providers but its not released yet on NPM. So this code should be removed eventually once a later SDK version is released.
@nicholaspai nicholaspai marked this pull request as draft November 26, 2024 17:54
@nicholaspai nicholaspai marked this pull request as ready for review November 26, 2024 19:27
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.

No showstoppers for me here. I do worry a bit about the long-term maintainability of this though. Feels like we need to upstream some of this feedback.

Comment on lines +141 to +145
return new Contract(
l1ClaimingService.l2Contract.contract.address,
l1ClaimingService.l2Contract.contract.interface,
l2Provider
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this alternatively work?

Suggested change
return new Contract(
l1ClaimingService.l2Contract.contract.address,
l1ClaimingService.l2Contract.contract.interface,
l2Provider
);
return l1ClaimingService.l2Contract.contract.connect(l2Provider);

Comment on lines +147 to +156
export function getL1MessageServiceContractFromL1ClaimingService(
l1ClaimingService: L1ClaimingService,
l1Provider: ethers.providers.Provider
): Contract {
return new Contract(
l1ClaimingService.l1Contract.contract.address,
l1ClaimingService.l1Contract.contract.interface,
l1Provider
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

Comment on lines +19 to +22
// Normally we avoid importing directly from a node_modules' /dist package but we need access to some
// of the internal classes and functions in order to replicate SDK logic so that we can by pass hardcoded
// ethers.Provider instances and use our own custom provider instead.
import { L2MessageServiceContract } from "@consensys/linea-sdk/dist/lib/contracts";
Copy link
Contributor

Choose a reason for hiding this comment

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

wdyt about exporting these from a new file, so we can contain it and only have to document it there? i.e. src/finalizer/utils/linea/import.ts or something.

messageHash: string,
l2Provider: ethers.providers.Provider
): Promise<OnChainMessageStatus> {
const l2Contract = new Contract(messageService.contract.address, messageService.contract.interface, l2Provider);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also wondering if you can just connect the provider to the existing contract, but not sure whether it might be some weird type.

Suggested change
const l2Contract = new Contract(messageService.contract.address, messageService.contract.interface, l2Provider);
const l2Contract = messageService.contract.connect(l2Provider);

Copy link
Contributor

@bmzig bmzig left a comment

Choose a reason for hiding this comment

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

This looks good to me. Have you been able to finalize a L2 -> L1 message?

@nicholaspai
Copy link
Member Author

This looks good to me. Have you been able to finalize a L2 -> L1 message?

I haven't been able to time it well. I think one way to do it is i can temporarily pause the production finalizer for linea and run this locally.

Copy link
Contributor

@james-a-morris james-a-morris left a comment

Choose a reason for hiding this comment

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

This makes sense but I think we should avoid accessing the Linea package in an unintended way. We've forked/patched packages before so that they play nicely with our imports - this could be a viable workaround.

Otherwise there's nothing that stands out - I'll approve pending my comments

@@ -209,6 +210,7 @@ export async function arbStackFinalizer(
logger.debug({
at: `Finalizer#${networkName}Finalizer`,
message: `Withdrawal event for ${amountFromWei} of ${l1TokenInfo.symbol} is too recent to finalize`,
timeUntilFinalization: `${((event.blockNumber - latestBlockToFinalize) * l2BlockTime) / 60 / 60}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we want to floor this? Could be good for readability to at least toFixed() this output to keep the logs clean

Comment on lines +25 to +27
import { L1MessageServiceContract, L2MessageServiceContract } from "@consensys/linea-sdk/dist/lib/contracts";
import { L1ClaimingService } from "@consensys/linea-sdk/dist/lib/sdk/claiming/L1ClaimingService";
import { MessageSentEvent } from "@consensys/linea-sdk/dist/typechain/L2MessageService";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the only location we need these imports? Could we make a patchfile to have these vars be exported?

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.

4 participants