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

DAPP action replay improvements #16250

Merged
merged 12 commits into from
Nov 29, 2022
Merged

DAPP action replay improvements #16250

merged 12 commits into from
Nov 29, 2022

Conversation

jpuri
Copy link
Contributor

@jpuri jpuri commented Oct 21, 2022

Fixes: #16174

The PR improves DAPP action replay. As the background is loaded and its state is completely initialised a message is sent to inpage provider to replay actions.

To be merged after this PR is merged: #16075

@github-actions
Copy link
Contributor

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 jpuri added the DO-NOT-MERGE Pull requests that should not be merged label Oct 21, 2022
@jpuri jpuri marked this pull request as ready for review October 21, 2022 10:28
@jpuri jpuri requested a review from a team as a code owner October 21, 2022 10:28
@jpuri jpuri requested review from NidhiKJha, digiwand, rekmarks, naugtur and a team and removed request for a team October 21, 2022 10:28
@jpuri jpuri requested a review from kumavis as a code owner October 24, 2022 07:55
@metamaskbot
Copy link
Collaborator

Builds ready [40793dd]
Page Load Metrics (2468 ± 52 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint982428348680326
domContentLoaded22152662244810551
load22152676246810952
domInteractive22152662244810551

app/scripts/contentscript.js Outdated Show resolved Hide resolved
app/scripts/contentscript.js Show resolved Hide resolved
app/scripts/contentscript.js Outdated Show resolved Hide resolved
test/e2e/snaps/enums.js Outdated Show resolved Hide resolved
@jpuri jpuri force-pushed the dapp_action_replay_improvements branch from e7ad374 to 3d8a9ad Compare October 26, 2022 07:52
@jpuri jpuri requested a review from digiwand October 26, 2022 07:55
@metamaskbot
Copy link
Collaborator

Builds ready [c4723f9]
Page Load Metrics (2590 ± 121 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint953821336029
domContentLoaded206731842557254122
load206732102590252121
domInteractive206731842557254122

@@ -261,10 +261,14 @@ const setupPageStreams = () => {
pageChannel = pageMux.createStream(PROVIDER);
};

// The field below is used to ensure that replay is done only once for each restart.
let REPLAY_ENABLED = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

It took me a little bit of time to wrap my head around this logic. Now I see that REPLAY_ENABLED, in other words, means something like canSendExtensionConnectedMessage

In the case that the listener receiving the message expands on the logic, this comment and variable name could become outdated. REPLAY_ENABLED works. I'm just mentioning this here in case we want to take a preventative and potentially more scalable approach by renaming this

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm back with a follow-up thought...

Essentially, this might just be me, but the naming here isn't sitting with me well. It seems to go from retry -> connect -> retry.

In this PR, REPLAY_ENABLED is used to send the METAMASK_EXTENSION_STREAM_CONNECT message which is then mapped to a message for retryOnMessage

https://github.com/MetaMask/providers/blob/main/src/StreamProvider.ts

this._jsonRpcConnection = createStreamMiddleware({
  retryOnMessage: 'METAMASK_EXTENSION_STREAM_CONNECT',
});

what if we align the naming across the code to something like:
CAN_SEND_RETRY_ACTIONS_ON_CONNECT_MSG
METAMASK_EXTENSION_RETRY_ACTIONS_ON_CONNECT
retryActionsOnConnectMessage
?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

I'd rename:

METAMASK_EXTENSION_STREAM_CONNECT => METAMASK_EXTENSION_CONNECT_CAN_RETRY
REPLAY_ENABLED => METAMASK_EXTENSION_CONNECT_SENT
retryOnMessage => retryActionsOnConnectMessage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

I did renamed first 2 suggestions, changing the third is hard as it is used in 2 different repos.

@metamaskbot
Copy link
Collaborator

Builds ready [1864752]
Page Load Metrics (2345 ± 72 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint90150113189
domContentLoaded21292730232915173
load21332730234515072
domInteractive21292730232915173

@metamaskbot
Copy link
Collaborator

Builds ready [164d9f1]
Page Load Metrics (2395 ± 58 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint962325337651312
domContentLoaded20732585235510651
load21822729239512158
domInteractive20732585235510651

@metamaskbot
Copy link
Collaborator

Builds ready [f98ce46]
Page Load Metrics (2135 ± 102 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint902165205450216
domContentLoaded17442640211820799
load174426402135213102
domInteractive174426402118207100

digiwand
digiwand previously approved these changes Oct 31, 2022
Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

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

LGTM!

as suggested above, updating retryOnMessage => retryActionsOnConnectMessage in the other 2 repos you mentioned would be a nice-to-have; not a blocker here though

digiwand added a commit that referenced this pull request Nov 2, 2022
planning to be readded in follow-up PR: #16250
@metamaskbot
Copy link
Collaborator

Builds ready [1dc318f]
Page Load Metrics (2332 ± 124 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint942580276553266
domContentLoaded180730082316258124
load182030082332259124
domInteractive180730082316258124

danjm
danjm previously approved these changes Nov 3, 2022
Copy link
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

@hilvmason hilvmason added the PR - P1 identifies PRs deemed priority for Extension team label Nov 7, 2022
Base automatically changed from mv3-dapp-sendMessage-after-SW-inactivity to develop November 14, 2022 17:18
@metamaskbot
Copy link
Collaborator

Builds ready [e5cbbbe]
Page Load Metrics (2088 ± 76 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint92128104105
domContentLoaded16662232205115675
load16762304208815876
domInteractive16662232205115675
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 703 bytes
  • ui: 8576 bytes
  • common: 409 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [ab819c7]
Page Load Metrics (2262 ± 111 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint952360232488235
domContentLoaded163826182239232112
load163826182262230111
domInteractive163826182239232112
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 703 bytes
  • ui: 8576 bytes
  • common: 409 bytes

@jpuri jpuri requested a review from digiwand November 22, 2022 10:14
const setupExtensionStreams = () => {
METAMASK_EXTENSION_CONNECT_SENT = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe METAMASK_EXTENSION_CONNECT_SENT -> METAMASK_EXTENSION_CAN_SEND_RETRY? thoughts?

cc: @naugtur

Copy link
Member

@Gudahtt Gudahtt Nov 24, 2022

Choose a reason for hiding this comment

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

Agreed that calling this "connect sent" isn't ideal, because it doesn't really represent whether the extension has connected. After we send the retry command, it remains true that the extension has connected, but this is false.

Maybe instead of "can send retry", it should be "should send retry"? Or "send retry when ready"

OR maybe it would be simpler to flip this around. Use this boolean to track when the retry has already been sent, call it "METAMASK_EXTENSION_RETRY_SENT", and set it to false here. Then we can set to true in extensionStreamMessageListener

Copy link
Contributor

Choose a reason for hiding this comment

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

How about we call it what it is - a semaphore.

METAMASK_EXTENSION_CONNECT_SEMAPHORE

Copy link
Contributor

Choose a reason for hiding this comment

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

Code looks good to me but I agree with @Gudahtt 's comment about variable naming

@Gudahtt

This comment was marked as resolved.

segun
segun previously approved these changes Nov 23, 2022
@metamaskbot
Copy link
Collaborator

Builds ready [44acf02]
Page Load Metrics (2444 ± 132 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1202791473517
domContentLoaded187628762434276132
load187628762444275132
domInteractive187628762434276132
Bundle size diffs
  • background: 0 bytes
  • ui: 0 bytes
  • common: 0 bytes

Gudahtt
Gudahtt previously approved these changes Nov 24, 2022
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM! Though there are some open suggestions on improving that variable name

segun
segun previously approved these changes Nov 25, 2022
@jpuri jpuri dismissed stale reviews from segun and Gudahtt via e4bcda4 November 28, 2022 05:15
@jpuri jpuri requested review from segun, digiwand and Gudahtt November 28, 2022 05:15
@metamaskbot
Copy link
Collaborator

Builds ready [50e2322]
Page Load Metrics (2159 ± 114 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint103153125147
domContentLoaded158523792133233112
load158525052159236114
domInteractive158523792133233112
Bundle size diffs
  • background: 0 bytes
  • ui: 0 bytes
  • common: 0 bytes

@jpuri
Copy link
Contributor Author

jpuri commented Nov 29, 2022

I am merging this PR, I am working on a following PR where I will address re-naming suggestion.

@jpuri jpuri merged commit ea882d4 into develop Nov 29, 2022
@jpuri jpuri deleted the dapp_action_replay_improvements branch November 29, 2022 17:03
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR - P1 identifies PRs deemed priority for Extension team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MV3: Improve DAPP action replay
10 participants