Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 207 additions & 91 deletions cascade/validator/lane_d.py

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions docs/MINER_LANE_D.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ blocks, about 24 h) of `submit`, or the entry expires (`ready_expired`).
charged: they go back to `pending` (`pending_floor`) and are duelled at the
next settlement against the new king. Only if no held entry passes are the
new clears gated, and the highest LCB crowns.
- **Your windows start at your own reveal.** Every entry is judged in a
cohort of its own, on the windows that are unseen from its own reveal
time T (and the king's, if the king is newer). A later entry never
shrinks your set, and an earlier entry that cannot meet the floors yet
never blocks yours. Entries are judged in reveal order, earliest first,
sharing the settlement's `max_windows_per_settlement` budget. If the
budget runs short of `min_windows`, the later entries wait
(`pending_floor`) for the next settlement. Only the cut-off decides
which windows you can be judged on: entries may share windows, and a
window you were judged on in an earlier duel (against any king) stays
eligible.

## How you are paid

Expand Down
2 changes: 2 additions & 0 deletions tests/accept/w5c/PATHS
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ cascade/validator/lane_d_frozen.py
# RV5: the audit counts the house's rows and re-derives the house judgement
# (cohorts[].house_digest, verdicts[].house) from the signed rows.
cascade/audit/lane_d.py
# owner 2026-12-01: the miner doc states the own-T cohort rule.
docs/MINER_LANE_D.md
72 changes: 40 additions & 32 deletions tests/accept/w5c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,57 @@ behaviour is change 3, and those tests fail on main.

## Contract (`settle_lane_d`, `cascade/validator/lane_d.py`)

### Cohort formation

- A cohort is every open entry, judged against the same KING_D at the same
stage, whose `frozen_set` is frozen at this settlement. That includes an
entry frozen and deferred at an earlier settlement.
- An entry that is still unfrozen is not a member. Its T does not enter the
cohort's max-T, and it does not shrink the intersection. It stays
### Cohort formation (owner 2026-12-01: one cohort per member, own T)

- Each open entry whose `frozen_set` is frozen at this settlement is its own
miner cohort, judged against KING_D. That includes an entry frozen and
deferred at an earlier settlement. ("It shouldn't reset the window, it
should only be from when they submitted.") Until 2026-12-01 the frozen
entries formed ONE joint cohort judged forward of the latest member's T.
- An entry that is still unfrozen is not judged and stays
`pending` / `pending_floor`.
- `cohorts[].members` is ordered by T (`reveal_ts`) ascending, with ties
broken by digest. It is not digest order and not input order.
- `cohorts[].t_max` is max(T over the members and the king).
- Cohorts are indexed in T (`reveal_ts`) order, ties by digest. It is not
digest order and not input order.
- `cohorts[].t_max` is max(the member's T, the king's T).

### The judged set

- The set is the intersection of the members' frozen sets that is eligible
(§1.3, W5a) for the cohort's `t_max`. It also needs a usable target and a
usable forecast from the king and every member.
- A window that is eligible for a member's own T but not for `t_max` is
excluded, even though it is in that member's frozen set.
- Every member and the king are scored on exactly this set
- A member's set is its frozen set that is eligible (§1.3, W5a) for its own
`t_max`, with a usable target and a usable forecast from the king and the
member. A window the member was judged on in an earlier duel (against any
king) stays in (owner 2026-12-01: "Miners should be able to use the same
windows; it should be driven by cut-off"), and members share windows. No
other member's T or frozen set shrinks it.
- The settlement's `max_windows_per_settlement` budget is shared across the
cohorts, earliest reveal first (a window judged in two cohorts counts once).
- A window an earlier cohort of the settlement judged under a different
`windows[]` record (another snapshot, or another fresh / embargo class at
that cohort's bound) is left out (one record per window, fail closed).
- The member and the king are scored on exactly this set
(`rows`, `cohorts[].window_ids`, `set_sha256 = sha256("\n".join(sorted ids))`).

### Floors after the intersection: latest-T deferral

- If the set misses `min_windows` or `min_clusters`, the member with the
latest T is deferred. Then `t_max` and the set are recomputed for the
remaining members, and this repeats until the set meets the floors or no
member is left.
- A deferred entry is not judged: no rows, no verdict, not in `judged`, and
no cohort if every member is deferred. It gets one `skipped` record with
the typed reason `pending_floor` (in `ENTRY_REASONS`), and its state stays
`pending` / `pending_floor` with `used_windows == []`. Its `frozen_set`
stays frozen and unchanged.
- At the next settlement it is a cohort member again, judged on its
unchanged frozen set: the cohort's `set_sha256` equals the frozen set's.
### Floors per member

- If a member's draw misses `min_windows` or `min_clusters` (or the minimum
fresh share, or the budget left), that member is deferred alone. No other
member is affected.
- A deferred entry is not judged: no rows, no verdict, not in `judged`. It
gets one `skipped` record with the typed reason `pending_floor` (in
`ENTRY_REASONS`), and its state stays `pending` / `pending_floor` with
`used_windows` unchanged (a record of what it was judged on; it no longer
excludes anything). Its `frozen_set` stays frozen and unchanged.
- At the next settlement it is judged on its frozen set: the cohort's
`set_sha256` equals the frozen set's.
- The released satellite checkers (890fe6d1, 0445a442) pay a report with
several miner cohorts (`test_w5c_own_t.py`).

### Verdict: max-T against KING_D

- Each verdict's `lcb`, `gain` and `cleared` equal
`judge_cohort(king_scores, member_scores, clusters=sources, cfg, seed=report["seed"])`.
This is computed from the report's own rows over `cohorts[].window_ids` in
order, with the members in cohort order. It is the joint `cohort_maxt_lcbs`
over the cohort against KING_D (`verdicts[].king_digest`).
This is computed from the report's own rows of that cohort over
`cohorts[].window_ids` in order. It is `cohort_maxt_lcbs` over the cohort
against KING_D (`verdicts[].king_digest`).

### Proposed change 3 (accepted): the house bar

Expand Down
114 changes: 61 additions & 53 deletions tests/accept/w5c/test_w5c_cohort.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""W5c through `settle_lane_d`: cohort formation, the intersection eligible for
the cohort's max-T, latest-T deferral, floors after the intersection, the
max-T comparison against KING_D, determinism (plan rev6 §1.3 Cohorts, T9).
"""W5c through `settle_lane_d`: cohort formation (one cohort per frozen entry,
in reveal order, owner 2026-12-01), each judged on the set eligible for its
own T, floors per member, the max-T comparison against KING_D, determinism
(plan rev6 §1.3 Cohorts, T9).

The pool holds three §1.3 bands, a day apart:

* band A (8 windows): eligible for T_A only;
* band B (8 windows): eligible for T_A and T_B;
* band C (24 windows): eligible for T_A, T_B and T_C.

So A freezes on 40 windows, B on 32, C on 24, and the cohort {A, B, C} is
judged on band C alone. The genesis house holds KING_D (T earlier than all).
So A freezes on 40 windows, B on 32, C on 24, and each is judged on its own
set (before 2026-12-01 the joint cohort {A, B, C} was judged on band C alone). The genesis house holds KING_D (T earlier than all).
"""

from __future__ import annotations
Expand Down Expand Up @@ -100,68 +101,73 @@ def test_cohort_fixture_bands_and_frozen_sets(tmp_path):
assert state["entries"][e["digest"]]["frozen_set"]["frozen"] is True


# ── cohort formation + intersection for max-T ───────────────────────────────
# ── cohort formation: one cohort per member, in reveal order ────────────────
#
# owner 2026-12-01 ("it shouldn't reset the window, it should only be from
# when they submitted"): each frozen entry is its own cohort, judged on the
# windows eligible from ITS OWN T; no joint set cut to the latest member's T.


def test_t9_cohort_is_every_entry_frozen_this_settlement_ordered_by_t(tmp_path):
def _cohort_of(report, e) -> dict:
(c,) = [c for c in report["cohorts"] if e["digest"] in c["members"]]
return c


def test_t9_each_frozen_entry_is_its_own_cohort_ordered_by_t(tmp_path):
a_band, b_band, c_band = _bands()
A, B, C = _entries()
s, *_ = _run(tmp_path, a_band + b_band + c_band, (A, B, C), order=(C, A, B))
(cohort,) = s.report["cohorts"]
assert cohort["members"] == [A["digest"], B["digest"], C["digest"]], \
"the cohort is not the frozen entries ordered by T"
assert cohort["t_max"] == T_C, "the cohort's T is not max(T over cohort and king)"
assert sorted(s.report["judged"]) == sorted(cohort["members"])
cohorts = sorted(s.report["cohorts"], key=lambda c: c["index"])
assert [c["members"] for c in cohorts] == [[A["digest"]], [B["digest"]], [C["digest"]]], \
"the cohorts are not one per frozen entry in T order"
assert [c["t_max"] for c in cohorts] == [T_A, T_B, T_C], \
"a cohort's T is not max(its member's T, the king's)"
assert sorted(s.report["judged"]) == sorted(m for c in cohorts for m in c["members"])


def test_t9_cohort_is_judged_on_the_intersection_eligible_for_max_t(tmp_path):
def test_t9_each_member_is_judged_on_the_set_eligible_for_its_own_t(tmp_path):
a_band, b_band, c_band = _bands()
A, B, C = _entries()
s, _, h, *_ = _run(tmp_path, a_band + b_band + c_band, (A, B, C))
(cohort,) = s.report["cohorts"]
want = set(wids(c_band))
assert sorted(cohort["window_ids"]) == sorted(want), \
"windows eligible for a member's own T but not the cohort's max-T were judged"
assert cohort["set_sha256"] == set_sha(want)
for dg in (A["digest"], B["digest"], C["digest"], h["digest"]):
assert rows_of(s.report, dg) == want, f"{dg[:8]} not scored on the shared set"
assert not rows_of(s.report, A["digest"]) & set(wids(a_band + b_band))
for e, want in ((A, a_band + b_band + c_band), (B, b_band + c_band), (C, c_band)):
cohort = _cohort_of(s.report, e)
assert sorted(cohort["window_ids"]) == wids(want), \
f"{e['digest'][:8]} was not judged on the windows eligible for its own T"
assert cohort["set_sha256"] == set_sha(wids(want))
assert rows_of(s.report, e["digest"]) == set(wids(want))
# KING_D is scored in every cohort: on the union of the members' sets.
assert rows_of(s.report, h["digest"]) == set(wids(a_band + b_band + c_band))


def test_an_unfrozen_entry_is_not_a_cohort_member(tmp_path):
a_band, b_band, c_band = _bands()
A, B, C = _entries()
late = entry("late", reveal_ts=T_LATE) # no window is eligible for its T
s, path, *_ = _run(tmp_path, a_band + b_band + c_band, (A, B, C, late))
(cohort,) = s.report["cohorts"]
assert late["digest"] not in cohort["members"]
assert cohort["t_max"] == T_C, "an unfrozen entry's T entered the cohort's max-T"
assert sorted(cohort["window_ids"]) == wids(c_band)
assert all(late["digest"] not in c["members"] for c in s.report["cohorts"])
assert max(c["t_max"] for c in s.report["cohorts"]) == T_C, \
"an unfrozen entry's T entered a cohort's max-T"
assert sorted(_cohort_of(s.report, C)["window_ids"]) == wids(c_band)
rec = read_state(path)["entries"][late["digest"]]
assert (rec["status"], rec["reason"]) == ("pending", "pending_floor")
assert rec["frozen_set"]["frozen"] is False
assert rows_of(s.report, late["digest"]) == set()


# ── floors after the intersection: latest-T deferral ────────────────────────
# ── floors per member: a member short of them waits alone ───────────────────


def test_t9_latest_t_member_is_deferred_when_the_intersection_misses_the_floors(tmp_path):
def test_t9_a_member_short_of_the_floors_waits_alone(tmp_path):
from cascade.validator.lane_d_state import ENTRY_REASONS

a_band, b_band, c_band = _bands()
A, B, C = _entries()
s, path, h, *_ = _run(tmp_path, a_band + b_band + c_band, (A, B, C),
skip={C["digest"]: _short_c(c_band)})
(cohort,) = s.report["cohorts"]
assert cohort["members"] == [A["digest"], B["digest"]], \
"the latest-T member was not the one deferred"
assert cohort["t_max"] == T_B, "the cohort's max-T was not recomputed after the deferral"
want = set(wids(b_band + c_band))
assert sorted(cohort["window_ids"]) == sorted(want)
assert rows_of(s.report, A["digest"]) == want
assert rows_of(s.report, B["digest"]) == want
assert rows_of(s.report, h["digest"]) == want
assert [c["members"] for c in s.report["cohorts"]] == [[A["digest"]], [B["digest"]]], \
"the member short of its floors was not the one deferred"
assert sorted(_cohort_of(s.report, A)["window_ids"]) == wids(a_band + b_band + c_band)
assert sorted(_cohort_of(s.report, B)["window_ids"]) == wids(b_band + c_band)

assert rows_of(s.report, C["digest"]) == set(), "a deferred entry was judged"
assert verdict_of(s.report, C["digest"]) is None
Expand Down Expand Up @@ -247,24 +253,26 @@ def test_verdicts_are_cohort_max_t_against_king_d_on_the_shared_set(tmp_path):
a_band, b_band, c_band = _bands()
A, B, C = _entries()
s, _, h, _, _, cfg = _run(tmp_path, a_band + b_band + c_band, (A, B, C))
(cohort,) = s.report["cohorts"]
assert cohort["king_digest"] == h["digest"]
order = list(cohort["window_ids"])
assert len(s.report["cohorts"]) == 3
src = {w["window_id"]: w["source"] for w in s.report["windows"]}
by = {(r["digest"], r["window_id"]): (r["crps"], r["mase"]) for r in s.report["rows"]}

def scores(dg):
pairs = [by[(dg, w)] for w in order]
return (np.asarray([p[0] for p in pairs]), np.asarray([p[1] for p in pairs]))

want = judge_cohort(scores(h["digest"]), [scores(m) for m in cohort["members"]],
clusters=[src[w] for w in order], cfg=cfg, seed=s.report["seed"])
for m, w in zip(cohort["members"], want, strict=True):
v = verdict_of(s.report, m)
assert v["king_digest"] == h["digest"] and v["cohort"] == cohort["index"]
assert v["lcb"] == w["lcb"] and v["gain"] == w["gain"], \
"a verdict is not the cohort's joint max-T result against KING_D"
assert v["cleared"] is w["cleared"]
for cohort in s.report["cohorts"]:
assert cohort["king_digest"] == h["digest"]
order = list(cohort["window_ids"])
by = {(r["digest"], r["window_id"]): (r["crps"], r["mase"]) for r in s.report["rows"]
if r["cohort"] == cohort["index"]}

def scores(dg, order=order, by=by):
pairs = [by[(dg, w)] for w in order]
return (np.asarray([p[0] for p in pairs]), np.asarray([p[1] for p in pairs]))

want = judge_cohort(scores(h["digest"]), [scores(m) for m in cohort["members"]],
clusters=[src[w] for w in order], cfg=cfg, seed=s.report["seed"])
for m, w in zip(cohort["members"], want, strict=True):
v = verdict_of(s.report, m)
assert v["king_digest"] == h["digest"] and v["cohort"] == cohort["index"]
assert v["lcb"] == w["lcb"] and v["gain"] == w["gain"], \
"a verdict is not its cohort's max-T result against KING_D"
assert v["cleared"] is w["cleared"]


# ── determinism ─────────────────────────────────────────────────────────────
Expand Down
6 changes: 4 additions & 2 deletions tests/accept/w5c/test_w5c_house_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def test_house_report_rows_are_king_d_and_members_only(chains, scenario):

def _house_king_reports(chains, tmp_path):
"""Reports where the house holds KING_D: BOUNDARY_1 (K1 vs H0) of the
house chain, and a W5c three-member cohort vs the genesis house."""
house chain, and three W5c member cohorts vs the genesis house."""
c = chains("bad", "good")
a = group("bandA", 2, band_start(T_A))
b = group("bandB", 2, band_start(T_B))
Expand All @@ -248,7 +248,9 @@ def _house_king_reports(chains, tmp_path):
pool = write_pool(tmp_path / "pool", recs, "w5c-cohort")
s = settle(lane_d_cfg(), BOUNDARY_1, pool, list(members), h, fc, uids(*members),
tmp_path / "state" / "lane_d_state.json")
assert s.report["cohorts"] and set(s.report["cohorts"][0]["window_ids"]) == set(wids(cc))
# owner 2026-12-01: one cohort per member, each on its own-T set
assert [set(c["window_ids"]) for c in s.report["cohorts"]] == \
[set(wids(a + b + cc)), set(wids(b + cc)), set(wids(cc))]
# BOUNDARY_2: K1 is judged while the house holds KING_D (BOUNDARY_1
# lists no entry, rev6.11 (b)).
return [("house-chain-b2", c["reports"][1]), ("cohort", s.report)]
Expand Down
Loading
Loading