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

fix: LIT-3607 - Use StaticJsonRpcProvider to improve performance of RPC requests #537

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

MaximusHaximus
Copy link
Contributor

Reference issue - ethers-io/ethers.js#901 Cuts our RPC request time costs approximately in half by eliminating a sequential call to get chainId from every(!) contract call we make

Description

Replaced ethers JSONRPCProvider instances with StaticJSONRPCProvider
This eliminates unnecessary RPC calls to get chainId every time we use one of our contract methods.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Ran localtests against datil-dev, datil-test and cayenne

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

new ethers.providers.JsonRpcProvider(
this.config.rpcUrl || LIT_CHAINS['lit'].rpcUrls[0]
new ethers.providers.StaticJsonRpcProvider(
this.config.rpcUrl || RPC_URL_BY_NETWORK[this.config.litNetwork]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed a bug here; we were always using LIT_CHAINS['lit'] here. It just so happened that due to internal override logic inside of the contracts SDK this actually worked.

Copy link
Collaborator

@Ansonhkg Ansonhkg Jul 17, 2024

Choose a reason for hiding this comment

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

Should we do this in the constructor instead? so that this.config.rpcUrl is always defined,

eg:

    if (!this.config.rpcUrl) {
      this.config.rpcUrl = RPC_URL_BY_NETWORK[this.config.litNetwork];
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

…requests

Reference issue - ethers-io/ethers.js#901
Cuts our RPC request cost approx in half by eliminating a sequential call to get `chainId` from every(!) contract call we make
Copy link
Collaborator

@Ansonhkg Ansonhkg left a comment

Choose a reason for hiding this comment

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

This LGTM!

Should we merge this #538 into this? WDYT.?

UPDATE 1:

@FedericoAmura
Copy link
Contributor

Just tested this with the pkp mint demo and not only this saves the time on every contract call, it was also making that request in a loop every a few seconds. There is a massive bandwidth and rpc load save as every client would be making those constantly

Huge improvement! 🔥

@Ansonhkg Ansonhkg merged commit 66c6af0 into master Jul 24, 2024
4 checks passed
@Ansonhkg Ansonhkg deleted the LIT-3607-StaticJSONRPCProvider branch July 24, 2024 10:35
@Ansonhkg Ansonhkg mentioned this pull request Jul 24, 2024
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.

3 participants