apow-cli 0.9.3 → 0.9.5
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/README.md +2 -2
- package/dist/config.js +1 -0
- package/dist/errors.js +1 -1
- package/dist/grinder-http.js +3 -3
- package/dist/miner.js +17 -7
- package/dist/preflight.js +1 -1
- package/local/gpu/grinder-cuda.cu +79 -12
- package/package.json +1 -1
- package/skill.md +3 -3
package/README.md
CHANGED
|
@@ -132,7 +132,7 @@ An LLM is required to mint your Mining Rig NFT (one-time identity verification).
|
|
|
132
132
|
|
|
133
133
|
| Provider | Model | Cost/call | Notes |
|
|
134
134
|
|----------|-------|-----------|-------|
|
|
135
|
-
| ClawRouter | `blockrun/eco` |
|
|
135
|
+
| ClawRouter | `blockrun/eco` | ~$0.006 | Recommended. Zero credentials, pays with USDC via x402 |
|
|
136
136
|
| OpenAI | `gpt-4o-mini` | ~$0.001 | Cheapest API key option, fast |
|
|
137
137
|
| Gemini | `gemini-2.5-flash` | ~$0.001 | Fast, good accuracy |
|
|
138
138
|
| DeepSeek | `deepseek-chat` | ~$0.001 | Fast, accessible in China |
|
|
@@ -166,7 +166,7 @@ apow fund --chain base --no-swap
|
|
|
166
166
|
|
|
167
167
|
## x402 GPU Grinding
|
|
168
168
|
|
|
169
|
-
No GPU? No problem. Remote RTX 4090 nonce grinding via the [x402 payment protocol](https://www.x402.org/) —
|
|
169
|
+
No GPU? No problem. Remote RTX 4090 nonce grinding via the [x402 payment protocol](https://www.x402.org/) — ~$0.006/grind (dynamic pricing tracks actual GPU cost), zero setup:
|
|
170
170
|
|
|
171
171
|
```bash
|
|
172
172
|
# In your .env (enabled automatically when USE_X402=true)
|
package/dist/config.js
CHANGED
|
@@ -114,6 +114,7 @@ exports.config = {
|
|
|
114
114
|
useX402Grind: process.env.USE_X402_GRIND !== undefined
|
|
115
115
|
? process.env.USE_X402_GRIND === "true"
|
|
116
116
|
: useX402, // defaults to USE_X402 value when not explicitly set
|
|
117
|
+
staleCheckIntervalMs: parseInt(process.env.STALE_CHECK_INTERVAL ?? "60", 10) * 1000,
|
|
117
118
|
};
|
|
118
119
|
function requirePrivateKey() {
|
|
119
120
|
if (!exports.config.privateKey) {
|
package/dist/errors.js
CHANGED
|
@@ -129,7 +129,7 @@ const patterns = [
|
|
|
129
129
|
test: (m) => m.includes("x402 GPU grind payment failed"),
|
|
130
130
|
classify: () => ({
|
|
131
131
|
category: "setup",
|
|
132
|
-
userMessage: "Insufficient USDC for x402 GPU grinding
|
|
132
|
+
userMessage: "Insufficient USDC for x402 GPU grinding",
|
|
133
133
|
recovery: "Send USDC to your wallet on Base, or set USE_X402_GRIND=false to disable remote grinding",
|
|
134
134
|
}),
|
|
135
135
|
},
|
package/dist/grinder-http.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* HTTP x402 nonce grinder — pay-per-grind GPU mining via GrindProxy.
|
|
4
4
|
*
|
|
5
5
|
* Sends {challenge, target, address} to a remote GPU endpoint (default:
|
|
6
|
-
* grind.apow.io). Payment (
|
|
7
|
-
* x402
|
|
8
|
-
* authorization and retries. No accounts, no API keys.
|
|
6
|
+
* grind.apow.io). Payment (dynamic USDC pricing based on GPU cost) is
|
|
7
|
+
* handled automatically via x402 — the server returns 402, the client
|
|
8
|
+
* signs a USDC authorization and retries. No accounts, no API keys.
|
|
9
9
|
*
|
|
10
10
|
* Front-running is cryptographically impossible: nonces are bound to
|
|
11
11
|
* keccak256(challenge, msg.sender, nonce) — a nonce ground for address A
|
package/dist/miner.js
CHANGED
|
@@ -193,7 +193,7 @@ async function startMining(tokenId) {
|
|
|
193
193
|
console.log(` Grinder: ${ui.bold(modeLabel)}`);
|
|
194
194
|
// Hint for JS-only miners without x402 grind
|
|
195
195
|
if (!useNative && !useHttpGrind) {
|
|
196
|
-
console.log(` ${ui.dim("Tip: Add USE_X402_GRIND=true for 10-100x faster mining (
|
|
196
|
+
console.log(` ${ui.dim("Tip: Add USE_X402_GRIND=true for 10-100x faster mining (~$0.006/grind).")}`);
|
|
197
197
|
}
|
|
198
198
|
console.log("");
|
|
199
199
|
while (true) {
|
|
@@ -269,14 +269,16 @@ async function startMining(tokenId) {
|
|
|
269
269
|
const smhlElapsed = elapsedSeconds(smhlStart);
|
|
270
270
|
console.log(` ${ui.dim(`SMHL solved (${(smhlElapsed * 1000).toFixed(1)}ms)`)}`);
|
|
271
271
|
// Grind nonce — native GPU/CPU if available, JS fallback
|
|
272
|
-
// Abort and re-fetch challenge
|
|
273
|
-
//
|
|
274
|
-
|
|
272
|
+
// Abort and re-fetch challenge periodically to avoid grinding a dead
|
|
273
|
+
// nonce after another miner wins the block. Configurable via
|
|
274
|
+
// STALE_CHECK_INTERVAL env var (seconds, default 60).
|
|
275
|
+
const staleCheckMs = config_1.config.staleCheckIntervalMs;
|
|
275
276
|
let grind = null;
|
|
277
|
+
let staleRestarts = 0;
|
|
276
278
|
while (!grind) {
|
|
277
279
|
const abortController = new AbortController();
|
|
278
280
|
const nonceSpinner = ui.spinner(`Grinding nonce (${modeLabel})...`);
|
|
279
|
-
// Background staleness checker
|
|
281
|
+
// Background staleness checker
|
|
280
282
|
const staleTimer = setInterval(async () => {
|
|
281
283
|
try {
|
|
282
284
|
const fresh = (await wallet_1.publicClient.readContract({
|
|
@@ -285,14 +287,15 @@ async function startMining(tokenId) {
|
|
|
285
287
|
functionName: "getMiningChallenge",
|
|
286
288
|
}));
|
|
287
289
|
if (fresh[0] !== challengeNumber) {
|
|
288
|
-
|
|
290
|
+
staleRestarts++;
|
|
291
|
+
nonceSpinner.stop(`Challenge changed — restarting grind (stale #${staleRestarts})`);
|
|
289
292
|
abortController.abort();
|
|
290
293
|
}
|
|
291
294
|
}
|
|
292
295
|
catch {
|
|
293
296
|
// RPC hiccup — don't abort, just skip this check
|
|
294
297
|
}
|
|
295
|
-
},
|
|
298
|
+
}, staleCheckMs);
|
|
296
299
|
try {
|
|
297
300
|
// Race all available grinders — first valid nonce wins
|
|
298
301
|
const grinders = [];
|
|
@@ -302,6 +305,7 @@ async function startMining(tokenId) {
|
|
|
302
305
|
if (abortController.signal.aborted)
|
|
303
306
|
throw err;
|
|
304
307
|
// Native failed but don't abort the race — others may still win
|
|
308
|
+
console.log(` ${ui.dim(`Native grinder error: ${err instanceof Error ? err.message : String(err)}`)}`);
|
|
305
309
|
return new Promise(() => { }); // hang forever (race will resolve via another grinder)
|
|
306
310
|
}));
|
|
307
311
|
}
|
|
@@ -310,6 +314,8 @@ async function startMining(tokenId) {
|
|
|
310
314
|
.catch((err) => {
|
|
311
315
|
if (abortController.signal.aborted)
|
|
312
316
|
throw err;
|
|
317
|
+
// Log x402 errors visibly — payment failures, timeouts, etc.
|
|
318
|
+
console.log(` ${ui.dim(`x402 GPU grinder error: ${err instanceof Error ? err.message : String(err)}`)}`);
|
|
313
319
|
return new Promise(() => { });
|
|
314
320
|
}));
|
|
315
321
|
}
|
|
@@ -343,6 +349,10 @@ async function startMining(tokenId) {
|
|
|
343
349
|
const freshSmhl = (0, smhl_1.normalizeSmhlChallenge)(freshChallenge[2]);
|
|
344
350
|
smhlSolution = (0, smhl_1.solveSmhlAlgorithmic)(freshSmhl);
|
|
345
351
|
console.log(` ${ui.dim("SMHL re-solved, grinding fresh challenge...")}`);
|
|
352
|
+
if (staleRestarts >= 3 && staleRestarts % 3 === 0) {
|
|
353
|
+
ui.warn(`Challenge has gone stale ${staleRestarts} times — grinder may be too slow for current difficulty.`);
|
|
354
|
+
ui.warn(`Tip: increase STALE_CHECK_INTERVAL (current: ${staleCheckMs / 1000}s) or use a faster grinder.`);
|
|
355
|
+
}
|
|
346
356
|
grind = null; // loop again
|
|
347
357
|
continue;
|
|
348
358
|
}
|
package/dist/preflight.js
CHANGED
|
@@ -253,7 +253,7 @@ async function runPreflight(level) {
|
|
|
253
253
|
const resp = await fetch(healthUrl, { signal: AbortSignal.timeout(5000) });
|
|
254
254
|
if (resp.ok) {
|
|
255
255
|
const host = new URL(grindUrl).hostname;
|
|
256
|
-
results.push({ label: `GrindProxy: ${host} (
|
|
256
|
+
results.push({ label: `GrindProxy: ${host} (dynamic pricing)`, passed: true });
|
|
257
257
|
}
|
|
258
258
|
else {
|
|
259
259
|
results.push({
|
|
@@ -25,12 +25,16 @@
|
|
|
25
25
|
#include <cstdint>
|
|
26
26
|
#include <ctime>
|
|
27
27
|
#include <chrono>
|
|
28
|
+
#include <csignal>
|
|
28
29
|
#include <unistd.h>
|
|
29
30
|
#include <sys/select.h>
|
|
30
31
|
|
|
31
32
|
#define MAX_ADDRS 8
|
|
32
33
|
#define MAX_LINE 4096
|
|
33
34
|
|
|
35
|
+
// Signal state — declared early so run_grind can check it
|
|
36
|
+
static volatile sig_atomic_t got_signal = 0;
|
|
37
|
+
|
|
34
38
|
// ── Keccak round constants ──
|
|
35
39
|
|
|
36
40
|
__constant__ uint64_t RC[24] = {
|
|
@@ -270,7 +274,7 @@ static void compute_target_be(uint64_t target_be[4], const uint8_t target[32]) {
|
|
|
270
274
|
static void configure_dispatch(GrindParams* params, const int weights[], int num_addrs,
|
|
271
275
|
uint64_t* out_batch_size, int* out_grid_size) {
|
|
272
276
|
const int BLOCK_SIZE = 256;
|
|
273
|
-
const uint64_t RAW_BATCH = 1ULL <<
|
|
277
|
+
const uint64_t RAW_BATCH = 1ULL << 24; // 16M — faster first-nonce latency (check 16x more often)
|
|
274
278
|
|
|
275
279
|
int total_weight = 0;
|
|
276
280
|
for (int a = 0; a < num_addrs; a++) total_weight += weights[a];
|
|
@@ -331,19 +335,51 @@ static bool run_grind(GrindParams* params, GrindResult* result,
|
|
|
331
335
|
}
|
|
332
336
|
}
|
|
333
337
|
|
|
334
|
-
//
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
// Check CUDA errors
|
|
339
|
+
cudaError_t err = cudaGetLastError();
|
|
340
|
+
if (err != cudaSuccess) {
|
|
341
|
+
fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(err));
|
|
342
|
+
cudaDeviceReset();
|
|
343
|
+
auto t1 = std::chrono::steady_clock::now();
|
|
344
|
+
double elapsed = std::chrono::duration<double>(t1 - t0).count();
|
|
345
|
+
printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
|
|
346
|
+
fflush(stdout);
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// In daemon mode, check for ABORT / EOF / signal between batches
|
|
351
|
+
if (check_abort) {
|
|
352
|
+
// Check for fatal signal (SIGHUP from SSH death, SIGTERM, etc.)
|
|
353
|
+
if (got_signal) {
|
|
354
|
+
cudaDeviceSynchronize();
|
|
355
|
+
auto t1 = std::chrono::steady_clock::now();
|
|
356
|
+
double elapsed = std::chrono::duration<double>(t1 - t0).count();
|
|
357
|
+
printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
|
|
358
|
+
fflush(stdout);
|
|
359
|
+
return false; // Signal received — exit grind
|
|
360
|
+
}
|
|
361
|
+
if (stdin_has_data()) {
|
|
362
|
+
char abort_buf[MAX_LINE];
|
|
363
|
+
if (fgets(abort_buf, sizeof(abort_buf), stdin)) {
|
|
364
|
+
// Trim
|
|
365
|
+
char* p = abort_buf;
|
|
366
|
+
while (*p == ' ' || *p == '\t') p++;
|
|
367
|
+
if (strncmp(p, "ABORT", 5) == 0) {
|
|
368
|
+
cudaDeviceSynchronize();
|
|
369
|
+
auto t1 = std::chrono::steady_clock::now();
|
|
370
|
+
double elapsed = std::chrono::duration<double>(t1 - t0).count();
|
|
371
|
+
printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
|
|
372
|
+
fflush(stdout);
|
|
373
|
+
return false; // Aborted
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
// fgets returned NULL = EOF (SSH connection died)
|
|
377
|
+
cudaDeviceSynchronize();
|
|
342
378
|
auto t1 = std::chrono::steady_clock::now();
|
|
343
379
|
double elapsed = std::chrono::duration<double>(t1 - t0).count();
|
|
344
380
|
printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
|
|
345
381
|
fflush(stdout);
|
|
346
|
-
return false; //
|
|
382
|
+
return false; // EOF — exit immediately
|
|
347
383
|
}
|
|
348
384
|
}
|
|
349
385
|
}
|
|
@@ -356,6 +392,26 @@ static bool run_grind(GrindParams* params, GrindResult* result,
|
|
|
356
392
|
return true;
|
|
357
393
|
}
|
|
358
394
|
|
|
395
|
+
// Signal handler — sets flag so grind loop exits quickly
|
|
396
|
+
static void signal_handler(int sig) {
|
|
397
|
+
// Write signal info to stderr (async-signal-safe)
|
|
398
|
+
const char* name = "UNKNOWN";
|
|
399
|
+
switch(sig) {
|
|
400
|
+
case SIGTERM: name = "SIGTERM"; break;
|
|
401
|
+
case SIGINT: name = "SIGINT"; break;
|
|
402
|
+
case SIGPIPE: name = "SIGPIPE"; break;
|
|
403
|
+
case SIGHUP: name = "SIGHUP"; break;
|
|
404
|
+
case SIGUSR1: name = "SIGUSR1"; break;
|
|
405
|
+
case SIGUSR2: name = "SIGUSR2"; break;
|
|
406
|
+
}
|
|
407
|
+
fprintf(stderr, "SIGNAL %d (%s) received\n", sig, name);
|
|
408
|
+
fflush(stderr);
|
|
409
|
+
got_signal = sig;
|
|
410
|
+
// Re-raise to get default behavior
|
|
411
|
+
signal(sig, SIG_DFL);
|
|
412
|
+
raise(sig);
|
|
413
|
+
}
|
|
414
|
+
|
|
359
415
|
// ── Daemon mode: persistent CUDA process ──
|
|
360
416
|
static int run_daemon() {
|
|
361
417
|
const int BLOCK_SIZE = 256;
|
|
@@ -374,13 +430,24 @@ static int run_daemon() {
|
|
|
374
430
|
grind_kernel<<<1, 1>>>(params, result);
|
|
375
431
|
cudaDeviceSynchronize();
|
|
376
432
|
|
|
377
|
-
|
|
433
|
+
// Ignore SIGPIPE (critical for daemon writing to SSH channel)
|
|
434
|
+
signal(SIGPIPE, SIG_IGN);
|
|
435
|
+
// Install signal handlers for debugging other signals
|
|
436
|
+
signal(SIGTERM, signal_handler);
|
|
437
|
+
signal(SIGINT, signal_handler);
|
|
438
|
+
signal(SIGHUP, signal_handler);
|
|
439
|
+
signal(SIGUSR1, signal_handler);
|
|
440
|
+
signal(SIGUSR2, signal_handler);
|
|
441
|
+
signal(SIGSEGV, signal_handler);
|
|
442
|
+
signal(SIGABRT, signal_handler);
|
|
443
|
+
|
|
444
|
+
fprintf(stderr, "CUDA daemon ready (pid=%d)\n", getpid());
|
|
378
445
|
printf("READY\n");
|
|
379
446
|
fflush(stdout);
|
|
380
447
|
|
|
381
448
|
// Main loop: read challenges from stdin
|
|
382
449
|
char line[MAX_LINE];
|
|
383
|
-
while (fgets(line, sizeof(line), stdin)) {
|
|
450
|
+
while (!got_signal && fgets(line, sizeof(line), stdin)) {
|
|
384
451
|
// Trim leading whitespace
|
|
385
452
|
char* p = line;
|
|
386
453
|
while (*p == ' ' || *p == '\t') p++;
|
package/package.json
CHANGED
package/skill.md
CHANGED
|
@@ -290,7 +290,7 @@ CHAIN=base
|
|
|
290
290
|
| `CUDA_GRINDER_PATH` | No | auto-detected | Explicit path to local CUDA grinder binary |
|
|
291
291
|
| `CPU_GRINDER_PATH` | No | auto-detected | Explicit path to CPU-C grinder binary |
|
|
292
292
|
| `CPU_THREADS` | No | All CPU cores | Thread count for CPU-C grinder |
|
|
293
|
-
| `USE_X402_GRIND` | No | same as `USE_X402` | Enable remote GPU grinding via x402 (
|
|
293
|
+
| `USE_X402_GRIND` | No | same as `USE_X402` | Enable remote GPU grinding via x402 (dynamic pricing, ~$0.006/grind). Set `false` to disable even when `USE_X402=true`. |
|
|
294
294
|
| `GRIND_URL` | No | `https://grind.apow.io/grind` | Custom GrindProxy endpoint URL (for self-hosted grinding) |
|
|
295
295
|
| `VAST_IP` | No | - | Remote VAST.ai GPU host IP (for remote CUDA mining) |
|
|
296
296
|
| `VAST_PORT` | No | - | Remote VAST.ai GPU SSH port |
|
|
@@ -303,7 +303,7 @@ CHAIN=base
|
|
|
303
303
|
|
|
304
304
|
| Provider | Model | Cost per call | Notes |
|
|
305
305
|
|---|---|---|---|
|
|
306
|
-
| ClawRouter | `blockrun/eco` |
|
|
306
|
+
| ClawRouter | `blockrun/eco` | ~$0.006 | **Recommended.** Zero credentials, pays with USDC via x402 |
|
|
307
307
|
| OpenAI | `gpt-4o-mini` | ~$0.001 | Cheapest API key option, fast, reliable |
|
|
308
308
|
| Gemini | `gemini-2.5-flash` | ~$0.001 | Fast, good accuracy |
|
|
309
309
|
| DeepSeek | `deepseek-chat` | ~$0.001 | Fast, accessible in China |
|
|
@@ -561,7 +561,7 @@ Supported grinders (all race in parallel -- first nonce wins, falls back to JS a
|
|
|
561
561
|
|
|
562
562
|
### x402 GPU Grinding (Remote RTX 4090)
|
|
563
563
|
|
|
564
|
-
No GPU? Add `USE_X402_GRIND=true` to your `.env` for remote RTX 4090 nonce grinding at
|
|
564
|
+
No GPU? Add `USE_X402_GRIND=true` to your `.env` for remote RTX 4090 nonce grinding at ~$0.006/grind (dynamic pricing) via the [x402 payment protocol](https://www.x402.org/). Zero setup, zero API keys — payment is automatic from your mining wallet's USDC balance.
|
|
565
565
|
|
|
566
566
|
```bash
|
|
567
567
|
# In your .env (enabled automatically when USE_X402=true)
|