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
4 changes: 2 additions & 2 deletions .github/workflows/laned-king-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: laned-king-sync
# Copies the signed lane D index (champions/lane_d/index.json) into the repo
# and writes one card pair per king: champions/lane_d/<digest>/
# {PROVENANCE.json, MODEL_CARD.md} (LANE_D_PLAN §11.1, W13). No weights in
# git: the checkpoints live on the Hippius Hub, the R2 public mirror and the
# HF dataset tensorlink-dev/cascade-lane-d-kings.
# git: the checkpoints live on the mirrors of [lane_d_ops] king_mirrors (owner
# 2026-12-01: the Hippius Hub only by default).
#
# scripts/laned_king_sync.py reads the public index, verifies it under the
# pinned [manifest] validator_hotkey and writes through
Expand Down
33 changes: 23 additions & 10 deletions cascade/lane_d/mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,34 @@ def _r2_client(storage, environ: Mapping[str, str]):
def open_live_mirrors(cfg, *, context: int, hotkey: str, digest: str,
environ: Mapping[str, str] | None = None,
hub_api=None, hf_api=None, r2_client=None,
tmp_dir: str | os.PathLike | None = None) -> dict:
"""``{"hub", "r2", "hf"}`` mirror clients for one king from the loaded
``ChainConfig`` (``[storage]``). The ``*_api`` / ``r2_client`` arguments
tmp_dir: str | os.PathLike | None = None, names=None) -> dict:
"""The mirror clients of ``names`` (the king mirrors,
:func:`cascade.lane_d.publish.king_mirror_names`: the Hub only by
default) for one king from the loaded ``ChainConfig`` (``[storage]``); no
other mirror's client is built. The ``*_api`` / ``r2_client`` arguments
replace the live backends (tests). ``tmp_dir`` is where the Hub and HF
mirrors download a file for a read-back (default: the system temp
directory)."""
from .publish import king_mirror_names

env = os.environ if environ is None else environ
storage = cfg.storage
hub = hub_api if hub_api is not None else _LazyApi(lambda: _hub_api(env))
hf = hf_api if hf_api is not None else _LazyApi(lambda: _hf_api(env))
r2 = (lambda: r2_client) if r2_client is not None else _lazy(lambda: _r2_client(storage, env))
return {"hub": hub_mirror(hub, namespace=str(getattr(storage, "hub_namespace", "cascade")),
context=context, hotkey=hotkey, digest=digest, tmp_dir=tmp_dir),
"r2": S3Mirror(r2, bucket=r2_bucket(storage)),
"hf": hf_mirror(hf, tmp_dir=tmp_dir)}
out: dict = {}
for name in king_mirror_names(names):
if name == "hub":
hub = hub_api if hub_api is not None else _LazyApi(lambda: _hub_api(env))
out[name] = hub_mirror(hub, namespace=str(getattr(storage, "hub_namespace",
"cascade")),
context=context, hotkey=hotkey, digest=digest,
tmp_dir=tmp_dir)
elif name == "r2":
r2 = ((lambda: r2_client) if r2_client is not None
else _lazy(lambda: _r2_client(storage, env)))
out[name] = S3Mirror(r2, bucket=r2_bucket(storage))
else:
hf = hf_api if hf_api is not None else _LazyApi(lambda: _hf_api(env))
out[name] = hf_mirror(hf, tmp_dir=tmp_dir)
return out


class _LazyApi:
Expand Down
77 changes: 54 additions & 23 deletions cascade/lane_d/ops_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
``lane_d_state.json`` and its persisted reports.
* ``king-check``: every crowned persisted report against the signed lane D
index (and, given local copies, the vault and the mirrors): §11.1 "one
digest, one identity" via :func:`cascade.lane_d.publish.check_one_digest`.
digest, one identity" via :func:`cascade.lane_d.publish.check_one_digest`,
over the king mirrors only (``[lane_d_ops] king_mirrors`` of
``--chain-toml``; without it the default, the Hub only).
With ``--path-unit`` (the installed ``cascade-laned-king-publish.path``) it
also fails when that unit does not watch the folder the validator writes
publish requests to (``lane_d_publish_requests`` beside ``--state``).
Expand All @@ -42,16 +44,17 @@
* ``king-publish``: for every crowned persisted report not yet in the signed
index (the validator's settlement step leaves a
``laned_king_publish_request/1`` per crowning), copy the king from the vault
to the Hub, R2 and HF mirrors (:func:`cascade.lane_d.publish.publish_king`,
to the king mirrors (``[lane_d_ops] king_mirrors``, default the Hippius Hub
only; :func:`cascade.lane_d.publish.publish_king`,
read-back re-hash), re-sign ``champions/lane_d/index.json`` with the
validator hotkey, put it on the public store and write the local copy
``king-check`` reads. A checkpoint is never held in memory: it is spooled
to a directory on disk (``--spool-dir``, default the directory of
``--state``; removed when the job ends) and streamed from there, so the job
runs on the box. It refuses (exit 1, nothing written) when that disk has
less free than the king's files, one read-back and 1 GiB.
* ``takedown``: B13, unpublish one king from the Hub and HF mirrors and
re-sign the index (``--reason licence|rights``).
* ``takedown``: B13, unpublish one king from the configured Hub / HF king
mirrors and re-sign the index (``--reason licence|rights``).

Exit codes (every job): 0 done / nothing to do / dry-run planned; 1 an input
is unreadable or invalid, or a check found a problem (nothing written);
Expand Down Expand Up @@ -392,6 +395,25 @@ def delete(self, key: str) -> None:
return out


def _king_mirrors(args, cfg=None) -> tuple[str, ...]:
"""``[lane_d_ops] king_mirrors`` of ``cfg`` (else of ``--chain-toml`` when
given), else the default (the Hub only)."""
from .publish import DEFAULT_KING_MIRRORS

if cfg is None and getattr(args, "chain_toml", None) is not None:
from ..shared.config import load_chain_config

cfg = load_chain_config(args.chain_toml)
if cfg is None:
return DEFAULT_KING_MIRRORS
from ..shared.config.lane_d_ops import lane_d_ops_config

try:
return lane_d_ops_config(cfg).king_mirrors
except ValueError as e:
raise JobError(str(e)) from None


def king_check(args) -> dict:
from ..validator.lane_d_report import verify_report
from .publish import check_one_digest, verify_index
Expand All @@ -401,6 +423,7 @@ def king_check(args) -> dict:
if index is not None and not verify_index(index, args.signer_ss58):
raise JobError(f"{args.index} does not verify under {args.signer_ss58}")
mirrors = _mirrors(args.mirror)
names = _king_mirrors(args)
vault = FilesystemStorage(args.vault_dir) if args.vault_dir else None
full = vault is not None and bool(mirrors)
problems: dict[str, list[str]] = {}
Expand All @@ -419,7 +442,8 @@ def king_check(args) -> dict:
problems[f"{b}"] = ["index_missing"]
continue
if full:
found = check_one_digest(index=index, report=report, vault=vault, mirrors=mirrors)
found = check_one_digest(index=index, report=report, vault=vault, mirrors=mirrors,
king_mirrors=names)
else: # index-only check (no local copies)
entry = next((k for k in index.get("kings") or ()
if isinstance(k, dict) and k.get("digest") == report["crowned"]), None)
Expand Down Expand Up @@ -551,13 +575,15 @@ def _fs_or_live(args, cfg_needed: bool):
return cfg, vault


def _mirrors_for(args, cfg, king: dict, tmp_dir: Path | None = None) -> dict:
def _mirrors_for(args, cfg, king: dict, names: tuple[str, ...],
tmp_dir: Path | None = None) -> dict:
"""The clients of the king mirrors ``names`` only."""
if args.mirror:
return _mirrors(args.mirror)
return {k: v for k, v in _mirrors(args.mirror).items() if k in names}
from .mirrors import open_live_mirrors

return open_live_mirrors(cfg, context=int(king["context"]), hotkey=str(king["hotkey"]),
digest=str(king["digest"]), tmp_dir=tmp_dir)
digest=str(king["digest"]), tmp_dir=tmp_dir, names=names)


class _TermAsExit:
Expand Down Expand Up @@ -650,6 +676,7 @@ def king_publish(args) -> dict:
from .mirrors import open_live_vault

vault = open_live_vault(cfg)
names = _king_mirrors(args, cfg)
signer = _signer(args)

def alert(doc: dict) -> None:
Expand All @@ -661,21 +688,21 @@ def alert(doc: dict) -> None:
try:
with _TermAsExit():
res = publish_king(hotkey=king["hotkey"], digest=king["digest"], vault=vault,
mirrors=_mirrors_for(args, cfg, king, tmp_dir=spool),
alert=alert, spool_dir=spool)
mirrors=_mirrors_for(args, cfg, king, names, tmp_dir=spool),
alert=alert, spool_dir=spool, king_mirrors=names)
except PublishError as e:
raise JobError(f"king {king['digest'][:16]}: {e}") from None
published.append(res)
kings = [*(index or {}).get("kings", ()), *planned]
new_index = build_index(kings, signer)
_write_index(args, new_index, cfg)
log.warning("lane_d_ops_king_published %d king(s) on the mirrors; index re-signed with %d "
"king(s)", len(planned), len(new_index["kings"]))
log.warning("lane_d_ops_king_published %d king(s) on the mirrors %s; index re-signed with "
"%d king(s)", len(planned), list(names), len(new_index["kings"]))
return {**out, "action": "published", "mirrors": published}


def takedown_job(args) -> dict:
from .publish import PublishError, takedown
from .publish import PublishError, takedown, takedown_mirror_names

index = _local_index(args.index, args.signer_ss58)
if index is None:
Expand All @@ -689,21 +716,22 @@ def takedown_job(args) -> dict:
log.info("lane_d_ops_takedown_planned %s is already taken down (%s)", args.digest[:16],
king["takedown"])
return {**out, "action": "current"}
names = _king_mirrors(args)
gone = list(takedown_mirror_names(names))
if args.dry_run:
log.info("lane_d_ops_takedown_planned would unpublish %s from the Hub and HF (%s, block "
"%d)", args.digest[:16], args.reason, args.block)
return {**out, "action": "planned"}
log.info("lane_d_ops_takedown_planned would unpublish %s from %s (%s, block %d)",
args.digest[:16], gone, args.reason, args.block)
return {**out, "action": "planned", "mirrors": gone}
cfg, _ = _fs_or_live(args, cfg_needed=not args.mirror or not args.index_store_dir)
mirrors = _mirrors_for(args, cfg, king)
mirrors = _mirrors_for(args, cfg, king, tuple(gone))
try:
new_index = takedown(index, digest=args.digest, reason=args.reason, block=args.block,
mirrors={k: v for k, v in mirrors.items() if k in ("hub", "hf")},
signer=_signer(args))
mirrors=mirrors, signer=_signer(args), king_mirrors=names)
except PublishError as e:
raise JobError(str(e)) from None
_write_index(args, new_index, cfg)
log.warning("lane_d_ops_takedown_done %s unpublished from the Hub and HF (%s); index "
"re-signed", args.digest[:16], args.reason)
log.warning("lane_d_ops_takedown_done %s unpublished from %s (%s); index re-signed",
args.digest[:16], gone, args.reason)
return {**out, "action": "taken_down"}


Expand Down Expand Up @@ -811,6 +839,9 @@ def common(sp):
k.add_argument("--signer-ss58", required=True, help="the pinned report / index signer")
k.add_argument("--vault-dir", type=Path, default=None, help="local vault copy (full check)")
k.add_argument("--mirror", action="append", default=[], help="NAME=DIR local mirror copy")
k.add_argument("--chain-toml", type=Path, default=None,
help="the deployed chain.toml ([lane_d_ops] king_mirrors: the mirrors "
"checked; default the Hub only)")
k.add_argument("--path-unit", type=Path, default=None,
help="the installed cascade-laned-king-publish.path: fail unless it watches "
"lane_d_publish_requests beside --state")
Expand All @@ -834,7 +865,7 @@ def publication(sp, *, index_help: str):
help="filesystem vault (testnet / tests); default the live vault")
sp.add_argument("--mirror", action="append", default=[],
help="NAME=DIR filesystem mirror (testnet / tests); default the live "
"Hub, R2 and HF mirrors")
"king mirrors ([lane_d_ops] king_mirrors, default the Hub only)")
sp.add_argument("--index-store-dir", type=Path, default=None,
help="filesystem public store for the index; default the manifest store")
sp.add_argument("--wallet-name", default=None)
Expand All @@ -853,7 +884,7 @@ def publication(sp, *, index_help: str):
publication(kp, index_help="the local champions/lane_d/index.json copy king-check reads")
kp.set_defaults(job_func=king_publish)

td = jobs.add_parser("takedown", help="B13: unpublish one king from the Hub and HF")
td = jobs.add_parser("takedown", help="B13: unpublish one king from its Hub / HF mirrors")
td.add_argument("--digest", required=True)
td.add_argument("--reason", required=True, choices=("licence", "rights"))
td.add_argument("--block", type=int, required=True, help="the block of the claim")
Expand Down
Loading
Loading