]> zoso.dev Git - libnemo.git/commitdiff
Fix this later.
authorChris Duncan <chris@zoso.dev>
Mon, 6 Jan 2025 22:41:58 +0000 (14:41 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 6 Jan 2025 22:41:58 +0000 (14:41 -0800)
perf/block.perf.js
src/lib/workers/powgpu.ts

index e2deeb7fdba06cf95ae09e48aca55c0095f47014..aacb70c11009634f4cef8f4292b90c8700b1f3e9 100644 (file)
@@ -23,7 +23,7 @@ await suite('Block performance', async () => {
                ]
                for (let i = 0; i < 6; i++) {
                        const start = performance.now()
-                       const work = await PowGpu.find(hashes[i])
+                       const work = await PowGpu.search(hashes[i])
                        const end = performance.now()
                        times.push(end - start)
                        console.log(`${work} (${end - start} ms) ${hashes[i]}`)
index 42decd50c8fea5e6cd6905051f5ff86eb214debe..3acd609304fb369d9eb648a57570d8d96a71965f 100644 (file)
@@ -470,7 +470,7 @@ export class PowGpu extends WorkerInterface {
        * @param {string} hash - Hexadecimal hash of previous block, or public key for new accounts
        * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation
        */
-       static async search (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, threshold: number = 0xfffffff8): Promise<void> {
+       static async search (hashHex: string, threshold: number = 0xfffffff8): Promise<string> {
                if (!/^[A-Fa-f0-9]{64}$/.test(hashHex)) throw new TypeError(`Invalid hash ${hashHex}`)
                if (typeof threshold !== 'number') throw new TypeError(`Invalid threshold ${threshold}`)
 
@@ -479,7 +479,7 @@ export class PowGpu extends WorkerInterface {
                        if (performance.now() > 8000) {
                                throw new Error(`WebGPU device failed to load in time.`)
                        }
-                       setTimeout(async () => { await this.search(hashHex, callback, threshold) }, 100)
+                       setTimeout(async () => { await this.search(hashHex, threshold) }, 100)
                        return
                }
 
@@ -550,10 +550,9 @@ export class PowGpu extends WorkerInterface {
 
                if (found) {
                        const hex = nonce.toString(16).padStart(16, '0')
-                       typeof callback === 'function' && callback(hex)
-                       return
+                       return hex
                } else {
-                       setTimeout(async () => { await this.search(hashHex, callback, threshold) })
+                       setTimeout(async () => { return await this.search(hashHex, threshold) })
                }
        }
 }