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

Quit if native bcrypto bindings are missing #729

Merged
merged 1 commit into from
Oct 31, 2019

Conversation

pinheadmz
Copy link
Member

This addresses user concern #572
and replaces bcoin-org/bcrypto#9

Test by moving or renaming the build directory in bcrypto which will force bcrypto to use nodejs crypto or proprietary crypto scripts for everything.

This PR throws an Error during handleOpen() that the bindings could not be found unless user explicitly sets NODE_BACKEND=js or NODE_BACKEND=node

@braydonf
Copy link
Contributor

As using JavaScript for many core operations such as secp256k1 verification and signing is really slow. I think it's a good idea to make it clear to the user that C/C++ code is not being used, as it's not practical to run a full node without it. Requiring user action to acknowledge that before proceeding can likely save debugging effort and confusion.

However, I'm not sure that this is the correct place for the check, and seems like it should be part of the build and install. For example, secp256k1-node gives a warning during install if the build fails, and I think there have been specific environment variables to have it error in specific cases.

Also related pull requests:

@tynes
Copy link
Member

tynes commented Mar 29, 2019

However, I'm not sure that this is the correct place for the check, and seems like it should be part of the build and install.

Are you suggesting a change to bcrypto or having a postInstall npm script?

I do like the idea of this PR because users should not end up running the JS backend if they did not intend to.

@pinheadmz
Copy link
Member Author

@tynes see bcoin-org/bcrypto#9 (comment)
This check won't be added to bcrypto. I like the idea of a post-install script, but are there scenarios in which the bindings could be installed correctly but then somehow moved or corrupted in some way that the user wouldn't know at run time?

@braydonf
Copy link
Contributor

braydonf commented May 3, 2019

Okay, yeah there is a case where install may not have been run. Switching nodejs versions may be one of those cases. I ran into this the other day when I saw unusually very slow block verification times, and then npm rebuild fixed it. Would have been good to get a message.

lib/node/node.js Outdated Show resolved Hide resolved
@codecov-io

This comment has been minimized.

@pinheadmz
Copy link
Member Author

Just noticed this commit in hsd:

handshake-org/hsd@4d7fdf4

Adds the same check as this PR, but in bin/node and quits if the primary hash functions are not built.

lib/node/node.js Outdated Show resolved Hide resolved
@pinheadmz
Copy link
Member Author

So, the idea of putting the backend check in bin makes sense to me -- those files will never be run in a browser like lib/node/node.js where I have the check now. I'm thinking the best approach is to port the commit from hsd to bcoin's bin/node and bin/spvnode and of course change the function to sha256(). Thoughts?

@pinheadmz
Copy link
Member Author

pinheadmz commented Oct 31, 2019

Ok I replaced the commit in this PR with a port of the hsd commit. Just changed blake2b to sha256. Note that secp256k1 is also checked, but I'm not sure how one would be built without the other. (C vs C++ compiler?)

To test:

$ cd bcoin/node_modules/bcrypto
$ mv build build-1
$ bcoin

Bindings for bcrypto were not built.
Please build them before continuing.

@braydonf braydonf changed the title node: require bindings or user-set backend Quit if native bcrypto bindings are missing Oct 31, 2019
braydonf added a commit that referenced this pull request Oct 31, 2019
Quit if native bcrypto bindings are missing
@braydonf braydonf merged commit d553f0a into bcoin-org:master Oct 31, 2019
@braydonf braydonf removed the ready for review Ready to be reviewed label Oct 31, 2019
@braydonf
Copy link
Contributor

braydonf commented Nov 5, 2019

So this has already been helpful, and warnings will appear if switching between nodejs versions and not rebuilding.

@braydonf braydonf added this to the 2.0.0 milestone Jan 6, 2020
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.

4 participants