From: Chris Duncan Date: Sun, 13 Apr 2025 04:59:01 +0000 (-0700) Subject: Print server error if it does not launch, typically due to puppeteer issue. Reset... X-Git-Tag: v4.1.1~1 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=7ad47fe6fa03ee9c3feb2fa4677e9dc326830b65;p=nano-pow.git Print server error if it does not launch, typically due to puppeteer issue. Reset on error reading from GPU instead of trying an infinite dispatch loop. Reduce interval for checking that GPU is not busy to half a second. Reset initialization flag when resetting NanoPowGpu. Fix abort call on timeout in cli. Extend CLI abort timeout to a full minute to accomodate low-power devices. Fix whitespace for inline help. --- diff --git a/src/bin/cli.ts b/src/bin/cli.ts index a0b8699..3355a6f 100755 --- a/src/bin/cli.ts +++ b/src/bin/cli.ts @@ -45,9 +45,9 @@ If using --validate, results will also include validity properties. -h, --help show this dialog --debug enable additional logging output - --benchmark generate work for specified number of random hashes + --benchmark generate work for specified number of random hashes - -b, --batch process all data before returning final results as array + -b, --batch process all data before returning final results as array -d, --difficulty override the minimum difficulty value -e, --effort increase demand on GPU processing -v, --validate check an existing work value instead of searching for one @@ -145,7 +145,7 @@ const start = performance.now() for (const hash of hashes) { try { body.hash = hash - const kill = setTimeout(aborter.abort, 5000) + const kill = setTimeout(() => aborter.abort(), 60000) const response = await fetch(`http://localhost:${process.env.NANO_POW_PORT}`, { method: 'POST', body: JSON.stringify(body), diff --git a/src/bin/nano-pow.sh b/src/bin/nano-pow.sh index 6229e98..5fa0d37 100755 --- a/src/bin/nano-pow.sh +++ b/src/bin/nano-pow.sh @@ -11,6 +11,10 @@ mkdir -p "$NANO_POW_LOGS"; if [ "$1" = '--server' ]; then shift; node "$SCRIPT_DIR"/server.js > "$NANO_POW_LOGS"/nano-pow-server-$(date -u -Iseconds).log 2>&1 & echo "$!" > "$NANO_POW_HOME"/server.pid; + sleep 0.1; + if [ "$(ps | grep $(cat $NANO_POW_HOME/server.pid))" = '' ]; then + cat $(ls -td "$NANO_POW_LOGS"/* | head -n1); + fi; else node "$SCRIPT_DIR"/cli.js "$@"; fi; diff --git a/src/lib/gl/index.ts b/src/lib/gl/index.ts index 4d638b4..c277d7b 100644 --- a/src/lib/gl/index.ts +++ b/src/lib/gl/index.ts @@ -220,6 +220,7 @@ export class NanoPowGl { NanoPowGl.#drawProgram = null NanoPowGl.#gl = null NanoPowGl.#busy = false + NanoPowGl.#isInitialized = false NanoPowGl.init() } @@ -363,7 +364,7 @@ export class NanoPowGl { setTimeout(async (): Promise => { const result = this.work_generate(hash, options) resolve(result) - }, 100) + }, 500) }) } if (this.#isInitialized === false) this.init() @@ -463,7 +464,7 @@ export class NanoPowGl { setTimeout(async (): Promise => { const result = this.work_validate(work, hash, options) resolve(result) - }, 100) + }, 500) }) } if (this.#isInitialized === false) this.init() diff --git a/src/lib/gpu/index.ts b/src/lib/gpu/index.ts index 067a168..8f484aa 100644 --- a/src/lib/gpu/index.ts +++ b/src/lib/gpu/index.ts @@ -110,6 +110,7 @@ export class NanoPowGpu { NanoPowGpu.#gpuBuffer?.destroy() NanoPowGpu.#uboBuffer?.destroy() NanoPowGpu.#busy = false + NanoPowGpu.#isInitialized = false NanoPowGpu.init() } @@ -207,7 +208,8 @@ export class NanoPowGpu { this.#cpuBuffer.unmap() } catch (err) { console.warn(`Error getting data from GPU. ${err}`) - return this.#dispatch(pipeline, seed, hash, difficulty, passes) + this.#cpuBuffer.unmap() + this.reset() } if (this.#debug) console.log('gpuBuffer data', data) if (data == null) throw new Error(`Failed to get data from buffer.`) @@ -228,7 +230,7 @@ export class NanoPowGpu { setTimeout(async (): Promise => { const result = this.work_generate(hash, options) resolve(result) - }, 100) + }, 500) }) } if (this.#isInitialized === false) this.init() @@ -307,7 +309,7 @@ export class NanoPowGpu { setTimeout(async (): Promise => { const result = this.work_validate(work, hash, options) resolve(result) - }, 100) + }, 500) }) } if (this.#isInitialized === false) this.init()