Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Conversation

@zone117x
Copy link
Contributor

@zone117x zone117x commented Nov 7, 2019

This PR drastically speeds up the user registration and restoration process, by using the native Web Crypto operations in blockstack.js v21-alpha hirosystems/stacks.js#691.

Some sample benchmarks using a Pixel 3 XL, on both Chrome and Firefox:

  • ~10 seconds when using browser.blockstack.org.
  • ~2 seconds when using this branch.

Additional performance testing is needed with lower-end Android phones, and regression testing is needed on all platforms.

This PR has an absurd changeset from the process of trying to debug errors while getting this working. Notably, all the synchronous code that needed to be refactored into asynchronous.

Debugging capabilities essentially were non-existent -- like readable stack traces, breakpoints in mocha tests, breakpoints within Chrome, etc.

Some of these notable tangental changes are:

  • Completely removed Flow. Few files had Flow annotations, and its build process involvement was a major pain when debugging.
  • Updated all the linting related dependencies.
  • Updated most of the toolchain dependencies (babel, webpack).

Now that the material code that actually needs changed is known, it is possible to cherrypick out only those changes. Let me know if we want to try that.

@moxiegirl
Copy link

moxiegirl commented Nov 13, 2019

@zone117x Does this work require that we update all the package.json files on the samples?

@zone117x zone117x marked this pull request as ready for review November 18, 2019 20:51
Copy link
Contributor

@hstove hstove left a comment

Choose a reason for hiding this comment

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

Overall these are fantastic changes. I was a bit intimidated by the number of files changed, but the vast majority are simple changes due to removing Flow and @utils/@common resolvers.

The actual crypto code looks sound to me, and is familiar since I had to do some similar migration away from the HDNode interface for @blockstack/keychain.

I am curious about where exactly we're getting the W3C crypto polyfill. Is it because of the Babel changes, which include core-js? I didn't see anything in core-js about W3C crypto specifically. Or, are they just coming from blockstack.js?

I am impressed and grateful for this PR. I haven't finished a full functional QA yet, but there are tons of QOL improvements in this code.


import { HDNode } from 'bitcoinjs-lib'
import { bip32 } from 'bitcoinjs-lib'
import * as bip39 from 'bip39'
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to do a bunch of these changes as well in @blockstack/keychain. I'm not sure if it's worth more refactoring to bring that package in here (maybe that would help QA that package) but it's worth keeping in mind.

} from '@utils'
import { isCoreEndpointDisabled } from '@utils/window-utils'
} from '../../../utils'
import { isCoreEndpointDisabled } from '../../../utils/window-utils'
Copy link
Contributor

Choose a reason for hiding this comment

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

Another point for the future (if ever) - since packaging a core node is gone, we could probably remove this and other code references.

const dataBuffer = Buffer.from(encryptedBackupPhrase, 'hex')
const { password } = this.state

const updateProfileUrls = localIdentities.map((identity, index) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Good refactor - this file could certainly use more of it


// Stub out workers
const workers = ['encrypt', 'decrypt', 'crypto-check']
const workers = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Were these not necessary because of the webpack Workbox plugin?

]
},
{
test: /\.worker\.js$/,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, so we just aren't using Web Workers anymore, since these are now async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. Should I get rid of the rest of the workerize related dependencies and setup?

Copy link
Contributor

Choose a reason for hiding this comment

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

It wouldn't hurt to remove the dependency - is there other setup I'm missing?

@hstove
Copy link
Contributor

hstove commented Nov 19, 2019

Functional QA I'm doing:

  • Wallet testing
    • Sending BTC
  • Profile testing
    • Change profile image
    • Change profile info
    • Github social proof (not working?)
  • Decrypting master keychain
  • Sign in with recovery code
  • Sign in with seed
  • Getting new identities
  • Registering a new identity on an existing keychain
  • Signing up from scratch

Signing in with my magic recovery code still seems kind of slow and UI blocking - though not completely. Might have just been a one-off. Signing up was quick and definitely not blocking.

Github social proofs didn't work, but they're probably already broken? I know we changed the cheerio import, so wanted to double check that.

@hstove
Copy link
Contributor

hstove commented Nov 19, 2019

I'm seeing a weird issue with sending a BTC payment. I have $30 USD in my wallet, about 0.004 BTC, and no matter how much I try and send, I get "Not enough coin to fund fees transaction fees. Fees would be 5824, specified spend is 10". I see this comes from blockstack.js - is this an issue of not having the right UXTO's to put together a TX?

@zone117x
Copy link
Contributor Author

@hstove

I am curious about where exactly we're getting the W3C crypto polyfill.

The W3C crypto usage comes from blockstack.js, in this PR hirosystems/stacks.js#737

It's not really a crypto (Node.js module) polyfill, because there are no synchronous W3C crypto APIs available to create a polyfill. That blockstack.js PR directly uses the environment-native crypto APIs.

@zone117x
Copy link
Contributor Author

@hstove

I'm seeing a weird issue with sending a BTC payment

This appears to be an existing behavior, sending small btc amounts can trigger an incorrect error message. Created an issue: #1984

@timstackblock
Copy link
Contributor

@zone117x @hstove I cant send anything out of the wallet with this new release

Screen Shot 2019-12-11 at 11 27 28 AM

@hstove hstove merged commit e44718e into develop Jan 16, 2020
@stackatron stackatron removed this from the DevX 2020 Q1 - Sprint 2 milestone Feb 18, 2020
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.

7 participants