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: Cleanup pending txs if nonce already executed #4158

Merged
merged 3 commits into from
Sep 18, 2024
Merged

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Sep 11, 2024

What it solves

Follow up to #4025

This is needed in order for #4069 to work since migration transactions are always replaced and their pending state is stuck indefinitely which bricks the safe.

How this PR fixes it

  • Stores the nonce for each pending transaction
  • Extends the pending tx cleanup logic in the tx history middleware by not just checking if there is a matchin txId but also if there is a matching nonce and in case there is and txIds don't match it means the pending transaction got replaced so it is safe to clear it

ToDo

  • Extend tests for txHistorySlice
  • (optional) Simplify test mocks by using a builder

How to test it

  1. Open the same safe in two different browsers
  2. Execute a transaction with the same nonce at the same time from each browser
  3. Observe both pending states to be cleared as soon as one of the transactions is executed

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 Sep 11, 2024

Copy link

github-actions bot commented Sep 11, 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 Sep 11, 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 949.79 KB (🟡 +199 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!

Seven Pages Changed Size

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

Page Size (compressed) First Load
/apps/open 53.59 KB (🟡 +8 B) 1003.38 KB
/transactions 73.84 KB (🟡 +8 B) 1023.63 KB
/transactions/history 73.81 KB (🟡 +8 B) 1023.6 KB
/transactions/messages 39.21 KB (🟡 +8 B) 989 KB
/transactions/msg 29.59 KB (🟡 +8 B) 979.38 KB
/transactions/queue 31.31 KB (🟡 +8 B) 981.1 KB
/transactions/tx 21.14 KB (🟡 +8 B) 970.93 KB
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

github-actions bot commented Sep 11, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.51% (+0.04% 🔼)
11895/15150
🔴 Branches
59.21% (+0.19% 🔼)
3074/5192
🟡 Functions
65.96% (+0.11% 🔼)
1895/2873
🟡 Lines
79.96% (+0.04% 🔼)
10732/13422
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / useRedefine.ts
98.28% 95.24% 100% 100%
🟢
... / index.ts
91.67% 70% 100% 91.67%
🔴
... / index.tsx
50.82% 2.63% 8.33% 55.56%
🟡
... / RedefineHint.tsx
54.55% 0% 0% 60%
🟡
... / RedefineBalanceChange.tsx
71.79% 7.14% 11.11% 71.05%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟡
... / useDraftBatch.ts
62.07% (-0.89% 🔻)
0% (-100% 🔻)
20%
65.38% (-1.28% 🔻)
🟢
... / index.tsx
82.35% (-8.82% 🔻)
66.67% (-16.67% 🔻)
50% (-12.5% 🔻)
83.87% (-9.68% 🔻)
🟢
... / config.tsx
86.96% (-0.54% 🔻)
100% 100% 100%

Test suite run success

1484 tests passing in 203 suites.

Report generated by 🧪jest coverage report action from c88b6b6

Copy link
Member

@schmanu schmanu left a comment

Choose a reason for hiding this comment

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

The fix looks good 💯
Should improve a lot of stuck Safes with pending txs.

@@ -25,6 +25,7 @@ describe('txHistorySlice', () => {
const state = {
pendingTxs: {
Copy link
Member

Choose a reason for hiding this comment

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

Lets add a test for the new pending state clearing here.

@francovenica
Copy link
Contributor

LGTM.

Opened the same safe in 2 browsers, create a tx that is ready for execution and in each browser I connected with a different owner.
I executed the tx at the same time in both browsers. I see that as soon as one tx is accepted and is being indexed, the other browser shows the tx not in pending anymore. The current behavior is, if the tx takes a bit to index, the tx in the other browser would look as ready to be executed again, showing the error message that the tx was reverted, but as soon the indexing ends, it shows the success status.

@usame-algan usame-algan merged commit 0617f63 into dev Sep 18, 2024
16 checks passed
@usame-algan usame-algan deleted the pending-tx-cleanup branch September 18, 2024 07:34
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants