]> zoso.dev Git - nano-pow.git/commitdiff
Add debug logging to GPU.
authorChris Duncan <chris@zoso.dev>
Wed, 12 Mar 2025 21:18:25 +0000 (14:18 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 12 Mar 2025 21:18:25 +0000 (14:18 -0700)
src/classes/gpu.ts

index dc9b00fb55aba0cb591c15a2ac5a63d81ad0bfd3..0d98770cd0e921855cfc56434c471aa4d285b26d 100644 (file)
@@ -234,6 +234,7 @@ export class NanoPowGpu {
                        ? 0x800
                        : options.effort * 0x100
                this.#debug = !!(options?.debug)
+               if (this.#debug) console.log('blockhash', hash)
                if (this.#debug) console.log('search options', JSON.stringify(options))
 
                // Ensure WebGPU is initialized before calculating
@@ -259,6 +260,7 @@ export class NanoPowGpu {
                        if (this.#debug) console.log(`seed: ${seed}`)
                        const data = await this.#dispatch(this.#searchPipeline, seed, hash, threshold, effort)
                        nonce = data.getBigUint64(0, true)
+                       if (this.#debug) console.log('nonce', nonce, nonce.toString(16).padStart(16, '0'))
                        this.#busy = !data.getUint32(8)
                        times.push(performance.now() - start)
                } while (this.#busy)
@@ -290,6 +292,7 @@ export class NanoPowGpu {
                        ? 0xfffffff8
                        : options.threshold
                this.#debug = !!(options?.debug)
+               if (this.#debug) console.log('blockhash', hash)
                if (this.#debug) console.log('validate options', JSON.stringify(options))
 
                // Ensure WebGPU is initialized before calculating
@@ -307,11 +310,11 @@ export class NanoPowGpu {
                const seed = BigInt(`0x${work}`)
                if (this.#debug) console.log(`work: ${work}`)
                const data = await this.#dispatch(this.#validatePipeline, seed, hash, threshold, 1)
-               const nonce = data.getBigUint64(0, true).toString(16).padStart(16, '0')
-               if (this.#debug) console.log(`nonce: ${nonce}`)
+               const nonce = data.getBigUint64(0, true)
+               if (this.#debug) console.log('nonce', nonce, nonce.toString(16).padStart(16, '0'))
                const found = !!data.getUint32(8)
                this.#busy = false
-               if (found && work !== nonce) throw new Error(`Nonce (${nonce}) found but does not match work (${work})`)
+               if (found && work !== nonce.toString(16).padStart(16, '0')) throw new Error(`Nonce (${nonce.toString(16).padStart(16, '0')}) found but does not match work (${work})`)
                return found
        }
 }