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 speed-up/cancel: don't update existing transaction data #14355

Merged
merged 5 commits into from
Apr 14, 2022

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Apr 5, 2022

Fixes #14284

Explanation:

EIP-1559 v2 introduced new logic for speed up and cancellation. This new logic updates metamask state data of the existing transaction (the one being replaced / "sped up" / "cancelled"). We should not do this. Instead, we should use the data of the existing transaction (in particular the nonce) to create an entirely new transaction.

The error was caught because of the new transaction update methods introduced in #13646. Those methods (correctly) throw an error when attempting to update a transaction that is not in an "unapproved" state.

This PR fixes this by maintaining transaction data for speed ups and cancels in front-end / react state, instead of modifying the background transaction.

@danjm danjm requested a review from a team as a code owner April 5, 2022 12:13
@danjm danjm requested a review from mcmire April 5, 2022 12:13
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2022

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.

@jpuri
Copy link
Contributor

jpuri commented Apr 5, 2022

Hi @danjm : we may need to do more code cleanup. I will run this branch locally and check.

@seaona
Copy link
Contributor

seaona commented Apr 6, 2022

@danjm is this addressing this reported error too? (is it the same?) #14341

@jpuri
Copy link
Contributor

jpuri commented Apr 6, 2022

@danjm is this addressing this reported error too? (is it the same?) #14341

@seaona : I do not think its is fixing this issue as this error is in EIP-1559 V2 implementation.

minimumGasLimit,
editGasMode,
setRetryTxMeta,
);
return (
<GasFeeContext.Provider value={gasFeeDetails}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @danjm , I would prefer to see 2 changes in this PR:

  1. Move logic const [retryTxMeta, setRetryTxMeta] = useState({ to useGasFeeInputs hook as that is place where all logic of this context lies. I would avoid passing setRetryTxMeta down to 2 levels.
  2. Remove previous gas details that I added here: https://github.com/MetaMask/metamask-extension/blob/develop/ui/hooks/gasFeeInput/useTransactionFunctions.js#L44 they are redundant now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jpuri I just pushed a commit for your first suggestion.

For the second suggestion, are previous gas params still needed for this code to work -> https://github.com/MetaMask/metamask-extension/blob/develop/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js#L109

useEffect(() => {
    // For cancel and speed-up medium / high option is disabled if
    // gas used in transaction + 10% is greater tham estimate
    if (
      (editGasMode === EDIT_GAS_MODES.CANCEL ||
        editGasMode === EDIT_GAS_MODES.SPEED_UP) &&
      (priorityLevel === PRIORITY_LEVELS.MEDIUM ||
        priorityLevel === PRIORITY_LEVELS.HIGH)
    ) {
      const estimateGreater = !gasEstimateGreaterThanGasUsedPlusTenPercent(
        transaction.previousGas || transaction.txParams,
        gasFeeEstimates,
        priorityLevel,
      );
      setEstimateGreaterThanGasUse(estimateGreater);
    }
  }, [editGasMode, gasFeeEstimates, priorityLevel, transaction]);

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking may be we can use this field _transaction.originalGasEstimate we need previousGas to derive new estimate type Plus 10 Percent for cancel and speedup transactions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, originalGasEstimate is just the gas limit

I think previousGas might be needed

@danjm
Copy link
Contributor Author

danjm commented Apr 6, 2022

@seaona That might be related... not sure. We should investigate

@jpuri
Copy link
Contributor

jpuri commented Apr 7, 2022

@danjm : changes look good, I added small feedback here. Also build breaking.

jpuri
jpuri previously approved these changes Apr 8, 2022
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 except breaking build.

jpuri
jpuri previously approved these changes Apr 12, 2022
jpuri
jpuri previously approved these changes Apr 14, 2022

expect(
screen.queryAllByTitle(`${EXPECTED_ETH_FEE_2} ETH`).length,
).toBeGreaterThan(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@metamaskbot
Copy link
Collaborator

Builds ready [8ee6553]
Page Load Metrics (1338 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint841288164258124
domContentLoaded11811683132411254
load12001694133811455
domInteractive11811683132411254

highlights:

storybook

@danjm danjm merged commit b7b041c into develop Apr 14, 2022
@danjm danjm deleted the fix-speedup-v10.13.0 branch April 14, 2022 15:50
@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot speed up/cancel type 2 transaction
5 participants