From ae227e85d25e6c5a19a723691856192a4007b7ca Mon Sep 17 00:00:00 2001 From: tensorlink-dev Date: Fri, 4 Dec 2026 00:01:52 +0000 Subject: [PATCH] lane D: same-period entries share one cohort on their overlap, held together until it meets the floors Owner 2026-12-03: entries judged in the same settlement were separate cohorts on different windows, so the max-T band never corrected across them (22:27: three uncorrected duels). Now miner entries revealed in the same settlement period (reveal block in (B_n, B_n+1], 900 blocks) with the same KING_D and stage are ONE cohort, judged on the windows they all share (the intersection of their frozen sets = eligible for the latest cut-off, so no window predates any member's reveal). The group is held together (every member pending_floor) until that overlap meets the floors; a short joint draw reopens each member's frozen set once and redraws jointly. Entries of different periods keep their own cohorts (unchanged). Main-validator only: satellites re-derive max-T per cohort from the report's rows and already accept multi-member cohorts; new acceptance test runs the 0445a442 / 890fe6d1 checkers on a same-period report (burn None, no findings). Fixture entries now carry a reveal block that follows their reveal time. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BMT4D7f8wd5dXsASyWUBwe --- cascade/validator/lane_d.py | 80 ++++++++++++++-- tests/accept/w5c/helpers.py | 11 ++- tests/accept/w5c/test_w5c_own_t.py | 54 +++++++++++ tests/accept/w_hz/helpers.py | 5 +- tests/unit/test_lane_d_joint_cohort.py | 121 +++++++++++++++++++++++++ 5 files changed, 262 insertions(+), 9 deletions(-) create mode 100644 tests/unit/test_lane_d_joint_cohort.py diff --git a/cascade/validator/lane_d.py b/cascade/validator/lane_d.py index 1a65df524..c6fc35281 100644 --- a/cascade/validator/lane_d.py +++ b/cascade/validator/lane_d.py @@ -1160,6 +1160,25 @@ def _window_embargo_fields(w: dict, v, h: int) -> dict: "freq_class": freq_class(freq), "h": int(h), "origin": int(w["target_ts"][0])} +# Owner 2026-12-03 ("they should be corrected ... not same eval windows"; +# "the submission period should take precedence: if they are in the same +# settlement submission period (3 hour window) they are held until they have +# enough windows"): miner entries revealed in the same settlement period are +# ONE cohort on the windows they all share, held together until that overlap +# meets the floors. Lane D settlements fall on multiples of 900 blocks +# (12 s blocks: 3 h) since block 9136800. +SETTLEMENT_PERIOD_BLOCKS = 900 +SETTLEMENT_PERIOD_SECONDS = 3 * 3600 + + +def submission_period(rec: dict) -> int: + """The settlement period an entry was revealed in: ``(B_n, B_n+1]`` by + reveal block (``reveal_ts`` in 3 h steps when a record has no block).""" + if rec.get("reveal_block") is not None: + return (int(rec["reveal_block"]) - 1) // SETTLEMENT_PERIOD_BLOCKS + return (int(rec["reveal_ts"]) - 1) // SETTLEMENT_PERIOD_SECONDS + + def _cohort_plan(jobs: list, *, king_ts_of, pools: list[dict], forecasts: dict, cfg, picks: dict, block_hash, cap_seed: str, pub_ready, pinned: dict[str, str], windows_out: dict, floored=frozenset()): @@ -1175,8 +1194,14 @@ def _cohort_plan(jobs: list, *, king_ts_of, pools: list[dict], forecasts: dict, members, records, is_house, bars, king_ts, eligible, refused, seen, picked, draw)``. Each miner member is judged on the windows eligible from its own cut-off (``max(T_E, T_K)``), whatever any other member or an - earlier duel used; consecutive members whose candidate sets coincide - (record for record) share one cohort and one draw. The draws share + earlier duel used. Owner 2026-12-03: miner members revealed in the same + settlement period (:func:`submission_period`, same KING_D and stage) are + ONE cohort and one draw on the windows they all share (the intersection + of their frozen sets: eligible for every member's cut-off), so the max-T + band corrects across them; the group is held together (every member + ``pending_floor``) until that overlap meets the floors. Consecutive + members of different periods whose candidate sets coincide (record for + record) still share one cohort and one draw. The draws share ``max_windows_per_settlement``, earliest reveal first; a member whose draw misses the floors waits ``pending_floor`` alone. Each cohort's picked windows enter ``pinned`` / ``windows_out`` before it is yielded @@ -1193,6 +1218,19 @@ def _cohort_plan(jobs: list, *, king_ts_of, pools: list[dict], forecasts: dict, while jobs: kd, stage, members, recs, is_house = jobs.pop(0) members = list(members) + if not is_house and len(members) == 1: + period = submission_period(recs[members[0]]) + rest = [] + for job in jobs: + jkd, jstage, jms, jrecs, jhouse = job + if not jhouse and jkd == kd and jstage == stage and len(jms) == 1 \ + and submission_period(jrecs[jms[0]]) == period: + members.append(jms[0]) + recs = {**recs, jms[0]: jrecs[jms[0]]} + else: + rest.append(job) + jobs[:] = rest + group = len(members) > 1 king_ts = king_ts_of(kd) # DEC-CA-0076 (owner 2026-11-24): KING_D is the only bar. At genesis # it is the house; after the first miner crown the house is no @@ -1209,7 +1247,13 @@ def _cohort_plan(jobs: list, *, king_ts_of, pools: list[dict], forecasts: dict, # A member without a public score set (never asked of the eval host) # cannot be judged on the combined rule: it waits (fail closed). A # floored member was not asked: the floors below skip it. - for m in [m for m in members if m not in floored and not pub_ready(m)]: + unscored = [m for m in members if m not in floored and not pub_ready(m)] + if group and unscored: + # the group is judged together or not at all + for m in members: + yield ("skip", m, "king_unscored" if m in unscored else "pending_floor", recs[m]) + continue + for m in unscored: yield ("skip", m, "king_unscored", recs[m]) members.remove(m) if not members: @@ -1223,8 +1267,13 @@ def _cohort_plan(jobs: list, *, king_ts_of, pools: list[dict], forecasts: dict, advanced.add(m) if rec["frozen_set"]["frozen"] and m not in floored: frozen.append(m) - else: - yield ("skip", m, "pending_floor", rec) + if group and len(frozen) < len(members): + for m in members: + yield ("skip", m, "pending_floor", recs[m]) + continue + for m in members: + if m not in frozen: + yield ("skip", m, "pending_floor", recs[m]) members = frozen if not members: continue @@ -1248,7 +1297,11 @@ def cands_of(ms, recs, bars=bars, king_ts=king_ts): # window for window and record for record, join this cohort: one # draw serves them all (the draw each would get alone), so they share # the window budget instead of each spending it. - while not is_house and jobs and not jobs[0][4] and jobs[0][0] == kd: + while not is_house and not group and jobs and not jobs[0][4] and jobs[0][0] == kd \ + and len(jobs[0][2]) == 1 \ + and not any(submission_period(jobs[0][3][jobs[0][2][0]]) + == submission_period(j[3][j[2][0]]) + for j in jobs[1:] if not j[4] and len(j[2]) == 1): nm = jobs[0][2][0] nrec = jobs[0][3][nm] if nm in floored or not pub_ready(nm): @@ -1267,6 +1320,21 @@ def cands_of(ms, recs, bars=bars, king_ts=king_ts): members.append(nm) eligible, refused, seen_c = cands_of(members, recs) picked, drawn, ok = _drawn(eligible, cfg, block_hash, budget, seen_c) + if group and not ok and any(m not in reopened for m in members): + # the group's overlap misses the floors: each member's frozen set + # reopens once (as for a lone member) and the group redraws jointly + for m in members: + if m not in reopened: + reopened.add(m) + recs[m]["frozen_set"] = _advance_member(recs[m], pools, int(king_ts), cfg, + cap_seed, reopen=True) + eligible, refused, seen_c = cands_of(members, recs) + picked, drawn, ok = _drawn(eligible, cfg, block_hash, budget, seen_c) + if group and not ok: + # held together until the overlap meets the floors + for m in members: + yield ("skip", m, "pending_floor", recs[m]) + continue if not ok and budget >= int(cfg.min_windows) \ and any(m not in reopened for m in members): # A frozen set whose draw misses the floors (or the fresh share) diff --git a/tests/accept/w5c/helpers.py b/tests/accept/w5c/helpers.py index c5d1827bd..92058ba27 100644 --- a/tests/accept/w5c/helpers.py +++ b/tests/accept/w5c/helpers.py @@ -201,8 +201,15 @@ def fixture_key(name: str): return keypair_class().create_from_uri(f"//w5c-{name}") -def entry(name: str, *, reveal_ts: int, ready_block: int = ARM_BLOCK + 40, - reveal_block: int = ARM_BLOCK + 60) -> dict: +def entry(name: str, *, reveal_ts: int, ready_block: int | None = None, + reveal_block: int | None = None) -> dict: + # owner 2026-12-03: entries revealed in the same settlement period share a + # cohort, so a fixture's reveal block follows its reveal time (12 s blocks + # from T0); T_A / T_B / T_C (a day apart) are in different periods + if reveal_block is None: + reveal_block = ARM_BLOCK + 60 + (int(reveal_ts) - T0) // 12 + if ready_block is None: + ready_block = int(reveal_block) - 20 return {"hotkey": fixture_key(name).ss58_address, "digest": digest(f"w5c {name}"), "context": 4096, "coldkey_at_ready": fixture_key(f"{name}-cold").ss58_address, "ready_block": int(ready_block), "reveal_block": int(reveal_block), diff --git a/tests/accept/w5c/test_w5c_own_t.py b/tests/accept/w5c/test_w5c_own_t.py index 16ff2ea84..499884817 100644 --- a/tests/accept/w5c/test_w5c_own_t.py +++ b/tests/accept/w5c/test_w5c_own_t.py @@ -278,3 +278,57 @@ def test_the_released_checkers_pay_several_miner_cohorts(tmp_path, release): assert res["burn"] is None, res assert res["findings"] == [], res assert res["n_cohorts"] == 2 and res["n_rows"] == len(rep["rows"]) + + +# ── owner 2026-12-03: one cohort per submission period ────────────────────── + + +def _same_period_report(tmp_path, only_bob=False): + """Alice (T0) and Bob (T0 + 1 h): the same settlement period. Fleet one + lies between them (Alice only); fleet two follows Bob (both). + ``only_bob``: the same settlement with Bob alone.""" + from cascade.validator.lane_d import load_pool_for, submission_period + + cfg = band_cfg(**OVER) + t_bob = T0 + HOUR + alice, bob, h = entry("alice", reveal_ts=T0), entry("bob", reveal_ts=t_bob), house() + assert submission_period(alice) == submission_period(bob) + one, two = _fleet("one", T0 + HOUR // 4), _fleet("two", t_bob + HOUR) + d = write_band_pool(tmp_path / "pool", one + two, feeds=feeds_for(one + two, EMBARGO), + snapshot="same-period") + p = load_pool_for(d, cfg) + es = [bob] if only_bob else [alice, bob] + fc = forecasts([p], [e["digest"] for e in es], h["digest"]) + out = settle(cfg, BOUNDARY_1, d, es, h, fc, + {e["hotkey"]: CHALLENGER_UID + i for i, e in enumerate(es)}, + tmp_path / "state.json", HASH_A) + return out.report, alice, bob + + +def test_same_period_members_share_one_cohort_bounded_by_the_latest_t(tmp_path): + rep, alice, bob = _same_period_report(tmp_path) + assert [c["members"] for c in rep["cohorts"]] == [[alice["digest"], bob["digest"]]] + assert [c["t_max"] for c in rep["cohorts"]] == [bob["reveal_ts"]] + # the overlap is Bob's own set (Alice's cut-off is earlier): the joint + # cohort is judged on exactly the windows Bob alone would be judged on + alone, *_ = _same_period_report(tmp_path / "alone", only_bob=True) + assert rep["cohorts"][0]["window_ids"] == alone["cohorts"][0]["window_ids"] + assert {v["digest"] for v in rep["verdicts"]} == {alice["digest"], bob["digest"]} + + +@pytest.mark.parametrize("release", [r for r, _ in RELEASED]) +def test_the_released_checkers_pay_a_same_period_cohort(tmp_path, release): + """No burn and no finding from the checker of either deployed release on + a report whose two miner members share one cohort (max-T across both).""" + rep, *_ = _same_period_report(tmp_path) + assert len(rep["cohorts"]) == 1 and len(rep["cohorts"][0]["members"]) == 2 + got = subprocess.run(["git", "-C", str(REPO), "cat-file", "-e", f"{release}^{{commit}}"], + capture_output=True, text=True) + assert got.returncode == 0, f"release {release} is not in this clone: {got.stderr}" + tree = old_tree(tmp_path, release) + raw = {**BAND_RAW, **LIVE_ONLY, **OVER} + res = run_old_checker(tree, rep, raw, fixture_key("signer").ss58_address, tmp_path) + assert res["transient"] == "", res + assert res["burn"] is None, res + assert res["findings"] == [], res + assert res["n_cohorts"] == 1 and res["n_rows"] == len(rep["rows"]) diff --git a/tests/accept/w_hz/helpers.py b/tests/accept/w_hz/helpers.py index b0b8fe053..a73eacfcc 100644 --- a/tests/accept/w_hz/helpers.py +++ b/tests/accept/w_hz/helpers.py @@ -218,9 +218,12 @@ def fixture_key(name: str): def entry(name: str, *, reveal_ts: int = T0) -> dict: + # owner 2026-12-03: entries revealed in the same settlement period share a + # cohort, so the reveal block follows the reveal time (12 s blocks from T0) + reveal_block = ARM_BLOCK + 60 + (int(reveal_ts) - T0) // 12 return {"hotkey": fixture_key(name).ss58_address, "digest": digest(f"w_hz {name}"), "context": 4096, "coldkey_at_ready": fixture_key(f"{name}-cold").ss58_address, - "ready_block": ARM_BLOCK + 40, "reveal_block": ARM_BLOCK + 60, + "ready_block": reveal_block - 20, "reveal_block": reveal_block, "reveal_ts": int(reveal_ts)} diff --git a/tests/unit/test_lane_d_joint_cohort.py b/tests/unit/test_lane_d_joint_cohort.py new file mode 100644 index 000000000..7948dd7be --- /dev/null +++ b/tests/unit/test_lane_d_joint_cohort.py @@ -0,0 +1,121 @@ +"""Owner 2026-12-03: miner entries revealed in the same settlement period +(``submission_period``) are ONE cohort on the windows they all share (the +intersection of their frozen sets), so the max-T band corrects across them; +the group is held together (all ``pending_floor``) until that overlap meets +the floors. Entries of different periods keep their own cohorts. Pure +python: eligibility, the draw and the window records are stubbed.""" + +from __future__ import annotations + +from types import SimpleNamespace + +from cascade.validator import lane_d, lane_d_frozen + +P = lane_d.SETTLEMENT_PERIOD_BLOCKS + + +def _cfg(**kw): + base = dict(min_windows=2, min_clusters=1, max_source_share=1.0, + min_fresh_window_share=0.0, max_windows_per_settlement=100) + base.update(kw) + return SimpleNamespace(**base) + + +def _frozen(ids, frozen=True): + ids = sorted(ids) + return {"frozen": frozen, "window_ids": ids, "sources": {i: "src" for i in ids}, + "set_sha256": lane_d_frozen.set_sha256(ids), "seed": "old", "t_max": 10} + + +def _run(monkeypatch, jobs, *, need, floored=frozenset(), pub=lambda d: True): + """``need``: the draw passes iff it holds at least ``need`` windows.""" + def advance(rec, *a, reopen=False, **k): + return rec["frozen_set"] + monkeypatch.setattr(lane_d, "_advance_member", advance) + + def cohort_set(pools_, members, bars, king_ts, recs, *a, **k): + ids = set.intersection(*(set(recs[m]["frozen_set"]["window_ids"]) for m in members)) + return [({"window_id": i, "source": "src"}, {"sha256": "p"}, None) + for i in sorted(ids)], {} + monkeypatch.setattr(lane_d, "_cohort_set", cohort_set) + monkeypatch.setattr(lane_d, "_seen_set", lambda *a, **k: []) + monkeypatch.setattr(lane_d, "_same_record", lambda c, *a, **k: c) + + def drawn(picked, cfg_, bh, budget, seen=()): + picked = picked[:max(0, int(budget))] + return picked, {"n": len(picked)}, len(picked) >= need + monkeypatch.setattr(lane_d, "_drawn", drawn) + monkeypatch.setattr(lane_d, "_window_record", lambda w, *a, **k: {"id": w["window_id"]}) + forecasts = {"K": {}, **{j[2][0]: {} for j in jobs}} + return list(lane_d._cohort_plan( + jobs, king_ts_of=lambda kd: 5, pools=[], forecasts=forecasts, cfg=_cfg(), picks={}, + block_hash="h", cap_seed="seed", pub_ready=pub, pinned={}, windows_out={}, + floored=floored)) + + +def _job(m, ids, block, stage="first", house=False, frozen=True): + rec = {"reveal_ts": block * 12, "reveal_block": block, "frozen_set": _frozen(ids, frozen)} + return ("K", stage, [m], {m: rec}, house) + + +def _cohorts(steps): + return [(s[3], sorted(w["window_id"] for w, _, _ in s[11])) for s in steps if s[0] == "cohort"] + + +def _skips(steps): + return [(s[1], s[2]) for s in steps if s[0] == "skip"] + + +def test_submission_period_is_by_reveal_block(): + assert lane_d.submission_period({"reveal_block": 10 * P + 1}) == 10 + assert lane_d.submission_period({"reveal_block": 11 * P}) == 10 + assert lane_d.submission_period({"reveal_block": 11 * P + 1}) == 11 + assert lane_d.submission_period({"reveal_ts": 3 * 3600}) == 0 + + +def test_same_period_members_share_one_cohort_on_the_overlap(monkeypatch): + b = 100 * P + jobs = [_job("a", "pqrstu", b + 10), _job("b", "rstu", b + 300), _job("c", "stuv", b + 800)] + steps = _run(monkeypatch, jobs, need=2) + assert _cohorts(steps) == [(["a", "b", "c"], ["s", "t", "u"])] + assert _skips(steps) == [] + + +def test_short_overlap_holds_the_whole_group(monkeypatch): + b = 100 * P + jobs = [_job("a", "pqrstu", b + 10), _job("b", "rstu", b + 300), _job("c", "uvwx", b + 800)] + steps = _run(monkeypatch, jobs, need=2) + assert _cohorts(steps) == [] + assert _skips(steps) == [("a", "pending_floor"), ("b", "pending_floor"), + ("c", "pending_floor")] + + +def test_an_unfrozen_member_holds_its_group(monkeypatch): + b = 100 * P + jobs = [_job("a", "pqrs", b + 10), _job("b", "pqrs", b + 20, frozen=False)] + steps = _run(monkeypatch, jobs, need=2) + assert _cohorts(steps) == [] + assert sorted(_skips(steps)) == [("a", "pending_floor"), ("b", "pending_floor")] + + +def test_different_periods_keep_their_own_cohorts(monkeypatch): + jobs = [_job("a", "pqrstu", 100 * P + 10), _job("b", "rstu", 101 * P + 10)] + steps = _run(monkeypatch, jobs, need=2) + assert _cohorts(steps) == [(["a"], ["p", "q", "r", "s", "t", "u"]), + (["b"], ["r", "s", "t", "u"])] + + +def test_an_older_period_group_does_not_wait_for_a_newer_one(monkeypatch): + jobs = [_job("a", "pqrs", 100 * P + 10), _job("b", "pqrs", 100 * P + 20), + _job("c", "wxyz", 101 * P + 10), _job("d", "zz", 101 * P + 20)] + steps = _run(monkeypatch, jobs, need=2) + assert _cohorts(steps) == [(["a", "b"], ["p", "q", "r", "s"])] + assert sorted(_skips(steps)) == [("c", "pending_floor"), ("d", "pending_floor")] + + +def test_house_and_other_stage_stay_separate(monkeypatch): + b = 100 * P + jobs = [_job("a", "pqrs", b + 10), _job("b", "pqrst", b + 20, stage="confirm"), + _job("h", "pqrs", b + 30, house=True)] + steps = _run(monkeypatch, jobs, need=2) + assert [c[0] for c in _cohorts(steps)] == [["a"], ["b"], ["h"]]