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 default gas race condition #8490

Merged
merged 1 commit into from
May 1, 2020
Merged

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented May 1, 2020

A race condition exists where after adding an unapproved transaction, it could be mutated and then replaced when the default gas parameters are set. This happens because the transaction is added to state and broadcast before the default gas parameters are set, because calculating the default gas parameters to use takes some time. Once they've been calculated, the false assumption was made that the transaction hadn't changed.

The method responsible for setting the default gas now retrieves an up-to-date copy of txMeta, and conditionally sets the defaults only if they haven't yet been set.

This race condition was introduced in #2962, though that PR also added a loading screen that avoided this issue by preventing the user from interacting with the transaction until after the gas had been estimated. Unfortunately this loading screen was not carried forward to the new UI.

@Gudahtt
Copy link
Member Author

Gudahtt commented May 1, 2020

This depends upon #8489

@Gudahtt
Copy link
Member Author

Gudahtt commented May 1, 2020

Apparently I broke something. Investigating it now. Edit: I had accidentally changed how an estimateGas failure was handled - this has now been fixed.

I do think this solution is sound in principle at least. Though preventing interactions with the transaction in the UI while the default gas is loading would be ideal as well.

@Gudahtt Gudahtt force-pushed the fix-default-gas-race-condition branch from 4c764ec to 27b6b2c Compare May 1, 2020 03:51
@kumavis
Copy link
Member

kumavis commented May 1, 2020

seems like we need some rxjs flow that ignores stale values

@metamaskbot
Copy link
Collaborator

Builds ready [27b6b2c]
Page Load Metrics (692 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint338642147
domContentLoaded3887956907838
load3947976927837
domInteractive3887956907938

@metamaskbot
Copy link
Collaborator

Builds ready [27b6b2c]
Page Load Metrics (651 ± 17 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint309142189
domContentLoaded5977326503617
load5997346513617
domInteractive5977316503617

@metamaskbot
Copy link
Collaborator

Builds ready [27b6b2c]
Page Load Metrics (674 ± 25 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint308037105
domContentLoaded5977736725225
load5997756745225
domInteractive5977736725225

@metamaskbot
Copy link
Collaborator

Builds ready [27b6b2c]
Page Load Metrics (660 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint328240105
domContentLoaded3617996587737
load3638016607837
domInteractive3617996587737

@metamaskbot
Copy link
Collaborator

Builds ready [27b6b2c]
Page Load Metrics (639 ± 15 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint308738126
domContentLoaded6037456373115
load6057466393215
domInteractive6037456373115

@Gudahtt Gudahtt force-pushed the fix-default-gas-race-condition branch 2 times, most recently from e67bc95 to c75b58a Compare May 1, 2020 11:44
@Gudahtt Gudahtt changed the base branch from remove-unnecessary-tx-meta-properties to develop May 1, 2020 11:44
@Gudahtt Gudahtt marked this pull request as ready for review May 1, 2020 11:44
@Gudahtt Gudahtt requested a review from a team as a code owner May 1, 2020 11:44
@metamaskbot
Copy link
Collaborator

Builds ready [c75b58a]
Page Load Metrics (689 ± 28 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31493852
domContentLoaded6158126875727
load6168186895728
domInteractive6148126875727

A race condition exists where after adding an unapproved transaction,
it could be mutated and then replaced when the default gas parameters
are set. This happens because the transaction is added to state and
broadcast before the default gas parameters are set, because
calculating the default gas parameters to use takes some time.
Once they've been calculated, the false assumption was made that the
transaction hadn't changed.

The method responsible for setting the default gas now retrieves an
up-to-date copy of `txMeta`, and conditionally sets the defaults only
if they haven't yet been set.

This race condition was introduced in #2962, though that PR also added
a loading screen that avoided this issue by preventing the user from
interacting with the transaction until after the gas had been
estimated. Unfortunately this loading screen was not carried forward to
the new UI.
@Gudahtt Gudahtt force-pushed the fix-default-gas-race-condition branch from c75b58a to f00fa8b Compare May 1, 2020 15:02
@metamaskbot
Copy link
Collaborator

Builds ready [f00fa8b]
Page Load Metrics (646 ± 30 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint308740157
domContentLoaded5888836446330
load5908846466330
domInteractive5888826446330

Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

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

Yes, I believe this is good.

@Gudahtt Gudahtt merged commit 5b5b67a into develop May 1, 2020
@Gudahtt Gudahtt deleted the fix-default-gas-race-condition branch May 1, 2020 15:25
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.

4 participants