tahowallet / extension

Taho, the community owned and operated Web3 wallet.
https://taho.xyz
GNU General Public License v3.0
3.11k stars 394 forks source link

WIP: Undetermenistic internal state changes causes freezes and unexpected feature breakage all over #2550

Open greg-nagy opened 1 year ago

greg-nagy commented 1 year ago

We had some mysterious bugs before, and the common theme for them is the icon of the token is switching from the proper asset icon to the default placeholder. This change frequently happens on nondeterministic time intervals.

In previous situations, the send transaction failed because it went to the wrong address and swap was also affected. Do you have the exact context @Naxsun or @VladUXUI? It was a pool swap and a separate instance where the send tx seemed to go to the contract address.

The swap completely stopped working, and I had to reinstall the extension to get out of this.

https://user-images.githubusercontent.com/7690112/199694985-8859d6fc-3743-451c-931c-ac0f7b772721.mp4

Other signals for this problem are

Theory for the root cause: Background updates redux store in the background > redux store change is propagated to the UI through port communication/webext-redux > when the changes are integrated into the UI proxy store a change event is generated > that doesn't affect the UI because react or selectors filter these changes BUT the async thunk is fired somehow > which is propagated to the background > goto step 1

I have a hunch that the root cause of this mystery bug is behind most of our user issues.

Affected functionality: all around the extension, performance, send, swaps.

[^1]: The recording was done on a dev build, but the issue is present in the 0.17.6 release build [^2]: Wenn video embed github?

Shadowfiend commented 1 year ago

Wenn video embed github?

About 17 months ago 😜

Shadowfiend commented 1 year ago

A quick remark on the hypothesis: I would be surprised if anything that happens in swap state management is easily ascribed to background script issues, because the swap page's frontend state management is so complicated and almost certainly has bugs.

jagodarybacka commented 1 year ago

fixed the video for u @greg-nagy 😄

Naxsun commented 1 year ago

@greg-nagy It's a while ago. What I was able to dig up quickly are issues that may be related, but not 100% sure. Does that help?

https://github.com/tallycash/extension/issues/1832 https://github.com/tallycash/extension/issues/2320

greg-nagy commented 1 year ago

@Naxsun thx, this helps!

also found the issue: https://github.com/tallycash/extension/issues/2403

I think this one is also related: https://github.com/tallycash/extension/issues/1898

mhluongo commented 1 year ago

I think this is a few independent issues...? It'd be good to break it out rather than a catch-all "high severity" bug that doesn't have clear reproduction steps.

I think you're trying to jump from a few issues to a solution, but we don't have evidence that they share a root cause. Instead, I think...

I have a hunch that the root cause of this mystery bug is behind most of our user issues.

I think we should avoid this sort of thinking in our issues. Let's get crisp here! In the meantime, I'm removing the high-severity label to keep from messing up sprint planning / miscommunicating our confidence here.

greg-nagy commented 1 year ago

thanks for pushing me to define better issues! You are correct. I went with my gut instinct here, and this issue is more of a pitch for a spike than an actionable task. I will collect more info and try to get to the root cause before ticketing the work. Let's treat this as a placeholder until then.

The issue is meant to be dedicated to UI rerenders caused by seemingly unrelated events. This behavior signals — at least to me — that somewhere, somehow, they are coupled together. Put it differently: What triggers the code path that leads to the flicker?

Not in scope for this issue: Concrete implementations fixes — swaps, asset merge

Seemingly related symptoms

Problems/working questions:

Shadowfiend commented 1 year ago

The spurious updates are probably due to some of the gnarlier selectors like account totals that require a lot of info. Very likely some things that can be rendered conditionally to reduce triggers, and some selectors that might be able to be refined for better dependencies.

Shadowfiend commented 1 year ago

Also of note: deeper understanding of the patch stuff is 💯 worth it as well. Any patching that changes object identity is going to trigger updates. The empty array hunch feels sound---relaying empty arrays is not incorrect, but detecting when pre and post change arrays are both zero-length and suppressing those updates could definitely reduce invalidation of certain object trees in useful ways.

greg-nagy commented 1 year ago

To jot down before I forget Every main tab component is rerendering 3-5 times on every route change. This multiplies the rerenders coming from selectors.

The selector issue is likely to come from the fact that

Still open questions