From 4184348dd2338e8742d94e30676d32335cf3a5c0 Mon Sep 17 00:00:00 2001 From: tensorlink-dev Date: Tue, 1 Dec 2026 05:38:55 +0000 Subject: [PATCH] feat(lane D): carry the published court across the report gap (owner 2026-12-01) "Miners only stop getting paid when someone beats them." While a settlement's lane D report is not yet known, the weight fold pays the court of the most recent published, verified settlement at most [lane_d] court_carry_max_settlements (default 2) settlements back, instead of burning lane D's share; it switches to the new court as soon as it is known (the existing catch-up pulls that push forward). None ever published, or only older than the bound: burn, as before. - receipt: lane_d_court_boundary (drop-when-default) names the carried boundary; older receipts keep their bytes and verify. - audit: lane_d_pay / fetch_lane_d_record read the record at the carried boundary, bounded by court_carry_boundaries; a vector that is not that court's, a record of another boundary or one past the bound still burns lane D's share. - satellite: follows a carried receipt; carries the newest published court within the same bound when the settlement's own report is not published; switches to the own court once it is. - the knob stays out of the eval host's judge request; the signed lane D report format is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BMT4D7f8wd5dXsASyWUBwe --- cascade/audit/checks.py | 38 +++- cascade/audit/main.py | 10 +- cascade/shared/config/lane_d.py | 31 +++ cascade/shared/receipt.py | 23 ++ cascade/validator/lane_d.py | 16 +- cascade/validator/lane_d_wiring.py | 9 +- cascade/validator/receipts.py | 8 +- cascade/validator/satellite.py | 108 ++++++++- cascade/validator/weights.py | 75 ++++++- docs/MINER_LANE_D.md | 5 + tests/accept/w8b/PATHS | 16 ++ tests/accept/w8b/test_w8b_court_carry.py | 187 ++++++++++++++++ .../w8b/test_w8b_court_carry_satellite.py | 207 ++++++++++++++++++ .../w8b/test_w8b_exact_boundary_absent.py | 15 +- 14 files changed, 726 insertions(+), 22 deletions(-) create mode 100644 tests/accept/w8b/test_w8b_court_carry.py create mode 100644 tests/accept/w8b/test_w8b_court_carry_satellite.py diff --git a/cascade/audit/checks.py b/cascade/audit/checks.py index c56fa072a..191a51c92 100644 --- a/cascade/audit/checks.py +++ b/cascade/audit/checks.py @@ -3121,13 +3121,40 @@ def lane_d_court_payees(lane_d) -> dict[int, str]: return {u: h for u, h in out.items() if u not in clash} +def lane_d_court_boundary(receipt: RoundReceipt, cfg: ChainConfig) -> tuple[int, str | None]: + """Owner 2026-12-01: the boundary whose lane D court the receipt's vector + paid — the settlement's own, or the earlier one it names in + ``lane_d_court_boundary`` (the settlement's report was not yet known + when the vector was set). ``(boundary, None)``, or ``(named, why)`` when + the named boundary is not one of the ``[lane_d] + court_carry_max_settlements`` settlements before it + (:func:`~cascade.shared.config.lane_d.court_carry_boundaries`).""" + from ..shared.config.lane_d import court_carry_boundaries + + boundary = int(receipt.epoch_start_block) + named = int(getattr(receipt, "lane_d_court_boundary", 0) or 0) + if not named: + return boundary, None + n = int(getattr(cfg.lane_d, "court_carry_max_settlements", 0) or 0) + allowed = court_carry_boundaries(cfg.round, boundary, n) + if named not in allowed: + return named, (f"the receipt's carried lane D court boundary {named} is not one of the " + f"{n} settlement(s) before {boundary} ({allowed}; [lane_d] " + f"court_carry_max_settlements)") + return named, None + + def lane_d_pay(receipt: RoundReceipt, cfg: ChainConfig, lane_d) -> LaneDPay: """rev6.18 B1/B3: lane D's pay at the settlement ``receipt`` closes, from the lane D record (the signed report and its W7c receipt record; ``None`` = no record). Record-level failures and every ``burn``-class :func:`cascade.audit.lane_d.lane_d_findings` code burn lane D's share only; ``alert``-class codes keep the signed court paid. The codes are - :data:`cascade.audit.lane_d.REFUSAL_CODES`.""" + :data:`cascade.audit.lane_d.REFUSAL_CODES`. + + Owner 2026-12-01: a receipt naming ``lane_d_court_boundary`` paid the + court of that earlier published settlement (:func:`lane_d_court_boundary` + bounds it); the record is then the one published at that boundary.""" import hashlib from .lane_d import ( @@ -3138,7 +3165,9 @@ def lane_d_pay(receipt: RoundReceipt, cfg: ChainConfig, lane_d) -> LaneDPay: lane_d_findings, ) - boundary = int(receipt.epoch_start_block) + boundary, carry_why = lane_d_court_boundary(receipt, cfg) + if carry_why is not None: + return LaneDPay(code="lane_d_boundary_mismatch", detail=carry_why) if lane_d is None: return LaneDPay(code="lane_d_record_missing", detail=f"lane D pays at the settlement {boundary} but no lane D record " @@ -3164,7 +3193,10 @@ def lane_d_pay(receipt: RoundReceipt, cfg: ChainConfig, lane_d) -> LaneDPay: if isinstance(b, bool) or not isinstance(b, int) or b != boundary: return LaneDPay(code="lane_d_boundary_mismatch", detail=f"the lane D {what}'s boundary {b!r} is not the " - f"settlement's {boundary}") + f"settlement's {boundary}" + + (f" (the court it carried; the settlement is " + f"{int(receipt.epoch_start_block)})" + if boundary != int(receipt.epoch_start_block) else "")) try: body = hashlib.sha256(_canon({k: v for k, v in report.items() if k != "signature"}) ).hexdigest() diff --git a/cascade/audit/main.py b/cascade/audit/main.py index b467f8120..4e691cfdc 100644 --- a/cascade/audit/main.py +++ b/cascade/audit/main.py @@ -557,13 +557,21 @@ def fetch_lane_d_record(receipt: RoundReceipt, store) -> dict | None: """rev6.18 B1: the lane D record of the settlement ``receipt`` closes — ``{"report", "receipt"}`` — read from the published layout, the receipt record preferring the one the signed round receipt embeds (W14). - ``None``: nothing is published (lane D's share burns). An unparseable + ``None``: nothing is published (lane D's share burns). A receipt naming + ``lane_d_court_boundary`` (a carried court) reads the record published + at that boundary. An unparseable object yields ``report`` / ``receipt`` ``None`` (malformed: lane D's share burns). Any other read failure raises (the caller retries).""" from ..shared.hippius import ObjectNotFound b = int(receipt.epoch_start_block) rec = getattr(receipt, "lane_d", None) + carried = int(getattr(receipt, "lane_d_court_boundary", 0) or 0) + if carried: + # owner 2026-12-01: the vector paid the court of this earlier published + # settlement (lane_d_pay bounds it); the embedded record is the + # settlement's own, so the published one at ``carried`` is read + b, rec = carried, None if not isinstance(rec, dict): try: rec = _strict_json(store.get_text(LANE_D_RECEIPT_KEY.format(boundary=b))) diff --git a/cascade/shared/config/lane_d.py b/cascade/shared/config/lane_d.py index c03799f4b..073910d02 100644 --- a/cascade/shared/config/lane_d.py +++ b/cascade/shared/config/lane_d.py @@ -160,6 +160,14 @@ class LaneDConfig: # they replace the retired geometric ``king_decay``. reward_prior_kings: int = 2 court_weights: tuple[float, ...] = (0.80, 0.15, 0.05) + # Owner 2026-12-01 ("miners only stop getting paid when someone beats + # them"): while a settlement's lane D report is not yet known, the weight + # vector pays the court of the most recent published settlement at most + # this many settlements back (0 = never carry: the share burns, the rule + # before). Older than that, or none ever published: lane D's share burns. + # A weight-side knob only: not a signed report parameter, not part of the + # eval host's judge request (lane_d_config_record leaves it out). + court_carry_max_settlements: int = 2 # Rate limits, queue and TTLs (D3, D8, A1, A8, A9, B10). max_entries_per_settlement: int = 8 max_open_per_coldkey: int = 2 @@ -429,6 +437,8 @@ def on_era(name: str, block: int) -> None: gate_suites=suites, gate_weights=gate_w, tau_public=tau, d_margin_start=d_start, d_margin_warmup_settlements=d_warmup, reward_prior_kings=rpk, court_weights=court_w, + court_carry_max_settlements=_int(ld.get("court_carry_max_settlements", 2), + "court_carry_max_settlements", lo=0, hi=64), max_entries_per_settlement=_int(ld.get("max_entries_per_settlement", 8), "max_entries_per_settlement", lo=1), max_open_per_coldkey=_int(ld.get("max_open_per_coldkey", 2), @@ -449,6 +459,26 @@ def on_era(name: str, block: int) -> None: ) +def court_carry_boundaries(round_cfg, boundary: int, max_settlements: int) -> list[int]: + """The settlement boundaries before ``boundary`` whose published lane D + court a vector at ``boundary`` may carry while ``boundary``'s own report + is not yet known, newest first: at most ``max_settlements`` of them + (``[lane_d] court_carry_max_settlements``), each the previous boundary on + the grid in force just before the later one (a cadence change is + honoured). One function, so the weight fold and the audit agree.""" + from .rounds import effective_epoch_blocks + + out: list[int] = [] + b = int(boundary) + for _ in range(max(0, int(max_settlements))): + if b <= 0: + break + eb = max(1, int(effective_epoch_blocks(round_cfg, b - 1))) + b = (b - 1) // eb * eb + out.append(b) + return out + + # ── rev6.18 B5: the qualified lane D scoring environments ──────────────────── # # The list is a committed file (``deploy/laned/scoring_envs.toml``), not a @@ -664,6 +694,7 @@ def host_record_problem(host: object) -> str | None: "RETIRED_LANE_D_F4_KEYS", "RETIRED_LANE_D_KEYS", "LaneDConfig", + "court_carry_boundaries", "lane_d_crown_bar", "parse_lane_d", ] diff --git a/cascade/shared/receipt.py b/cascade/shared/receipt.py index 8c21d2c4d..2f3c6e3f4 100644 --- a/cascade/shared/receipt.py +++ b/cascade/shared/receipt.py @@ -657,6 +657,14 @@ class RoundReceipt: # inside the signed body so satellites burn only lane D's share on an # absent settlement. None on every unarmed receipt (bytes unchanged). lane_d: dict | None = None + # Owner 2026-12-01 ("miners only stop getting paid when someone beats + # them"; drop-when-default): the earlier settlement boundary whose + # published lane D court this vector paid because the settlement's own + # lane D report was not yet known (``[lane_d] court_carry_max_settlements`` + # bounds it). 0 = the settlement's own court, or none (every receipt + # before this rule; bytes unchanged). The audit reads the lane D record at + # this boundary instead of the settlement's. + lane_d_court_boundary: int = 0 receipt_version: int = RECEIPT_VERSION signature: str | None = None # validator-hotkey signature over canonical_body @@ -743,6 +751,8 @@ def canonical_body(self) -> bytes: body["sentinel"] = json.loads(json.dumps(self.sentinel, sort_keys=True)) if self.lane_d is not None: body["lane_d"] = json.loads(json.dumps(self.lane_d, sort_keys=True)) + if self.lane_d_court_boundary: + body["lane_d_court_boundary"] = int(self.lane_d_court_boundary) return json.dumps( body, sort_keys=True, separators=(",", ":"), allow_nan=False ).encode("utf-8") @@ -801,6 +811,7 @@ def build_receipt( bench_report: dict | None = None, sentinel: dict | None = None, lane_d: dict | None = None, + lane_d_court_boundary: int | None = None, ) -> RoundReceipt: """Assemble a receipt from live-loop objects (``seeds`` is a ``RoundSeeds``). @@ -850,9 +861,20 @@ def build_receipt( bench_report=None if bench_report is None else dict(bench_report), sentinel=None if sentinel is None else dict(sentinel), lane_d=None if lane_d is None else dict(lane_d), + lane_d_court_boundary=int(lane_d_court_boundary or 0), ) +def _lane_d_court_boundary_of(raw) -> int: + """``lane_d_court_boundary`` of a received receipt: a block >= 0 (absent + = 0). Anything else raises ``ValueError`` (a schema problem).""" + if raw is None: + return 0 + if isinstance(raw, bool) or not isinstance(raw, int) or raw < 0: + raise ValueError(f"lane_d_court_boundary must be a block >= 0; got {raw!r}") + return int(raw) + + def dump_receipt(receipt: RoundReceipt) -> str: """Serialise a receipt (including signature) to a JSON string.""" body = json.loads(receipt.canonical_body().decode("utf-8")) @@ -1046,6 +1068,7 @@ def _receipt_from_obj(obj: dict) -> RoundReceipt: else None), sentinel=(dict(obj["sentinel"]) if isinstance(obj.get("sentinel"), dict) else None), lane_d=(dict(obj["lane_d"]) if isinstance(obj.get("lane_d"), dict) else None), + lane_d_court_boundary=_lane_d_court_boundary_of(obj.get("lane_d_court_boundary")), receipt_version=version, signature=obj.get("signature"), ) diff --git a/cascade/validator/lane_d.py b/cascade/validator/lane_d.py index 77bbf24ef..6dba084a8 100644 --- a/cascade/validator/lane_d.py +++ b/cascade/validator/lane_d.py @@ -1802,12 +1802,21 @@ def plain_json(obj, where: str = "$"): raise TypeError(f"{where}: {type(obj).__name__} is not plain JSON") +# Weight-side ``[lane_d]`` knobs the judge never reads: left out of the judge +# request, so an eval host on a release without them still parses it. +_JUDGE_SKIP_FIELDS = frozenset({"court_carry_max_settlements"}) + + def lane_d_config_record(cfg) -> dict: """The ``[lane_d]`` config as plain JSON (:func:`lane_d_config_from_record` - inverts it exactly).""" + inverts it exactly), without the weight-side knobs + (:data:`_JUDGE_SKIP_FIELDS`, the release default on the other side).""" import dataclasses - return plain_json(dataclasses.asdict(cfg), "lane_d") + rec = dataclasses.asdict(cfg) + for k in _JUDGE_SKIP_FIELDS: + rec.pop(k, None) + return plain_json(rec, "lane_d") def _tuples(v): @@ -1821,7 +1830,8 @@ def lane_d_config_from_record(rec: dict): from ..shared.config.lane_d import LaneDConfig - names = {f.name: f for f in dataclasses.fields(LaneDConfig)} + names = {f.name: f for f in dataclasses.fields(LaneDConfig) + if f.name not in _JUDGE_SKIP_FIELDS} if not isinstance(rec, dict) or set(rec) != set(names): raise ValueError("lane D judge request: the [lane_d] record names other fields") kw = {k: (_tuples(v) if isinstance(v, list) else v) for k, v in rec.items()} diff --git a/cascade/validator/lane_d_wiring.py b/cascade/validator/lane_d_wiring.py index 278ecdf3e..2e091e1da 100644 --- a/cascade/validator/lane_d_wiring.py +++ b/cascade/validator/lane_d_wiring.py @@ -278,10 +278,11 @@ def court_for(self, boundary: int) -> list[int | None] | None: """The court uids of the settlement this step PUBLISHED (or followed) at EXACTLY ``boundary`` (``None`` when there is none: lane D's share burns). Exact, never the latest one at or before ``boundary``: the - audit (``cascade.audit.checks.lane_d_pay``) pays only a record at the - settlement's own boundary, and a restarted node, a satellite and CI - hold no older court, so a carried-forward court would fork a running - node from them. Memory only; never raises.""" + weight fold carries an older court itself, only within ``[lane_d] + court_carry_max_settlements`` and named in the receipt's + ``lane_d_court_boundary`` (owner 2026-12-01), which the audit + (``cascade.audit.checks.lane_d_pay``) reads. Memory only; never + raises.""" try: b = int(boundary) with self._lock: diff --git a/cascade/validator/receipts.py b/cascade/validator/receipts.py index 429ea853d..2aedafea7 100644 --- a/cascade/validator/receipts.py +++ b/cascade/validator/receipts.py @@ -60,12 +60,15 @@ def build_round_receipt( king_check_scores: tuple = (), sentinel: dict | None = None, lane_d: dict | None = None, + lane_d_court_boundary: int | None = None, ) -> RoundReceipt: """Assemble the round's public receipt (pure — no I/O, no signing). ``lane_d`` (LANE_D_PLAN W14) is the settlement's lane D receipt record (present, or ``status: "absent"``), passed through to the receipt; - ``None`` (unarmed) keeps today's bytes. + ``None`` (unarmed) keeps today's bytes. ``lane_d_court_boundary`` + (owner 2026-12-01): the earlier settlement whose published lane D + court the vector carried (``None`` / 0: its own; bytes unchanged). ``era_base_seed`` (DEC-CA-0043, era settlements only) is ``block_seed(era.seed_block)``: the era's training seeds derive from @@ -107,6 +110,7 @@ def build_round_receipt( emission=emission, king_check=king_check, king_check_scores=king_check_scores, lane_c=lane_c, lane_c_pay=lane_c_pay, sentinel=sentinel, lane_d=lane_d, + lane_d_court_boundary=lane_d_court_boundary, lane_c_registrations=lane_c_registrations, **self._netconfig_receipt_kw(), **self._satellite_receipt_kw(manifest), @@ -150,6 +154,7 @@ def build_round_receipt( emission=emission, king_check=king_check, king_check_scores=king_check_scores, lane_c=lane_c, lane_c_pay=lane_c_pay, sentinel=sentinel, lane_d=lane_d, + lane_d_court_boundary=lane_d_court_boundary, lane_c_registrations=lane_c_registrations, **self._netconfig_receipt_kw(), **self._satellite_receipt_kw(manifest), @@ -325,6 +330,7 @@ def _publish_round_receipt( king_check=self._king_check_for(str(manifest.round_id)), king_check_scores=self._king_check_scores_for(str(manifest.round_id)), sentinel=self._receipt_sentinel(client, manifest, epoch_start), + lane_d_court_boundary=getattr(self, "_last_lane_d_carry", None), ) if wallet is not None: receipt = sign_receipt(receipt, wallet) diff --git a/cascade/validator/satellite.py b/cascade/validator/satellite.py index 1033a0dd6..e70907f40 100644 --- a/cascade/validator/satellite.py +++ b/cascade/validator/satellite.py @@ -178,6 +178,43 @@ class Replay: # with lane D's share on ``burn_uid`` (lanes A/B/C identical); a lane D # payee the satellite's metagraph does not register burns to it. vector_d_burned: list[float] | None = None + # owner 2026-12-01: the earlier boundary whose published lane D court + # ``vector`` pays because the settlement's own lane D report was not yet + # known (0 = its own court, or none): sync re-checks for the own report. + lane_d_carried: int = 0 + + +def _with_court_boundary(receipt, court_boundary: int): + """``receipt`` with ``lane_d_court_boundary`` = ``court_boundary``, still + verifying against the bytes the main validator signed (a satellite-side + view for the audit's lane D reads; never published).""" + body = getattr(receipt, "_received_body", None) or receipt.canonical_body() + out = replace(receipt, lane_d_court_boundary=int(court_boundary)) + object.__setattr__(out, "_received_body", body) + return out + + +def _carried_lane_d_record(receipt, cfg: ChainConfig, reader: Any): + """Owner 2026-12-01 ("miners only stop getting paid when someone beats + them"), the satellite side of the carry: the settlement's own lane D + record is not published and the receipt names no carried court, so the + newest record published at most ``[lane_d] court_carry_max_settlements`` + settlements back (:func:`~cascade.shared.config.lane_d.court_carry_boundaries`, + the bound the main validator and the audit use) is read instead. + ``(boundary, record)`` or ``(0, None)``. A read failure raises + :class:`Transient`.""" + from ..audit.main import fetch_lane_d_record + from ..shared.config.lane_d import court_carry_boundaries + + n = int(getattr(cfg.lane_d, "court_carry_max_settlements", 0) or 0) + for b in court_carry_boundaries(cfg.round, int(receipt.epoch_start_block), n): + try: + rec = fetch_lane_d_record(_with_court_boundary(receipt, b), reader) + except Exception as e: # noqa: BLE001 — a read failure is retried, never a burn + raise Transient(f"lane-d-fetch: {e}") from e + if rec is not None: + return b, rec + return 0, None def _fail(check: str, detail: str, *, advance: bool = True) -> Replay: @@ -478,6 +515,15 @@ def replay_receipt(receipt, cfg: ChainConfig, *, reader: Any, prev: dict | None, lane_d = fetch_lane_d_record(receipt, reader) except Exception as e: # noqa: BLE001 — a read failure is retried, never a burn raise Transient(f"lane-d-fetch: {e}") from e + if lane_d is None and not int(getattr(receipt, "lane_d_court_boundary", 0) or 0): + # owner 2026-12-01: the settlement's report is not published yet; + # the newest published court within the bound is paid meanwhile + cb, carried_rec = _carried_lane_d_record(receipt, cfg_r, reader) + if carried_rec is not None: + log.warning("round=%s lane D report at %d not published; carrying the " + "court published at %d", rid, int(receipt.epoch_start_block), cb) + receipt, lane_d = _with_court_boundary(receipt, cb), carried_rec + d_carried = int(getattr(receipt, "lane_d_court_boundary", 0) or 0) if pays_d else 0 # d. the audit's tier-0 re-derivation (verdict, cohort, bench gate from the # trainer-signed report, king check / ladder, lane payouts, weights) rows = audit_receipt(receipt, cfg_audit, tier=0, client=None, @@ -541,6 +587,26 @@ def replay_receipt(receipt, cfg: ChainConfig, *, reader: Any, prev: dict | None, burn_lanes=frozenset(scoped)) if vec is None: return _fail("weights-derive", why) + if d_carried and not lane_d_burn and not why: + # the carried court verified; once the settlement's own report is + # published and verifies, its court is paid instead (the main + # validator's re-asserts switch the same way) + own = _with_court_boundary(receipt, 0) + try: + own_rec = fetch_lane_d_record(own, reader) + except Exception as e: # noqa: BLE001 — keep the carried court, retried by sync + log.info("round=%s own lane D record unreadable yet (%s)", rid, e) + own_rec = None + if own_rec is not None: + own_vec, own_why = derive_weights(own, cfg_r, lane_d=own_rec, + burn_lanes=frozenset(scoped)) + if own_vec is not None and not own_why: + twin, _ = derive_weights(own, cfg_r, lane_d=None, burn_lanes=frozenset(scoped)) + log.info("round=%s lane D: the settlement's own court is published; paying " + "it instead of the court carried from %d", rid, d_carried) + return Replay(ok=True, vector=list(own_vec), burn_uid=int(cfg_r.scoring.burn_uid), + attribution=_attribution(own, lane_d_court_payees(own_rec)), + vector_d_burned=None if twin is None else list(twin)) def _paid(v: list[float]) -> Replay: """``v`` set; when it pays lane D's verified court (#913) the court's @@ -551,7 +617,8 @@ def _paid(v: list[float]) -> Replay: twin, _ = derive_weights(receipt, cfg_r, lane_d=None, burn_lanes=frozenset(scoped)) return Replay(ok=True, vector=list(v), burn_uid=burn, attribution=_attribution(receipt, lane_d_court_payees(lane_d)), - vector_d_burned=None if twin is None else list(twin)) + vector_d_burned=None if twin is None else list(twin), + lane_d_carried=d_carried) if scoped: # containment: the failed lane's share burns; lane A (and lane D, @@ -623,6 +690,12 @@ class SatelliteState: failing: str = "" failing_detail: str = "" failing_round: str = "" + # owner 2026-12-01: the verified vector pays the lane D court carried from + # this earlier boundary (0 = none); ``lane_d_prev_anchor`` is the anchor + # its receipt replayed against, so sync can replay it again once the + # settlement's own lane D report is published. + lane_d_carried: int = 0 + lane_d_prev_anchor: dict | None = None def to_json(self) -> str: return json.dumps(self.__dict__, sort_keys=True, indent=2) @@ -782,6 +855,8 @@ def sync(self, client=None) -> None: anchor = self.state.anchor if anchor is not None and str(latest.round_id) == anchor["round_id"]: self._caught_up = not self.state.failing + if self.state.lane_d_carried and not self.state.failing: + self._recheck_carried_court(latest, client) return try: chain = self._pending(latest) @@ -794,6 +869,7 @@ def sync(self, client=None) -> None: return for receipt in chain: rid = str(receipt.round_id) + prev_anchor = self.state.anchor try: res = replay_receipt(receipt, self.cfg, reader=self.reader, prev=self.state.anchor, client=client) @@ -818,6 +894,8 @@ def sync(self, client=None) -> None: if res.vector is not None: st.vector, st.burn_uid, st.attribution = res.vector, res.burn_uid, res.attribution st.vector_d_burned = res.vector_d_burned + st.lane_d_carried = int(res.lane_d_carried) if res.vector is not None else 0 + st.lane_d_prev_anchor = prev_anchor if st.lane_d_carried else None log.info("round=%s verified (%s)", rid, "vector derived" if res.vector is not None else "no vector recorded; " "the standing vector stays") @@ -825,6 +903,34 @@ def sync(self, client=None) -> None: self._caught_up = not self.state.failing self._persist() + def _recheck_carried_court(self, latest, client=None) -> None: + """Owner 2026-12-01: the verified vector pays a carried lane D court; + once the settlement's own lane D report is published, replay the same + receipt again so its own court is paid (the main validator's + re-asserts switch the same way). Never raises.""" + from ..audit.main import LANE_D_REPORT_KEY + + st = self.state + try: + self.reader.get_text(LANE_D_REPORT_KEY.format( + boundary=int(latest.epoch_start_block))) + except Exception: # noqa: BLE001 — not published yet (or unreadable): next poll + return + try: + res = replay_receipt(latest, self.cfg, reader=self.reader, + prev=st.lane_d_prev_anchor, client=client) + except Exception as e: # noqa: BLE001 — keep the carried court, retried next poll + log.info("round=%s lane D own-court re-check deferred (%s)", latest.round_id, e) + return + if not res.ok or res.vector is None or res.lane_d_carried: + return + st.vector, st.burn_uid, st.attribution = res.vector, res.burn_uid, res.attribution + st.vector_d_burned = res.vector_d_burned + st.lane_d_carried, st.lane_d_prev_anchor = 0, None + log.info("round=%s lane D: switched from the carried court to the settlement's own", + latest.round_id) + self._persist() + # ── weights ── def desired(self, *, now_block: int, hotkeys: list[str]) -> tuple[list[float], str, str]: diff --git a/cascade/validator/weights.py b/cascade/validator/weights.py index e24bb512f..cfe592c26 100644 --- a/cascade/validator/weights.py +++ b/cascade/validator/weights.py @@ -429,6 +429,7 @@ def _apply_weights_inner(self, client: object, round_id: str, reward_uids: list[ self._last_lane_b_pay = None self._last_lane_c_pay = None self._last_emission = None + self._last_lane_d_carry = None try: n_uids = client.n_uids() # type: ignore[attr-defined] if boundary is None: @@ -470,12 +471,18 @@ def _apply_weights_inner(self, client: object, round_id: str, reward_uids: list[ d_live = (boundary is not None and lane_d is not None and lane_d.active(int(boundary)) and not self.cfg.validator.force_burn) d_known: list | None = None + d_from = None if d_live: ready, d_known = self._lane_d_court_ready(client, int(boundary)) if not ready: self._lane_d_court_missing = int(boundary) + # owner 2026-12-01: the newest published court within + # [lane_d] court_carry_max_settlements is paid meanwhile + d_from, d_known = self._lane_d_carried_court(int(boundary)) + self._last_lane_d_carry = d_from d_court = (self._lane_d_court(int(boundary), known=d_known) - if d_live and not self._lane_d_genesis(int(boundary)) + if d_live and not self._lane_d_genesis( + int(boundary if d_from is None else d_from)) else None) if lane_c_on or d_court is not None: from ..shared.emission import EmissionPolicy @@ -579,8 +586,14 @@ def _set_policy_vector(self, client: object, round_id: str, reward_uids: list[in log.info("round=%s weights set under the DEC-CA-0055 policy %s: %s", round_id, policy.as_record(), {u: round(w, 4) for u, w in enumerate(vec) if w > 0}) if d_court is not None: - log.info("round=%s lane D court at boundary %d: %s", round_id, boundary, - d_court or "none published (lane D share burns)") + carried = getattr(self, "_last_lane_d_carry", None) + if carried is not None: + log.info("round=%s lane D court at boundary %d: %s, CARRIED from the " + "published settlement at %d (this settlement's report is not yet " + "known)", round_id, boundary, d_court, carried) + else: + log.info("round=%s lane D court at boundary %d: %s", round_id, boundary, + d_court or "none published (lane D share burns)") with contextlib.suppress(Exception): self._last_weight_block = int(client.current_block()) # type: ignore[attr-defined] return vec @@ -590,9 +603,11 @@ def _lane_d_court_ready(self, client: object, boundary: int) -> tuple[bool, list it. Returns ``(ready, court)``: ``court`` is what ``court_for`` answered when it is known (the fold's one read on that path), and ``ready`` is False when it is still unknown, i.e. lane D's share - burns in this vector. Exact boundary only: nothing is carried forward - from an older settlement (``court_for``'s contract; the audit pays a - record at the settlement's own boundary). + does not pay it in this vector. Exact boundary only (``court_for``'s + contract); when it is unknown the fold carries the newest published + court within the bound instead (:meth:`_lane_d_carried_court`, owner + 2026-12-01) and the receipt names that boundary + (``lane_d_court_boundary``), which the audit reads. 1. Already published or followed by this process: nothing to do. 2. Once per boundary: make sure the boundary's step is submitted (the @@ -650,6 +665,54 @@ def read() -> list | None: boundary, e) return court is not None, court + def _lane_d_carried_court(self, boundary: int) -> tuple[int | None, list | None]: + """Owner 2026-12-01 ("miners only stop getting paid when someone + beats them"): ``boundary``'s lane D report is not yet known, so the + vector pays the court of the most recent PUBLISHED settlement before + it, at most ``[lane_d] court_carry_max_settlements`` settlements back + (:func:`~cascade.shared.config.lane_d.court_carry_boundaries`, the + grid the audit checks the receipt's ``lane_d_court_boundary`` + against). Each candidate is read from memory (``court_for``) or the + signed settlement published there (``load_published``, verified by + the audit's lane D checker). Returns ``(carried boundary, court)``, + or ``(None, None)`` when none is known in the bound (none ever + published, or the newest is too old): lane D's share burns. The + switch to ``boundary``'s own court happens on the next push that + knows it (:meth:`_lane_d_catch_up` pulls that push forward). Never + raises.""" + from ..shared.config.lane_d import court_carry_boundaries + + step = getattr(self, "lane_d_step", None) + court_for = getattr(step, "court_for", None) + if not callable(court_for): + return None, None + try: + n = int(getattr(self.cfg.lane_d, "court_carry_max_settlements", 0) or 0) + cands = court_carry_boundaries(self.cfg.round, int(boundary), n) + except Exception as e: # noqa: BLE001 — lane D never reaches the weight push + log.warning("lane D: no carried court at boundary %d (%s); its share burns", + boundary, e) + return None, None + load = getattr(step, "load_published", None) + for b in cands: + try: + court = court_for(int(b)) + if court is None and callable(load) and load(int(b)): + court = court_for(int(b)) + except Exception as e: # noqa: BLE001 — lane D never reaches the weight push + log.warning("lane D: the court published at boundary %d is unreadable (%s)", + b, e) + continue + if court is not None: + log.warning("lane D: no published report at boundary %d yet; paying the court " + "of the published settlement at %d (%s), carried at most %d " + "settlement(s)", boundary, b, list(court), n) + return int(b), list(court) + if cands: + log.warning("lane D: no published report at boundary %d nor at the %d settlement(s) " + "before it (%s); lane D's share burns", boundary, len(cands), cands) + return None, None + def _lane_d_catch_up(self, client: object) -> None: """The last vector that landed burned lane D's share because no court was known at its boundary, and the court has arrived since: pull the diff --git a/docs/MINER_LANE_D.md b/docs/MINER_LANE_D.md index 6532ea41e..8f88e6cca 100644 --- a/docs/MINER_LANE_D.md +++ b/docs/MINER_LANE_D.md @@ -239,6 +239,11 @@ Lane D pays a **court**: the king and up to two prior kings, split limit. Empty seats renormalise over the miner kings that exist. A deregistered king's seat burns to `burn_uid` (unchanged): its uid no longer resolves, so it is never paid to whoever holds that uid now. +Between a settlement boundary and the publication of that settlement's lane D +report, the court of the most recent published settlement keeps being paid (at +most `court_carry_max_settlements`, default 2, settlements back; older or none +published: lane D's share burns), so a court stops being paid only when someone +beats it. **Genesis (DEC-CA-0076).** Until a miner is first crowned, lane D pays nobody and burns nothing. Its share stays with lane A, its `takes_from` lane, so the diff --git a/tests/accept/w8b/PATHS b/tests/accept/w8b/PATHS index f5e60f18d..aaf770afd 100644 --- a/tests/accept/w8b/PATHS +++ b/tests/accept/w8b/PATHS @@ -39,3 +39,19 @@ docs/VALIDATOR.md # (lane A's BenchScores keys, the ones cascade/website reads). Never gate, # crown, pay, signed report or any consensus value; main validator only. cascade/validator/lane_d_king_bench.py +# Owner 2026-12-01 ("miners only stop getting paid when someone beats them"): +# while a settlement's lane D report is not yet known, the weight fold +# (weights.py, above) pays the newest published court at most [lane_d] +# court_carry_max_settlements settlements back and the round receipt names it +# (lane_d_court_boundary, drop-when-default); the audit reads the record at +# that boundary and bounds it; a satellite carries the same way and switches +# to the own court once published (satellite.py, above). The signed lane D +# report format is unchanged; the knob stays out of the eval host's judge +# request. +cascade/shared/config/lane_d.py +cascade/shared/receipt.py +cascade/validator/receipts.py +cascade/validator/lane_d.py +cascade/audit/checks.py +cascade/audit/main.py +docs/MINER_LANE_D.md diff --git a/tests/accept/w8b/test_w8b_court_carry.py b/tests/accept/w8b/test_w8b_court_carry.py new file mode 100644 index 000000000..8eb818919 --- /dev/null +++ b/tests/accept/w8b/test_w8b_court_carry.py @@ -0,0 +1,187 @@ +"""Lane D's court is carried across the publish gap (owner 2026-12-01). + +"Miners only stop getting paid when someone beats them." Mainnet: the +vector at a settlement boundary went out as ``{0: 1.0}`` (lane D's share +burned) until that boundary's lane D report was published, then +``{0: 0.95, 164: 0.05}``. Contract: while the boundary's report is not yet +known, the weight fold pays the court of the most recent PUBLISHED +settlement at most ``[lane_d] court_carry_max_settlements`` (default 2) +settlements back, records that boundary for the receipt +(``lane_d_court_boundary``), and switches to the boundary's own court as soon +as it is known. None ever published, or only older than the bound: burn. + +On main the fold reads the exact boundary only: every carried case burns, +the knob does not exist and no carry boundary is recorded. +""" + +from __future__ import annotations + +import tomllib +from dataclasses import replace + +import pytest + +from . import helpers as h + +B4 = h.ARM_BLOCK + 4 * h.SETTLEMENT + + +class PubStep: + """A lane D step: ``courts`` known in memory, ``published`` loadable from + the bucket (``load_published``), ``genesis`` the house-held ones.""" + + def __init__(self, courts=None, published=None, genesis=()): + self.courts = {int(b): list(c) for b, c in (courts or {}).items()} + self.published = {int(b): list(c) for b, c in (published or {}).items()} + self.genesis = set(genesis) + self.loads: list[int] = [] + + def __call__(self, boundary): + return None + + def court_for(self, boundary): + c = self.courts.get(int(boundary)) + return None if c is None else list(c) + + def genesis_for(self, boundary): + return int(boundary) in self.courts and int(boundary) in self.genesis + + def load_published(self, boundary): + self.loads.append(int(boundary)) + if int(boundary) in self.published: + self.courts[int(boundary)] = list(self.published[int(boundary)]) + return int(boundary) in self.courts + + +def _cfg(tmp_path, **lane_d): + cfg = h.chain_cfg(tmp_path / "v", lanes_bc=False) + if lane_d: + cfg = replace(cfg, lane_d=replace(cfg.lane_d, **lane_d)) + return cfg + + +def _push(r, block): + r.lane_d_court_wait_s = 0.0 + chain = h.PollChain(block) + r._reassert_weights_at_head(chain) + return chain + + +def test_pending_report_pays_the_previous_published_court(tmp_path): + cfg = _cfg(tmp_path) + step = PubStep(courts={h.B2: [h.CHALLENGER_UID]}) + r = h.runner(cfg, step=step) + chain = _push(r, h.B3 + 5) + assert h.close(chain.last_vector(), h.want_vector(r, cfg, h.B3, [h.CHALLENGER_UID])), \ + "lane D's share burned while B3's report was pending (B2's court was published)" + assert getattr(r, "_last_lane_d_carry", None) == h.B2, "the carried boundary is not recorded" + + +def test_a_restarted_node_carries_the_court_it_loads_from_the_bucket(tmp_path): + cfg = _cfg(tmp_path) + step = PubStep(published={h.B2: [h.CHALLENGER_UID]}) + r = h.runner(cfg, step=step) + chain = _push(r, h.B3 + 5) + assert h.close(chain.last_vector(), h.want_vector(r, cfg, h.B3, [h.CHALLENGER_UID])) + assert step.loads[:2] == [h.B3, h.B2], step.loads + assert getattr(r, "_last_lane_d_carry", None) == h.B2 + + +def test_the_new_court_replaces_the_carried_one_once_published(tmp_path): + cfg = _cfg(tmp_path) + step = PubStep(courts={h.B2: [h.CHALLENGER_UID]}) + r = h.runner(cfg, step=step) + chain = _push(r, h.B3 + 5) + assert getattr(r, "_last_lane_d_carry", None) == h.B2 + step.courts[h.B3] = [h.OTHER_UID] + chain.block = h.B3 + 5 + h.INTERVAL + r._reassert_weights_at_head(chain) + assert len(chain.pushes) == 2 + assert h.close(chain.last_vector(), h.want_vector(r, cfg, h.B3, [h.OTHER_UID])) + assert getattr(r, "_last_lane_d_carry", "missing") is None, \ + "the vector paying B3's own court still records a carried boundary" + + +def test_no_published_settlement_ever_burns(tmp_path): + cfg = _cfg(tmp_path) + step = PubStep() + r = h.runner(cfg, step=step) + chain = _push(r, h.B3 + 5) + assert h.close(chain.last_vector(), h.want_vector(r, cfg, h.B3, [])) + assert step.loads == [h.B3, h.B2, h.B1], \ + f"the fold did not look for a published court before burning: {step.loads}" + assert getattr(r, "_last_lane_d_carry", "missing") is None + + +def test_a_court_older_than_the_bound_burns(tmp_path): + step = PubStep(courts={h.B1: [h.CHALLENGER_UID]}) + cfg = _cfg(tmp_path / "two") + r = h.runner(cfg, step=step) + chain = _push(r, B4 + 5) # B1 is 3 settlements back + assert h.close(chain.last_vector(), h.want_vector(r, cfg, B4, [])) + assert getattr(r, "_last_lane_d_carry", "missing") is None + cfg3 = _cfg(tmp_path / "three", court_carry_max_settlements=3) + r3 = h.runner(cfg3, step=PubStep(courts={h.B1: [h.CHALLENGER_UID]})) + chain3 = _push(r3, B4 + 5) + assert h.close(chain3.last_vector(), h.want_vector(r3, cfg3, B4, [h.CHALLENGER_UID])), \ + "[lane_d] court_carry_max_settlements = 3 did not carry B1's court" + cfg0 = _cfg(tmp_path / "zero", court_carry_max_settlements=0) + r0 = h.runner(cfg0, step=PubStep(courts={h.B2: [h.CHALLENGER_UID]})) + assert h.close(_push(r0, h.B3 + 5).last_vector(), h.want_vector(r0, cfg0, h.B3, [])) + + +def test_a_carried_genesis_settlement_carves_nothing(tmp_path): + cfg = _cfg(tmp_path) + r = h.runner(cfg, step=PubStep(courts={h.B2: [None]}, genesis={h.B2})) + chain = _push(r, h.B3 + 5) + off = replace(cfg, lane_d=replace(cfg.lane_d, from_block=0)) + want = h.runner(off) + wchain = _push(want, h.B3 + 5) + assert h.close(chain.last_vector(), wchain.last_vector()) + assert getattr(r, "_last_lane_d_carry", None) == h.B2 + + +def test_court_carry_knob_parses_and_round_trips(tmp_path): + from cascade.shared.config import lane_d as ld_mod + from cascade.shared.config import parse_chain_config + + raw = tomllib.loads(h._shipped_raw()) + assert getattr(parse_chain_config(raw).lane_d, "court_carry_max_settlements", None) == 2 + raw.setdefault("lane_d", {})["court_carry_max_settlements"] = 5 + cfg = parse_chain_config(raw) + assert getattr(cfg.lane_d, "court_carry_max_settlements", None) == 5, \ + "load_chain_config does not parse [lane_d] court_carry_max_settlements" + for bad in (-1, 1.5, True, 65): + raw["lane_d"]["court_carry_max_settlements"] = bad + with pytest.raises(ValueError): + parse_chain_config(raw) + boundaries = getattr(ld_mod, "court_carry_boundaries", None) + assert callable(boundaries), "court_carry_boundaries is missing" + assert boundaries(cfg.round, h.B3, 2) == [h.B2, h.B1] + assert boundaries(cfg.round, h.B3, 0) == [] + # the eval host's judge request never carries the weight-side knob + from cascade.validator.lane_d import lane_d_config_from_record, lane_d_config_record + + rec = lane_d_config_record(cfg.lane_d) + assert "court_carry_max_settlements" not in rec + assert lane_d_config_from_record(rec).court_weights == cfg.lane_d.court_weights + + +def test_the_receipt_records_the_carried_boundary_drop_when_default(): + import json + + from cascade.shared.receipt import RoundReceipt, _receipt_from_obj + + names = set(RoundReceipt.__dataclass_fields__) + assert "lane_d_court_boundary" in names, "RoundReceipt has no lane_d_court_boundary" + base = dict(round_id="r", status="rejected", epoch_start_block=h.B3, epoch_block_hash="", + base_seed=1, generation_seed=1, training_seed=1, manifest={}, + reject_reason="no_king_challenger_pair") + plain = RoundReceipt(**base) + assert "lane_d_court_boundary" not in json.loads(plain.canonical_body()) + carried = RoundReceipt(**base, lane_d_court_boundary=h.B2) + body = json.loads(carried.canonical_body()) + assert body["lane_d_court_boundary"] == h.B2 + assert _receipt_from_obj(body).lane_d_court_boundary == h.B2 + with pytest.raises(ValueError): + _receipt_from_obj({**body, "lane_d_court_boundary": "x"}) diff --git a/tests/accept/w8b/test_w8b_court_carry_satellite.py b/tests/accept/w8b/test_w8b_court_carry_satellite.py new file mode 100644 index 000000000..ed71af7d0 --- /dev/null +++ b/tests/accept/w8b/test_w8b_court_carry_satellite.py @@ -0,0 +1,207 @@ +"""The carried lane D court on the audit and satellite side (owner 2026-12-01). + +Yuma pays a carried court only when more than half the stake carries it, so +the satellite path carries too. The main validator's receipt names the +earlier boundary whose published court its vector paid +(``lane_d_court_boundary``, drop-when-default: older receipts keep their +bytes); the audit reads the lane D record published at that boundary, +bounded by ``[lane_d] court_carry_max_settlements``, and still refuses a +vector that is not that court's. A satellite whose settlement's own report +is not yet published carries the newest published court within the same +bound, and switches to the own court once it is published. The signed lane +D report format is unchanged. + +On main the receipt has no such field, the audit reads only the +settlement's own boundary and a satellite burns lane D's share in the gap. +""" + +from __future__ import annotations + +import copy +import json +from dataclasses import replace + +import pytest + +pytest.importorskip("bittensor.sp_core") + +from . import test_w8b_satellite_lane_d as s # noqa: E402 + +LANE_D_UID, PRIOR_UID, SHARE = s.LANE_D_UID, s.PRIOR_UID, s.SHARE +offline = s.offline + + +def _court_cfg(tmp_path): + """The #913 court config with lane D armed four settlements before + settlement 0, so the earlier boundaries a court is carried from judge.""" + from tests.unit.test_satellite_replay import BOUNDARIES + + cfg = s._court_cfg(tmp_path) + arm = _carry_boundaries(cfg, BOUNDARIES[0], 4)[-1] - 1 + return replace(cfg, lane_d=replace(cfg.lane_d, from_block=arm)) + + +def _has_field() -> None: + from cascade.shared.receipt import RoundReceipt + + assert "lane_d_court_boundary" in RoundReceipt.__dataclass_fields__, \ + "RoundReceipt has no lane_d_court_boundary" + + +def _carry_boundaries(cfg, boundary, n): + from cascade.shared.config import lane_d as ld_mod + + fn = getattr(ld_mod, "court_carry_boundaries", None) + assert callable(fn), "court_carry_boundaries is missing" + return fn(cfg.round, boundary, n) + + +def _settle(tmp_path, store, *, carried=None, court=(LANE_D_UID, PRIOR_UID)): + """Settlement 0 whose recorded vector pays ``court`` in lane D's share, + naming ``carried`` as the court's boundary when given.""" + from tests.unit.test_satellite_replay import HOTKEYS, make_settlement + + cfg = _court_cfg(tmp_path / "cfg") + n = len(HOTKEYS) + + def tamper(rc): + rc = replace(rc, weights=tuple(s._court_vector(cfg, rc.reward_uids, n, list(court)))) + return rc if carried is None else replace(rc, lane_d_court_boundary=int(carried)) + receipt, _ = make_settlement(cfg, store, 0, tamper=tamper) + return cfg, receipt + + +def _main_cfg(cfg): + from cascade.validator.satellite import pin_main_validator + from tests.unit.test_satellite_replay import MAIN_KP + + return pin_main_validator(cfg, MAIN_KP.ss58_address) + + +def _record(store, boundary): + return {"report": json.loads(store.get_text(f"lane-d/reports/lane_d_report_{boundary}.json")), + "receipt": json.loads(store.get_text( + f"lane-d/receipts/lane_d_receipt_{boundary}.json"))} + + +# ── the audit ─────────────────────────────────────────────────────────────── + + +def test_audit_accepts_a_carried_court_receipt_and_rejects_a_wrong_one(tmp_path, offline): + from cascade.audit.checks import FAIL, PASS, WARN, check_lane_d_pay, derive_weights, lane_d_pay + from cascade.audit.main import fetch_lane_d_record + from tests.unit.test_satellite_replay import BOUNDARIES, DictStore + + _has_field() + store = DictStore() + cfg0 = _court_cfg(tmp_path / "c0") + prev, prev2, prev3 = _carry_boundaries(cfg0, BOUNDARIES[0], 3) + s._publish_report(store, s._paying_report(cfg0, prev)) + s._publish_report(store, s._paying_report(cfg0, prev2)) + cfg, receipt = _settle(tmp_path / "ok", store, carried=prev) + mcfg = _main_cfg(cfg) + rec = fetch_lane_d_record(receipt, store) + assert rec is not None and rec["report"]["boundary"] == prev, \ + "the audit did not read the record at the carried boundary" + pay = lane_d_pay(receipt, mcfg, rec) + assert pay.paid and pay.court == [LANE_D_UID, PRIOR_UID], pay.why + vec, why = derive_weights(receipt, mcfg, lane_d=rec) + assert why == "" and vec == pytest.approx(list(receipt.weights), abs=1e-12) + row = check_lane_d_pay(receipt, mcfg, rec) + assert row.status in (PASS, WARN) and "ld_verifier" not in row.detail, row.detail + + # a vector that is not the carried court's: lane D's share burns + _, wrong = _settle(tmp_path / "wrong", DictStore(), carried=prev, court=(LANE_D_UID,)) + assert check_lane_d_pay(wrong, mcfg, rec).status == FAIL + # the record of another boundary than the one named + assert lane_d_pay(receipt, mcfg, _record(store, prev2)).code == "lane_d_boundary_mismatch" + # a carried boundary past [lane_d] court_carry_max_settlements + s._publish_report(store, s._paying_report(cfg0, prev3)) + _, old = _settle(tmp_path / "old", DictStore(), carried=prev3) + assert lane_d_pay(old, mcfg, _record(store, prev3)).code == "lane_d_boundary_mismatch" + # a receipt without the field still pays its own boundary's record only + _, own = _settle(tmp_path / "own", DictStore()) + assert lane_d_pay(own, mcfg, rec).code == "lane_d_boundary_mismatch" + + +def test_a_carried_receipt_round_trips_and_verifies(tmp_path): + from cascade.shared.receipt import dump_receipt, load_receipt, verify_receipt_signature + from tests.unit.test_satellite_replay import BOUNDARIES, MAIN_KP, DictStore + + _has_field() + cfg0 = _court_cfg(tmp_path / "c0") + prev = _carry_boundaries(cfg0, BOUNDARIES[0], 1)[0] + _, receipt = _settle(tmp_path / "r", DictStore(), carried=prev) + back = load_receipt(dump_receipt(receipt)) + assert back.lane_d_court_boundary == prev + assert verify_receipt_signature(back, MAIN_KP.ss58_address) + + +# ── the satellite ─────────────────────────────────────────────────────────── + + +def test_satellite_follows_a_receipt_that_carried_the_court(tmp_path, offline): + from tests.unit.test_satellite_replay import BOUNDARIES, DictStore, FakeClient, _runner + + _has_field() + store = DictStore() + cfg0 = _court_cfg(tmp_path / "c0") + prev = _carry_boundaries(cfg0, BOUNDARIES[0], 1)[0] + s._publish_report(store, s._paying_report(cfg0, prev)) + cfg, receipt = _settle(tmp_path, store, carried=prev) + recorded = [float(w) for w in receipt.weights] + runner = _runner(cfg, store, tmp_path / "sat") + client = FakeClient(BOUNDARIES[0] + 300) + doc = runner.poll(client) + assert doc["last_failing_check"] == "", doc + assert client.pushed[-1] == recorded, "the satellite did not pay the carried court" + assert runner.state.lane_d_carried == prev + + # the settlement's own report is published: the satellite switches to it + s._publish_report(store, s._paying_report(cfg0, BOUNDARIES[0])) + runner.poll(FakeClient(BOUNDARIES[0] + 400)) + assert runner.state.lane_d_carried == 0, "the satellite never switched to the own court" + assert runner.state.vector == pytest.approx(recorded, abs=1e-12) + + +def test_satellite_carries_the_previous_court_while_the_report_is_pending(tmp_path, offline): + from tests.unit.test_satellite_replay import BOUNDARIES, DictStore, FakeClient, _runner + + store = DictStore() + cfg0 = _court_cfg(tmp_path / "c0") + prev = _carry_boundaries(cfg0, BOUNDARIES[0], 1)[0] + s._publish_report(store, s._paying_report(cfg0, prev)) + cfg, receipt = _settle(tmp_path, store) # the main paid the same court + recorded = [float(w) for w in receipt.weights] + runner = _runner(cfg, store, tmp_path / "sat") + client = FakeClient(BOUNDARIES[0] + 300) + doc = runner.poll(client) + assert doc["last_failing_check"] == "", doc + assert client.pushed[-1][LANE_D_UID] == pytest.approx(recorded[LANE_D_UID]), \ + "lane D's share burned while the settlement's report was pending" + assert client.pushed[-1] == recorded + + +def test_satellite_burns_when_the_newest_court_is_past_the_bound(tmp_path, offline): + import cascade.validator.satellite as sat_mod + from tests.unit.test_satellite_replay import BOUNDARIES, DictStore, FakeClient, _runner + + assert callable(getattr(sat_mod, "_carried_lane_d_record", None)), \ + "the satellite has no carried-court path" + store = DictStore() + cfg0 = _court_cfg(tmp_path / "c0") + prev3 = _carry_boundaries(cfg0, BOUNDARIES[0], 3)[2] + s._publish_report(store, s._paying_report(cfg0, prev3)) + cfg, receipt = _settle(tmp_path, store) + recorded = [float(w) for w in receipt.weights] + burn = int(cfg.scoring.burn_uid) + client = FakeClient(BOUNDARIES[0] + 300) + doc = _runner(cfg, store, tmp_path / "sat").poll(client) + assert doc["last_failing_check"] == "", doc # lane D only, never the whole vector + assert client.pushed[-1][LANE_D_UID] == pytest.approx(0.0, abs=1e-12) + assert client.pushed[-1][burn] > recorded[burn] + # the same court within a widened bound is carried + cfg3 = replace(cfg, lane_d=replace(cfg.lane_d, court_carry_max_settlements=3)) + client3 = FakeClient(BOUNDARIES[0] + 300) + _runner(cfg3, copy.deepcopy(store), tmp_path / "sat3").poll(client3) + assert client3.pushed[-1] == recorded diff --git a/tests/accept/w8b/test_w8b_exact_boundary_absent.py b/tests/accept/w8b/test_w8b_exact_boundary_absent.py index 3fa502961..04bab79d5 100644 --- a/tests/accept/w8b/test_w8b_exact_boundary_absent.py +++ b/tests/accept/w8b/test_w8b_exact_boundary_absent.py @@ -6,7 +6,10 @@ satellite and CI hold no older court; a running node that carried the last court (or the house genesis) forward paid what every other node burned. With no record at ``b`` a running node and a fresh node now push - the same vector. + the same vector. Owner 2026-12-01: that vector is the weight fold's + bounded carry (``[lane_d] court_carry_max_settlements``) of the newest + PUBLISHED court, recorded in the receipt's ``lane_d_court_boundary`` for + the audit, never the step's memory of an unpublished one. 2. ``LaneDStep.abandon(b)``: the worker moved past ``b`` unsettled ⇒ the W14 absent record (``infra_deferred``) is published at ``b`` and becomes the latest pointer, the next settlement extends it, and the audit's fetch + @@ -55,8 +58,14 @@ def test_no_record_at_b_is_the_same_vector_on_a_running_and_a_fresh_node(tmp_pat assert h.close(vec_running, vec_fresh), \ ("running and fresh nodes diverge at a boundary with no lane D record", _nonzero(vec_running), _nonzero(vec_fresh)) - assert h.close(vec_running, h.want_vector(r, cfg, missing, [])), \ - "no lane D record at b: lane D's whole share burns (the audit's expectation)" + prev = settled[-1] + carried = SimpleNamespace( + court_for=lambda b: running.court_for(prev) if b == missing else None, + genesis_for=lambda b: running.genesis_for(prev) if b == missing else False) + vec_carried, _ = h.vector_at(cfg, at, step=carried) + assert h.close(vec_running, vec_carried), \ + "no lane D record at b: the newest published court (b's predecessor) is carried" + assert getattr(r, "_last_lane_d_carry", None) == prev # ── abandon: the absent infra_deferred record ───────────────────────────────