@le-space/rootfs 0.3.26 → 0.3.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/rootfs",
3
- "version": "0.3.26",
3
+ "version": "0.3.28",
4
4
  "description": "Shared rootfs contract parsing, reference profile assets, and build helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -306,19 +306,22 @@ def sign_aleph_message(unsigned_message: dict[str, object], private_key: str) ->
306
306
 
307
307
  def broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[int, dict]:
308
308
  url = urllib.parse.urljoin(api_host.rstrip("/") + "/", "api/v0/messages")
309
- attempts = [
310
- {"sync": True, "message": message},
311
- {**message, "sync": True},
312
- dict(message),
313
- ]
309
+ request_body = {"sync": True, "message": message}
310
+ max_attempts = 3
314
311
  last: tuple[int, dict] | None = None
315
- for attempt in attempts:
316
- last = post_json(url, attempt)
312
+ for index in range(max_attempts):
313
+ last = post_json(url, request_body)
317
314
  if 200 <= last[0] < 300:
318
315
  return last
319
- if last is None:
320
- raise RuntimeError("Aleph broadcast failed before any attempt was made")
321
- raise RuntimeError(f"Aleph broadcast failed: {last[0]} {json_dumps(last[1])}")
316
+ publication_status = last[1].get("publication_status") if isinstance(last[1], dict) else None
317
+ retryable = last[0] >= 500 or (
318
+ isinstance(publication_status, dict)
319
+ and isinstance(publication_status.get("status"), str)
320
+ and publication_status.get("status").strip().lower() == "error"
321
+ )
322
+ if index >= max_attempts - 1 or not retryable:
323
+ raise RuntimeError(f"Aleph broadcast failed: {last[0]} {json_dumps(last[1])}")
324
+ raise RuntimeError("Aleph broadcast failed: retry budget exhausted")
322
325
 
323
326
 
324
327
  def parse_post_record(entry: object) -> dict[str, object] | None:
@@ -155,22 +155,16 @@ def is_retryable_broadcast_failure(http_status: int, payload: object) -> bool:
155
155
 
156
156
  def broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[int, object]:
157
157
  url = urllib.parse.urljoin(api_host.rstrip("/") + "/", "api/v0/messages")
158
- attempts = [
159
- {"sync": True, "message": message},
160
- {**message, "sync": True},
161
- dict(message),
162
- ]
163
- for index, attempt in enumerate(attempts):
164
- http_status, payload = post_json(url, attempt)
158
+ request_body = {"sync": True, "message": message}
159
+ max_attempts = 3
160
+ for index in range(max_attempts):
161
+ http_status, payload = post_json(url, request_body)
165
162
  if 200 <= http_status < 300:
166
163
  return http_status, payload
167
- can_retry = index < len(attempts) - 1 and (
168
- is_invalid_message_format(http_status, payload)
169
- or is_retryable_broadcast_failure(http_status, payload)
170
- )
164
+ can_retry = index < max_attempts - 1 and is_retryable_broadcast_failure(http_status, payload)
171
165
  if not can_retry:
172
166
  raise RuntimeError(f"Aleph broadcast failed: {http_status} {json_dumps(payload)}")
173
- raise RuntimeError("Aleph broadcast failed: no compatible request format was accepted")
167
+ raise RuntimeError("Aleph broadcast failed: retry budget exhausted")
174
168
 
175
169
 
176
170
  def parse_post_record(entry: object) -> dict[str, object] | None:
@@ -246,13 +246,13 @@ def build_post_content(
246
246
  owner_authorization: dict[str, object] | None,
247
247
  relay_proof: dict[str, object],
248
248
  now_ms: int,
249
+ now_seconds: float,
249
250
  ref: str,
250
251
  post_type: str,
251
252
  ) -> dict[str, object]:
252
253
  content = {
253
254
  "peerId": peer_id,
254
255
  "multiaddrs": multiaddrs,
255
- "browserMultiaddrs": browser_multiaddrs if browser_multiaddrs else None,
256
256
  "registrationId": registration_id,
257
257
  "profile": profile,
258
258
  "version": version,
@@ -266,12 +266,14 @@ def build_post_content(
266
266
  "relayProof": relay_proof,
267
267
  "updatedAt": now_ms,
268
268
  }
269
+ if browser_multiaddrs:
270
+ content["browserMultiaddrs"] = browser_multiaddrs
269
271
  return {
270
272
  "type": post_type,
271
273
  "address": sender,
272
274
  "ref": ref,
273
275
  "content": content,
274
- "time": now_ms,
276
+ "time": now_seconds,
275
277
  }
276
278
 
277
279
 
@@ -347,22 +349,16 @@ def is_retryable_broadcast_failure(http_status: int, payload: object) -> bool:
347
349
 
348
350
  def broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[int, object]:
349
351
  url = urllib.parse.urljoin(api_host.rstrip("/") + "/", "api/v0/messages")
350
- attempts = [
351
- {"sync": True, "message": message},
352
- {**message, "sync": True},
353
- dict(message),
354
- ]
355
- for index, attempt in enumerate(attempts):
356
- http_status, payload = post_json(url, attempt)
352
+ request_body = {"sync": True, "message": message}
353
+ max_attempts = 3
354
+ for index in range(max_attempts):
355
+ http_status, payload = post_json(url, request_body)
357
356
  if 200 <= http_status < 300:
358
357
  return http_status, payload
359
- can_retry = index < len(attempts) - 1 and (
360
- is_invalid_message_format(http_status, payload)
361
- or is_retryable_broadcast_failure(http_status, payload)
362
- )
358
+ can_retry = index < max_attempts - 1 and is_retryable_broadcast_failure(http_status, payload)
363
359
  if not can_retry:
364
360
  raise RuntimeError(f"Aleph broadcast failed: {http_status} {json_dumps(payload)}")
365
- raise RuntimeError("Aleph broadcast failed: no compatible request format was accepted")
361
+ raise RuntimeError("Aleph broadcast failed: retry budget exhausted")
366
362
 
367
363
 
368
364
  def parse_post_record(entry: object) -> dict[str, object] | None:
@@ -538,6 +534,7 @@ def main() -> None:
538
534
  owner_authorization,
539
535
  relay_proof,
540
536
  now_ms,
537
+ now_seconds,
541
538
  ref,
542
539
  post_type,
543
540
  )
@@ -284,24 +284,18 @@ def _post_json(url: str, body: dict[str, object]) -> tuple[int, object]:
284
284
 
285
285
  def _broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[int, object]:
286
286
  url = f"{api_host.rstrip('/')}/api/v0/messages"
287
- attempts = [
288
- {"sync": True, "message": message},
289
- {**message, "sync": True},
290
- dict(message),
291
- ]
292
- for index, attempt in enumerate(attempts):
293
- http_status, payload = _post_json(url, attempt)
287
+ request_body = {"sync": True, "message": message}
288
+ max_attempts = 3
289
+ for index in range(max_attempts):
290
+ http_status, payload = _post_json(url, request_body)
294
291
  if 200 <= http_status < 300:
295
292
  return http_status, payload
296
- can_retry = index < len(attempts) - 1 and (
297
- _is_invalid_message_format(http_status, payload)
298
- or _is_retryable_broadcast_failure(http_status, payload)
299
- )
293
+ can_retry = index < max_attempts - 1 and _is_retryable_broadcast_failure(http_status, payload)
300
294
  if not can_retry:
301
295
  raise RuntimeError(
302
296
  f"Aleph bootstrap status broadcast failed: {http_status} {_json_dumps(payload)}"
303
297
  )
304
- raise RuntimeError("Aleph bootstrap status broadcast failed: no compatible request format was accepted")
298
+ raise RuntimeError("Aleph bootstrap status broadcast failed: retry budget exhausted")
305
299
 
306
300
 
307
301
  def _publish_vm_bootstrap_config_signal(record: dict) -> None: