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

Blake3Hasher is not a constructor when using in the worker threads #29

Closed
sureshvenkata12 opened this issue Dec 12, 2021 · 12 comments
Closed

Comments

@sureshvenkata12
Copy link

When using Blake3Hasher in the worker threads, I get the following error:

TypeError [Error]: blake_hash_1.Blake3Hasher is not a constructor

@Brooooooklyn
Copy link
Owner

Please provide the reproduce codes

@Brooooooklyn
Copy link
Owner

I've tested @napi-rs/blake-hash@1.3.0 with node:16.13.1 and macOS:12.0.1 x64, everything work fine:

index.js

const { Worker } = require('worker_threads')

const worker = new Worker('./worker.js')

worker.on('message', (message) => {
  console.log(message)
})

worker.js

const { parentPort } = require('worker_threads')

const { Blake3Hasher } = require('@napi-rs/blake-hash')

const hasher = new Blake3Hasher()
hasher.update('hello')

parentPort.postMessage(hasher.digest('hex'))

@Brooooooklyn
Copy link
Owner

Tested on debian:9 with node:14.18.2, also works fine @sureshvenkata12

@Brooooooklyn
Copy link
Owner

@sureshvenkata12 do you have any codes or git branch I can debug?

@Brooooooklyn
Copy link
Owner

In ironfish/build/src/workerPool/tasks/mineHeader.js, the return type of require('@napi-rs/blake-hash-darwin-x64') became {}, an empty object. I don't know why because the start process of ironfish is too complex.

@sureshvenkata12
Copy link
Author

Do you have any idea what might be the issue? I will look into it deeper if you have any pointers. I've tried napi-rs/canvas package in the worker, it worked well.

@Brooooooklyn
Copy link
Owner

@sureshvenkata12 thanks for your investigation, I'll dig into this issue when I have time.

@Brooooooklyn
Copy link
Owner

Brooooooklyn commented Dec 22, 2021

@sureshvenkata12 Please try the https://github.com/Brooooooklyn/blake-hash/releases/tag/v1.3.1. It should fix this bug.

@dguenther
Copy link

v1.3.1 works based on my testing, thanks for the update!

@sureshvenkata12
Copy link
Author

@dguenther btw, how did you find out me trying "blake-hash" for ironfish? I guess, you will incorporate this into the main, and I will not have any advantage over others now :)

@dguenther
Copy link

It was just a coincidence! We wanted to test a native addon replacement for blake3 to address WASM out of memory issues.

@Brooooooklyn
Copy link
Owner

@dguenther You can consider https://napi.rs/ to replace neon in ironfish too. It provides more functionality and is easier to use.

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

No branches or pull requests

3 participants