mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-05 19:28:25 +00:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017pEArg58zWxDJ7EzzzPdXT
This commit is contained in:
+4
-9
@@ -214,15 +214,10 @@ class PoWPublishQueue(
|
||||
difficulty = difficulty,
|
||||
persistAs = persistAs,
|
||||
owner = pubKey,
|
||||
mine = { isActive ->
|
||||
val toMine =
|
||||
if (clock != null) {
|
||||
EventTemplate<T>(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
|
||||
|
||||
@@ -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."*
|
||||
|
||||
Reference in New Issue
Block a user