nano-pow 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.js +4 -4
- package/dist/bin/nano-pow.sh +4 -0
- package/dist/bin/server.js +25 -4
- package/dist/main.min.js +8 -5
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { getRandomValues } from "node:crypto";
|
|
5
5
|
import { createInterface } from "node:readline/promises";
|
|
6
6
|
process.title = "NanoPow CLI";
|
|
7
|
-
process.env.NANO_POW_DEBUG
|
|
7
|
+
delete process.env.NANO_POW_DEBUG;
|
|
8
8
|
process.env.NANO_POW_EFFORT = "";
|
|
9
9
|
process.env.NANO_POW_PORT = "5041";
|
|
10
10
|
function log(...args2) {
|
|
@@ -38,9 +38,9 @@ If using --validate, results will also include validity properties.
|
|
|
38
38
|
|
|
39
39
|
-h, --help show this dialog
|
|
40
40
|
--debug enable additional logging output
|
|
41
|
-
|
|
41
|
+
--benchmark <value> generate work for specified number of random hashes
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
-b, --batch process all data before returning final results as array
|
|
44
44
|
-d, --difficulty <value> override the minimum difficulty value
|
|
45
45
|
-e, --effort <value> increase demand on GPU processing
|
|
46
46
|
-v, --validate <value> check an existing work value instead of searching for one
|
|
@@ -129,7 +129,7 @@ const start = performance.now();
|
|
|
129
129
|
for (const hash of hashes) {
|
|
130
130
|
try {
|
|
131
131
|
body.hash = hash;
|
|
132
|
-
const kill = setTimeout(aborter.abort,
|
|
132
|
+
const kill = setTimeout(() => aborter.abort(), 6e4);
|
|
133
133
|
const response = await fetch(`http://localhost:${process.env.NANO_POW_PORT}`, {
|
|
134
134
|
method: "POST",
|
|
135
135
|
body: JSON.stringify(body),
|
package/dist/bin/nano-pow.sh
CHANGED
|
@@ -11,6 +11,10 @@ mkdir -p "$NANO_POW_LOGS";
|
|
|
11
11
|
if [ "$1" = '--server' ]; then
|
|
12
12
|
shift;
|
|
13
13
|
node "$SCRIPT_DIR"/server.js > "$NANO_POW_LOGS"/nano-pow-server-$(date -u -Iseconds).log 2>&1 & echo "$!" > "$NANO_POW_HOME"/server.pid;
|
|
14
|
+
sleep 0.1;
|
|
15
|
+
if [ "$(ps | grep $(cat $NANO_POW_HOME/server.pid))" = '' ]; then
|
|
16
|
+
cat $(ls -td "$NANO_POW_LOGS"/* | head -n1);
|
|
17
|
+
fi;
|
|
14
18
|
else
|
|
15
19
|
node "$SCRIPT_DIR"/cli.js "$@";
|
|
16
20
|
fi;
|
package/dist/bin/server.js
CHANGED
|
@@ -6,19 +6,40 @@ import { subtle } from "node:crypto";
|
|
|
6
6
|
import { lookup } from "node:dns/promises";
|
|
7
7
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
8
8
|
import * as http from "node:http";
|
|
9
|
-
import { hostname } from "node:os";
|
|
9
|
+
import { homedir, hostname } from "node:os";
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
process.title = "NanoPow Server";
|
|
12
12
|
const MAX_REQUEST_SIZE = 1024;
|
|
13
13
|
const MAX_BODY_SIZE = 158;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
let DEBUG = !!(process.env.NANO_POW_DEBUG || false);
|
|
15
|
+
let EFFORT = +(process.env.NANO_POW_EFFORT || 8);
|
|
16
|
+
let PORT = +(process.env.NANO_POW_PORT || 5040);
|
|
17
17
|
let browser;
|
|
18
18
|
let page;
|
|
19
19
|
function log(...args) {
|
|
20
20
|
if (DEBUG) console.log(new Date(Date.now()).toLocaleString(), "NanoPow", args);
|
|
21
21
|
}
|
|
22
|
+
async function loadConfig() {
|
|
23
|
+
const contents = await readFile(join(homedir(), ".nano-pow", "config"), "utf-8");
|
|
24
|
+
if (typeof contents === "string") {
|
|
25
|
+
const config = contents.split("\n");
|
|
26
|
+
for (const line of config) {
|
|
27
|
+
const debugMatch = line.match(/^[ \t]*debug[ \t]*(true|false)[ \t]*(#.*)?$/i);
|
|
28
|
+
if (Array.isArray(debugMatch)) {
|
|
29
|
+
DEBUG = !!process.env.NANO_POW_DEBUG || debugMatch?.[1] === "true" || false;
|
|
30
|
+
}
|
|
31
|
+
const effortMatch = line.match(/^[ \t]*effort[ \t]*(\d{1,2})[ \t]*(#.*)?$/i);
|
|
32
|
+
if (Array.isArray(effortMatch)) {
|
|
33
|
+
EFFORT = +(process.env.NANO_POW_EFFORT || effortMatch?.[1] || 8);
|
|
34
|
+
}
|
|
35
|
+
const portMatch = line.match(/^[ \t]*port[ \t]*(\d{1,5})[ \t]*(#.*)?$/i);
|
|
36
|
+
if (Array.isArray(portMatch)) {
|
|
37
|
+
PORT = +(process.env.NANO_POW_PORT || portMatch?.[1] || 5040);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
await loadConfig();
|
|
22
43
|
async function respond(res, data) {
|
|
23
44
|
let statusCode = 500;
|
|
24
45
|
let headers = { "Content-Type": "application/json" };
|
package/dist/main.min.js
CHANGED
|
@@ -227,6 +227,7 @@ var NanoPowGl = class _NanoPowGl {
|
|
|
227
227
|
_NanoPowGl.#drawProgram = null;
|
|
228
228
|
_NanoPowGl.#gl = null;
|
|
229
229
|
_NanoPowGl.#busy = false;
|
|
230
|
+
_NanoPowGl.#isInitialized = false;
|
|
230
231
|
_NanoPowGl.init();
|
|
231
232
|
}
|
|
232
233
|
static #logAverages(times) {
|
|
@@ -353,7 +354,7 @@ var NanoPowGl = class _NanoPowGl {
|
|
|
353
354
|
setTimeout(async () => {
|
|
354
355
|
const result2 = this.work_generate(hash, options);
|
|
355
356
|
resolve(result2);
|
|
356
|
-
},
|
|
357
|
+
}, 500);
|
|
357
358
|
});
|
|
358
359
|
}
|
|
359
360
|
if (this.#isInitialized === false) this.init();
|
|
@@ -438,7 +439,7 @@ var NanoPowGl = class _NanoPowGl {
|
|
|
438
439
|
setTimeout(async () => {
|
|
439
440
|
const result2 = this.work_validate(work, hash, options);
|
|
440
441
|
resolve(result2);
|
|
441
|
-
},
|
|
442
|
+
}, 500);
|
|
442
443
|
});
|
|
443
444
|
}
|
|
444
445
|
if (this.#isInitialized === false) this.init();
|
|
@@ -604,6 +605,7 @@ var NanoPowGpu = class _NanoPowGpu {
|
|
|
604
605
|
_NanoPowGpu.#gpuBuffer?.destroy();
|
|
605
606
|
_NanoPowGpu.#uboBuffer?.destroy();
|
|
606
607
|
_NanoPowGpu.#busy = false;
|
|
608
|
+
_NanoPowGpu.#isInitialized = false;
|
|
607
609
|
_NanoPowGpu.init();
|
|
608
610
|
}
|
|
609
611
|
static #logAverages(times) {
|
|
@@ -683,7 +685,8 @@ var NanoPowGpu = class _NanoPowGpu {
|
|
|
683
685
|
this.#cpuBuffer.unmap();
|
|
684
686
|
} catch (err) {
|
|
685
687
|
console.warn(`Error getting data from GPU. ${err}`);
|
|
686
|
-
|
|
688
|
+
this.#cpuBuffer.unmap();
|
|
689
|
+
this.reset();
|
|
687
690
|
}
|
|
688
691
|
if (this.#debug) console.log("gpuBuffer data", data);
|
|
689
692
|
if (data == null) throw new Error(`Failed to get data from buffer.`);
|
|
@@ -703,7 +706,7 @@ var NanoPowGpu = class _NanoPowGpu {
|
|
|
703
706
|
setTimeout(async () => {
|
|
704
707
|
const result2 = this.work_generate(hash, options);
|
|
705
708
|
resolve(result2);
|
|
706
|
-
},
|
|
709
|
+
}, 500);
|
|
707
710
|
});
|
|
708
711
|
}
|
|
709
712
|
if (this.#isInitialized === false) this.init();
|
|
@@ -773,7 +776,7 @@ var NanoPowGpu = class _NanoPowGpu {
|
|
|
773
776
|
setTimeout(async () => {
|
|
774
777
|
const result2 = this.work_validate(work, hash, options);
|
|
775
778
|
resolve(result2);
|
|
776
|
-
},
|
|
779
|
+
}, 500);
|
|
777
780
|
});
|
|
778
781
|
}
|
|
779
782
|
if (this.#isInitialized === false) this.init();
|