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

[Wallet] Fix web3 syncing sagas #809

Merged
merged 2 commits into from
Sep 4, 2019
Merged

[Wallet] Fix web3 syncing sagas #809

merged 2 commits into from
Sep 4, 2019

Conversation

jmrossy
Copy link
Contributor

@jmrossy jmrossy commented Sep 2, 2019

Description

The current web3 sync saga would sometimes allow sagas waiting for web3 ready to proceed even before web3 is really ready, causing tx errors. This fixes that issue and cleans up a bit, particularly around the related redux state.

Tested

Synced to Alfajores and sent a tx. Confirmed logs look right.

Related issues

Backwards compatibility

Yes

@@ -17,7 +17,7 @@ export function* waitForRehydrate() {

export function* waitWeb3LastBlock() {
yield waitForGethConnectivity()
yield checkWeb3Sync()
yield waitForWeb3Sync()
Copy link
Contributor Author

@jmrossy jmrossy Sep 2, 2019

Choose a reason for hiding this comment

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

@cmcewen IIRC you recommended calling this check but wait is what it's really doing. Mind if we rename?

Copy link
Contributor

Choose a reason for hiding this comment

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

Volpe and I had a discussion about this - the reason I don't like using wait is that it actually makes a call to get the latest block to the geth node. Since I think we treat the waitFor generators as free in terms of cost, I would be wary of someone just adding this elsewhere and we end up doing a bunch of duplicate polling. I think waitFor should imply solely waiting on state changes.

_CHECK_SYNC_PROGRESS_TIMEOUT,
_checkWeb3SyncProgressClaim,
checkWeb3Sync,
checkWeb3SyncProgress,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@martinvol I do like the convention of _ before functions only exported to test, but until this VSCode bug gets fixed, it just causes a headache :(
prettier/prettier-vscode#716
We'd need to either disable VS code import organizing entirely (would not recommend) or fix this file manually before lint will pass.
Suggest we table this convention for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, no problem. Disabling VS code import organizing might not be a bad a idea since the pre-commit hook also sorts imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah but the way it de-dupes imports for you and removes unused ones is really nice

} else {
Logger.error(TAG, `checking web3 sync progress: ${error}`)
Logger.error(TAG, 'Unexpected sync error', 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.

@martinvol it's better to provide the error as the 3rd param to Logger.error, which has special logic to extract and format the error message nicely

}
return false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@martinvol previously, you were not throwing or returning false in this case, which allowed the calling function to finish as though syncing were done.

@@ -36,68 +34,67 @@ const MNEMONIC_BIT_LENGTH = (ETH_PRIVATE_KEY_LENGTH * 8) / 2

const TAG = 'web3/saga'
// The timeout for web3 to complete syncing and the latestBlock to be > 0
const CHECK_SYNC_PROGRESS_TIMEOUT = 60000
export const SYNC_TIMEOUT = 60000
const BLOCK_CHAIN_CORRUPTION_ERROR = "Error: CONNECTION ERROR: Couldn't connect to node on IPC."
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this to a json as nice to have?

@codecov
Copy link

codecov bot commented Sep 4, 2019

Codecov Report

Merging #809 into master will decrease coverage by 0.04%.
The diff coverage is 75.86%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #809      +/-   ##
=========================================
- Coverage   66.94%   66.9%   -0.05%     
=========================================
  Files         239     239              
  Lines        7121    7103      -18     
  Branches      408     474      +66     
=========================================
- Hits         4767    4752      -15     
+ Misses       2277    2273       -4     
- Partials       77      78       +1
Flag Coverage Δ
#mobile 66.9% <75.86%> (-0.05%) ⬇️
Impacted Files Coverage Δ
packages/mobile/src/web3/actions.ts 78.04% <ø> (-0.53%) ⬇️
packages/mobile/src/web3/reducer.ts 54.54% <100%> (+17.04%) ⬆️
packages/mobile/src/networkInfo/saga.ts 50% <50%> (ø) ⬆️
packages/mobile/src/web3/saga.ts 60% <76.92%> (+0.38%) ⬆️
packages/mobile/src/pincode/Pincode.tsx 78.94% <0%> (-5.87%) ⬇️
packages/mobile/src/send/RequestConfirmation.tsx 68.85% <0%> (-1.47%) ⬇️
packages/mobile/src/pincode/SystemAuth.tsx 53.12% <0%> (-1.17%) ⬇️
packages/mobile/src/fees/CalculateFee.tsx 82.35% <0%> (-0.51%) ⬇️
...mobile/src/navigator/WithDispatchAfterNavigate.tsx 46.66% <0%> (ø) ⬆️
packages/mobile/src/account/Profile.tsx 100% <0%> (ø) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e0884a...18489ea. Read the comment docs.

@jmrossy jmrossy merged commit 8783f20 into master Sep 4, 2019
@jmrossy jmrossy deleted the rossy/wa-sync-fix branch September 4, 2019 08:36
aaronmgdr added a commit that referenced this pull request Sep 5, 2019
* master:
  Export geth metrics from StatefulSet tx-nodes and validators (#827)
  Adjust governance end-to-end gold total supply block number  (#853)
  [Blockchain API] Add currency conversion endpoint to blockchain api (#855)
  [Wallet] Fix Payment Requests and DRY up confirmation card code (#831)
  Use HTTPS instead of SSH for ethereumjs-vm (#850)
  Kill end-to-end celo-blockchain instances with SIGINT (#849)
  [CLI]Minor code improvement in CLI, remove ts-ignore-next-line (#796)
  [wallet] Always allow users to view backup key (#825)
  [contractkit] Complete Exchange Wrapper (#801)
  [Wallet] Fix web3 syncing sagas (#809)
  Aaronmgdr/social links connect (#792)
  Deploy integration (#806)
  [wallet] upgrade react-redux (#812)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wait for web3 doesn't work when web3 false reports sync done
5 participants