GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(challenge): disable a relay whose deferred rescue it cannot serve · CortexLM/hypertrain@a141d3f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • network-v2.md
  • src/hypertrain/challenge
    • store.py
  • tests/challenge
    • test_service_network_v2.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/network-v2.md‎

Copy file name to clipboardExpand all lines: docs/network-v2.md
+9-1Lines changed: 9 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@ Multi-chunk custody without a receipt disables the relay key at once only when
264264
the master holds the original and it proves every chunk hash. Otherwise the key
265265
is disabled only after rescued bytes hash to `delta_hash`: the grant could not
266266
tie those chunk hashes to the commit, so a mismatch answers 422 and leaves the
267-
relay enabled.
267+
relay enabled. A rescue the relay cannot serve at all (HTTP error, including a
268+
backend 503, or a signed response other than `SERVED`) disables the key too: two
269+
pinned auditors already proved the failure and the relay cannot produce its own
270+
signed custody. The fallback answers `rescued: false, disabled: true`; the
271+
`relay-disabled` id is `relay_id:assignment_epoch:key_id` and earlier evidence wins.
272+
While a grant is live, `upload-grant` returns the same signed grant for the same
273+
chunk list and 409 for another list.
274+
A relay whose granted chunks do not assemble to `delta_hash` answers 400
275+
`AssemblyMismatch`, records it on the upload and skips it in later recovery.
268276
Retention release waits for finality, disputes and vesting; signed extensions,
269277
overlapping old/new keys and drain preserve existing retrieval authority.
270278

Collapse file

‎src/hypertrain/challenge/store.py‎

Copy file name to clipboardExpand all lines: src/hypertrain/challenge/store.py
+35-15Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5677,6 +5677,8 @@ async def relay_fallback_v2(
56775677
self, run_id: str, failure_hash: str, client: Any
56785678
) -> dict[str, Any]:
56795679
"""Rescue exact signed bytes; fallback grants never renew the original cutoff."""
5680+
import httpx
5681+
56805682
from hypertrain.data.stream_store import spool
56815683
from hypertrain.protocol import relay_envelope
56825684
from hypertrain.protocol.relay_messages import (
@@ -5848,21 +5850,10 @@ async def relay_fallback_v2(
58485850
relay = RelayClient(registry, client)
58495851
recovered = bytearray()
58505852
responses = []
5851-
for request_raw, signer in requests:
5852-
with spool() as payload:
5853-
response = await relay.retrieval(request_raw, payload, relay_public=signer)
5854-
if RetrievalResponse.model_validate(response.body).status != "SERVED":
5855-
raise ChallengeError(409, "original acknowledged bytes unavailable for rescue")
5856-
payload.seek(0)
5857-
recovered.extend(payload.read())
5858-
responses.append((request_raw, response))
5859-
with self._tx():
5860-
self._snapshot_current_v2(manifest)
5861-
if len(recovered) != grant.size or sha256_hex(bytes(recovered)) != grant.delta_hash:
5862-
raise ChallengeError(422, "rescued original bytes differ from signed commit")
5863-
self.objects.put(bytes(recovered))
5864-
disabled = f"{grant.relay_id}:{grant.assignment_epoch}:{failure.key_id}"
5865-
if not self._db.execute( # Deferred by relay_failure_v2; earlier evidence wins.
5853+
disabled = f"{grant.relay_id}:{grant.assignment_epoch}:{failure.key_id}"
5854+
5855+
def disable() -> None: # Deferred by relay_failure_v2; earlier evidence wins.
5856+
if not self._db.execute(
58665857
"SELECT 1 FROM records_v2 WHERE run_id=? AND kind='relay-disabled' AND id=?",
58675858
(run_id, disabled),
58685859
).fetchone():
@@ -5872,6 +5863,35 @@ async def relay_fallback_v2(
58725863
disabled,
58735864
{"key_id": failure.key_id, "evidence_hash": failure_hash},
58745865
)
5866+
5867+
unavailable = False
5868+
try:
5869+
for request_raw, signer in requests:
5870+
with spool() as payload:
5871+
response = await relay.retrieval(request_raw, payload, relay_public=signer)
5872+
if RetrievalResponse.model_validate(response.body).status != "SERVED":
5873+
unavailable = True
5874+
break
5875+
payload.seek(0)
5876+
recovered.extend(payload.read())
5877+
responses.append((request_raw, response))
5878+
except httpx.HTTPError:
5879+
unavailable = True
5880+
if unavailable:
5881+
# Two pinned observers proved the contractual failure and the relay cannot serve
5882+
# its own signed custody either: a dead relay. Bytes that are served but hash
5883+
# wrong (422 below) can be miner framing and never disable.
5884+
with self._tx():
5885+
self._snapshot_current_v2(manifest)
5886+
disable()
5887+
self._notify_processes_v2()
5888+
return {"rescued": False, "disabled": True, "relay_id": grant.relay_id}
5889+
with self._tx():
5890+
self._snapshot_current_v2(manifest)
5891+
if len(recovered) != grant.size or sha256_hex(bytes(recovered)) != grant.delta_hash:
5892+
raise ChallengeError(422, "rescued original bytes differ from signed commit")
5893+
self.objects.put(bytes(recovered))
5894+
disable()
58755895
for request_raw, response in responses:
58765896
self._put_record_v2(
58775897
run_id,
Collapse file

‎tests/challenge/test_service_network_v2.py‎

Copy file name to clipboardExpand all lines: tests/challenge/test_service_network_v2.py
+43-3Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,8 @@ async def drain():
34653465
"forged",
34663466
"held-chunk-only",
34673467
"held-forged",
3468+
"dead-relay",
3469+
"unavailable-relay",
34683470
],
34693471
)
34703472
def test_complete_receipt_prefix_rescue_http(network, monkeypatch, tmp_path, invalid):
@@ -3474,7 +3476,7 @@ def test_complete_receipt_prefix_rescue_http(network, monkeypatch, tmp_path, inv
34743476
import anyio
34753477
import httpx
34763478

3477-
from hypertrain.data.store import LocalFSStore
3479+
from hypertrain.data.store import CorruptObjectError, LocalFSStore, StoreError
34783480
from hypertrain.data.stream_store import StreamStore
34793481
from hypertrain.protocol import envelope_v2, relay_envelope
34803482
from hypertrain.protocol.relay_messages import (
@@ -3517,7 +3519,14 @@ def test_complete_receipt_prefix_rescue_http(network, monkeypatch, tmp_path, inv
35173519
# unheld delta lets upload_grant_v2 sign such a manifest.
35183520
forged = invalid in {"forged", "held-forged"}
35193521
sent = b"x" * (4 << 20) + b"y" if forged else payload
3520-
chunk_only = invalid in {"chunk-only", "forged", "held-chunk-only", "held-forged"}
3522+
chunk_only = invalid in {
3523+
"chunk-only",
3524+
"forged",
3525+
"held-chunk-only",
3526+
"held-forged",
3527+
"dead-relay",
3528+
"unavailable-relay",
3529+
}
35213530
chunks = UploadChunkManifest(
35223531
size=len(payload),
35233532
chunks=[
@@ -3735,6 +3744,14 @@ def disabled():
37353744
return
37363745
if chunk_only:
37373746
assert not failure.json()["disabled"] and disabled() == 0
3747+
if invalid in {"dead-relay", "unavailable-relay"}:
3748+
3749+
async def down(*args):
3750+
if invalid == "dead-relay":
3751+
raise StoreError("backend unavailable") # relay app answers HTTP 503
3752+
raise CorruptObjectError("bit rot") # relay signs RetrievalResponse UNAVAILABLE
3753+
3754+
relay.backing.get = down
37383755
app = relay_app(relay, "x" * 32)
37393756
monkeypatch.setattr(
37403757
httpx,
@@ -3744,7 +3761,30 @@ def disabled():
37443761
rescued = network.client.post(
37453762
network.url + f"/admin/relay-fallback/{evidence.digest()}", headers=admin()
37463763
)
3747-
if invalid == "chunk-only":
3764+
if invalid in {"dead-relay", "unavailable-relay"}:
3765+
# Two pinned auditors proved the failure and the relay cannot serve the rescue.
3766+
assert rescued.status_code == 200, rescued.text
3767+
assert rescued.json()["disabled"] and not rescued.json()["rescued"]
3768+
row = network.store._db.execute(
3769+
"SELECT id,data FROM records_v2 WHERE kind='relay-disabled'"
3770+
).fetchall()
3771+
assert [(r[0], json.loads(r[1])) for r in row] == [
3772+
(
3773+
f"local:{grant.assignment_epoch}:k1",
3774+
{"key_id": "k1", "evidence_hash": evidence.digest()},
3775+
)
3776+
]
3777+
with network.store._tx():
3778+
network.store._db.execute(
3779+
"DELETE FROM records_v2 WHERE kind='relay-assignment' AND id=?",
3780+
(f"0:{HOT[0].ss58}",),
3781+
)
3782+
network.store._put_record_v2(run_id, "round", "0", {"body": opened})
3783+
network.store._put_record_v2(run_id, "assignment", f"0:{HOT[0].ss58}", {})
3784+
fresh = network.client.get(network.url + f"/rounds/0/relay/{HOT[0].ss58}")
3785+
assert fresh.status_code == 503, fresh.text # the only relay is out of selection
3786+
assert "no approved healthy relay" in fresh.text
3787+
elif invalid == "chunk-only":
37483788
assert rescued.status_code == 200, rescued.text
37493789
assert network.store.objects.get(grant.delta_hash) == payload
37503790
assert disabled() == 1

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.