Skip to content
Merged
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
38 changes: 35 additions & 3 deletions cascade/audit/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 "
Expand All @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion cascade/audit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
31 changes: 31 additions & 0 deletions cascade/shared/config/lane_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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",
]
23 changes: 23 additions & 0 deletions cascade/shared/receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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``).

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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"),
)
Expand Down
16 changes: 13 additions & 3 deletions cascade/validator/lane_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,12 +1834,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):
Expand All @@ -1853,7 +1862,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()}
Expand Down
9 changes: 5 additions & 4 deletions cascade/validator/lane_d_wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion cascade/validator/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading