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: fall back to bundled chainlist #23392

Merged
merged 13 commits into from
Oct 17, 2024
Merged

Conversation

legobeat
Copy link
Contributor

@legobeat legobeat commented Mar 8, 2024

Description

The list of known chains is fetched at runtime from https://chainid.network/chains.json and cached. There are some issues with the way this works:

  • MetaMask will not have a list of chains until online (if ever)
  • When the 24h cache timeout expires, the chainlist becomes unavailable

This PR addresses this by:

  • Refactoring out https://chainid.network/chains.json into constant CHAIN_SPEC_URL
  • Add new optional option allowStale to fetchWithCache. If set to true, it will falling back to return any entry instead of throwing an error when a request fail.
  • Set allowStale to true for all requests to CHAIN_SPEC_URL
  • Seed the fetch cache for CHAIN_SPEC_URL with eth-chainlist, which is the same data exposed via a published npm package.
    • Open for suggestions on if this should be bundled differently - maybe we want our own equivalent mirror?

While an improvement, this could still be further improved.

  • The bundled result could be used immediately in all cases without waiting for response
  • The cached data could be updated asynchronously in the background, without being prompted by user action

I currently consider these out-of-scope for this PR.

Or put more generally: Decoupling the fetching of the data from its use would be even better.
Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

github-actions bot commented Mar 8, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@legobeat legobeat force-pushed the bundled-chainlist branch from cebf9f3 to 68fb696 Compare March 8, 2024 10:19
@legobeat legobeat changed the title fall back to bundled chainlist fix: fall back to bundled chainlist Mar 8, 2024
@legobeat legobeat force-pushed the bundled-chainlist branch 3 times, most recently from a8d5e7a to c5e6d96 Compare March 8, 2024 10:44
@legobeat legobeat marked this pull request as ready for review March 8, 2024 23:43
@legobeat legobeat requested a review from a team as a code owner March 8, 2024 23:43
@legobeat legobeat force-pushed the bundled-chainlist branch 3 times, most recently from c6803f7 to a80c5de Compare March 12, 2024 09:44
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 65.99%. Comparing base (df218fa) to head (a7e126f).

Files Patch % Lines
app/scripts/metamask-controller.js 77.78% 2 Missing ⚠️
shared/lib/fetch-with-cache.ts 60.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #23392      +/-   ##
===========================================
- Coverage    66.00%   65.99%   -0.00%     
===========================================
  Files         1348     1348              
  Lines        52503    52512       +9     
  Branches     13494    13492       -2     
===========================================
+ Hits         34651    34655       +4     
- Misses       17852    17857       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@legobeat legobeat force-pushed the bundled-chainlist branch 9 times, most recently from f55d571 to 3c0ca43 Compare March 19, 2024 00:20
@naugtur
Copy link
Contributor

naugtur commented Mar 19, 2024

things to consider here:

  • bundle size may be a concern (0.5MB package size)
  • security concern - what's the risk of it containing malformed or malicious data?

possible alternatives:

  • ship our own copy of current state of the online endpoint and put it in MM as an asset or as a package we publish ourselves.

@Gudahtt any ideas who's owning this bit and could have opinions?

@legobeat legobeat force-pushed the bundled-chainlist branch 2 times, most recently from dd35f12 to 0233e33 Compare March 19, 2024 21:15
@legobeat legobeat force-pushed the bundled-chainlist branch from 0233e33 to 6e421c2 Compare March 27, 2024 05:22
@legobeat legobeat requested review from a team as code owners March 27, 2024 05:22
@legobeat legobeat force-pushed the bundled-chainlist branch 2 times, most recently from 42a293c to 84bfb7d Compare March 27, 2024 23:44
@legobeat legobeat force-pushed the bundled-chainlist branch 6 times, most recently from d1b8315 to 900e425 Compare October 15, 2024 22:49
@legobeat legobeat added this pull request to the merge queue Oct 17, 2024
Merged via the queue into MetaMask:develop with commit 01ea106 Oct 17, 2024
76 checks passed
@legobeat legobeat deleted the bundled-chainlist branch October 17, 2024 04:39
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2024
@gauthierpetetin gauthierpetetin added release-12.7.0 Issue or pull request that will be included in release 12.7.0 release-12.6.0 Issue or pull request that will be included in release 12.6.0 and removed release-12.7.0 Issue or pull request that will be included in release 12.7.0 labels Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.6.0 Issue or pull request that will be included in release 12.6.0 team-confirmations Push issues to confirmations team team-security
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants