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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ python commit.py commit-repo \
--wallet.hotkey <hotkey>
```

### Commit CDN URL for PLY file storage
```bash
python commit.py commit-cdn-url \
--cdn-url <s3-compatible-storage-url> \
--wallet.name <wallet> \
--wallet.hotkey <hotkey>
```

### List all commitments
```bash
python commit.py list-all
Expand Down
63 changes: 63 additions & 0 deletions commit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import json
import requests
import sys

import bittensor as bt
Expand Down Expand Up @@ -73,6 +74,61 @@ def commit_repo_cmd(
)


@cli.command("commit-cdn-url")
@click.option(
"--cdn-url",
required=True,
help="URL of the S3 compatible object storage that saves the generated PLY files"
)
@click.option("--netuid", default=17, show_default=True)
@click.option(
"--subtensor.endpoint", "subtensor_endpoint", default="finney", show_default=True
)
@click.option("--wallet.name", "wallet_name", required=True)
@click.option("--wallet.hotkey", "wallet_hotkey", required=True)
@click.option("--wallet.path", "wallet_path", default=None)
def commit_cdn_url_cmd(
cdn_url: str,
netuid: int,
subtensor_endpoint: str,
wallet_name: str,
wallet_hotkey: str,
wallet_path: str | None,
) -> None:
"""Commit PLY file storage on-chain."""
try:
response = requests.head(cdn_url, timeout=10)
if not response.ok:
click.echo(
json.dumps(
{
"success": False,
"error": f"CDN URL {cdn_url} is not accessible: {response.status_code}"
}
)
)
raise SystemExit(1)
except requests.RequestException as e:
click.echo(
json.dumps(
{
"success": False,
"error": f"CDN URL {cdn_url} is not accessible: {str(e)}"
}
)
)
raise SystemExit(1)

_run_commit(
data={"cdn_url": cdn_url},
netuid=netuid,
subtensor_endpoint=subtensor_endpoint,
wallet_name=wallet_name,
wallet_hotkey=wallet_hotkey,
wallet_path=wallet_path,
)


def _run_commit(
*,
data: dict,
Expand Down Expand Up @@ -133,6 +189,7 @@ def _parse_commitments(commitments: dict) -> list[dict]:
for hotkey, entries in commitments.items():
latest_commit: tuple[int, str] | None = None
latest_repo: tuple[int, str] | None = None
latest_cdn_url: tuple[int, str] | None = None

for block, data in entries:
try:
Expand All @@ -148,6 +205,10 @@ def _parse_commitments(commitments: dict) -> list[dict]:
if latest_repo is None or block > latest_repo[0]:
latest_repo = (block, repo)

if cdn_url := parsed.get("cdn_url"):
if latest_cdn_url is None or block > latest_cdn_url[0]:
latest_cdn_url = (block, cdn_url)

if latest_commit is None:
continue

Expand All @@ -158,6 +219,8 @@ def _parse_commitments(commitments: dict) -> list[dict]:
"commit_block": latest_commit[0],
"repo": latest_repo[1] if latest_repo else None,
"repo_block": latest_repo[0] if latest_repo else None,
"cdn_url": latest_cdn_url[1] if latest_cdn_url else None,
"cdn_url_block": latest_cdn_url[0] if latest_cdn_url else None,
}
)

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ bittensor==9.12.2
bittensor-wallet==4.0.1
click==8.3.1
pydantic==2.12.4
pydantic-settings==2.12.0
pydantic-settings==2.12.0
requests==2.32.5