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: [Counterfactual] Add event bus and pending state #3242

Merged
merged 11 commits into from
Feb 15, 2024
Merged

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Feb 12, 2024

What it solves

Part of #3156

How this PR fixes it

  • Adds an Event Bus for SafeCreationEvents
  • Dispatches SafeCreationEvents when deploying a counterfactual safe
  • Persists pending state status in undeployedSafesSlice
  • Shows notifications for SafeCreationEvents
  • Monitors undeployedSafes if they are relaying or processing
  • Checks for an undeployedSafe if its already deployed on-chain and cleans up local storage in case it is
  • Supports cancellation and speed-up safe creations
  • Disables the create button in the safe creation flow and adds a loading spinner while submitting

How to test it

Happy path:

  1. Create a counterfactual safe
  2. Deploy safe via "Activate now" or with first tx
  3. Observe Processing notification showing
  4. Observe the "Activate now" button is disabled and has a loading state on it
  5. Observe a Success notification
  6. The undeployed state should be cleaned up

Pending state is persisted:

  1. Create a counterfactual safe
  2. Deploye safe via "Activate now" or with first tx
  3. Observe Processing notification showing
  4. Reload the app
  5. Observe the "Activate now" button is disabled and has a loading state on it
  6. Observe a Success notification

Sad path:

  1. Create a counterfactual safe
  2. Deploy safe via "Activate now" or with first tx with too little gas
  3. Observe Processing notification
  4. Observe Timeout error after a while
  5. Cancel transaction in wallet and execute again
  6. This time speed up the transaction
  7. Observe a success notification

Cleaning state:

  1. Create a counterfactual safe
  2. Deploy the safe via "Activate now" and immediately close the app
  3. Wait until the transaction is successfully executed via wallet
  4. Open the app again
  5. Observe the undeployed state is cleaned up

Creation Loading state:

  1. Go through the safe creation flow
  2. Press Create
  3. Observe that the Create button is disabled and has a loading spinner

Screenshots

Checklist

  • I've tested the branch on mobile πŸ“±
  • I've documented how it affects the analytics (if at all) πŸ“Š
  • I've written a unit/e2e test for it (if applicable) πŸ§‘β€πŸ’»

Copy link

github-actions bot commented Feb 12, 2024

Copy link

github-actions bot commented Feb 12, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: βœ… success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

github-actions bot commented Feb 12, 2024

Coverage report

St.❔
Category Percentage Covered / Total
🟑 Statements
78.66% (-0.27% πŸ”»)
11524/14650
πŸ”΄ Branches
56.68% (-0.29% πŸ”»)
2580/4552
🟑 Functions
63.51% (-0.21% πŸ”»)
1833/2886
🟒 Lines
80% (-0.23% πŸ”»)
10396/12995
Show new covered files 🐣
St.❔
File Statements Branches Functions Lines
🟒
... / storeHydrator.tsx
100% 100% 100% 100%
🟒
... / safeCreationEvents.ts
70% 100% 66.67% 87.5%
Show files with reduced coverage πŸ”»
St.❔
File Statements Branches Functions Lines
🟒
... / addressBookSlice.ts
86.49% (-2.7% πŸ”»)
44.44% (-11.11% πŸ”»)
87.5% 92.31%
🟒
... / persistStore.ts
95.24% (-0.92% πŸ”»)
66.67% (-13.33% πŸ”»)
100%
94.12% (-0.88% πŸ”»)
πŸ”΄
... / undeployedSafesSlice.ts
38.24% (-5.76% πŸ”»)
33.33% (+33.33% πŸ”Ό)
50% (-10% πŸ”»)
45.83% (-4.17% πŸ”»)
🟒
... / txMonitor.ts
91.86% (-1.08% πŸ”»)
91.3% 95.24% 92.59%
🟑
... / index.ts
69.49% (-0.18% πŸ”»)
63.64% (+1.14% πŸ”Ό)
43.75% (-3.31% πŸ”»)
68.63% (-0.24% πŸ”»)
πŸ”΄
... / test-utils.tsx
58.82% (-3.34% πŸ”»)
66.67% 37.5%
57.58% (-3.54% πŸ”»)
🟒
... / SignMessage.tsx
89.89%
82.35% (-0.98% πŸ”»)
66.67% 90.7%
πŸ”΄
... / GlobalPushNotifications.tsx
60.42% (-1.35% πŸ”»)
35.85% (-2.33% πŸ”»)
55% (-2.14% πŸ”»)
57.06% (-1.5% πŸ”»)
🟑
... / index.tsx
73.08%
61.54% (-1.42% πŸ”»)
53.33% 73.74%
πŸ”΄
... / utils.ts
36.36% (-11.87% πŸ”»)
26.83% (-10.67% πŸ”»)
21.43% (-8.57% πŸ”»)
36.11% (-11.89% πŸ”»)
🟒
... / index.tsx
81% (-1.47% πŸ”»)
51.16% (-1.34% πŸ”»)
72.73%
81.91% (-1.6% πŸ”»)

Test suite run success

1399 tests passing in 190 suites.

Report generated by πŸ§ͺjest coverage report action from 90a523c

Copy link

github-actions bot commented Feb 12, 2024

πŸ“¦ Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. πŸ€–

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 1.02 MB (🟑 +921 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Three Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/home 41.27 KB (🟑 +3 B) 1.06 MB
/new-safe/create 31.91 KB (🟑 +48 B) 1.06 MB
/settings/setup 72.18 KB (🟑 +108 B) 1.1 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

We'll have to refactor all those event buses/associated notifications eventually. There are now regular txs, messages, safe creations. Lots of copypasta.

src/features/counterfactual/ActivateAccount.tsx Outdated Show resolved Hide resolved
src/features/counterfactual/services/safeCreationEvents.ts Outdated Show resolved Hide resolved
src/features/counterfactual/services/safeCreationEvents.ts Outdated Show resolved Hide resolved
src/features/counterfactual/utils.ts Show resolved Hide resolved
src/hooks/usePendingSafeStatuses.ts Outdated Show resolved Hide resolved
src/hooks/usePendingSafeStatuses.ts Outdated Show resolved Hide resolved
src/hooks/usePendingSafeStatuses.ts Outdated Show resolved Hide resolved
src/hooks/usePendingSafeNotifications.ts Outdated Show resolved Hide resolved
src/pages/_app.tsx Outdated Show resolved Hide resolved
src/pages/_app.tsx Outdated Show resolved Hide resolved
# Conflicts:
#	src/features/counterfactual/utils.ts
@francovenica
Copy link
Contributor

The happy path and cleaning state work fine

Question:
Given the statement:
"We are not detecting cancellation and speed-up transactions. This is a general issue that we have since the ethers v6 upgrade so I suggest to ignore it when testing"

I can't test the other 2 scenarios:
The cancel one is not removing the pending state, but given the statement it would be expected

The speeding up one is working in the sense that the safe is being deployed, but the pending state also never goes away, I don't get a "deployed" notification from the safe and I have to hard refresh to have the "undeployed safes" key from the local storage cleared

So the question is. Should I ignore those 2 and test them in the RC?

Copy link

github-actions bot commented Feb 14, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: βœ… success
  • Annotations: 0 total

Report generated by eslint-plus-action

@usame-algan
Copy link
Member Author

usame-algan commented Feb 14, 2024

So the question is. Should I ignore those 2 and test them in the RC?

I found a fix for this that wasn't documented in ethers v6 but now we should detect cancellations and speed-ups correctly. I also fixed it for the normal safe creation flow since it was broken there as well. Additionally, I increased the timeout from 1 minute to 2 minutes since I think 1 minute is too fast for this kind of case i.e. transaction is not executing so the user first checks why and then chooses speed-up or cancel this would most likely take more than one minute.

I also added one more test case to check that the Create button now has a loading state when in the safe creation flow. Noticed that it can take a second or two to find the next available nonce so its better to have a loading indication there.

@francovenica
Copy link
Contributor

The loading status in the create button looks good
The cancelation of the tx works fine. The pending status stops and a notification saying "cancelled" is shown.

Issue:
With speed up I still have issues.
I tested 2 times with different outcomes:
First time: I waited for 5 mins and the pending status never went away. I reloaded the page and the pending status kept going for 5 seconds, stopped and I got this error
image

Second time: This time the pending status went away quickly, but I still got a different error:
image

In both cases the tx worked, so the safe was deployed just fine, but my guess is that the system is still waiting for the original tx instead of the new one that is replacing it

Copy link

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: βœ… success
  • Annotations: 0 total

Report generated by eslint-plus-action

@usame-algan
Copy link
Member Author

@francovenica I fixed the issue that an error was shown even if there was a speed-up.

There are still two other issues:

  1. Sometimes there is an error shown immediately after Submitting ("Transaction not found"). I suspect this happens more on Sepolia than on other networks because there might be fewer nodes that pick up the transaction from the pool. I don't think we can do much here
  2. Sometimes cancellation/speed-up is not picked up and its stuck in processing until it times out. I am still looking into the cause of this but I would suggest we move on and fix it separately as this looks like an ethers v6 issue to me

@francovenica
Copy link
Contributor

I tried twice and it works really well both times. Didn't have more issues

LGTM

@usame-algan usame-algan merged commit f2421e2 into dev Feb 15, 2024
15 checks passed
@usame-algan usame-algan deleted the cf-events branch February 15, 2024 12:46
@github-actions github-actions bot locked and limited conversation to collaborators Feb 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants