Skip to content

3.1 dual-writer (3/5): carry owner and peer settlement - #767

Merged
RobertClarke merged 30 commits into
3.x.xfrom
RobertClarke/p31-carry-owner
Oct 19, 2026
Merged

RobertClarke merged 30 commits into
3.x.xfrom
RobertClarke/p31-carry-owner

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Do not merge: part of the 3.1 stack, teed up for review.

Stack position 3/5: 3.x.x ← D1 (identity and peer sync) ← D2 (window cuts) ← D3 (this PR) ← D4 (readiness) ← D6 (E2E). The design is in CONTRACT.md of the 3.1 run: two independent writers, one carry owner. Background is in PR #761.

With PRISM_DUAL_WRITER off, nothing here changes behaviour:

  • every statement is 3.0's text;
  • every new statement is a dual-only variant;
  • money-path vectors and the existing suites are unchanged.

No migration.

What changes

Carry-free work on the non-owner (ledger/carry.rs)

  • One gate decides which prior balances work is built on: the job snapshot, the refresh probe and payout_state.
  • In dual mode it starts closed, so priors are empty. Each eligible miner is paid its gross; sub-floor gross is swept and stays owed. Every delta is ≥ 0 (invariant 2).
  • Every gate change is fenced by one payout revision bump. A snapshot reads the gate after it reads the revision under SETTLEMENT_LOCK, which the bump also takes, so work built under the old mode is always superseded. And while the gate is closed, or a change of it awaits its bump, the offer reservation never takes a block on carry-paying work for current work, whatever its revision: it goes through the 3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478 capture bound. If the gate moves between the reservation and the send, the block is not sent and its reservation returns to pending, due again at once.
  • Work is also carry-free whenever this node's journal no longer claims ownership. The snapshot reads the journal under the same lock, so a carry-owner release takes effect at its commit, not at the guard's next check.
  • Landing, confirmation and the 3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478 records measure against the canonical balances. A landing that rebuilds a window from current balances (its as-issued snapshot is gone) reads the balances of the window's own mode, never today's gate. In dual mode a carry-free block is never a divergent landing.

The owner guard (carry_owner.rs)

  • Work pays carry only while four things agree:
    • the database's node identity (D-9);
    • PRISM_CARRY_OWNER;
    • this node's latest row in the append-only journal qbit_prism_node_roles;
    • a live read of the peer's journal since process start.
  • Once confirmed, the owner keeps paying while the peer is unreachable: the peer can only acquire after reading this node's release row.
  • Once the peer's latest row is a release, only a claim that carry-owner transfer made after reading it pays: the acquire records the peer epoch it read. Otherwise the state is claim_not_vetted.
  • Each of these means carry-free plus an alert:
    • both nodes claim ownership, or the peer's live journal claims it behind a newer row this node holds of it (peer_journal_behind: a rolled-back peer);
    • the peer holds a newer row of this node's;
    • this node's latest epoch falls below one the running guard already read (a rollback the lineage check cannot see; a restart's own-log check recovers the rows);
    • the setting and the journal disagree.
  • The confirmation is cleared on every return that does not pay.
  • The guard seeds the journal only once the own-log latch (D-8) is set and a live read shows the peer holds no row of this node. It never seeds again after reading a row.
  • no_journal_row and peer_not_seeded, which every fresh start passes through, are quiet only during start-up: 2 minutes after the own-log latch is first set, or the first 10 minutes without one.
  • Metrics: qbit_prism_carry_owner_state{state}, qbit_prism_carry_owner_alert, qbit_prism_carry_owner_peer_checks_total{result}.

Peer settlement (ledger/blocks.rs, ledger/divergence.rs)

  • Peer blocks arrive prepared (D-1, D-10). The existing reconciler confirms, deactivates and matures them as local state, sets the halt on a mature disconnect, and bumps the revision once per change. So the owner's balances include a peer's landings once its own chain view confirms them.
  • Which node found a block is read from the extranonce1 in its coinbase (each node hands out its own half), at this node's PRISM_STRATUM_EXTRANONCE2_SIZE and only where the coinbase tag sits right before it. A block issued with another width or tag names no finder here. It counts as this node's own only when it carries this node's origin and this node holds its outbox row, which is local and never copied. That covers this node's own block found before its width or tag changed. An adopted block has no outbox row, so a cross-width adoption is sponsored here only by takeover. Adoption reads a peer record's own width, so it lands either way (tested end to end). A dual writer refuses to start without a coinbase tag of at least 4 bytes. A block found on the peer's work writes no divergence record here, is not counted as found, and credits no deferred share, whichever node landed it. The pair must issue work with one PRISM_COINBASE_TAG and one PRISM_STRATUM_EXTRANONCE2_SIZE: each node reads the peer's from the coinbase suffix of the peer's newest synced prepared record, and while they differ the guard builds carry-free work on both nodes under the alerting state layout_mismatch, no zero-fee fanout is sponsored as its finder or taken over (a held CPFP package is finished), and no block is adopted. carry-owner status prints the mismatch.

Peer fanouts (broadcaster.rs, ledger/fanout.rs)

  • Either node broadcasts a mature fanout: the transaction is identical and claims are per database.
  • The finder's node CPFP-sponsors a zero-fee fanout, so the two nodes do not fund conflicting children.
  • The other node takes the fanout over once it is overdue and its finder silent:
    • Overdue (Ledger::fanout_sponsor, which also fences the funding reservation): the block matured here, and the finder's newest work held here (a synced prepared record) was published, at least 30 minutes ago.
    • Silent: the finder's own database shows its newest work, aged by its own clock, to be 30 minutes old. Every peer URL is read at once, and the youngest work wins. Or the database fails three checks in a row, over a minute at least, and the stale copy here decides.
    • broadcaster::sponsors_fanout runs the fence, then the liveness check. One check runs at a time, and its verdict serves every fanout for 30 s.
    • A living frontend publishes work every few minutes, so this catches a dead frontend as well as a dead node. A stalled sync, a short blip or clock skew does not trigger it while the finder's database answers.
  • The takeover acts only while the fanout is neither confirmed nor in this node's mempool, and a node finishes any package it holds (Held).

Blocks found by a dying node, S8 (coordinator/adoption.rs)

  • Every 30 s, an incremental pass over a link-checked cache finds pool blocks on the active chain that are at least 60 deep (about an hour) and have no rows here.
  • It rebuilds each one's audit from the finder's synced prepared record (matched by template transactions), and requires the block's commitment root and exact coinbase. It lands the block with Ledger::land_adopted_block.
  • It starts only once the own-log latch is set (D-8), like the submit loop: an adopted block's rows are this node's own, so a node restored from a backup adopts nothing before its own-log recovery has raised its sequences and pulled back its lost landings.
  • While the peer is reachable and the sync is still pulling blocks or prepared records it lags on, it adopts and reports nothing. A lag counts only while its pulls succeed, and one pass goes through every 10 minutes.
  • An unadoptable block is retried and alerted every 10 minutes, with a final ALERT when it leaves the 1,440-block lookback.
  • The peer's prepared records are kept 24 h past their expiry.

qbit-prism-server carry-owner status|release|transfer (carry_owner/transfer.rs, tools.rs)

  • release journals the release with the tip height, read under SETTLEMENT_LOCK, and bumps the revision, in one transaction.
  • transfer refuses unless:
    • the peer answers over PRISM_PEER_DATABASE_URL (never the fallback, which may reach a copy lagging its journal) and does not claim ownership, neither in the newer of its live and synced rows nor in its live journal;
    • this node's journal is current;
    • the release is buried by the orphan depth, at least 2 blocks;
    • --from-height is no higher than the tip the peer's last claim recorded (an acquire's), or 0 for a peer that owned since its seed, and the peer's claims were read live;
    • a scan of the active chain from there finds every pool block landed and confirmed here.
  • Before writing, it re-reads the peer: its latest row must still be the one the checks read. Right before the acquire, under the lock, the scanned tip must still be on the active chain.
  • It copies that row into this node's journal as the peer sync does (apply_node_roles), then journals acquire with the peer epoch it checked.
  • Documented in docs/prism-ledger-ops.md, section "Dual writer: carry owner and peer settlement (3.1)".

Notes for reviewers

  • Adopted blocks and counting. An adopted block carries the adopter as its origin (D-10), but found counts, divergence records and fanout sponsorship follow its finder, read from the coinbase. If the finder returns and lands its own copy, only the finder counts it. Neither node records it as divergent elsewhere.
  • Takeover conflicts. A finder that is alive but cut off from the other node for 30 minutes looks dead to it, and can still meet a second sponsor. One funding coin then stays locked until an operator releases it. Fee-bearing fanouts, the mainnet configuration, need no sponsor.
  • No durable record of unadoptable blocks. One would need a table, and this PR adds no migration. The 10-minute repeat and the final ALERT are logs. The final ALERT comes only from a running loop, so a block that leaves the lookback while none runs (the frontend down, or waiting for its own-log latch) is not reported. A restore waiting for its peer raises the peer sync's own rollback-evidence ALERT.
  • The solving share of an adopted block is not credited. It was the finder's deferred row (D-11), part of the dead node's unsynced tail.

Follow-ups

  • Finder attribution after a layout restore. A node restored from a backup that predates a block's offer, whose width or tag also changed since, has lost that block's outbox row and leaves its own fanout to the takeover. A width or tag mismatch between the nodes is refused (layout_mismatch), which closes the crafted-extranonce2 double-sponsor Codex raised (thread 4290444234). The reconcile count of peer first confirmations and the divergence record still read attribution for blocks issued before a mismatch was noticed; new work is carry-free meanwhile, so they create no debt.
  • A peer layout mismatch outliving the peer's records. The peer's layout comes from its records held here, else its primary database; with neither showing its work it is taken to match, so a dead peer cannot hold the survivor carry-free. A mismatch seen while records were held is therefore forgotten if they expire while the primary is out of reach (Codex thread 4290988542). A refinement would persist the last observed peer layout and require an operator acknowledgement to clear it.
  • Fencing a release against an offer already reserved. Right before submitblock, a carry-paying offer rechecks the gate and reads this node's journal, but does not hold the release out across the RPC (Codex thread 4291126776). A late block needs this process to stall for the release depth between that read and the call, plus a reorganization at least that deep. A database fence would close it: carry-owner release refusing while a carry-paying candidate of this node is offer_reserved.
  • An adoption test with a quarantined peer share inside the window (D1's quarantine). The coinbase-root check refuses that case today, but no test pins it.
  • Report-only adoption passes before the own-log latch, so a block that leaves the lookback during a latch wait still gets its last ALERT.
  • A gated test of the reservation's closed-gate branch. Carry-paying work offered behind a closed or unfenced gate should be refused when capture is off, or bounded when it is on. Today only the predicate is unit-tested (carry_paying_not_current). The dual-writer fixture needs an opened-then-closed gate with carried balances, which this PR does not have yet.
  • Make a carry gate change and its revision bump one unit. The gate moves before a bump that can fail. The reservation now covers offers, but share crediting and other revision readers still see the old revision until the bump commits.
  • Name the carry gate in capture refusals. A refusal caused only by the gate, with equal revisions, is logged and counted as a superseded payout revision.
  • Waits counted twice after a gate-moved release. A reservation returned to pending because the gate moved has already run its standby and peer-ingest waits, and the retry counts them again.

How it was tested

  • tests/carry_owner_invariants.rs (pure, 12 tests). A model of invariants 1 and 2 against the real apply_payout_policy, over random owner, non-owner and foreign blocks, sync lag, reorgs and maturity.
  • tests/carry_owner_postgres.rs (gated, 9 tests). Covers:
    • the gate and its fencing, and a release taking effect at its commit while the gate is still open;
    • carry-free snapshots against non-empty canonical balances;
    • current-balance window reads by the reference's mode;
    • a peer block's confirmation, reorg, maturity and mature-disconnect halt;
    • divergence records, including single-writer parity.
  • tests/carry_owner_guard_postgres.rs (gated, 12 tests, two databases). Covers:
    • transfer reading the peer only over PRISM_PEER_DATABASE_URL, refusing while that path is down even with the fallback answering;
    • seeding, the start rule, and seeding behind the latch and the peer's rows;
    • conflicts, and both rolled-back-journal cases;
    • claims vetted against a release;
    • release, and transfer refusals and success, including the journal tail copy and a scanned tip reorganised away before the acquire;
    • a node's newest work aged by its own database's clock.
  • tests/carry_owner_adoption.rs (gated, end to end with the fake node):
    • S8 adoption, direct and CTV, with the share ledger unchanged;
    • holding back while the sync is pulling, and not while its lag is stale;
    • refusal without a record, and the adoption loop adopting only once the own-log latch is set;
    • a peer-found fanout funded only once overdue and its finder silent, read live from a second database standing in for the finder's, and finished once held.
  • Unit tests for the guard's decision table, the transfer checks (including the scan bound), the chain walk, the gate and the finder's half.
  • Observability contract and inventory updated.
  • Single-writer regression run, locally on ee06c17b; the later commits change no single-writer path. All passed:
    • ledger_postgres (250), b478_payout_integrity, b478_capture_overpay, ctv_fanout_bookkeeping;
    • window_balance_order, fanout_revision_bump, compact_prepared_storage, observability, b478_stale_revision_block.
  • Under heavy host load, one test each in ledger_postgres and b478_capture_overpay, and a group of lib tests, failed. They pass when rerun alone.
    • Exception: D2's a_dual_writer_snapshot_refuses_without_the_origin_index counts advisory locks cluster-wide, so it fails whenever another database on the server holds one. Reported to D2.
  • money_path_vectors is unchanged.

🤖 Generated with Claude Code

@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-window-cuts branch from 8919a2b to d04cdc4 Compare October 10, 2026 10:28

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93d901ae0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T19:20:09.582594Z 21cf3ae New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-carry-owner branch from 93d901a to cae3115 Compare October 10, 2026 11:01
@blacksmith-sh

This comment has been minimized.

@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-window-cuts branch from 7769999 to ef4391a Compare October 10, 2026 11:05

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cae3115394

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

RobertClarke added a commit that referenced this pull request Oct 10, 2026
…row; classify the carry owner's checkout sites

From Codex's review of cae3115 (PR #767): the guard took only the newest
of the peer's live and synced rows, so a peer whose database was rolled
back to an older claim, behind the release this node's copy holds, could
act on that claim while this node kept paying. The guard is now
carry-free on any live claim of the peer's, as transfer already refuses
one.

The pool-acquire census (scripts/check_prism_pool_acquires.py):
- the guard and the carry-owner commands check out through Ledger::acquire;
- the journal helpers run SQL on the caller's connection (&mut *connection);
- the peer reads through PeerJournal get their own policy, peer-journal;
- the remaining carry-owner, fanout, adoption and guard-spawn sites are
  classified.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 10, 2026
…row; classify the carry owner's checkout sites

From Codex's review of cae3115 (PR #767): the guard took only the newest
of the peer's live and synced rows, so a peer whose database was rolled
back to an older claim, behind the release this node's copy holds, could
act on that claim while this node kept paying. The guard is now
carry-free on any live claim of the peer's, as transfer already refuses
one.

The pool-acquire census (scripts/check_prism_pool_acquires.py):
- the guard and the carry-owner commands check out through Ledger::acquire;
- the journal helpers run SQL on the caller's connection (&mut *connection);
- the peer reads through PeerJournal get their own policy, peer-journal;
- the remaining carry-owner, fanout, adoption and guard-spawn sites are
  classified.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-carry-owner branch from 359539d to 7a2ea81 Compare October 10, 2026 11:40

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a2ea81b80

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

RobertClarke added a commit that referenced this pull request Oct 10, 2026
…t; let transfer recognize earlier pool markers

From Codex's review of 7a2ea81 (PR #767):

- transfer read the peer's latest rows and its latest claim in two reads,
  which a primary and a lagging fallback URL could answer differently; a
  missing claim then left the scan unbounded. PeerJournal::view reads both
  in one REPEATABLE READ snapshot on one connection, and scan_start refuses
  a peer that released when no claim of its can be read.
- The chain scan recognized pool blocks by the current coinbase tag and
  pool-fee program only. carry-owner transfer takes the earlier ones
  (--also-tag, --also-fee-program, repeatable), and the ops doc says when to
  pass them, and that S8 adoption recognizes only the current ones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a06a8b7bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 476fdd9950

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

RobertClarke added a commit that referenced this pull request Oct 10, 2026
The final round's merge of the stack below: D3's 476fdd9 (#767), with
D2's 5e7eac6 and D1's 036d449 in it. One conflict, by hand: server.rs's
comment on the tasks that wait for the own-log latch keeps D3's adoption
beside this branch's listeners, which wait through admission. The pool
checkout census, the metrics inventory and the gated list merged clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d9d9dde22

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@blacksmith-sh

This comment has been minimized.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 835963e0fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa9ca5383f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7acc0424b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1aba7413aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

RobertClarke added a commit that referenced this pull request Oct 10, 2026
The final round's catch-up merge: D3's 61eacad (#767, Codex-approved),
eight commits past 476fdd9. No conflicts; the pool checkout census and
the metrics inventory still match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member Author

CI on b38fba8: one known flake, unrelated to this PR.

  • Failed: "Rust PRISM PostgreSQL and multi-instance contracts (shard 3)" (job 116762989652). The failing test was compact_runtime_e2e::issued_expiry_during_sql_wait_does_not_publish_or_renew_original_identity, with Error: proxy connection task failed: the test's TCP proxy lost its connection under runner load. 34 of 35 tests in that binary passed.
  • Unrelated to this PR: neither this PR nor the 3.1 stack touches that test. Its file last changed on 3.x.x in 3.x.x: time candidate claim leases on the taker's monotonic clock, label database refusals truthfully, and page a PostgreSQL outage on its own rule (#581) #646.
  • Passes locally: the test passed three times in a row on the same head.
  • Downstream only: "Prove every Rust PRISM gated test executed" and "Lint, compile, and test" failed only because the shard failed (SHARD_RESULT: failure, so no manifest was uploaded).
  • Everything else is green: 17 jobs passed.

Our token cannot rerun Actions jobs.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c8c72b6da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@RobertClarke

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6264cd4f27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d8897c099

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7ce81ec5e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

RobertClarke and others added 19 commits October 19, 2026 15:15
…e token renewal

Codex P1 on 0d9d9dd. The reservation decides whether carry-paying work
is current, but submit_block comes after the found-block wait (up to
PRISM_PEER_INGEST_WAIT_MS) and the token renewal. A gate that moved in
that interval let a block reserved as current be sent while the peer
might also pay carry.

Right after the strictly-live renewal, immediately before the send, the
offer now rechecks the gate in memory. A block reserved as current whose
work is carry-paying is not sent if the gate is now closed or unfenced,
or has changed at all since the reservation. That includes a gate closed
and reopened meanwhile, since the peer may have paid the same balances
while it was closed; the gate now counts its changes for this check.

Its reservation returns to pending through release_unmade_offer, the
#522 release for a call never made. It is due again at once rather than
after the pending backoff, and the next attempt's reservation takes the
#478 capture path, or abandons the block with capture off. The check
reads only memory, so the renewal stays the last database step before
the send. Leased candidates, reserved without a revision check, are
unchanged. The ops doc's offer_reserved row names the new release, and a
unit test pins carry_paying_unsendable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re census

454ccca moved release_unsent_offer's transaction into release_unsent,
which release_unmade_offer shares, so the census saw an unclassified
site and a stale one. It is the same ledger checkout, renamed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…before extranonce1

Codex P1 on 835963e. PRISM_STRATUM_EXTRANONCE2_SIZE is not in the
pair's fingerprint. finder_node read extranonce1 at this node's width,
so on a peer block issued with another width it read four other bytes,
which could fall in this node's half: both nodes then took the block
for their own, and both funded conflicting CPFP children of its
zero-fee fanout, leaving the losing wallet's coin reserved.

finder_node now reads extranonce1 at this node's width only where the
coinbase tag sits right before it, as every coinbase this pool builds
has it. A block issued with another width therefore names no node, and
found_here falls back to its origin: a peer-landed block is never taken
for this node's own. This is a check of one placement, not a search
over widths, which a short tag or crafted extranonce bytes could fool.
An empty tag checks nothing, as before. The ledger records the tag with
the width (set_coinbase_layout), and unit tests cover a peer block
issued with widths 4 and 12 against a local 8, another tag, and an
empty one. The ops doc says to keep the width and a non-empty tag the
same on both nodes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This closes the extranonce2-width class. Only two paths read a peer's
coinbase with this node's PRISM_STRATUM_EXTRANONCE2_SIZE:
- adoption's suffix check, which reads the issuing width from the
  record since 476fdd9;
- finder attribution, which since 18c18b5 reads extranonce1 only where
  the tag sits right before it. A block issued with another width names
  no finder, and its origin decides.
Every other width use builds or serves this node's own work.

The gated refusal test's control now adopts the block on a second
frontend whose width is half the one the work was issued with. The
adoption loop waits for the own-log latch, then adopts the block from
its own record, and the rebuilt coinbase is byte for byte the block's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on fa9ca53. finder_node names no node for a block issued with
another extranonce2 width, and found_here then fell back to the block's
origin. An adopted block carries the adopter as its origin, so the
adopter took a cross-width adopted block for its own find. It sponsored
the zero-fee fanout at once, bypassing the takeover's overdue and
silence checks, while a recovered finder, whose own layout names it,
sponsored it too: conflicting CPFP children, and a wallet coin left
reserved.

Every coinbase a dual-writer node builds names it: the tag sits right
before its own extranonce1. A coinbase that names no node was therefore
issued elsewhere, and found_here no longer falls back to the origin for
it. Such a block is sponsored here only by takeover, adopted or not.
Without a recorded layout or a coinbase, the origin still decides. A
node that changes its own tag or width while its blocks still await
fanouts stops taking them for its own finds, which the ops doc already
rules out.

The gated refusal test now checks that, after the narrow-width frontend
adopts the block, only the issuing layout names its finder. Unit tests
cover an adopted cross-width block and an unparseable coinbase with this
node's origin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… bytes

Codex P1 on a7acc04. finder_node reads extranonce1 only where the
coinbase tag sits right before it, but PRISM_COINBASE_TAG may be empty,
and an empty tag verifies nothing. With unequal extranonce2 widths, both
nodes could then take a block for their own find and fund conflicting
CPFP children. A tag of a byte or two could also match by chance.

A dual writer now refuses to start unless PRISM_COINBASE_TAG has at
least 4 bytes (the default /PRISM/ has 7). Single writers keep their
choice, an empty tag included. A unit test covers the check, the README
and the ops doc say so, and D1's dual_writer and config_cli suites still
pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…until it stays so for the takeover delay

Codex P1 on 1aba741. When the finder's database answered with no work
of its node at all, finder_silent took that as silence on the first
read. That happens just after the frontend starts, or once its expired
work is pruned. A live finder could still sponsor its overdue fanout as
its own while this node took it over: conflicting CPFP children.

Such an answer is now unknown: the liveness state notes since when the
checks have found no work, any check that finds work clears that, and
the finder counts as silent only once there has been none for
SPONSOR_TAKEOVER_AFTER. The gated takeover test runs a finder whose
database holds no work: it is not taken over at once, and it is taken
over once the checks have found none for the delay
(assume_no_work_since). The ops doc says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t change

Codex P1 on 7c8c72b. finder_node reads extranonce1 at this node's current
PRISM_STRATUM_EXTRANONCE2_SIZE and coinbase tag. A block this node found
before either changed therefore named no node, and found_here took it for
the peer's. The peer read no finder either, so neither node sponsored the
zero-fee fanout as its finder.

A coinbase that names no node now counts as this node's find when the block
carries this node's origin and this node holds the block's outbox row. The
outbox is local and never copied, and an adopted block has none, so a
cross-width adoption is still sponsored here only by takeover (a7acc04).
Without a recorded layout or the coinbase, the origin still decides. The
fanout sponsor, reconcile and divergence reads each select the outbox flag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…time

Codex P2 on 6264cd4. compact_prepared_on_parent fetched every prepared
record on a block's parent, each joined to its template and balances, in
one fetch_all. A parent that stays current for hours, as in a chain stall
on a busy mempool, holds many such records from both writers, so a single
adoption could hold all of them in memory at once on the survivor.

compact_prepared_on_parent now returns only the keys, newest first, and
compact_prepared_held loads and decodes one record at a time, expired or
not. A record that is gone, does not decode or has lost its blobs is
reported among the block's refusal reasons. The pool-acquire census
classifies the new checkout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on 4d8897c. With no prepared record of the finder's held here
(none synced yet, or its copies expired after the 24-hour retention), the
fence found every matured fanout overdue at once. The broadcaster then took
it over after its finder's database failed three checks over one minute,
an outage that only means silence when the stale copy here already shows
the takeover delay. A live finder behind an asymmetric database outage
could have its fanout funded twice.

The fence now reports such a fanout as Unwitnessed rather than Overdue,
and the broadcaster takes it over on an outage only once the outage itself
has lasted SPONSOR_TAKEOVER_AFTER. A database that answers is read as
before. The cached verdict is re-evaluated against each caller's outage
threshold, so one fanout's verdict never shortens another's wait.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on a7ce81e. PeerJournal::work_age combined the peer's URLs by
the youngest age and let any age override a path that answered with no
work. When the current path holds none (a frontend just restarted) and a
lagging fallback still holds an old row, the stale age won, and the
broadcaster could take over a live finder's fanout once that row was 30
minutes old.

youngest_work_age now lets work younger than the takeover delay on any
path win, since it shows the finder alive. Otherwise a path with no work
makes the age unknown, which waits on the broadcaster's 30-minute no-work
timer. Only when every path shows stale work does the youngest decide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on 9c0b64f. Under two PRISM_STRATUM_EXTRANONCE2_SIZE widths, a
miner can place the coinbase tag and a value from the other node's range
inside its own extranonce2 at the narrower width's offset. Both nodes then
read themselves as the block's finder and fund conflicting CPFP children.
The tag-adjacency check only made accidental collisions rare, and the
pair's fingerprint binds neither the width nor the tag.

Each node now reads the peer's tag and width from the coinbase suffix of
the peer's newest prepared record it has synced, so no schema or grant
changes. While they differ from this node's:
- the carry owner guard builds carry-free work on either node under a new
  alerting reason, layout_mismatch;
- fanout_sponsor sponsors nothing as finder or by takeover, and only
  finishes a CPFP package it already holds;
- adoption refuses each block, which the pass reports with its ALERT.
carry-owner status prints the mismatch. The metric label, scrape contract,
generated metrics doc, census and ops docs follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on 57972c7. The guard's live read takes the first peer URL that
answers. An owner restored from a backup older than its release, started
while the peer's primary was out of reach, could read a lagging fallback
that still showed the peer as non-owner and this node's old claim. A
fresh guard then confirmed the peer and opened the carry gate while the
peer, which had acquired, was paying too.

PeerRead::Answered now says whether PRISM_PEER_DATABASE_URL answered.
Only that answer confirms the peer or lets this node seed its journal, as
carry-owner transfer already reads only the primary. A fallback answer
still stops payments: a claim, a newer row of this node's, or an unseeded
peer it shows counts. Once confirmed, an owner keeps paying through a
fallback answer, as through an unreachable peer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… held

Codex P1 on 02474ed. layout_mismatch reads the peer's coinbase layout from
its newest prepared record synced here, and took the layout to match when
none was held. While the jobs stream was refused or lagging, a pair with
two layouts could therefore pay carry, and sponsor fanouts as their finder.

With none of the peer's records held, the carry owner guard now reads the
peer's newest coinbase suffix live over PRISM_PEER_DATABASE_URL only
(PeerJournal::primary_suffix), and the ledger keeps it for the fanout and
adoption checks. The layout is unknown, and taken to match, only while the
primary shows no work or has never answered, so a peer whose records
expired and whose database is gone does not hold the survivor carry-free.
Held records decide and clear the live value. carry-owner status reads it
the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on d42ea51. With PRISM_PEER_DATABASE_URL out of reach, a lagging
fallback that answered with work 30 minutes old or more gave work_age that
stale age, and finder_silent took the finder for silent at once. That
skipped the outage timing, including the 30 minutes an Unwitnessed fanout
needs. A live finder whose primary this node cannot reach could have its
fanout funded twice.

PeerJournal::work_age now knows whether the primary answered. Without it,
only work younger than the takeover delay counts, as the finder alive; a
fallback's stale or empty answer is no answer, so the broadcaster times it
as an outage against the fanout's threshold. With the primary answering,
the rules are as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on 1b87916. carry-owner transfer's scan_start let --from-height
equal the tip the peer's last acquire recorded. If the chain reorganized
after that acquire to a fork below its tip, the peer, already owner,
could find carry-paying blocks at heights under it. The scan would miss
them, the transfer would pass without their landing rows, and this node
could pay the same carry again.

The scan must now start SCAN_REORG_MARGIN below the recorded tip: the
coinbase maturity, the depth PRISM already treats as final, where a
mature pool block disconnected is a fatal state. The default
--from-height 0 is unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on 11765f5. The offer rechecked only this frontend's in-memory
carry gate before submit_block. A carry-owner release, committed by the
operator's own process, reaches the gate only at the guard's next check, so
a carry-paying block reserved before the release could still be sent
after it. The new owner's transfer scan might already have read that tip,
and the block's carry could be paid twice.

Right before the send, alongside the gate, a carry-paying block reserved as
current work now also reads this node's latest journal row. If the row no
longer claims ownership, nothing is sent, and the reservation returns to
pending as for a moved gate. Carry-free work is unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…; refuse equal-epoch claims

Two Codex P1s on b4dbb57.

The offer's journal read before submit_block returned its error with ?,
after the reservation had committed. The failed attempt then kept the
block offer_reserved, which recovery treats as a call that may have run,
so a valid block would never be offered again. A read that fails is now
taken as withdrawn: nothing is sent, and the reservation returns to
pending as for a moved gate.

carry-owner transfer took the newer of the peer's live and synced claims
by epoch, and silently chose one when they differed at the same epoch, a
sign that the peer's journal was rewritten. A different recorded tip could
then let a later --from-height pass scan_start. Such a conflict now fails
scan_start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex P1 on e776ee9. The guard's check returned with ? when the peer
layout read failed, after the live peer read and before Guard::decide.
The run loop keeps the gate as it is on an error, so a claim the peer read
had just shown went undecided, and an open gate stayed open while the
peer might also be paying. A layout read that fails now counts as a
layout mismatch, so the check decides carry-free and alerts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke changed the base branch from RobertClarke/p31-window-cuts to 3.x.x October 19, 2026 19:15
@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-carry-owner branch from 4b1e8e5 to 21cf3ae Compare October 19, 2026 19:15
@RobertClarke
RobertClarke merged commit 44fd3e4 into 3.x.x Oct 19, 2026
39 checks passed
RobertClarke added a commit that referenced this pull request Oct 19, 2026
Rebased onto 3.x.x after #767 was squash-merged (44fd3e4), as one commit:
the branch merged D3 heads, so a commit-by-commit replay conflicts. The
tree is identical to the reviewed head 571fc6b.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 19, 2026
Rebased onto 3.x.x after #767 was squash-merged (44fd3e4), as one commit:
the branch merged D3 heads, so a commit-by-commit replay conflicts. The
tree is identical to the reviewed head 571fc6b.

Co-authored-by: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 19, 2026
The notes cover everything since v3.0.0-rc.6: #770's import-audits fix
(#765) and #760's idle-connection bound (#759), which would have shipped as
rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by
default. They describe the new settings, migrations 027, 028 and 031 (029
and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6
serves, the rollbacks, and the dual writer's known limits. The migration
guide's import-audits paragraph names this candidate in place of the
skipped rc.7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 20, 2026
* 3.x.x: version 3.1.0-rc.1

VERSION, the workspace version and both lockfiles move to 3.1.0-rc.1.
The fuzz lockfile also picks up hyper and hyper-util, which #769 added to
the server without refreshing it. The 3.0.0 and development-line notes
point at the new candidate; its own notes follow in this pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 release notes

The notes cover everything since v3.0.0-rc.6: #770's import-audits fix
(#765) and #760's idle-connection bound (#759), which would have shipped as
rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by
default. They describe the new settings, migrations 027, 028 and 031 (029
and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6
serves, the rollbacks, and the dual writer's known limits. The migration
guide's import-audits paragraph names this candidate in place of the
skipped rc.7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 notes: #773's pre-migrate tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 notes: the rollback to one writer stops and syncs the peer first

Codex on #774: DOWNGRADE fences nothing, so the peer must be stopped, and its
tail pulled, before the single-writer start; declare the tail lost only for a
peer that never returns with its own database.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke deleted the RobertClarke/p31-carry-owner branch November 3, 2026 20:47
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.

1 participant