Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Refactor create/processTransaction #3239

Merged
merged 24 commits into from Jan 13, 2022
Merged

Refactor create/processTransaction #3239

merged 24 commits into from Jan 13, 2022

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Jan 3, 2022

What it solves

Resolves #3187

How this PR fixes it

createTransaction and processTransaction were long, convuleted and had a lot of duplicate code. The code was revisted, tidied and refactored.

How to test it

All instances where transactions are created/approved are touched by the reafctoring of these two key functions. All methods need to be tested an confirmed that they work.

@iamacook iamacook marked this pull request as draft January 3, 2022 16:30
@github-actions
Copy link

github-actions bot commented Jan 3, 2022

CLA Assistant Lite All Contributors have signed the CLA.

@github-actions
Copy link

github-actions bot commented Jan 3, 2022

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 1 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@coveralls
Copy link

coveralls commented Jan 3, 2022

Pull Request Test Coverage Report for Build 1692074976

  • 12 of 119 (10.08%) changed or added relevant lines in 9 files are covered.
  • 159 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.08%) to 32.447%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/logic/safe/safeTxSigner.ts 0 1 0.0%
src/logic/safe/transactions/offchainSigner/EIP712Signer.ts 2 3 66.67%
src/logic/safe/transactions/offchainSigner/index.ts 1 2 50.0%
src/logic/contracts/safeContractErrors.ts 2 8 25.0%
src/logic/notifications/notificationBuilder.tsx 1 7 14.29%
src/logic/safe/store/actions/utils.ts 1 7 14.29%
src/logic/safe/store/actions/processTransaction.ts 1 12 8.33%
src/logic/safe/store/actions/createTransaction.ts 2 77 2.6%
Files with Coverage Reduction New Missed Lines %
src/logic/safe/store/actions/processTransaction.ts 1 4.17%
src/components/Modal/index.tsx 5 61.9%
src/routes/safe/components/Transactions/TxList/TxData.tsx 9 5.41%
src/routes/safe/components/Settings/Appearance/index.tsx 10 0%
src/components/AppLayout/index.tsx 11 0%
src/components/DecodeTxs/index.tsx 11 52.38%
src/routes/safe/components/Transactions/TxList/MultiSendDetails.tsx 13 4.26%
src/routes/CreateSafePage/components/SafeCreationProcess.tsx 49 4.92%
src/routes/opening/index.tsx 50 6.91%
Totals Coverage Status
Change from base Build 1683593087: 0.08%
Covered Lines: 3123
Relevant Lines: 8571

💛 - Coveralls

@github-actions
Copy link

github-actions bot commented Jan 3, 2022

Deployment links

🟠 Safe Rinkeby Safe Mainnet 🟣 Safe Polygon 🟡 Safe BSC Safe Arbitrum 🟢 Safe xDai

@github-actions
Copy link

github-actions bot commented Jan 3, 2022

E2E Tests Failed
Check the results here: https://github.com/gnosis/safe-react-e2e-tests/actions/runs/1692112373

Failed tests:

  • ❌ Safe Apps List Safe Apps List
  • ❌ Read-only transaction creation and review Read-only transaction creation and review
  • ❌ Safe Balances Safe Balances

@iamacook iamacook marked this pull request as ready for review January 5, 2022 11:17
@katspaugh katspaugh marked this pull request as draft January 10, 2022 08:28
@katspaugh katspaugh marked this pull request as ready for review January 10, 2022 16:17
Copy link
Member Author

@iamacook iamacook left a comment

Choose a reason for hiding this comment

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

Looking great!

src/logic/notifications/notificationBuilder.tsx Outdated Show resolved Hide resolved
src/logic/safe/store/actions/createTransaction.ts Outdated Show resolved Hide resolved
@iamacook
Copy link
Member Author

The merge conficts can be disregarded in place of the functions here. I discussed the changes I made with @katspaugh and they are already included in the refactor.


if (isExecution) {
dispatch(updateTransactionStatus({ safeTxHash: tx.safeTxHash, status: LocalTransactionStatus.PENDING_FAILED }))
this.safeTxHash = tx.safeTxHash
Copy link
Member

@mmv08 mmv08 Jan 12, 2022

Choose a reason for hiding this comment

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

Why does it have to be a property on the instance of the processor? It seems non-idiomatic from an OOP point of view. I would think about a processor as something that processes transactions and doesn't hold any state-specific to a transaction it processed. Imo such properties should be specific to the transaction instance, and there's one within the function body (txProps). So if it processes a transaction, it would still keep properties from the last processed transaction on the instance. I'm a little struggling to phrase my thoughts, but right now, the instance code is too tied to the previous processed transaction, but it's exported as a general-purpose class that can process/create multiple transactions

Copy link
Member

Choose a reason for hiding this comment

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

Adding info I discovered when talking with Aaron:
so because the same instance is reused across different transactions I think it's possible that methods that are called later may reference the wrong values. Like this.isExecution in onComplete. If I create a transaction that is supposed to be executed and isExecution is set to true, and after that, I create another one where this.isExecution is false. When onComplete is called for the first transaction this.isExecution will be false

Copy link
Member

@mmv08 mmv08 Jan 12, 2022

Choose a reason for hiding this comment

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

Haven't tested it though, but since the interface allows such scenario, it could be good to add a test for such cases with subsequent transactions

Copy link
Member

Choose a reason for hiding this comment

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

Oh, that's very no bueno. Singleton vs instantiating the class for every tx. 🤦
Great catch, thanks Mikhail!

Copy link
Member Author

Choose a reason for hiding this comment

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

@usame-algan and I have just adjusted it to instantiate the TxSender with every call. It would be great if you can take another look at it please @mikheevm @katspaugh

@@ -47,6 +48,7 @@ enum ErrorCodes {
_811 = '811: Error calculating ERC721 transfer data for adding a Safe owner',
_812 = '812: Error calculating ERC721 transfer data for removing a Safe owner',
_813 = '813: Error calculating ERC721 transfer data for replacing a Safe owner',
_814 = '814: Error performing an offline tx signature',
Copy link
Member

Choose a reason for hiding this comment

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

nit: it's not offline but off-chain

@@ -36,6 +37,24 @@ export const getContractErrorMessage = async ({
const contractOutput = abi.rawDecode(['string'], returnBuffer.slice(4))[0]
return decodeMessage(contractOutput)
} catch (e) {
return decodeMessage(e.message)
return null
Copy link
Member

Choose a reason for hiding this comment

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

just to double-check if we're hiding the error on purpose

Copy link
Member Author

Choose a reason for hiding this comment

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

If I understand correctly, this was causing the app to crash. It was being handled incorrectly and couldn't be decoded. @katspaugh, can you confirm?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we weren't handling this in any special way because it's not critical and there's no good recovery strategy. Other than logging, which is a good move.

if (isExecution) {
dispatch(updateTransactionStatus({ safeTxHash: tx.safeTxHash, status: LocalTransactionStatus.PENDING_FAILED }))
}
return
Copy link
Member

Choose a reason for hiding this comment

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

same here with error hiding

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add some logging here. Thanks for noticing it!

@mmv08
Copy link
Member

mmv08 commented Jan 12, 2022

It should be good to go now. Only a few things:

  1. Should we add some tests?
  2. (subjective) It seems to me that in the end, the refactor still ended up complex because the layers are still mixed up, it goes from sender to the action and then back to the sender again, and it's pretty hard to track what's going on. I'll leave the final word to the code owners.

@iamacook
Copy link
Member Author

1. Should we add some tests?

Tests are definitely needed. This is such a behemoth though that I'm not sure how we could approach this though. I'd be appreciative of any insight/help regarding this @gnosis/safe-web

2. (subjective) It seems to me that in the end, the refactor still ended up complex because the layers are still mixed up, it goes from sender to the action and then back to the sender again, and it's pretty hard to track what's going on. I'll leave the final word to the code owners.

I agree with this to some extent but when you compare what we have with what it was before, I think it is at least an improvement on the duplicity and messiness it was. As they are such integral Safe logic, however, I would more than welcome input on how we could improve them further. I'd love for them to be as perfect as they possible could be.

@github-actions
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 1 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@katspaugh
Copy link
Member

@francovenica @liliya-soroka merging this one w/o QA for now, we want to continue refactoring this but need it on dev to avoid conflicts.
Let's test in a follow-up PR.

@katspaugh katspaugh merged commit c3baa54 into dev Jan 13, 2022
@katspaugh katspaugh deleted the refactor-tx-fns branch January 13, 2022 10:19
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor createTransaction/processTransaction
4 participants