GeezerVison is showing github.com — Merge pull request #27 from CortexLM/feat/production-bootstrap · CortexLM/hypertrain@9da3b7f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/network-v2.md +34Lines changed: 34 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -166,6 +166,40 @@ No automatic migration is provided; separate operator resolution is required. | 166 | 166 | Funding uses signed `EscrowLock` via `POST /v2/runs/{run_id}/escrow/lock`, not a | 167 | 167 | CLI `--bond` flag. Test genesis has pinned nonfinancial origins; production mode | 168 | 168 | has separate reward authority/issuance bounds and no test-genesis conversion. | | 169 | + | | 170 | +Production funding is one coordinator-signed `ProductionBootstrap`, posted as an | | 171 | +`ht/2` envelope to `POST /v2/runs/{run_id}/admin/bootstrap` (admin bearer). The | | 172 | +run's `EconomicsPolicyV2.bootstrap_allocation_hash` pins its owner/units/maturity | | 173 | +list (`genesis_allocation_hash` over `[owner, units, mature_at]`); only | | 174 | +`ledger_mode="production"` may set it, and an unset field is omitted, so earlier | | 175 | +policy digests and run IDs are unchanged. Origins are | | 176 | +`ht-origin-bootstrap-v1|run|allocation_hash|index`. The ledger accepts it once per | | 177 | +run: the same `operation_id` and body replay the stored receipt, the same | | 178 | +`operation_id` with other content answers `OPERATION_CONFLICT`, and any second | | 179 | +bootstrap answers `PRODUCTION_BOOTSTRAP_FORBIDDEN`. It is refused when the inner | | 180 | +authority signature is not `reward_authority` (pinned to `coord_pubkey`), when | | 181 | +the envelope signer is not the coordinator, when the allocation differs from the | | 182 | +pin, when bootstrap plus issued and reserved shadow units would exceed | | 183 | +`max_total_issuance` (`TOTAL_ISSUANCE_BUDGET`; later rewards share the same cap), | | 184 | +when the run has no CUDA qualification (production refuses the CPU backend) and | | 185 | +when the latest beacon round is not BLS-verified (`UNVERIFIED_BEACON`). | | 186 | +Bootstrap units mature on the beacon loop and can be locked or transferred; | | 187 | +like genesis units they are collateral and never pay through `get_weights`. | | 188 | + | | 189 | +Production eligibility also needs the run's `economic-bound` record. `POST | | 190 | +/v2/runs/{run_id}/admin/economic-bound` (admin bearer, no body) writes it once, | | 191 | +coordinator-signed, only when the pinned policy satisfies | | 192 | +`q_floor*s_lower*beta*(R_collectible+S_min) >= G_max` in exact ppm integers | | 193 | +(`challenge/trust_v2.py:economic_bound`); otherwise it answers 409 and writes | | 194 | +nothing. The record binds the economics policy hash; later calls return it | | 195 | +unchanged, and a stored record for another policy answers 409. | | 196 | + | | 197 | +A test-ledger run published on the production challenge steers real emission: | | 198 | +as soon as its first live round finalizes and its reward matures, those units | | 199 | +enter `get_weights` like any production reward | | 200 | +(`tests/challenge/test_v2_weights_bridge.py::test_v2_matured_reward_reaches_get_weights`). | | 201 | +`ledger_mode="test"` does not keep a run out of on-chain weights; do not host a | | 202 | +test-ledger run on the production challenge unless that emission is intended. | 169 | 203 | Rewards are issued only through accepted finality, uniquely tracked by origin, | 170 | 204 | then mature after vesting/dispute conditions. Transfers preserve origin units; | 171 | 205 | fraud burns collectible exposure rather than redistributing it. Shadow work does | |
Collapse file Copy file name to clipboardExpand all lines: docs/operator.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -202,7 +202,7 @@ uv run --frozen python -m hypertrain.ops.manifest_v2 build \ | 202 | 202 | --exp-round 1000000 --state-dir /tmp/state --out /tmp/out | 203 | 203 | ``` | 204 | 204 |
| 205 | | -The example's `coord_pubkey`, two auditors, referees, `reward_authority` and relay public key are **placeholder SS58 public identities, not operational keys**. Replace them before a real run; `coord_pubkey` must match the service's K_coord. The example uses a tiny decoder, `ledger_mode="test"`, a pinned genesis allocation hash and one `.test` relay. It creates no dataset, genesis funding or training round. Custom CPU/GPU runs use the same three JSON shapes; provide valid model dimensions and parameter count, an audit budget of `2H`, and the H/step-bound-derived audit lease. Build computes `init_state_hash`; an existing value must match. It also rejects economics whose `reward_authority` differs from `training.coord_pubkey` (`PINNED_AUTHORITIES`) or whose `round_reward_units` differs from `training.budget.epochs_per_round * 1_000_000` (`MANIFEST_REWARD_BUDGET`). The service's configured auditor set must match `training.auditors`; the offline CLI cannot validate that configuration. Building needs the existing `trainer` extra (`uv sync --frozen --extra trainer`); help and example do not. | | 205 | +The example's `coord_pubkey`, two auditors, referees, `reward_authority` and relay public key are **placeholder SS58 public identities, not operational keys**. Replace them before a real run; `coord_pubkey` must match the service's K_coord. The example uses a tiny decoder, `ledger_mode="test"`, a pinned genesis allocation hash and one `.test` relay. It creates no dataset, genesis funding or training round. `example --ledger-mode production` instead writes a production economics policy pinning a placeholder bootstrap allocation (`bootstrap_allocation_hash`, no genesis); funding then uses `POST /v2/runs/{run_id}/admin/bootstrap` and `POST /v2/runs/{run_id}/admin/economic-bound` (see [network-v2.md](network-v2.md)). A test-ledger run hosted on the production challenge steers real emission once its first live reward matures; keep test-mode runs off the production challenge unless that is intended. Custom CPU/GPU runs use the same three JSON shapes; provide valid model dimensions and parameter count, an audit budget of `2H`, and the H/step-bound-derived audit lease. Build computes `init_state_hash`; an existing value must match. It also rejects economics whose `reward_authority` differs from `training.coord_pubkey` (`PINNED_AUTHORITIES`) or whose `round_reward_units` differs from `training.budget.epochs_per_round * 1_000_000` (`MANIFEST_REWARD_BUDGET`). The service's configured auditor set must match `training.auditors`; the offline CLI cannot validate that configuration. Building needs the existing `trainer` extra (`uv sync --frozen --extra trainer`); help and example do not. | 206 | 206 |
| 207 | 207 | The owner seed is an existing private, current-user-owned 0600 file containing 32 raw bytes or 64 hex characters; it is read through the miner's checked loader, never printed or copied. The shared loader strips leading/trailing ASCII whitespace bytes: provide hex for any raw seed whose first or last byte is ASCII whitespace. Choose an expiry drand round later than submission. Both commands require a new or empty output directory. Build writes `manifest.json`, `manifest-envelope.json`, five `policy-<name>.json` files, `relay-registry.json` and `index.json`. The index records `run_id`, `owner_ss58`, six canonical object hashes and hashes of the eight other files; it excludes its own hash. | 208 | 208 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/hypertrain/challenge/app.py +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -570,6 +570,17 @@ async def genesis_v2(run_id: str, request: Request, authorization: Auth = None) | 570 | 570 | admin(authorization) | 571 | 571 | return await run(store.for_run(run_id).genesis_v2, run_id, await v2_raw(request)) | 572 | 572 |
| | 573 | + @app.post("/v2/runs/{run_id}/admin/bootstrap") | | 574 | + async def bootstrap_v2(run_id: str, request: Request, authorization: Auth = None) -> Any: | | 575 | + admin(authorization) | | 576 | + hosted = store.for_run(run_id) | | 577 | + return await run(hosted.production_bootstrap_v2, run_id, await v2_raw(request)) | | 578 | + | | 579 | + @app.post("/v2/runs/{run_id}/admin/economic-bound") | | 580 | + async def economic_bound_v2(run_id: str, authorization: Auth = None) -> Any: | | 581 | + admin(authorization) | | 582 | + return await run(store.for_run(run_id).economic_bound_v2, run_id) | | 583 | + | 573 | 584 | @app.post("/v2/runs/{run_id}/admin/rounds") | 574 | 585 | async def open_v2(run_id: str, request: Request, authorization: Auth = None) -> Any: | 575 | 586 | admin(authorization) | |
Collapse file Copy file name to clipboardExpand all lines: src/hypertrain/challenge/store.py +48Lines changed: 48 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4145,6 +4145,54 @@ def genesis_v2(self, run_id: str, raw: bytes) -> dict[str, JsonValue]: | 4145 | 4145 | ) | 4146 | 4146 | return receipt.body() | 4147 | 4147 |
| | 4148 | + def production_bootstrap_v2(self, run_id: str, raw: bytes) -> dict[str, JsonValue]: | | 4149 | + """Pinned production issuance; units mature on the beacon loop, never pay out.""" | | 4150 | + from hypertrain.protocol.messages_v2 import ProductionBootstrap | | 4151 | + | | 4152 | + escrow, admission, _ = self._services(run_id) # production refuses CPU here | | 4153 | + with self._tx(): | | 4154 | + admission._beacon(self._now(self._db)) # production requires a BLS-verified round | | 4155 | + model = self._authenticated_v2(run_id, raw, "ProductionBootstrap", self._coord().ss58) | | 4156 | + assert isinstance(model, ProductionBootstrap) | | 4157 | + return escrow.production_bootstrap(model).body() | | 4158 | + | | 4159 | + def economic_bound_v2(self, run_id: str) -> dict[str, JsonValue]: | | 4160 | + """Write the immutable coordinator-signed record only when trust_v2 holds the bound.""" | | 4161 | + from hypertrain.challenge.trust_v2 import economic_bound | | 4162 | + from hypertrain.protocol.messages import Receipt | | 4163 | + | | 4164 | + escrow, _, _ = self._services(run_id) | | 4165 | + with self._tx(): | | 4166 | + row = self._db.execute( | | 4167 | + "SELECT data FROM records_v2 WHERE run_id=? AND kind='economic-bound' AND id='run'", | | 4168 | + (run_id,), | | 4169 | + ).fetchone() | | 4170 | + if row is not None: | | 4171 | + stored: dict[str, JsonValue] = json.loads(row[0]) | | 4172 | + if stored["economics_policy_hash"] != escrow.manifest.network.economics_policy_hash: | | 4173 | + raise ChallengeError(409, "immutable economic-bound record conflicts") | | 4174 | + return stored | | 4175 | + policy = escrow.policy | | 4176 | + if policy.ledger_mode != "production": | | 4177 | + raise ChallengeError(409, "economic-bound record is production only") | | 4178 | + if not economic_bound(policy): | | 4179 | + raise ChallengeError(409, "economic bound q*s*beta*(R+S)>=G fails") | | 4180 | + evidence: dict[str, JsonValue] = { | | 4181 | + "run_id": run_id, | | 4182 | + "economics_policy_hash": escrow.manifest.network.economics_policy_hash, | | 4183 | + "bound": "q*s*beta*(R+S)>=G", | | 4184 | + } | | 4185 | + now = self._now(self._db) | | 4186 | + receipt = Receipt( | | 4187 | + w=0, commit_hash=sha256_hex(canonicalize(evidence)), received_round=max(now, 1) | | 4188 | + ) | | 4189 | + record = { | | 4190 | + **evidence, | | 4191 | + "receipt": envelope_v2.seal(self._coord(), "Receipt", run_id, receipt, NEVER), | | 4192 | + } | | 4193 | + self._put_record_v2(run_id, "economic-bound", "run", record) | | 4194 | + return record | | 4195 | + | 4148 | 4196 | def _service_profile_v2(self, run_id: str) -> _ServiceCapacityV1: | 4149 | 4197 | """Derive the sole admitted tiny shape; never allocate tensors.""" | 4150 | 4198 | manifest = self._run_v2(run_id) | |
Collapse file Copy file name to clipboardExpand all lines: src/hypertrain/challenge/trust_v2.py +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -145,6 +145,17 @@ def audit_floor( | 145 | 145 | return AuditFloor(min(q, 1_000_000), required, allowed) | 146 | 146 |
| 147 | 147 |
| | 148 | +def economic_bound(policy: EconomicsPolicyV2) -> bool: | | 149 | + """Run-level q*s*beta*(R+S)>=G at the pinned audit floor; exact ppm integers.""" | | 150 | + return ( | | 151 | + policy.q_floor | | 152 | + * policy.s_lower_ppm | | 153 | + * policy.beta_ppm | | 154 | + * (policy.R_collectible_units + policy.S_min_units) | | 155 | + >= policy.G_max_units * 10**18 | | 156 | + ) | | 157 | + | | 158 | + | 148 | 159 | @dataclass(frozen=True, slots=True) | 149 | 160 | class AuditSelection: | 150 | 161 | selected: bool | |
Collapse file Copy file name to clipboardExpand all lines: src/hypertrain/ledger/escrow_v2.py +59-4Lines changed: 59 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | """Conserved origin units. SQLite event journal and receipts commit with bucket changes. | 2 | 2 |
| 3 | 3 | No legacy entitlement import, external deposit, client mint or client slash exists. | | 4 | +Production issuance outside rewards is one coordinator-signed, policy-pinned bootstrap. | 4 | 5 | The service supplies authenticated finality/replay and settlement from its own records. | 5 | 6 | """ | 6 | 7 |
| | 35 | 36 | EscrowTransfer, | 36 | 37 | Hex64, | 37 | 38 | OriginAllocation, | | 39 | + ProductionBootstrap, | 38 | 40 | RewardFinalize, | 39 | 41 | RunManifestV2, | 40 | 42 | ShadowReservationRequestV1, | @@ -55,7 +57,9 @@ def digest(model: BaseModel) -> str: | 55 | 57 | return body_digest(model.model_dump(mode="json")) | 56 | 58 |
| 57 | 59 |
| 58 | | -def authority_message(model: TestGenesis | RewardFinalize | ShadowRewardFinalizeV1) -> bytes: | | 60 | +def authority_message( | | 61 | + model: TestGenesis | ProductionBootstrap | RewardFinalize | ShadowRewardFinalizeV1, | | 62 | +) -> bytes: | 59 | 63 | """Origin authority signature is independent of the enclosing envelope signer.""" | 60 | 64 | return ( | 61 | 65 | b"hypertrain/origin/2|" | @@ -76,6 +80,10 @@ def genesis_origin_id(run_id: str, allocation_hash: str, index: int) -> str: | 76 | 80 | return sha256_hex(f"ht-origin-genesis-v2|{run_id}|{allocation_hash}|{index}".encode()) | 77 | 81 |
| 78 | 82 |
| | 83 | +def bootstrap_origin_id(run_id: str, allocation_hash: str, index: int) -> str: | | 84 | + return sha256_hex(f"ht-origin-bootstrap-v1|{run_id}|{allocation_hash}|{index}".encode()) | | 85 | + | | 86 | + | 79 | 87 | def reward_origin_id(run_id: str, w: int, hotkey: str, finalize_hash: str) -> str: | 80 | 88 | return sha256_hex(f"ht-origin-reward-v2|{run_id}|{w}|{hotkey}|{finalize_hash}".encode()) | 81 | 89 |
| @@ -306,7 +314,9 @@ def _event(self, operation_id: str, kind: str, request: str, owner: str) -> Escr | 306 | 314 | self.db.execute("INSERT INTO escrow_snapshots VALUES(?,?)", (operation_id, state)) | 307 | 315 | return receipt | 308 | 316 |
| 309 | | - def _authority(self, model: TestGenesis | RewardFinalize | ShadowRewardFinalizeV1) -> None: | | 317 | + def _authority( | | 318 | + self, model: TestGenesis | ProductionBootstrap | RewardFinalize | ShadowRewardFinalizeV1 | | 319 | + ) -> None: | 310 | 320 | if model.run_id != self.run_id or not verify( | 311 | 321 | decode_hotkey(self.policy.reward_authority), | 312 | 322 | authority_message(model), | @@ -351,6 +361,51 @@ def test_genesis(self, genesis: TestGenesis) -> EscrowReceipt: | 351 | 361 | self._issue(o, None, None) | 352 | 362 | return self._event(operation, "TEST_GENESIS", request, genesis.origins[0].owner) | 353 | 363 |
| | 364 | + def production_bootstrap(self, bootstrap: ProductionBootstrap) -> EscrowReceipt: | | 365 | + """One pinned production issuance per run; collateral like genesis, never emission.""" | | 366 | + self._authority(bootstrap) | | 367 | + with self.tx(): | | 368 | + request = bootstrap.model_dump_json(exclude={"authority_sig"}) | | 369 | + old = self._existing(bootstrap.operation_id, request) | | 370 | + if old is not None: | | 371 | + return old | | 372 | + if ( | | 373 | + self.policy.ledger_mode != "production" | | 374 | + or self.policy.bootstrap_allocation_hash is None | | 375 | + or self.db.execute( | | 376 | + "SELECT 1 FROM escrow_events WHERE kind='PRODUCTION_BOOTSTRAP'" | | 377 | + ).fetchone() | | 378 | + ): | | 379 | + raise EscrowError("PRODUCTION_BOOTSTRAP_FORBIDDEN") | | 380 | + alloc = [(o.owner, o.units, o.mature_at) for o in bootstrap.origins] | | 381 | + if ( | | 382 | + bootstrap.allocation_hash != self.policy.bootstrap_allocation_hash | | 383 | + or genesis_allocation_hash(alloc) != bootstrap.allocation_hash | | 384 | + ): | | 385 | + raise EscrowError("BOOTSTRAP_ALLOCATION") | | 386 | + pending = self.db.execute( | | 387 | + "SELECT COUNT(*) FROM records_v2 WHERE run_id=? AND kind='shadow-reservation' " | | 388 | + "AND json_extract(data,'$.accepted') IS NULL", | | 389 | + (self.run_id,), | | 390 | + ).fetchone()[0] | | 391 | + if ( | | 392 | + self.balances().issued | | 393 | + + pending * self.policy.round_reward_units | | 394 | + + bootstrap.total_units | | 395 | + > self.policy.max_total_issuance | | 396 | + ): | | 397 | + raise EscrowError("TOTAL_ISSUANCE_BUDGET") | | 398 | + for i, o in enumerate(bootstrap.origins): | | 399 | + if o.origin_id != bootstrap_origin_id(self.run_id, bootstrap.allocation_hash, i): | | 400 | + raise EscrowError("BOOTSTRAP_ORIGIN_DOMAIN") | | 401 | + self._issue(o, None, None) # hotkey NULL: payable() never emits these units | | 402 | + return self._event( | | 403 | + bootstrap.operation_id, | | 404 | + "PRODUCTION_BOOTSTRAP", | | 405 | + request, | | 406 | + bootstrap.origins[0].owner, | | 407 | + ) | | 408 | + | 354 | 409 | def reward_allocations( | 355 | 410 | self, reward: RewardFinalize | ShadowRewardFinalizeV1, evidence: FinalityEvidence | 356 | 411 | ) -> tuple[OriginAllocation, ...]: | @@ -973,8 +1028,8 @@ def pay(self, op: EscrowOperation, *, signer: str) -> EscrowReceipt: | 973 | 1028 | def payable(self, now_beacon: int) -> list[sqlite3.Row]: | 974 | 1029 | """Free units of live reward origins matured by now_beacon, oldest maturity first. | 975 | 1030 |
| 976 | | - Shadow (bootstrap) and genesis origins are collateral, never emission. Only units still | 977 | | - held by the origin's issued owner pay (its emptied reward_pending row marks it): units | | 1031 | + Shadow, production-bootstrap and genesis origins are collateral, never emission. Only units | | 1032 | + still held by the origin's issued owner pay (its emptied reward_pending row marks it): units | 978 | 1033 | transferred to another owner or a referee are not the earning hotkey's to emit. | 979 | 1034 | """ | 980 | 1035 | return self.db.execute( | |
Collapse file Copy file name to clipboardExpand all lines: src/hypertrain/ops/manifest_v2.py +8-4Lines changed: 8 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -153,7 +153,7 @@ def _build(args: argparse.Namespace) -> dict[str, JsonValue]: | 153 | 153 | return index | 154 | 154 |
| 155 | 155 |
| 156 | | -def _example() -> dict[str, bytes]: | | 156 | +def _example(ledger_mode: str = "test") -> dict[str, bytes]: | 157 | 157 | coord, auditor0, auditor1, referee, relay, cold, other = ( | 158 | 158 | encode_hotkey(bytes([i]) * 32) for i in range(1, 8) | 159 | 159 | ) | @@ -197,20 +197,23 @@ def _example() -> dict[str, bytes]: | 197 | 197 | max_object_bytes=1_000_000, max_body_bytes=65536, max_chunk_manifest_bytes=1048576 | 198 | 198 | ), | 199 | 199 | ) | | 200 | + allocation = genesis_allocation_hash([(cold, 20000, 1), (other, 10000, 1)]) | | 201 | + production = ledger_mode == "production" | 200 | 202 | economics = EconomicsPolicyV2( | 201 | | - ledger_mode="test", | | 203 | + ledger_mode="production" if production else "test", | 202 | 204 | G_max_units=100, | 203 | 205 | R_collectible_units=100, | 204 | 206 | S_min_units=1000, | 205 | 207 | beta_ppm=1_000_000, | 206 | 208 | gammaV_units=0, | 207 | 209 | s_lower_ppm=1_000_000, | 208 | 210 | q_floor=1_000_000, | 209 | | - genesis_allocation_hash=genesis_allocation_hash([(cold, 20000, 1), (other, 10000, 1)]), | | 211 | + genesis_allocation_hash=None if production else allocation, | 210 | 212 | reward_authority=coord, | 211 | 213 | round_reward_units=1_000_000, | 212 | 214 | max_total_issuance=20_000_000, | 213 | 215 | shadow_bootstrap_rounds=12, | | 216 | + bootstrap_allocation_hash=allocation if production else None, | 214 | 217 | ) | 215 | 218 | aggregation = AggregationPolicyV2( | 216 | 219 | arithmetic="flat-cclip-cap-v1", | @@ -295,13 +298,14 @@ def main(argv: list[str] | None = None) -> int: | 295 | 298 | build.add_argument("--state-dir", type=Path) | 296 | 299 | example = sub.add_parser("example", help="write tiny CPU inputs with public placeholders") | 297 | 300 | example.add_argument("--out", type=Path, required=True) | | 301 | + example.add_argument("--ledger-mode", choices=("test", "production"), default="test") | 298 | 302 | try: | 299 | 303 | args = parser.parse_args(argv) | 300 | 304 | if args.cmd == "build": | 301 | 305 | result = _build(args) | 302 | 306 | else: | 303 | 307 | _check_out(args.out) | 304 | | - files = _example() | | 308 | + files = _example(args.ledger_mode) | 305 | 309 | _write(args.out, files) | 306 | 310 | result = {"files": {name: sha256_hex(raw) for name, raw in files.items()}} | 307 | 311 | except ValidationError as error: | |
|