Skip to content

Fix fallback gas estimation#19746

Merged
Gudahtt merged 4 commits intodevelopfrom
fix-non-EIP-1559-gas-estimates
Jun 26, 2023
Merged

Fix fallback gas estimation#19746
Gudahtt merged 4 commits intodevelopfrom
fix-non-EIP-1559-gas-estimates

Conversation

@Gudahtt
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt commented Jun 23, 2023

Explanation

Our fallback gas estimation was failing due to a bug in the @metamask/controller-utils package. This was causing gas estimation to fail completely on certain networks (those not supported by our gas estimation APIs and non EIP-1559 compatibile), and it was causing the fallback gas estimation operation (in case our API was down) to fail across all networks.

Additionally, the legacy gas API has been disabled as part of this PR. This was required in order to cover this functionality with e2e tests (if the legacy gas API was enabled, that would take precedence over the code this PR is fixing).

I tried removing the legacy gas API in a separate PR, but that depends upon this bug fix, so they need to be changed together.

A few test IDs were added for the purpose of helping with writing the e2e tests.

Fixes #19735

Manual Testing Steps

Switch to the BNB network, and start the send or swaps flow. You should see an error like the one shown in the referenced issue if you're testing with develop or the v10.33.0 release candidate. With this PR, the error no longer appears.

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@Gudahtt Gudahtt requested a review from a team as a code owner June 23, 2023 21:26
@Gudahtt Gudahtt requested a review from hmalik88 June 23, 2023 21:26
@Gudahtt Gudahtt force-pushed the fix-non-EIP-1559-gas-estimates branch from 8478d3c to 7126883 Compare June 23, 2023 21:28
@Gudahtt
Copy link
Copy Markdown
Member Author

Gudahtt commented Jun 23, 2023

@metamaskbot update-policies

@metamaskbot
Copy link
Copy Markdown
Collaborator

No policy changes

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [7126883]
Page Load Metrics (1750 ± 70 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1132311593517
domContentLoaded15262115175014570
load15272115175014570
domInteractive15262115175014570
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: -16 bytes

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 23, 2023

Codecov Report

Merging #19746 (faa1753) into develop (3df690b) will increase coverage by 0.01%.
The diff coverage is 88.89%.

@@             Coverage Diff             @@
##           develop   #19746      +/-   ##
===========================================
+ Coverage    69.85%   69.86%   +0.01%     
===========================================
  Files          980      980              
  Lines        36911    36913       +2     
  Branches      9909     9909              
===========================================
+ Hits         25782    25786       +4     
+ Misses       11129    11127       -2     
Impacted Files Coverage Δ
app/scripts/metamask-controller.js 65.75% <0.00%> (+0.12%) ⬆️
...n-detail-item/transaction-detail-item.component.js 100.00% <ø> (ø)
...nts/app/confirm-gas-display/confirm-gas-display.js 100.00% <100.00%> (ø)
...m-legacy-gas-display/confirm-legacy-gas-display.js 93.55% <100.00%> (+0.22%) ⬆️
...omponents/app/gas-details-item/gas-details-item.js 100.00% <100.00%> (ø)

@Gudahtt Gudahtt force-pushed the fix-non-EIP-1559-gas-estimates branch 2 times, most recently from 569c56b to 962fec1 Compare June 26, 2023 12:33
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [962fec1]
Page Load Metrics (1435 ± 27 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint105170124178
domContentLoaded1357158514355727
load1357158514355727
domInteractive1357158514355727
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 bytes
  • ui: 0 bytes
  • common: -16 bytes

brad-decker
brad-decker previously approved these changes Jun 26, 2023
@Gudahtt Gudahtt force-pushed the fix-non-EIP-1559-gas-estimates branch from 962fec1 to 142f264 Compare June 26, 2023 17:41
Gudahtt added 2 commits June 26, 2023 15:14
Our fallback gas estimation was failing due to a bug in the
`@metamask/controller-utils` package. This was causing gas estimation
to fail completely on certain networks (those not supported by our gas
estimation APIs and non EIP-1559 compatibile), and it was causing the
fallback gas estimation operation (in case our API was down) to fail
across all networks.

Fixes #19735
E2E tests have been added to capture gas estimation. Cases are added
for our API, for the fallback estimate, and for non-EIP-1559 estimates.

As part of this work, the legacy gas API had to be disabled. This was
being used in e2e tests but was dead code in production. It needed to
be disabled to ensure the code under test was reachable.
@Gudahtt Gudahtt force-pushed the fix-non-EIP-1559-gas-estimates branch from 142f264 to cde2190 Compare June 26, 2023 17:44
});

describe('Send on a network that is not EIP-1559 compatible', function () {
it('show expected gas defaults', async function () {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test was failing prior to this PR

hardfork: 'london',
};

describe('Send on a network that is EIP-1559 compatible', function () {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These tests were already passing (both before and after this PR), but I included them here just to have all four code paths covered in the same file.

@Gudahtt
Copy link
Copy Markdown
Member Author

Gudahtt commented Jun 26, 2023

This has been updated with e2e tests

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [faa1753]
Page Load Metrics (1675 ± 64 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1143181534521
domContentLoaded14211955167513464
load14221955167513464
domInteractive14211954167513464
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -124 bytes
  • ui: 384 bytes
  • common: -16 bytes

Copy link
Copy Markdown
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

LGTM, nice work on the e2e tests

EIP1559APIEndpoint: `${gasApiBaseUrl}/networks/<chain_id>/suggestedGasFees`,
getCurrentNetworkLegacyGasAPICompatibility: () => {
const { chainId } = this.networkController.state.providerConfig;
return process.env.IN_TEST || chainId === CHAIN_IDS.MAINNET;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've since discovered that this legacy gas endpoint remains useful for non-EIP1559 chains that our APIs support (e.g. BSC and Polygon). But we can restore this for those chains in a later PR, they weren't using it yet anyway.

@Gudahtt Gudahtt merged commit ec7e7fd into develop Jun 26, 2023
@Gudahtt Gudahtt deleted the fix-non-EIP-1559-gas-estimates branch June 26, 2023 18:43
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 26, 2023
@metamaskbot metamaskbot added the release-10.34.0 Issue or pull request that will be included in release 10.34.0 label Jun 26, 2023
@danjm danjm removed the release-10.34.0 Issue or pull request that will be included in release 10.34.0 label Jun 27, 2023
@danjm danjm added release-blocker This bug is blocking the next release release-10.33.0 Issue or pull request that will be included in release 10.33.0 labels Jun 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-10.33.0 Issue or pull request that will be included in release 10.33.0 release-blocker This bug is blocking the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gas fee controller failing to get price estimates on BNB after bump to v6

5 participants