From 210a18fce25fb0b746ea9ce34100633e7c75bc30 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 13 Aug 2026 13:51:26 +0000 Subject: [PATCH] refactor(pow): drop the redundant pre-mining created_at stamp The queue re-wrapped the template with a fresh created_at before handing it to the miner, but the miner now stamps the top of its first pass from the same clock -- so a job that waited in the queue or was restored from disk picks up "now" either way. The send-without-pow fallback keeps its own stamp; nothing mines on that path. Also records the shipped created_at work in the plan doc, including why the new parameter goes after isActive (so trailing-lambda call sites keep binding to it). Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_017pEArg58zWxDJ7EzzzPdXT --- .../amethyst/commons/service/pow/PoWPublishQueue.kt | 13 ++++--------- quartz/plans/2026-08-13-gpu-pow-mining.md | 11 +++++++++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/service/pow/PoWPublishQueue.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/service/pow/PoWPublishQueue.kt index 49f42f3e58..e0e7f0f3ef 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/service/pow/PoWPublishQueue.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/service/pow/PoWPublishQueue.kt @@ -214,15 +214,10 @@ class PoWPublishQueue( difficulty = difficulty, persistAs = persistAs, owner = pubKey, - mine = { isActive -> - val toMine = - if (clock != null) { - EventTemplate(clock(), template.kind, template.tags, template.content) - } else { - template - } - PoWMiner.mine(toMine, pubKey, difficulty, minerThreads, isActive, clock) - }, + // the miner stamps the first pass from the same clock, so the job + // picks up "now" whether it waited in the queue or was restored + // from disk — no need to re-wrap the template here. + mine = { isActive -> PoWMiner.mine(template, pubKey, difficulty, minerThreads, isActive, clock) }, publish = onMined, // send-now fallback: the same template, minus the nonce the miner would // have added. created_at follows the mined path — refreshed to "now" for diff --git a/quartz/plans/2026-08-13-gpu-pow-mining.md b/quartz/plans/2026-08-13-gpu-pow-mining.md index fd296e1eb0..0f3de9a517 100644 --- a/quartz/plans/2026-08-13-gpu-pow-mining.md +++ b/quartz/plans/2026-08-13-gpu-pow-mining.md @@ -197,10 +197,12 @@ is no longer blocking any UI could use more. NIP-90 kinds 5970/6970 — hand the template to a DVM with real hardware. That beats every on-device option and is already specced. -## Advancing `created_at` while mining +## Advancing `created_at` while mining — SHIPPED Not a speedup — a correctness fix that this analysis is a prerequisite for, because -it interacts with the midstate. +it interacts with the midstate. Implemented as described below; `PoWMiner.run/mine` +take an optional `refreshCreatedAt: (() -> Long)?`, covered by +`quartz/…/PoWMinerCreatedAtTest.kt`. NIP-13: *"It is recommended to update the `created_at` as well during this process."* We do half of it. `PoWPublishQueue.enqueue(refreshCreatedAtOnStart = …)` and the @@ -224,6 +226,11 @@ frozen behaviour. The consumers are already correct — `PoWNostrSigner` forward `mined.createdAt` to `signer.sign(…)`, and the queue publishes the mined template — so this is contained inside `PoWMiner` plus one flag at the call sites. +The new parameter goes **last**, after `isActive`, so the trailing-lambda call sites +keep binding their lambda to `isActive`. Kotlin would otherwise silently retarget them +at `refreshCreatedAt`; the `Boolean`/`Long` mismatch makes that a compile error rather +than a bug, but those sites were rewritten to a named `isActive = { … }` anyway. + **"When we can" is already modelled.** Reuse `refreshCreatedAtOnStart`'s predicate rather than inventing a second one; its comment already states the exclusion — *"Must stay false for scheduled posts, whose future created_at is intentional."*