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

Speed up safe creation #2473

Merged
merged 12 commits into from
Jul 6, 2021
Merged

Speed up safe creation #2473

merged 12 commits into from
Jul 6, 2021

Conversation

juampibermani
Copy link
Contributor

@juampibermani juampibermani commented Jun 22, 2021

What it solves

Resolves #2362

How this PR fixes it

Waits for either the speed up tx or the original tx

How to test it

  • Create a creation safe tx with low gas price so it doesn't get confirmed
  • Accelerate the tx on MM
  • Wait for it to be confirmed

@juampibermani juampibermani self-assigned this Jun 22, 2021
@github-actions
Copy link

CLA Assistant Lite All Contributors have signed the CLA.

@github-actions
Copy link

github-actions bot commented Jun 22, 2021

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

@github-actions
Copy link

@juampibermani juampibermani changed the title wip: Speed up safe creation Speed up safe creation Jun 23, 2021
@juampibermani juampibermani marked this pull request as ready for review June 23, 2021 18:34
@github-actions
Copy link

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.

I think it's good enough as a bug fix at this point.

I've left some comments but I remember, @juampibermani, you mentioned you had ideas for a more significant refactoring of safeCreate. So perfecting this bug fix might be a dead end. I'd love to hear your refactoring ideas.

@@ -137,6 +137,8 @@ export const SafeDeployment = ({
(err: Error) => {
if (isTxPendingError(err)) {
dispatch(enqueueSnackbar({ ...NOTIFICATIONS.TX_PENDING_MSG }))
} else {
dispatch(enqueueSnackbar({ ...NOTIFICATIONS.CREATE_SAFE_FAILED_MSG }))
Copy link
Member

Choose a reason for hiding this comment

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

I think it wasn't being done before because the interface itself shows an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see the notification

Copy link
Member

Choose a reason for hiding this comment

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

There was no notification, I meant that the page itself shows an error graphic and suggests to retry.
Notification doesn't hurt though.

}
}
}, 500)
}
Copy link
Member

Choose a reason for hiding this comment

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

Looks good! It would be nice to extract this into a utility so that this setTimeout loop code doesn't clutter the safe creation function.

Signature suggestion: waitWithTimeout(comparator, onSuccess, onError, delay = 500, maxTimes = 1200).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I solved it in a simpler way, you can see the change in the last commit

// transaction found
return txMonitor({ sender, hash, data, nonce: transaction.nonce, gasPrice: transaction.gasPrice }, cb, options)
} else {
return txMonitor({ sender, hash, data }, cb, options)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like txMonitor itself also implements a recursive timeout loop.
So we could use waitWithTimeout here as well, and use a promise instead of the callback:

export const txMonitor = (txMonitorProps) => {
  return new Promise((resolve, reject) => {
    waitWithTimeout(() => { ... }, resolve, reject)
  })
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I solved it in a simpler way, you can see the change in the last commit

Copy link
Member

Choose a reason for hiding this comment

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

That was smart! 👏

@francovenica
Copy link
Contributor

I tried this twice and in both times it failed.
I tested it in the mainnet build since I can low the gas price there to make the safe creation slower. Then as soon as I signed I speed up the tx bumping up the gas to the "fast" setting. The tx is successful in the blockexplorer, but the safe creation gets stuck in the step 1. If the /open page is reloaded then it reaches to step 3 where it fails.
image

gif:
06-28-2021_x(2658)

if (nonce === undefined || gasPrice === undefined) {
// this block is accessed only the first time, to lookup the tx nonce and gasPrice
// find the nonce for the current tx
const transaction = await web3ReadOnly.eth.getTransaction(hash)
Copy link
Member

Choose a reason for hiding this comment

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

There are several places like this in txMonitor, where we don't catch a potential async exception.
I think txMonitor should return a promise instead of taking a callback. Then we can try-catch each await call and reject the returned promise in the catch.

@github-actions
Copy link

github-actions bot commented Jul 1, 2021

@github-actions
Copy link

github-actions bot commented Jul 1, 2021

@katspaugh katspaugh self-requested a review July 2, 2021 09:25
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.

* Refactor

* Add unit tests
@francovenica
Copy link
Contributor

francovenica commented Jul 2, 2021

I tried creating a safe with the lowest gas MM was suggesting (the slow setting) and then as soon as it was possible I sped it up with the "fast gas setting".
After that the safe creation process picked up on that new sped up tx and it finished the process successfully,

Note:
If after speeding up tx and the safe creation end you do not go straight to the safe and try to create a new on, the safe creation process will start again on its own and fail at step 3.
It seems that is detecting that tx that was overlapped by the sped up one. Now, this only happens if after creating a safe you don't even go to the newly created safe and start to create a new one instead

I won't report this as an issue since it is a really uncommon situation, still @dasanra and @juampibermani I leave it here you know the case exists.

I will pass the ticket

@katspaugh
Copy link
Member

If after speeding up tx and the safe creation end you do not go straight to the safe and try to create a new on, the safe creation process will start again on its own and fail at step 3.

I think we're supposed to clean up some localStorage cache when the creation succeeds.

@francovenica
Copy link
Contributor

francovenica commented Jul 5, 2021

Tried making the tx fail on purpose by setting the amount of gas really low.
Once the tx ended (in failure) in the block explorer, then the the safe creation process failed in step 5, since there is no contract to deploy (this is correct)

Tested by creating a safe normally (suggested gas price and amount) and cancelled the tx in MM right away, setting the gas price in "fast" so it would make sure the cancel gets mined first.
The safe creation gets stuck in the step 1 once the cancellation is mined. It seems seems the system is not expecting for the tx to be overwritten by a cancellation
If you reload the page while stuck in step 1, it will reload the safe process once again, but it will fail in step 3.

Issue to solve:
Safe creation should check if there is a cancellation of the original tx.

snapshot: every call is waiting for the original tx and not the cancellation.
The cancellation is this:
https://etherscan.io/tx/0x864969dce662f653e04e9ccd6a9f36323391125875e9fed58a7be8af26522b50
image

@katspaugh
Copy link
Member

It seems the system is not expecting for the tx to be overwritten by a cancellation

Just to make sure, this is the case in the current dev as well, isn't it?

@katspaugh katspaugh merged commit 68f4363 into dev Jul 6, 2021
@katspaugh katspaugh deleted the feature/2362-speedup-safe-creation branch July 6, 2021 13:49
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2021
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.

Speeding up a Safe creation leads to error in UI and failure of retry
4 participants