Skip to content

Mainnet readiness - #19

Merged
djh58 merged 20 commits into
mainfrom
dan/mainnet-deploy-requirements
Jul 14, 2026
Merged

djh58 merged 20 commits into
mainfrom
dan/mainnet-deploy-requirements

Conversation

@djh58

@djh58 djh58 commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add a fail-closed production deployment contract with immutable image inputs, host-backed state, operator-only profiles, exact chain identity, and bounded template readiness
  • consolidate permissionless mining and the bundled real-miner smoke onto one ordinary CKPool endpoint on port 3333, with exact Compose profile contracts and a deprecated compatibility alias
  • make PRISM share acknowledgments commit-backed, persist block-candidate intent atomically, replay pending work after restart, and require deployment-matched capacity evidence
  • harden node synchronization gates, template-refresh watchdogs, automatic lab wallet readiness, source and release provenance, CTV launch fee policy, service lifecycle behavior, and destructive cleanup safeguards
  • document the fresh-host mainnet deployment, storage, backup, recovery, and qualification procedures

Validation

  • python3 -m unittest discover -s tests -p 'test_*.py' (679 tests)
  • cargo test --locked --workspace --all-targets
  • make test-prism-postgres-ledger
  • make test-permissionless (accepted block through CKPool)
  • make test-real-miner (cpuminer accepted block through ckpool:3333)
  • make test-auxpow-stratum (shared real-miner image accepted an AuxPoW block)
  • permissionless, real-miner-smoke, AuxPoW, PRISM, and production Docker Compose contract renders
  • ShellCheck, shell syntax validation, Python compilation, and clean-diff checks
  • Bitcoin Core release digests checked against the published release manifest

Note

High Risk
Touches production deployment contracts, ledger durability, block submission outbox, and mainnet/AuxPoW/CKPool readiness gates—errors could affect payouts, share accounting, or pool availability on public chains.

Overview
Introduces a fail-closed production deployment path: compose.production.yaml pins digest-qualified images, absolute host bind mounts for chain/ledger/audit state, and disables lab-only services; DEPLOY_ENV_FILE and new *_IMAGE / *_DATA_SOURCE env knobs separate operator deploys from local .env. Mainnet unconditionally enforces release provenance (images, paths, PRISM capacity evidence); other chains can opt in via QBIT_REQUIRE_RELEASE_PROVENANCE. Docs cover mainnet sequence, Bitcoin tarball SHA256 verification, PRISM capacity qualification, and Postgres WAL/storage recovery.

Permissionless mining collapses onto a single ckpool on port 3333: the separate ckpool-real stack is removed in favor of real-miner-smoke sharing payout state with ordinary CKPool. CKPool/AuxPoW/PRISM preflight and supervisors tighten chain/genesis identity, explicit production payout addresses, template age bounds, and bounded refresh-failure exits. AuxPoW gains startup readiness checks (IBD, peers, fresh parent templates) and stricter mainnet rules (explicit addresses, no diagnostic header variants).

PRISM moves share ACKs to Postgres commit (batch/linger settings), adds qbit_block_candidate_outbox for durable block submission after restart, documents collection mode below PRISM_MIN_READY_MINERS, and validates deployment-matched capacity evidence via lab/prism/capacity_evidence.py. Makefile/CI add lab-mode guards, isolated test compose projects, purge-local-volumes with confirmation, and Postgres ledger + mainnet compose contract tests.

Reviewed by Cursor Bugbot for commit 9d2647d. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread lab/prism/prism_coordinator.py Resolved
Comment thread docker/ckpool/qbit-ckpool-preflight.py Resolved
Comment thread docker/ckpool/qbit-ckpool-preflight.py Resolved
Comment thread compose.yaml Resolved
Comment thread lab/auxpow/auxpow_coordinator.py Resolved
Comment thread docker/ckpool/qbit-ckpool-preflight.py Resolved
Comment thread lab/auxpow/auxpow_coordinator.py Resolved
djh58 and others added 6 commits July 13, 2026 17:37
Production validation now runs in two tiers. The behavioral tier
(non-default credentials, explicit payout addresses, strict difficulty
and readiness policies, zero stale grace, commit-pinned sources) keeps
its existing trigger: QBIT_PRODUCTION=1, QBIT_TOOLS_PRODUCTION=1, or
QBIT_CHAIN=mainnet. The release-provenance tier (digest-qualified
*_IMAGE references, absolute *_DATA_SOURCE host paths, and fresh PRISM
capacity evidence) is enforced unconditionally on mainnet -- no
environment variable can disable it there -- and on other chains only
with the new QBIT_REQUIRE_RELEASE_PROVENANCE=1 opt-in.

A production pool that builds its images from the pinned source in
place (for example a public testnet4 deployment) can never satisfy
digest-pinned image references or image-digest-matched capacity
evidence, so the previous single-tier gate made such deployments
impossible without weakening any real safety property they rely on.

The same tiering applies to every enforcement point of the capacity
evidence contract: scripts/check-env.sh, the PRISM coordinator startup
gate, and prism-self-check's capacity.evidence row. No check is
deleted or weakened; each is re-tiered with identical mainnet-always
semantics.

Co-Authored-By: Claude Fable 5 <[email protected]>
@djh58

djh58 commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

Production gate split: behavioral checks vs. release provenance

77c9397 splits the production gate into two tiers, and 80c8d48 merges current main (the CKPOOL_BTCSIG explicit-empty fix, #20) into this branch.

Why

The single-tier gate coupled two different contracts behind QBIT_PRODUCTION=1:

  1. Behavioral safety — non-default RPC credentials, explicit miner addresses, strict CKPool diff/readiness policies, PRISM ledger/signing configuration, PRISM_STRATUM_STALE_GRACE_SECONDS=0, chain/flag consistency, 40-hex source pins.
  2. Release provenance — digest-qualified *_IMAGE references, absolute *_DATA_SOURCE host paths, and fresh capacity evidence whose subject digest must equal PRISM_COORDINATOR_IMAGE's @sha256.

A live public testnet4 pool runs with QBIT_PRODUCTION=1 deliberately — it wants every behavioral check — but builds its images from the pinned source with compose up --build. Digest-qualified image references and image-digest-matched capacity evidence cannot exist for locally built images, so tier 2 could never pass there and the doctor became un-runnable on testnet4 (failures surfacing one at a time via fail-fast made this worse).

What changed

  • Behavioral tier: unchanged trigger (QBIT_PRODUCTION=1, QBIT_TOOLS_PRODUCTION=1, or QBIT_CHAIN=mainnet), all checks kept.
  • Release-provenance tier (check_prism_capacity_evidence + check_production_deployment_inputs): enforced unconditionally when QBIT_CHAIN=mainnet — no environment variable can disable it there — and on other chains only with the new QBIT_REQUIRE_RELEASE_PROVENANCE=1 opt-in (documented in .env.example next to the PRISM_CAPACITY_* block). The doctor prints an explicit release provenance not enforced for QBIT_CHAIN=<chain> notice when a production run skips the tier.
  • The same tiering is applied to the other two enforcement points of the capacity-evidence contract introduced by this PR, which would otherwise still have broken testnet4 at runtime: the PRISM coordinator startup gate (validate_prism_release_provenance_gate) and prism-self-check's capacity.evidence row. No check is deleted or weakened anywhere — only re-tiered, with identical mainnet-always semantics in all three places.

Validation

  • New end-to-end doctor tests: a fully-specified testnet4 production env (explicit addresses, non-default creds, PRISM ledger/signing vars, stale grace 0, pinned 40-hex commit, no digests / data sources / capacity vars) passes; the same env with QBIT_CHAIN=mainnet fails on the first provenance check for every value of the opt-out ("", 0, false); the opt-in flag enforces provenance on testnet4 and even without production mode.
  • Full suite: 689 tests OK; shellcheck -x and bash -n clean on all shell scripts.

A miner can resubmit the same solved block after a transient submit
outcome. The rebuilt candidate intent differs from the persisted one
only in pending_share.accepted_at_ms, so whenever the retry crossed a
millisecond boundary the durable outbox rejected it with "block
candidate payload mismatch" -- a timing-dependent failure seen in CI
and reproducible locally about one run in eight.

Compare candidates by an identity form that excludes the volatile
acknowledgment stamp, in both ledger backends and on both the
persist-intent and landed-append paths. The first persisted payload
stays authoritative and any divergence other than the stamp is still a
hard payload mismatch. The previously flaky transient-outcome test now
forces every call onto a new millisecond, and a ledger-level test pins
drift-idempotence, first-payload retention, and the surviving
mismatch error.

Co-Authored-By: Claude Fable 5 <[email protected]>
@djh58

djh58 commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

Follow-up 60d921a: fixed the timing-dependent CI failure that hit one of the two runs on 77c9397 (test_below_target_transient_outcome_closes_without_definitive_reject, ValueError: block candidate payload mismatch).

A resubmission of the same solved block after a transient outcome rebuilds its candidate intent with a fresh pending_share.accepted_at_ms, so whenever the retry crossed a millisecond boundary the durable outbox's idempotency hash rejected it (~1-in-8 locally). Both ledger backends now compare candidates by an identity form that excludes that volatile stamp, on both the persist-intent and landed-append paths; the first persisted payload stays authoritative and any other divergence is still a hard payload mismatch. The flaky test now forces every call onto a new millisecond (it fails deterministically on the pre-fix ledger), plus a ledger-level regression test. Suite: 690 tests OK.

djh58 and others added 2 commits July 14, 2026 11:13
Port of the fixes reviewed and merged on the private branch
(SwapLabsInc #175, commit 74ff97b):

- Classify template-policy misconfiguration (CKPOOL_TEMPLATE_MAX_AGE_SECONDS
  <= 0, CKPOOL_TEMPLATE_MAX_FUTURE_SECONDS < 0) as TemplateValidationError so
  the watchdog fails closed immediately instead of routing them through the
  transient-RPC grace window while CKPool keeps mining.

- Require a previousblockhash/tip mismatch to persist across three
  time-separated snapshots (1s apart) before fetch_and_validate_template
  raises MiningStateValidationError. A block arriving between
  getblocktemplate and getbestblockhash no longer kills the pool on an
  innocent tip advance, while a genuinely wedged or forked template builder
  still fails closed.

Co-Authored-By: Claude Fable 5 <[email protected]>
Before the ledger has accepted shares from PRISM_MIN_READY_MINERS
distinct miners, jobs run in collection mode, and a block solved on
such a job was silently withheld: the share was ledgered but the block
was never submitted. On a fresh ledger at bootstrap difficulty -- where
the high-diff listener's share floor sits above the network target and
every accepted share is also a valid block -- that structurally
discards the first solved block(s), and in the degenerate single-lane
case stalls the chain at its starting height while the pool keeps
acknowledging shares.

The collection bundle already commits the whole coinbase to the
submitting worker through a signed bootstrap manifest, so solver-pays-
all is a valid, auditable settlement. Make collection candidates
block-worthy: they submit through the same synchronous and queued paths
as ready-window candidates, are counted by a new
qbit_prism_collection_block_submissions_total metric with an explicit
log line, and carry a collection_only flag through the durable
block-candidate intent (absent in previously persisted intents, which
replay unchanged as ready-window candidates).

Also close the propagation gap after readiness flips: crossing
min_ready_miners is invisible to the template fingerprint, so already
connected miners kept their collection jobs until an unrelated event.
The template poller now latches the (monotonic) readiness transition
once and replaces outstanding collection jobs with windowed work on its
next pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
@djh58

djh58 commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

130724a closes a fresh-ledger block-withholding window in PRISM. Before the ledger has accepted shares from PRISM_MIN_READY_MINERS distinct miners, jobs run in collection mode — and a block solved on such a job was ledgered as an ordinary share and never submitted. At bootstrap difficulty (high-diff floor above the network target, where every accepted share is also a valid block) that structurally discards the first solved block(s); in the degenerate single-lane case it stalls the chain at its starting height while shares keep being acknowledged.

The collection bundle already commits the whole coinbase to the submitting worker via a signed bootstrap manifest — a valid, auditable solver-pays-all settlement — so collection candidates are now block-worthy through the same sync/queued submit paths, counted by qbit_prism_collection_block_submissions_total and logged explicitly. The collection_only flag rides the durable block-candidate intent (absent in previously persisted intents, which replay unchanged). Also fixed the propagation gap: readiness is invisible to the template fingerprint, so the poller now latches the monotonic readiness transition and replaces outstanding collection jobs on its next pass instead of waiting for an unrelated event (up to 90s, or unbounded on a quiet chain).

Suite: 693 tests OK. Mature ledgers (any live pool) never re-enter collection mode, so this is inert for existing deployments; it matters for fresh-ledger launches.

The zero-grace requirement sat in the behavioral production tier, so a
public test-chain pool running QBIT_PRODUCTION=1 could not credit
shares that raced a block within the miner job-switch latency (~2s):
during difficulty catch-up sprints every one of those shares became a
miner-visible reject, which reads as pool instability to rented
hashpower even though the work was real and the safety property --
never build a block on a stale template -- is enforced independently
of crediting.

Require PRISM_STRATUM_STALE_GRACE_SECONDS=0 only when
QBIT_CHAIN=mainnet, in all three enforcement points (check-env.sh,
the coordinator production gate, prism-self-check). Other chains may
configure a bounded grace window; grace-credited shares remain
excluded from block submission everywhere.

Co-Authored-By: Claude Fable 5 <[email protected]>
@djh58

djh58 commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

2215316 re-tiers the zero-stale-grace requirement to mainnet only, in all three enforcement points (doctor, coordinator startup gate, self-check). Rationale: the stale window on a share is the miner job-switch latency (~2s), and with zero grace every share racing a block becomes a miner-visible reject — during difficulty catch-up sprints on a public test chain that reads as pool instability to rented hashpower, even though the work is real. Public test chains may now configure a bounded grace window; mainnet still pins 0, and grace-credited shares remain excluded from block submission everywhere (the never-build-on-a-stale-template property is independent of crediting). Suite: 697 tests OK, shellcheck clean.

The chain-trust gate refuses to issue jobs while qbitd reports initial
block download, and a virgin regtest chain stays in IBD until its first
block -- so the harness deadlocked: no jobs without a block, no block
without jobs. Pre-mine one block before starting the coordinator; the
PRISM ledger stays empty, so the fresh-ledger collection path is still
what the miners exercise.

The first-difficulty probes also predated the stamped job floor: the
advertised share difficulty is now clamped to the network difficulty (a
share is never required to be harder than a block), with only the
high-diff wire floor holding above the clamp; password d=/md= bound
vardiff but do not lift the first job. Expect the clamp dynamically and
keep the 500k floor expectation. Finally, with every share also being a
block, a share in flight during the stop-after-block shutdown can land
one extra block, so the final height check requires at least -- not
exactly -- the target.

Verified end to end with one miner (PRISM_MIN_READY_MINERS=1): the
fresh-ledger collection candidate is submitted solver-pays-all and the
run passes through the evidence and verifier stages.

Co-Authored-By: Claude Fable 5 <[email protected]>
@djh58

djh58 commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

c55acb5 — ran the fresh-ledger end-to-end (D3 for the collection fix) and repaired the live regtest harness, which had been broken by this PR's own hardening in three ways:

  1. Fresh-chain IBD deadlock: the chain-trust gate refuses to issue jobs during initial block download, and a virgin regtest chain stays in IBD until its first block — no jobs without a block, no block without jobs. The harness now pre-mines one block (the PRISM ledger stays empty, so the fresh-ledger collection path is still exercised).
  2. Stale difficulty expectations: the stamped job floor clamps the advertised share difficulty to the network difficulty; only the high-diff wire floor holds above it, and password d=/md= bound vardiff without lifting the first job. Probes now expect the clamp dynamically.
  3. Exact-height assertion: with every share also being a block, an in-flight share can land one extra block during the stop-after-block shutdown; the final check now requires at least the target.

With those fixed, the run passes end-to-end with one miner and PRISM_MIN_READY_MINERS=1: the very first solved block rides a collection-mode job, is submitted solver-pays-all (collection-mode block candidate settles solver-pays-all in the coordinator log, counted by the new metric), lands on-chain, and the evidence/verifier stages pass.

One launch-planning note falls out of finding 1: the same IBD gate (coordinator chain-trust plus the ckpool preflight readiness gate) applies to a fresh mainnet — qbitd reports IBD=true whenever the tip is older than ~24h, so if the final mainnet genesis is timestamped well before public launch, no lane will serve work at t=0. Either timestamp the genesis close to launch or plan an explicit bootstrap posture for the first block; worth deciding before the launch runbook is frozen.

…quirements

# Conflicts:
#	compose.yaml
#	docker/ckpool/qbit-ckpool-preflight.py
#	scripts/check-env.sh
#	tests/test_check_env_production_gate.py
#	tests/test_qbit_ckpool_preflight.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e230222. Configure here.

Comment thread Makefile Resolved
djh58 added 2 commits July 14, 2026 15:14
…quirements

# Conflicts:
#	.env.example
#	README.md
#	compose.yaml
#	docker/ckpool/qbit-ckpool-preflight.py
#	docker/ckpool/start-ckpool.sh
#	tests/test_qbit_ckpool_preflight.py
@djh58
djh58 requested a review from kiwidream July 14, 2026 20:26
@djh58
djh58 merged commit 2aceecb into main Jul 14, 2026
5 checks passed
kiwidream added a commit that referenced this pull request Sep 4, 2026
…ited, not rejected

The production gate pinned PRISM_STRATUM_STALE_GRACE_SECONDS=0 on mainnet
(coordinator startup, scripts/check-env.sh, scripts/prism-self-check.py).
With a zero window every in-flight share on the just-replaced tip is
rejected with Stratum error 21 (stale-job / unknown-job) at each block,
and miner firmware counts any pool-side error as a reject: "stale" on the
miner side is only ever derived client-side, so the only way the pool
avoids a reject is to accept the share. That is exactly what the
stale-grace credit policy does (ack, ledger with credit_policy=stale-grace,
never block-submit), and the classification logic itself was verified
against the existing tip-flip tests.

Mainnet now follows the same bounded-grace rule as every other production
chain (default 3 s; an explicit 0 remains valid). The pin was added in #19
citing audit-bundle v1.1 verifier compatibility; this release's verifier
accepts v1.1, and the docs now say to keep external mirrors and verifiers
on a release that does too. No hot-path code changes.

On this release line the coordinator-side gate lives in
lab/prism/coordinator_config.py rather than lab/prism/prism_coordinator.py,
and its regression test lives in tests/test_prism_coordinator_config.py.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
kiwidream added a commit that referenced this pull request Sep 4, 2026
…ited, not rejected (#225)

* Stop forcing zero stale grace on mainnet so prior-tip shares are credited, not rejected

The production gate pinned PRISM_STRATUM_STALE_GRACE_SECONDS=0 on mainnet
(coordinator startup, scripts/check-env.sh, scripts/prism-self-check.py).
With a zero window every in-flight share on the just-replaced tip is
rejected with Stratum error 21 (stale-job / unknown-job) at each block,
and miner firmware counts any pool-side error as a reject: "stale" on the
miner side is only ever derived client-side, so the only way the pool
avoids a reject is to accept the share. That is exactly what the
stale-grace credit policy does (ack, ledger with credit_policy=stale-grace,
never block-submit), and the classification logic itself was verified
against the existing tip-flip tests.

Mainnet now follows the same bounded-grace rule as every other production
chain (default 3 s; an explicit 0 remains valid). The pin was added in #19
citing audit-bundle v1.1 verifier compatibility; this release's verifier
accepts v1.1, and the docs now say to keep external mirrors and verifiers
on a release that does too. No hot-path code changes.

On this release line the coordinator-side gate lives in
lab/prism/coordinator_config.py rather than lab/prism/prism_coordinator.py,
and its regression test lives in tests/test_prism_coordinator_config.py.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* check-env: validate the exported stale-grace value instead of dropping the check

Restore the ENV_ preservation for PRISM_STRATUM_STALE_GRACE_SECONDS so the
doctor validates the value Compose will hand the coordinator rather than
the .env.example default, and replace the removed mainnet-only equality
check with a lane-level non-negative numeric check that runs in every mode.
Without this, an exported value such as "not-a-number" passed the doctor
and then crashed the coordinator at startup in env_nonnegative_float().

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K8uGJEY2npTQuJPwS9Qg6M

* prism-self-check: parse stale grace with the coordinator's float semantics

The coordinator accepts any finite non-negative float for
PRISM_STRATUM_STALE_GRACE_SECONDS and check-env now validates the same
shape, but the self-check still parsed the value with int(), so a valid
fractional window such as 0.5 failed `make prism-self-check`. Parse a
finite non-negative decimal instead.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K8uGJEY2npTQuJPwS9Qg6M

* Validate stale grace with the coordinator's float conversion in the doctor and self-check

A hand-written regex cannot match env_nonnegative_float(): it rejected
valid runtime syntax such as 1e-1, .5 and 3., and accepted an integer
large enough to overflow to infinity at startup. Both check-env.sh and
prism-self-check.py now convert with float() and require a finite,
non-negative result, exactly as the coordinator does.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K8uGJEY2npTQuJPwS9Qg6M

* Address the rebase review: doc contradiction, doctor prerequisite, mainnet coverage

Four follow-ups from reviewing the rebase against this release line.

Docs: the ledger-ops share-accounting paragraph still told auditors to
upgrade "before operators enable stale-grace crediting", which contradicts
the deployment paragraph in the same document now that the window is on by
default. It also, along with two other lines, named the v1.1 bundle schema
without saying it is the logical schema; the on-disk body is the v2
container carrying logical_audit_bundle_schema once share segmentation is
on. Both are now stated precisely.

check-env: validating stale grace with python3 made the interpreter a hard
prerequisite for every prism-lane doctor run. Production already required
it for the difficulty validation, but lab bring-up did not, and README
lists Python 3 only for the unit-test helpers. Keep the hard failure in
production and skip the check with a doctor notice otherwise, with a test
covering both branches over a python3-free PATH.

Tests: the production environment fixtures still pinned the retired zero, so
every full-environment production test proved the old contract, and the
mainnet positive test asserted only that the old message was gone while its
non-zero exit came from unrelated missing inputs. The fixtures now carry the
bounded default, and the mainnet test runs a complete production environment
and asserts a clean exit for 3, 0.5, and an explicit 0.

---------

Co-authored-by: Alex <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: Robert Clarke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants