From 466dd0a313e319b476947c58cb95c6851c4128ac Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 6 Jan 2025 14:41:58 -0800 Subject: [PATCH] Fix this later. --- perf/block.perf.js | 2 +- src/lib/workers/powgpu.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/perf/block.perf.js b/perf/block.perf.js index e2deeb7..aacb70c 100644 --- a/perf/block.perf.js +++ b/perf/block.perf.js @@ -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]}`) diff --git a/src/lib/workers/powgpu.ts b/src/lib/workers/powgpu.ts index 42decd5..3acd609 100644 --- a/src/lib/workers/powgpu.ts +++ b/src/lib/workers/powgpu.ts @@ -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) => any, threshold: number = 0xfffffff8): Promise { + static async search (hashHex: string, threshold: number = 0xfffffff8): Promise { 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) }) } } } -- 2.34.1