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

Alert users when the network is busy #12268

Merged
merged 2 commits into from Jan 7, 2022
Merged

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Oct 1, 2021

When a lot of transactions are occurring on the network, such as during
an NFT drop, it drives gas fees up. When this happens, we want to not
only inform the user about this, but also dissuade them from using a
higher gas fee (as we have proved in testing that high gas fees can
cause bidding wars and exacerbate the situation).

The method for determining whether the network is "busy" is already
handled by GasFeeController, which exposes a networkCongestion
property within the gas fee estimate data. If this number exceeds 0.66 —
meaning that the current base fee is above the 66th percentile among the
base fees over the last several days — then we determine that the
network is "busy".

References

Fixes: #11307

Manual testing steps

There are two versions of this message: one for the "EIP-1559 V1" designs and one for the "EIP-1559 V2" designs. These designs impact the appearance of the confirm transaction screen and modal that appears when you edit the gas fee. You can switch from V1 to V2 locally by going into .metamaskrc and adding the following line:

EIP_1559_V2=1

Then re-running yarn start or yarn start:dev.

Once you've done this, attempt to send a transaction. Under the V1 design, you should see a message if the network is busy when you go to edit the gas fee. Under the V2 design, you should see a message if the network is busy right away on the confirm transaction screen.

What does it mean for the network to be busy? There isn't really a great way to see this because it depends on the base fee of the latest block (and the base fee of the last 20,000 blocks). That said, I made a dashboard that you can use to monitor current gas fees in realtime. It re-uses the same logic that the extension is using to determine network busyness, which is defined as when the current base fee ranks in the top third of all base fees over the last 20,000 blocks. I've provided this threshold on the dashboard. So, to test, you would wait until the current base fee is greater than this threshold. Once this happens and the base fee turns orange, try sending a transaction through the extension and you should see the "network busy" message. (Note: Based on recent base fees, this is likely to happen more often than not.)

Screencaps

eip_1559_v1_network_busy.mov
eip_1559_v2_network_busy.mov

@mcmire mcmire changed the title Alert users about high gas fees [WIP] Alert users about high gas fees Oct 1, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2021

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.

@@ -91,7 +91,7 @@ export default function EditGasDisplay({

useLayoutEffect(() => {
if (showAdvancedForm && scrollRef.current) {
scrollRef.current.scrollIntoView();
scrollRef.current.scrollIntoView?.();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added because the unit test I wrote for EditGasPopover choked on this. My guess is that this works differently in a jsdom environment than in a real environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still applicable, only I ended up writing a test for EditGasDisplay instead.

ui/hooks/useSafeGasEstimatePolling.test.js Outdated Show resolved Hide resolved
ui/store/actions.js Outdated Show resolved Hide resolved
ui/store/actions.js Outdated Show resolved Hide resolved
ui/pages/swaps/index.js Outdated Show resolved Hide resolved
ui/ducks/metamask/metamask.js Outdated Show resolved Hide resolved
@jpuri
Copy link
Contributor

jpuri commented Oct 5, 2021

Great work @mcmire , esp with test coverage.

@metamaskbot
Copy link
Collaborator

Builds ready [8d0a9bc]
Page Load Metrics (358 ± 44 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint2916373599244
domContentLoaded2816403499345
load2896403589244
domInteractive2816403499345

highlights:

storybook

@mcmire mcmire force-pushed the add-busy-network-warning branch 2 times, most recently from d8aa3f2 to a039c0e Compare November 3, 2021 20:41
package.json Outdated Show resolved Hide resolved
app/scripts/metamask-controller.js Outdated Show resolved Hide resolved
ui/ducks/metamask/metamask.js Outdated Show resolved Hide resolved
@mcmire mcmire changed the title [WIP] Alert users about high gas fees Alert users about high gas fees Nov 3, 2021
@mcmire mcmire marked this pull request as ready for review November 3, 2021 20:42
@mcmire mcmire requested a review from a team as a code owner November 3, 2021 20:42
@metamaskbot
Copy link
Collaborator

Builds ready [9a511a6]
Page Load Metrics (488 ± 52 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31269948710852
domContentLoaded30269847911254
load31069848810952
domInteractive30269847911254

highlights:

storybook

@metamaskbot
Copy link
Collaborator

Builds ready [596317b]
Page Load Metrics (1162 ± 76 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint631237282375180
domContentLoaded10311672116115876
load10311672116215876
domInteractive10311672116115876

highlights:

storybook

When a lot of transactions are occurring on the network, such as during
an NFT drop, it drives gas fees up. When this happens, we want to not
only inform the user about this, but also dissuade them from using a
higher gas fee (as we have proved in testing that high gas fees can
cause bidding wars and exacerbate the situation).

The method for determining whether the network is "busy" is already
handled by GasFeeController, which exposes a `networkCongestion`
property within the gas fee estimate data. If this number exceeds 0.66 —
meaning that the current base fee is above the 66th percentile among the
base fees over the last several days — then we determine that the
network is "busy".
@mcmire mcmire changed the title Alert users about high gas fees Alert users when the network is busy Jan 4, 2022
@@ -133,14 +133,6 @@ export default function EditGasDisplay({
return (
<div className="edit-gas-display">
<div className="edit-gas-display__content">
{warning && !isGasEstimatesLoading && (
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 opted to take off the warning prop because I didn't see it getting used. We can very easily just add a warning ourselves to this component.

@@ -24,24 +25,24 @@ const determineStatusInfo = (givenNetworkCongestion) => {
const color = GRADIENT_COLORS[colorIndex];
const sliderTickValue = colorIndex * 10;

if (networkCongestion <= 0.33) {
Copy link
Contributor Author

@mcmire mcmire Jan 4, 2022

Choose a reason for hiding this comment

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

I changed this slightly so that instead of:

  • not busy: <= 0.33
  • stable: > 0.33, <= 0.66
  • busy: > 0.66

It is now:

  • not busy: 0 up to 0.33
  • stable: 0.33 up to 0.66
  • busy: 0.66-

This is not strictly necessary to change, but given that I need to just test that the network is busy elsewhere, it made more sense in my head to say that the status changes to busy as soon as networkCongestion crosses 0.66 instead of as soon as it exceeds it. Happy to change this back though.

@@ -20,31 +20,31 @@ const renderComponent = ({ networkCongestion }) => {

describe('StatusSlider', () => {
it('should show "Not busy" when networkCongestion is less than 0.33', () => {
const { queryByText } = renderComponent({ networkCongestion: 0.32 });
Copy link
Contributor Author

@mcmire mcmire Jan 4, 2022

Choose a reason for hiding this comment

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

Apparently I forgot the difference between query* and get* 😆

At the same time all of these tests changed because the logic behind the slider changed.

export function getIsNetworkBusy(state) {
const gasFeeEstimates = getGasFeeEstimates(state);
return (
gasFeeEstimates?.networkCongestion >= NETWORK_CONGESTION_THRESHOLDS.BUSY
Copy link
Contributor Author

@mcmire mcmire Jan 4, 2022

Choose a reason for hiding this comment

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

Here's the corresponding busy check that I referenced here #12268 (comment)

@@ -105,6 +106,13 @@ const TransactionAlerts = ({
type="warning"
/>
)}
{isNetworkBusy ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This warning applies to the EIP-1559 V2 UI and will appear on the confirm transaction screen. It will NOT appear within the edit gas modal because we already have the status slider which indicates the status of the network.

@@ -1,172 +1,307 @@
import React from 'react';
Copy link
Contributor Author

@mcmire mcmire Jan 4, 2022

Choose a reason for hiding this comment

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

I opted to refactor these tests so that they're simpler and don't require us to recreate the Redux state so much. I can put these changes in another PR if necessary, but I will point out the additional check for isNetworkBusy regardless.

});
});

describe('if isNetworkBusy from useGasFeeContext is truthy', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here are the new tests for the isNetworkBusy warning.

@@ -10,8 +10,11 @@ import {
TRANSACTION_TYPES,
} from '../../shared/constants/transaction';
import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils';
import { getCurrentChainId, deprecatedGetCurrentNetworkId } from './selectors';
Copy link
Contributor Author

@mcmire mcmire Jan 4, 2022

Choose a reason for hiding this comment

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

The main change here is to have getSelectedAddress come from ui/selectors/selectors and not from ui/selectors. The previous change created a circular dependency between ui/selectors and ui/selectors/transactions, which prevented us from jest.mock'ing ui/selectors correctly in component tests.

import configureStore from '../../../store/store';
import EditGasDisplay from '.';

jest.mock('../../../selectors');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might have been the simplest component test file I've ever written 😆

@@ -156,6 +148,16 @@ export default function EditGasDisplay({
/>
</div>
)}
{isNetworkBusy ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This warning applies to the EIP-1559 V1 UI. Note that this warning appears within the edit gas modal, NOT the confirm transaction screen, unlike EIP-1559 V2. I could have added it to the confirm transaction screen, but it would be more work. Given that we are soon transitioning to the V2 UI I feel like this is an okay compromise for now, but happy to change if not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, in V@ as I understand we are showing network busy only on edit gas fee modal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In V2 it's slightly different — we are showing the network busy message on the confirm transaction screen, but not in the edit gas fee modal.

@metamaskbot
Copy link
Collaborator

Builds ready [0651d8b]
Page Load Metrics (1108 ± 40 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint621218339401192
domContentLoaded1025135511068340
load1025135511088440
domInteractive1025135511068340

highlights:

storybook

Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

LGTM

@mcmire mcmire merged commit 7b963ca into develop Jan 7, 2022
@mcmire mcmire deleted the add-busy-network-warning branch January 7, 2022 19:18
@github-actions github-actions bot locked and limited conversation to collaborators Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants