@optimystic/db-p2p 0.13.4 → 0.14.0

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.
Files changed (352) hide show
  1. package/README.md +6 -6
  2. package/dist/src/cluster/block-transfer-service.d.ts +67 -8
  3. package/dist/src/cluster/block-transfer-service.d.ts.map +1 -1
  4. package/dist/src/cluster/block-transfer-service.js +101 -62
  5. package/dist/src/cluster/block-transfer-service.js.map +1 -1
  6. package/dist/src/cluster/client.d.ts +18 -1
  7. package/dist/src/cluster/client.d.ts.map +1 -1
  8. package/dist/src/cluster/client.js +55 -39
  9. package/dist/src/cluster/client.js.map +1 -1
  10. package/dist/src/cluster/cluster-error.d.ts +38 -0
  11. package/dist/src/cluster/cluster-error.d.ts.map +1 -0
  12. package/dist/src/cluster/cluster-error.js +51 -0
  13. package/dist/src/cluster/cluster-error.js.map +1 -0
  14. package/dist/src/cluster/cluster-repo.d.ts +135 -3
  15. package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
  16. package/dist/src/cluster/cluster-repo.js +333 -58
  17. package/dist/src/cluster/cluster-repo.js.map +1 -1
  18. package/dist/src/cluster/commit-cert.d.ts +63 -0
  19. package/dist/src/cluster/commit-cert.d.ts.map +1 -0
  20. package/dist/src/cluster/commit-cert.js +108 -0
  21. package/dist/src/cluster/commit-cert.js.map +1 -0
  22. package/dist/src/cluster/service.d.ts +46 -11
  23. package/dist/src/cluster/service.d.ts.map +1 -1
  24. package/dist/src/cluster/service.js +97 -33
  25. package/dist/src/cluster/service.js.map +1 -1
  26. package/dist/src/cluster/spread-on-churn.d.ts +13 -0
  27. package/dist/src/cluster/spread-on-churn.d.ts.map +1 -1
  28. package/dist/src/cluster/spread-on-churn.js +34 -4
  29. package/dist/src/cluster/spread-on-churn.js.map +1 -1
  30. package/dist/src/cohort-topic/bootstrap-evidence-builder.d.ts +59 -0
  31. package/dist/src/cohort-topic/bootstrap-evidence-builder.d.ts.map +1 -0
  32. package/dist/src/cohort-topic/bootstrap-evidence-builder.js +79 -0
  33. package/dist/src/cohort-topic/bootstrap-evidence-builder.js.map +1 -0
  34. package/dist/src/cohort-topic/bootstrap-evidence-verifiers.d.ts +81 -0
  35. package/dist/src/cohort-topic/bootstrap-evidence-verifiers.d.ts.map +1 -0
  36. package/dist/src/cohort-topic/bootstrap-evidence-verifiers.js +93 -0
  37. package/dist/src/cohort-topic/bootstrap-evidence-verifiers.js.map +1 -0
  38. package/dist/src/cohort-topic/bootstrap-parent-reference.d.ts +108 -0
  39. package/dist/src/cohort-topic/bootstrap-parent-reference.d.ts.map +1 -0
  40. package/dist/src/cohort-topic/bootstrap-parent-reference.js +108 -0
  41. package/dist/src/cohort-topic/bootstrap-parent-reference.js.map +1 -0
  42. package/dist/src/cohort-topic/change-bridge.d.ts +65 -0
  43. package/dist/src/cohort-topic/change-bridge.d.ts.map +1 -0
  44. package/dist/src/cohort-topic/change-bridge.js +76 -0
  45. package/dist/src/cohort-topic/change-bridge.js.map +1 -0
  46. package/dist/src/cohort-topic/cohort-gossip-driver.d.ts +74 -0
  47. package/dist/src/cohort-topic/cohort-gossip-driver.d.ts.map +1 -0
  48. package/dist/src/cohort-topic/cohort-gossip-driver.js +87 -0
  49. package/dist/src/cohort-topic/cohort-gossip-driver.js.map +1 -0
  50. package/dist/src/cohort-topic/cohort-gossip-transport.d.ts +42 -0
  51. package/dist/src/cohort-topic/cohort-gossip-transport.d.ts.map +1 -0
  52. package/dist/src/cohort-topic/cohort-gossip-transport.js +57 -0
  53. package/dist/src/cohort-topic/cohort-gossip-transport.js.map +1 -0
  54. package/dist/src/cohort-topic/fret-trust-anchor.d.ts +100 -0
  55. package/dist/src/cohort-topic/fret-trust-anchor.d.ts.map +1 -0
  56. package/dist/src/cohort-topic/fret-trust-anchor.js +115 -0
  57. package/dist/src/cohort-topic/fret-trust-anchor.js.map +1 -0
  58. package/dist/src/cohort-topic/host.d.ts +573 -0
  59. package/dist/src/cohort-topic/host.d.ts.map +1 -0
  60. package/dist/src/cohort-topic/host.js +1460 -0
  61. package/dist/src/cohort-topic/host.js.map +1 -0
  62. package/dist/src/cohort-topic/index.d.ts +14 -0
  63. package/dist/src/cohort-topic/index.d.ts.map +1 -0
  64. package/dist/src/cohort-topic/index.js +14 -0
  65. package/dist/src/cohort-topic/index.js.map +1 -0
  66. package/dist/src/cohort-topic/membership-publish-sink.d.ts +14 -0
  67. package/dist/src/cohort-topic/membership-publish-sink.d.ts.map +1 -0
  68. package/dist/src/cohort-topic/membership-publish-sink.js +17 -0
  69. package/dist/src/cohort-topic/membership-publish-sink.js.map +1 -0
  70. package/dist/src/cohort-topic/membership-source.d.ts +36 -0
  71. package/dist/src/cohort-topic/membership-source.d.ts.map +1 -0
  72. package/dist/src/cohort-topic/membership-source.js +58 -0
  73. package/dist/src/cohort-topic/membership-source.js.map +1 -0
  74. package/dist/src/cohort-topic/peer-codec.d.ts +18 -0
  75. package/dist/src/cohort-topic/peer-codec.d.ts.map +1 -0
  76. package/dist/src/cohort-topic/peer-codec.js +26 -0
  77. package/dist/src/cohort-topic/peer-codec.js.map +1 -0
  78. package/dist/src/cohort-topic/peer-sig.d.ts +52 -0
  79. package/dist/src/cohort-topic/peer-sig.d.ts.map +1 -0
  80. package/dist/src/cohort-topic/peer-sig.js +83 -0
  81. package/dist/src/cohort-topic/peer-sig.js.map +1 -0
  82. package/dist/src/cohort-topic/protocols.d.ts +49 -0
  83. package/dist/src/cohort-topic/protocols.d.ts.map +1 -0
  84. package/dist/src/cohort-topic/protocols.js +58 -0
  85. package/dist/src/cohort-topic/protocols.js.map +1 -0
  86. package/dist/src/cohort-topic/reactivity-membership-gate.d.ts +49 -0
  87. package/dist/src/cohort-topic/reactivity-membership-gate.d.ts.map +1 -0
  88. package/dist/src/cohort-topic/reactivity-membership-gate.js +42 -0
  89. package/dist/src/cohort-topic/reactivity-membership-gate.js.map +1 -0
  90. package/dist/src/cohort-topic/size-estimator.d.ts +16 -0
  91. package/dist/src/cohort-topic/size-estimator.d.ts.map +1 -0
  92. package/dist/src/cohort-topic/size-estimator.js +16 -0
  93. package/dist/src/cohort-topic/size-estimator.js.map +1 -0
  94. package/dist/src/cohort-topic/stream-util.d.ts +19 -0
  95. package/dist/src/cohort-topic/stream-util.d.ts.map +1 -0
  96. package/dist/src/cohort-topic/stream-util.js +76 -0
  97. package/dist/src/cohort-topic/stream-util.js.map +1 -0
  98. package/dist/src/cohort-topic/threshold-crypto.d.ts +94 -0
  99. package/dist/src/cohort-topic/threshold-crypto.d.ts.map +1 -0
  100. package/dist/src/cohort-topic/threshold-crypto.js +178 -0
  101. package/dist/src/cohort-topic/threshold-crypto.js.map +1 -0
  102. package/dist/src/cohort-topic/topic-router.d.ts +41 -0
  103. package/dist/src/cohort-topic/topic-router.d.ts.map +1 -0
  104. package/dist/src/cohort-topic/topic-router.js +63 -0
  105. package/dist/src/cohort-topic/topic-router.js.map +1 -0
  106. package/dist/src/dispute/cascade.d.ts +179 -0
  107. package/dist/src/dispute/cascade.d.ts.map +1 -0
  108. package/dist/src/dispute/cascade.js +315 -0
  109. package/dist/src/dispute/cascade.js.map +1 -0
  110. package/dist/src/dispute/client.d.ts +2 -1
  111. package/dist/src/dispute/client.d.ts.map +1 -1
  112. package/dist/src/dispute/client.js +12 -3
  113. package/dist/src/dispute/client.js.map +1 -1
  114. package/dist/src/dispute/dispute-service.d.ts +41 -1
  115. package/dist/src/dispute/dispute-service.d.ts.map +1 -1
  116. package/dist/src/dispute/dispute-service.js +147 -21
  117. package/dist/src/dispute/dispute-service.js.map +1 -1
  118. package/dist/src/dispute/index.d.ts +2 -0
  119. package/dist/src/dispute/index.d.ts.map +1 -1
  120. package/dist/src/dispute/index.js +2 -0
  121. package/dist/src/dispute/index.js.map +1 -1
  122. package/dist/src/dispute/invalidation.d.ts +266 -0
  123. package/dist/src/dispute/invalidation.d.ts.map +1 -0
  124. package/dist/src/dispute/invalidation.js +405 -0
  125. package/dist/src/dispute/invalidation.js.map +1 -0
  126. package/dist/src/dispute/types.d.ts +14 -0
  127. package/dist/src/dispute/types.d.ts.map +1 -1
  128. package/dist/src/dispute/types.js.map +1 -1
  129. package/dist/src/index.d.ts +4 -0
  130. package/dist/src/index.d.ts.map +1 -1
  131. package/dist/src/index.js +4 -0
  132. package/dist/src/index.js.map +1 -1
  133. package/dist/src/libp2p-key-network.d.ts +8 -1
  134. package/dist/src/libp2p-key-network.d.ts.map +1 -1
  135. package/dist/src/libp2p-key-network.js +67 -8
  136. package/dist/src/libp2p-key-network.js.map +1 -1
  137. package/dist/src/libp2p-node-base.d.ts +57 -3
  138. package/dist/src/libp2p-node-base.d.ts.map +1 -1
  139. package/dist/src/libp2p-node-base.js +523 -6
  140. package/dist/src/libp2p-node-base.js.map +1 -1
  141. package/dist/src/matchmaking/aggregate-counts.d.ts +67 -0
  142. package/dist/src/matchmaking/aggregate-counts.d.ts.map +1 -0
  143. package/dist/src/matchmaking/aggregate-counts.js +60 -0
  144. package/dist/src/matchmaking/aggregate-counts.js.map +1 -0
  145. package/dist/src/matchmaking/index.d.ts +20 -0
  146. package/dist/src/matchmaking/index.d.ts.map +1 -0
  147. package/dist/src/matchmaking/index.js +20 -0
  148. package/dist/src/matchmaking/index.js.map +1 -0
  149. package/dist/src/matchmaking/module.d.ts +181 -0
  150. package/dist/src/matchmaking/module.d.ts.map +1 -0
  151. package/dist/src/matchmaking/module.js +221 -0
  152. package/dist/src/matchmaking/module.js.map +1 -0
  153. package/dist/src/matchmaking/protocols.d.ts +37 -0
  154. package/dist/src/matchmaking/protocols.d.ts.map +1 -0
  155. package/dist/src/matchmaking/protocols.js +42 -0
  156. package/dist/src/matchmaking/protocols.js.map +1 -0
  157. package/dist/src/matchmaking/provider-manager.d.ts +52 -0
  158. package/dist/src/matchmaking/provider-manager.d.ts.map +1 -0
  159. package/dist/src/matchmaking/provider-manager.js +74 -0
  160. package/dist/src/matchmaking/provider-manager.js.map +1 -0
  161. package/dist/src/matchmaking/query-handler.d.ts +34 -0
  162. package/dist/src/matchmaking/query-handler.d.ts.map +1 -0
  163. package/dist/src/matchmaking/query-handler.js +62 -0
  164. package/dist/src/matchmaking/query-handler.js.map +1 -0
  165. package/dist/src/matchmaking/query-transport.d.ts +180 -0
  166. package/dist/src/matchmaking/query-transport.d.ts.map +1 -0
  167. package/dist/src/matchmaking/query-transport.js +315 -0
  168. package/dist/src/matchmaking/query-transport.js.map +1 -0
  169. package/dist/src/matchmaking/seeker-manager.d.ts +39 -0
  170. package/dist/src/matchmaking/seeker-manager.d.ts.map +1 -0
  171. package/dist/src/matchmaking/seeker-manager.js +49 -0
  172. package/dist/src/matchmaking/seeker-manager.js.map +1 -0
  173. package/dist/src/matchmaking/seeker-walk-client.d.ts +127 -0
  174. package/dist/src/matchmaking/seeker-walk-client.d.ts.map +1 -0
  175. package/dist/src/matchmaking/seeker-walk-client.js +189 -0
  176. package/dist/src/matchmaking/seeker-walk-client.js.map +1 -0
  177. package/dist/src/matchmaking/traffic-validation.d.ts +128 -0
  178. package/dist/src/matchmaking/traffic-validation.d.ts.map +1 -0
  179. package/dist/src/matchmaking/traffic-validation.js +105 -0
  180. package/dist/src/matchmaking/traffic-validation.js.map +1 -0
  181. package/dist/src/network/network-manager-service.d.ts +4 -2
  182. package/dist/src/network/network-manager-service.d.ts.map +1 -1
  183. package/dist/src/network/network-manager-service.js +9 -3
  184. package/dist/src/network/network-manager-service.js.map +1 -1
  185. package/dist/src/protocol-client.d.ts +25 -0
  186. package/dist/src/protocol-client.d.ts.map +1 -1
  187. package/dist/src/protocol-client.js +126 -4
  188. package/dist/src/protocol-client.js.map +1 -1
  189. package/dist/src/reactivity/forwarder-host.d.ts +198 -0
  190. package/dist/src/reactivity/forwarder-host.d.ts.map +1 -0
  191. package/dist/src/reactivity/forwarder-host.js +355 -0
  192. package/dist/src/reactivity/forwarder-host.js.map +1 -0
  193. package/dist/src/reactivity/index.d.ts +19 -0
  194. package/dist/src/reactivity/index.d.ts.map +1 -0
  195. package/dist/src/reactivity/index.js +19 -0
  196. package/dist/src/reactivity/index.js.map +1 -0
  197. package/dist/src/reactivity/notify-transport.d.ts +70 -0
  198. package/dist/src/reactivity/notify-transport.d.ts.map +1 -0
  199. package/dist/src/reactivity/notify-transport.js +111 -0
  200. package/dist/src/reactivity/notify-transport.js.map +1 -0
  201. package/dist/src/reactivity/origination-manager.d.ts +110 -0
  202. package/dist/src/reactivity/origination-manager.d.ts.map +1 -0
  203. package/dist/src/reactivity/origination-manager.js +129 -0
  204. package/dist/src/reactivity/origination-manager.js.map +1 -0
  205. package/dist/src/reactivity/protocols.d.ts +43 -0
  206. package/dist/src/reactivity/protocols.d.ts.map +1 -0
  207. package/dist/src/reactivity/protocols.js +50 -0
  208. package/dist/src/reactivity/protocols.js.map +1 -0
  209. package/dist/src/reactivity/push-state-gossip.d.ts +132 -0
  210. package/dist/src/reactivity/push-state-gossip.d.ts.map +1 -0
  211. package/dist/src/reactivity/push-state-gossip.js +231 -0
  212. package/dist/src/reactivity/push-state-gossip.js.map +1 -0
  213. package/dist/src/reactivity/recover-transport.d.ts +167 -0
  214. package/dist/src/reactivity/recover-transport.d.ts.map +1 -0
  215. package/dist/src/reactivity/recover-transport.js +308 -0
  216. package/dist/src/reactivity/recover-transport.js.map +1 -0
  217. package/dist/src/reactivity/rotation-rereg-scheduler.d.ts +142 -0
  218. package/dist/src/reactivity/rotation-rereg-scheduler.d.ts.map +1 -0
  219. package/dist/src/reactivity/rotation-rereg-scheduler.js +223 -0
  220. package/dist/src/reactivity/rotation-rereg-scheduler.js.map +1 -0
  221. package/dist/src/reactivity/subscriber-registry.d.ts +47 -0
  222. package/dist/src/reactivity/subscriber-registry.d.ts.map +1 -0
  223. package/dist/src/reactivity/subscriber-registry.js +87 -0
  224. package/dist/src/reactivity/subscriber-registry.js.map +1 -0
  225. package/dist/src/reactivity/subscription-manager.d.ts +221 -0
  226. package/dist/src/reactivity/subscription-manager.d.ts.map +1 -0
  227. package/dist/src/reactivity/subscription-manager.js +302 -0
  228. package/dist/src/reactivity/subscription-manager.js.map +1 -0
  229. package/dist/src/reactivity/topic-bytes.d.ts +32 -0
  230. package/dist/src/reactivity/topic-bytes.d.ts.map +1 -0
  231. package/dist/src/reactivity/topic-bytes.js +34 -0
  232. package/dist/src/reactivity/topic-bytes.js.map +1 -0
  233. package/dist/src/repo/client.d.ts.map +1 -1
  234. package/dist/src/repo/client.js +51 -19
  235. package/dist/src/repo/client.js.map +1 -1
  236. package/dist/src/repo/cluster-coordinator.d.ts +9 -0
  237. package/dist/src/repo/cluster-coordinator.d.ts.map +1 -1
  238. package/dist/src/repo/cluster-coordinator.js +65 -22
  239. package/dist/src/repo/cluster-coordinator.js.map +1 -1
  240. package/dist/src/repo/coordinator-repo.d.ts +20 -0
  241. package/dist/src/repo/coordinator-repo.d.ts.map +1 -1
  242. package/dist/src/repo/coordinator-repo.js +101 -16
  243. package/dist/src/repo/coordinator-repo.js.map +1 -1
  244. package/dist/src/repo/service.d.ts +46 -1
  245. package/dist/src/repo/service.d.ts.map +1 -1
  246. package/dist/src/repo/service.js +79 -45
  247. package/dist/src/repo/service.js.map +1 -1
  248. package/dist/src/rpc-deadline.d.ts +37 -0
  249. package/dist/src/rpc-deadline.d.ts.map +1 -0
  250. package/dist/src/rpc-deadline.js +31 -0
  251. package/dist/src/rpc-deadline.js.map +1 -0
  252. package/dist/src/storage/block-storage.d.ts +2 -0
  253. package/dist/src/storage/block-storage.d.ts.map +1 -1
  254. package/dist/src/storage/block-storage.js +95 -2
  255. package/dist/src/storage/block-storage.js.map +1 -1
  256. package/dist/src/storage/i-block-storage.d.ts +25 -0
  257. package/dist/src/storage/i-block-storage.d.ts.map +1 -1
  258. package/dist/src/storage/storage-repo.d.ts +53 -2
  259. package/dist/src/storage/storage-repo.d.ts.map +1 -1
  260. package/dist/src/storage/storage-repo.js +193 -9
  261. package/dist/src/storage/storage-repo.js.map +1 -1
  262. package/dist/src/sync/client.d.ts +4 -1
  263. package/dist/src/sync/client.d.ts.map +1 -1
  264. package/dist/src/sync/client.js +5 -2
  265. package/dist/src/sync/client.js.map +1 -1
  266. package/dist/src/testing/cohort-topic-mesh-harness.d.ts +219 -0
  267. package/dist/src/testing/cohort-topic-mesh-harness.d.ts.map +1 -0
  268. package/dist/src/testing/cohort-topic-mesh-harness.js +467 -0
  269. package/dist/src/testing/cohort-topic-mesh-harness.js.map +1 -0
  270. package/dist/src/testing/matchmaking-mesh-harness.d.ts +187 -0
  271. package/dist/src/testing/matchmaking-mesh-harness.d.ts.map +1 -0
  272. package/dist/src/testing/matchmaking-mesh-harness.js +358 -0
  273. package/dist/src/testing/matchmaking-mesh-harness.js.map +1 -0
  274. package/dist/src/testing/mesh-harness.d.ts.map +1 -1
  275. package/dist/src/testing/mesh-harness.js +23 -1
  276. package/dist/src/testing/mesh-harness.js.map +1 -1
  277. package/dist/src/testing/reactivity-mesh-harness.d.ts +298 -0
  278. package/dist/src/testing/reactivity-mesh-harness.d.ts.map +1 -0
  279. package/dist/src/testing/reactivity-mesh-harness.js +663 -0
  280. package/dist/src/testing/reactivity-mesh-harness.js.map +1 -0
  281. package/package.json +7 -4
  282. package/src/cluster/block-transfer-service.ts +133 -68
  283. package/src/cluster/client.ts +64 -45
  284. package/src/cluster/cluster-error.ts +64 -0
  285. package/src/cluster/cluster-repo.ts +405 -55
  286. package/src/cluster/commit-cert.ts +139 -0
  287. package/src/cluster/service.ts +116 -44
  288. package/src/cluster/spread-on-churn.ts +328 -285
  289. package/src/cohort-topic/bootstrap-evidence-builder.ts +122 -0
  290. package/src/cohort-topic/bootstrap-evidence-verifiers.ts +132 -0
  291. package/src/cohort-topic/bootstrap-parent-reference.ts +159 -0
  292. package/src/cohort-topic/change-bridge.ts +109 -0
  293. package/src/cohort-topic/cohort-gossip-driver.ts +144 -0
  294. package/src/cohort-topic/cohort-gossip-transport.ts +74 -0
  295. package/src/cohort-topic/fret-trust-anchor.ts +153 -0
  296. package/src/cohort-topic/host.ts +2175 -0
  297. package/src/cohort-topic/index.ts +13 -0
  298. package/src/cohort-topic/membership-publish-sink.ts +20 -0
  299. package/src/cohort-topic/membership-source.ts +68 -0
  300. package/src/cohort-topic/peer-codec.ts +31 -0
  301. package/src/cohort-topic/peer-sig.ts +86 -0
  302. package/src/cohort-topic/protocols.ts +71 -0
  303. package/src/cohort-topic/reactivity-membership-gate.ts +77 -0
  304. package/src/cohort-topic/size-estimator.ts +16 -0
  305. package/src/cohort-topic/stream-util.ts +87 -0
  306. package/src/cohort-topic/threshold-crypto.ts +239 -0
  307. package/src/cohort-topic/topic-router.ts +77 -0
  308. package/src/dispute/cascade.ts +517 -0
  309. package/src/dispute/client.ts +12 -2
  310. package/src/dispute/dispute-service.ts +171 -24
  311. package/src/dispute/index.ts +42 -0
  312. package/src/dispute/invalidation.ts +587 -0
  313. package/src/dispute/types.ts +14 -0
  314. package/src/index.ts +4 -0
  315. package/src/libp2p-key-network.ts +67 -9
  316. package/src/libp2p-node-base.ts +633 -14
  317. package/src/matchmaking/aggregate-counts.ts +104 -0
  318. package/src/matchmaking/index.ts +20 -0
  319. package/src/matchmaking/module.ts +363 -0
  320. package/src/matchmaking/protocols.ts +51 -0
  321. package/src/matchmaking/provider-manager.ts +95 -0
  322. package/src/matchmaking/query-handler.ts +88 -0
  323. package/src/matchmaking/query-transport.ts +483 -0
  324. package/src/matchmaking/seeker-manager.ts +64 -0
  325. package/src/matchmaking/seeker-walk-client.ts +293 -0
  326. package/src/matchmaking/traffic-validation.ts +195 -0
  327. package/src/network/network-manager-service.ts +9 -2
  328. package/src/protocol-client.ts +119 -5
  329. package/src/reactivity/forwarder-host.ts +438 -0
  330. package/src/reactivity/index.ts +19 -0
  331. package/src/reactivity/notify-transport.ts +144 -0
  332. package/src/reactivity/origination-manager.ts +192 -0
  333. package/src/reactivity/protocols.ts +61 -0
  334. package/src/reactivity/push-state-gossip.ts +291 -0
  335. package/src/reactivity/recover-transport.ts +408 -0
  336. package/src/reactivity/rotation-rereg-scheduler.ts +256 -0
  337. package/src/reactivity/subscriber-registry.ts +96 -0
  338. package/src/reactivity/subscription-manager.ts +450 -0
  339. package/src/reactivity/topic-bytes.ts +37 -0
  340. package/src/repo/client.ts +54 -19
  341. package/src/repo/cluster-coordinator.ts +66 -26
  342. package/src/repo/coordinator-repo.ts +99 -15
  343. package/src/repo/service.ts +90 -42
  344. package/src/rpc-deadline.ts +45 -0
  345. package/src/storage/block-storage.ts +106 -3
  346. package/src/storage/i-block-storage.ts +27 -0
  347. package/src/storage/storage-repo.ts +209 -13
  348. package/src/sync/client.ts +5 -2
  349. package/src/testing/cohort-topic-mesh-harness.ts +613 -0
  350. package/src/testing/matchmaking-mesh-harness.ts +475 -0
  351. package/src/testing/mesh-harness.ts +22 -2
  352. package/src/testing/reactivity-mesh-harness.ts +922 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactivity-mesh-harness.js","sourceRoot":"","sources":["../../../src/testing/reactivity-mesh-harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAGH,OAAO,EACN,IAAI,EACJ,iBAAiB,EACjB,yBAAyB,EACzB,0BAA0B,EAC1B,SAAS,EACT,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,sBAAsB,EACtB,8BAA8B,EAC9B,oBAAoB,EACpB,kBAAkB,EAClB,6BAA6B,EAC7B,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,aAAa,EACb,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,GAwBtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,6B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CAAC;QACtC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,IAAI;QACT,yGAAyG;QACzG,oCAAoC;QACpC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3C,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;gBAC/B,CAAC,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC;YACrB,CAAC;QACF,CAAC;QACD,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CACD;AAED,qDAAqD;AACrD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAA8B,EAAE;IACzE,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimystic/db-p2p",
3
- "version": "0.13.4",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "description": "P2P database functionality for Optimystic",
6
6
  "main": "dist/src/index.js",
@@ -68,9 +68,11 @@
68
68
  "@chainsafe/libp2p-gossipsub": "^14.1.2",
69
69
  "@chainsafe/libp2p-noise": "^17.0.0",
70
70
  "@chainsafe/libp2p-yamux": "^8.0.1",
71
+ "@libp2p/autonat": "^3.0.21",
71
72
  "@libp2p/bootstrap": "^12.0.11",
72
73
  "@libp2p/circuit-relay-v2": "^4.1.3",
73
- "@libp2p/crypto": "^5.1.13",
74
+ "@libp2p/crypto": "^5.1.19",
75
+ "@libp2p/dcutr": "^3.0.21",
74
76
  "@libp2p/identify": "^4.0.10",
75
77
  "@libp2p/interface": "^3.1.0",
76
78
  "@libp2p/kad-dht": "^16.1.3",
@@ -79,7 +81,7 @@
79
81
  "@libp2p/tcp": "^11.0.10",
80
82
  "@libp2p/websockets": "^10.1.3",
81
83
  "@multiformats/multiaddr": "^13.0.1",
82
- "@optimystic/db-core": "^0.13.4",
84
+ "@optimystic/db-core": "^0.14.0",
83
85
  "async-mutex": "^0.5.0",
84
86
  "debug": "^4.4.3",
85
87
  "it-all": "^3.0.9",
@@ -88,7 +90,8 @@
88
90
  "it-pushable": "^3.2.3",
89
91
  "libp2p": "^3.1.3",
90
92
  "multiformats": "^13.4.2",
91
- "p2p-fret": "^0.4.0",
93
+ "p2p-fret": "^0.5.0",
94
+ "protons-runtime": "^6.0.0",
92
95
  "uint8arraylist": "^2.4.8",
93
96
  "uint8arrays": "^5.1.0"
94
97
  }
@@ -1,5 +1,5 @@
1
1
  import type { Startable, Stream } from '@libp2p/interface';
2
- import type { IRepo, PeerId, IPeerNetwork } from '@optimystic/db-core';
2
+ import type { IRepo, PeerId, IPeerNetwork, ActionId, ActionRev, IBlock, BlockId } from '@optimystic/db-core';
3
3
  import { pipe } from 'it-pipe';
4
4
  import * as lp from 'it-length-prefixed';
5
5
  import { fromString as u8FromString } from 'uint8arrays/from-string';
@@ -25,6 +25,13 @@ export interface BlockTransferRequest {
25
25
  reason: 'rebalance' | 'replication' | 'recovery';
26
26
  /** For push: base64-encoded block data per block ID */
27
27
  blockData?: Record<string, string>;
28
+ /**
29
+ * For push: the source's revision metadata per block ID. Carries the sender's
30
+ * `state.latest` so the replica's `latest` matches the source instead of being
31
+ * fabricated. Optional: an older sender omits it and the receiver falls back to a
32
+ * deterministic rev-1 replica (see {@link IBlockStorage.saveReplica}).
33
+ */
34
+ blockMeta?: Record<string, { rev: number; actionId: ActionId }>;
28
35
  }
29
36
 
30
37
  /** Response with block data */
@@ -37,13 +44,29 @@ export interface BlockTransferResponse {
37
44
 
38
45
  // --- Service (server-side handler) ---
39
46
 
47
+ /**
48
+ * Repo capability the service needs: read access for `handlePull` plus a local
49
+ * "save replica" path for `handlePush`. The replica path must land in the node's
50
+ * *local* storage (not the cluster-coordinated repo), so it is a distinct method
51
+ * from the `IRepo` commit funnel. `StorageRepo` implements this.
52
+ */
53
+ export interface IBlockReplicaStore extends IRepo {
54
+ /**
55
+ * Persist a replica of a block received out-of-band (churn re-replication).
56
+ * Seeds metadata if absent, advances `latest` monotonically, and makes the block
57
+ * durably servable via `get`. Idempotent for a fixed `(rev, actionId)`; a no-op
58
+ * (still durable) when an equal-or-newer revision is already present.
59
+ */
60
+ saveReplicatedBlock(blockId: BlockId, block: IBlock, source?: ActionRev): Promise<void>;
61
+ }
62
+
40
63
  export interface BlockTransferServiceInit {
41
64
  protocolPrefix?: string;
42
65
  }
43
66
 
44
67
  export interface BlockTransferServiceComponents {
45
68
  registrar: { handle: (...args: any[]) => Promise<void>; unhandle: (...args: any[]) => Promise<void> };
46
- repo: IRepo;
69
+ repo: IBlockReplicaStore;
47
70
  }
48
71
 
49
72
  /**
@@ -55,7 +78,7 @@ export interface BlockTransferServiceComponents {
55
78
  export class BlockTransferService implements Startable {
56
79
  private running = false;
57
80
  private readonly protocol: string;
58
- private readonly repo: IRepo;
81
+ private readonly repo: IBlockReplicaStore;
59
82
  private readonly registrar: BlockTransferServiceComponents['registrar'];
60
83
 
61
84
  constructor(
@@ -70,7 +93,14 @@ export class BlockTransferService implements Startable {
70
93
  async start(): Promise<void> {
71
94
  if (this.running) return;
72
95
  await this.registrar.handle(this.protocol, async (data: any) => {
73
- await this.handleRequest(data.stream);
96
+ // libp2p invokes the stream handler with the Stream as the FIRST positional argument
97
+ // (see cluster/repo/dispute services, which all use `(stream, connection)`). The block-
98
+ // transfer handler previously read `data.stream`, which is `undefined` for the positional
99
+ // shape — so `readRequest` ran `pipe(undefined, ...)` → "Empty pipeline", the receiver
100
+ // never replied, and every push/pull dialled this service hung with no response. Unwrap
101
+ // defensively (older shape passed `{ stream }`), mirroring sync/service.ts.
102
+ const stream = data?.stream ?? data;
103
+ await this.handleRequest(stream);
74
104
  });
75
105
  this.running = true;
76
106
  log('started on %s', this.protocol);
@@ -84,28 +114,45 @@ export class BlockTransferService implements Startable {
84
114
  }
85
115
 
86
116
  private async handleRequest(stream: Stream): Promise<void> {
117
+ const self = this;
87
118
  try {
88
- const request = await this.readRequest(stream);
89
- log('request type=%s blocks=%d reason=%s', request.type, request.blockIds.length, request.reason);
90
-
91
- let response: BlockTransferResponse;
92
- if (request.type === 'pull') {
93
- response = await this.handlePull(request);
94
- } else {
95
- response = await this.handlePush(request);
119
+ // Read the request, process it, and write the response on ONE continuous duplex
120
+ // pipe (mirrors cluster/repo/dispute services). The earlier read-to-end-then-write
121
+ // design deadlocked over a real stream: the client sends one length-prefixed request
122
+ // and holds its write side open awaiting the reply, so a receiver that drained the
123
+ // source until end-of-stream blocked forever — and the reply, written only after
124
+ // teardown, hit a closed stream. Yielding the response as soon as the request is read
125
+ // keeps both sides live.
126
+ const responses = pipe(
127
+ stream,
128
+ (source) => lp.decode(source),
129
+ async function* (source) {
130
+ for await (const msg of source) {
131
+ const request = JSON.parse(u8ToString(msg.subarray(), 'utf8')) as BlockTransferRequest;
132
+ log('request type=%s blocks=%d reason=%s', request.type, request.blockIds.length, request.reason);
133
+ let response: BlockTransferResponse;
134
+ try {
135
+ response = request.type === 'pull'
136
+ ? await self.handlePull(request)
137
+ : await self.handlePush(request);
138
+ } catch (error) {
139
+ log('error: %s', (error as Error).message);
140
+ response = { blocks: {}, missing: [] };
141
+ }
142
+ log('response blocks=%d missing=%d', Object.keys(response.blocks).length, response.missing.length);
143
+ yield u8FromString(JSON.stringify(response), 'utf8');
144
+ return; // one request → one response per stream
145
+ }
146
+ },
147
+ (source) => lp.encode(source)
148
+ );
149
+ for await (const chunk of responses) {
150
+ stream.send(chunk);
96
151
  }
97
-
98
- await this.sendResponse(stream, response);
99
- log('response blocks=%d missing=%d', Object.keys(response.blocks).length, response.missing.length);
100
- } catch (error) {
101
- log('error: %s', (error as Error).message);
102
- try {
103
- await this.sendResponse(stream, { blocks: {}, missing: [] });
104
- } catch {
105
- // ignore send errors
106
- }
107
- } finally {
108
- try { await stream.close(); } catch { /* ignore */ }
152
+ await stream.close();
153
+ } catch (err) {
154
+ log('error: %s', (err as Error).message);
155
+ try { stream.abort(err instanceof Error ? err : new Error(String(err))); } catch { /* ignore */ }
109
156
  }
110
157
  }
111
158
 
@@ -127,9 +174,12 @@ export class BlockTransferService implements Startable {
127
174
  return { blocks, missing };
128
175
  }
129
176
 
130
- // TODO: handlePush validates incoming block data but does not persist it.
131
- // The pushed data is a serialized IBlock, not a full BlockArchive with revisions.
132
- // Persistence should be wired when RebalanceMonitor integrates with BlockStorage.saveRestored().
177
+ /**
178
+ * Persist pushed blocks into local storage so the new owner holds a durable
179
+ * replica after churn. A block is reported `accepted` only if it was both
180
+ * received (parseable) AND successfully persisted; a parse or persist failure
181
+ * surfaces it as `missing` so the sender does not falsely treat it as replicated.
182
+ */
133
183
  private async handlePush(request: BlockTransferRequest): Promise<BlockTransferResponse> {
134
184
  const blocks: Record<string, string> = {};
135
185
  const missing: string[] = [];
@@ -138,50 +188,43 @@ export class BlockTransferService implements Startable {
138
188
  return { blocks: {}, missing: request.blockIds };
139
189
  }
140
190
 
141
- // Accept pushed blocks — for each block, validate we received parseable data
142
191
  for (const blockId of request.blockIds) {
143
192
  const data = request.blockData[blockId];
144
- if (data) {
145
- // Verify we received valid data
146
- try {
147
- JSON.parse(Buffer.from(data, 'base64').toString('utf8'));
148
- blocks[blockId] = data;
149
- } catch {
150
- missing.push(blockId);
151
- }
152
- } else {
193
+ if (!data) {
153
194
  missing.push(blockId);
195
+ continue;
154
196
  }
155
- }
156
197
 
157
- return { blocks, missing };
158
- }
198
+ // Decode + parse the wire payload into an IBlock.
199
+ let block: IBlock;
200
+ try {
201
+ block = JSON.parse(Buffer.from(data, 'base64').toString('utf8')) as IBlock;
202
+ } catch {
203
+ missing.push(blockId);
204
+ continue;
205
+ }
159
206
 
160
- private async readRequest(stream: Stream): Promise<BlockTransferRequest> {
161
- const messages: Uint8Array[] = [];
162
- await pipe(
163
- stream,
164
- lp.decode,
165
- async (source) => {
166
- for await (const msg of source) {
167
- messages.push(msg.subarray());
168
- }
207
+ // `JSON.parse` accepts `null`/primitives as valid JSON. Persisting a falsy or
208
+ // header-less "block" would seed metadata with no materialization, making every
209
+ // later `get` throw. Reject such payloads as missing rather than poison storage.
210
+ if (block === null || typeof block !== 'object' || (block as IBlock).header === undefined) {
211
+ log('push:invalid block=%s (not a structurally valid block)', blockId);
212
+ missing.push(blockId);
213
+ continue;
169
214
  }
170
- );
171
215
 
172
- if (messages.length === 0) {
173
- throw new Error('No request received');
216
+ // Persist locally. Only a received-AND-persisted block is reported accepted.
217
+ try {
218
+ const source = request.blockMeta?.[blockId];
219
+ await this.repo.saveReplicatedBlock(blockId, block, source);
220
+ blocks[blockId] = data;
221
+ } catch (error) {
222
+ log('persist:fail block=%s err=%s', blockId, (error as Error).message);
223
+ missing.push(blockId);
224
+ }
174
225
  }
175
226
 
176
- return JSON.parse(u8ToString(messages[0]!, 'utf8')) as BlockTransferRequest;
177
- }
178
-
179
- private async sendResponse(stream: Stream, response: BlockTransferResponse): Promise<void> {
180
- const bytes = u8FromString(JSON.stringify(response), 'utf8');
181
- const encoded = pipe([bytes], lp.encode);
182
- for await (const chunk of encoded) {
183
- stream.send(chunk);
184
- }
227
+ return { blocks, missing };
185
228
  }
186
229
  }
187
230
 
@@ -206,26 +249,48 @@ export class BlockTransferClient extends ProtocolClient {
206
249
  this.protocol = buildBlockTransferProtocol(protocolPrefix);
207
250
  }
208
251
 
209
- /** Pull blocks from the remote peer. */
252
+ /**
253
+ * Pull blocks from the remote peer.
254
+ *
255
+ * @param options Optional per-call deadlines/cancellation forwarded to the
256
+ * underlying request. `dialTimeoutMs` bounds connecting; `responseTimeoutMs`
257
+ * bounds waiting for the reply once connected; `signal` cancels the whole
258
+ * request. Omitting all of them preserves the previous uncapped behavior.
259
+ */
210
260
  async pullBlocks(
211
261
  blockIds: string[],
212
- reason: BlockTransferRequest['reason'] = 'rebalance'
262
+ reason: BlockTransferRequest['reason'] = 'rebalance',
263
+ options?: { signal?: AbortSignal; dialTimeoutMs?: number; responseTimeoutMs?: number }
213
264
  ): Promise<BlockTransferResponse> {
214
265
  const request: BlockTransferRequest = { type: 'pull', blockIds, reason };
215
- return await this.processMessage<BlockTransferResponse>(request, this.protocol);
266
+ return await this.processMessage<BlockTransferResponse>(request, this.protocol, options);
216
267
  }
217
268
 
218
- /** Push blocks to the remote peer. */
269
+ /**
270
+ * Push blocks to the remote peer.
271
+ *
272
+ * @param blockMeta Optional per-block source revision metadata (the sender's
273
+ * `state.latest`). When provided, the receiver replicates at the source's
274
+ * `(rev, actionId)`; when omitted, it falls back to a deterministic rev-1 replica.
275
+ * @param options Optional per-call deadlines/cancellation forwarded to the
276
+ * underlying request. `dialTimeoutMs` bounds connecting; `responseTimeoutMs`
277
+ * bounds waiting for the reply once connected (so a peer that connects but goes
278
+ * silent throws {@link ResponseTimeoutError} instead of hanging); `signal`
279
+ * cancels the whole request. Omitting all of them preserves the previous
280
+ * uncapped behavior.
281
+ */
219
282
  async pushBlocks(
220
283
  blockIds: string[],
221
284
  blockDataBuffers: Uint8Array[],
222
- reason: BlockTransferRequest['reason'] = 'rebalance'
285
+ reason: BlockTransferRequest['reason'] = 'rebalance',
286
+ blockMeta?: Record<string, { rev: number; actionId: ActionId }>,
287
+ options?: { signal?: AbortSignal; dialTimeoutMs?: number; responseTimeoutMs?: number }
223
288
  ): Promise<BlockTransferResponse> {
224
289
  const blockData: Record<string, string> = {};
225
290
  for (let i = 0; i < blockIds.length; i++) {
226
291
  blockData[blockIds[i]!] = Buffer.from(blockDataBuffers[i]!).toString('base64');
227
292
  }
228
- const request: BlockTransferRequest = { type: 'push', blockIds, reason, blockData };
229
- return await this.processMessage<BlockTransferResponse>(request, this.protocol);
293
+ const request: BlockTransferRequest = { type: 'push', blockIds, reason, blockData, ...(blockMeta ? { blockMeta } : {}) };
294
+ return await this.processMessage<BlockTransferResponse>(request, this.protocol, options);
230
295
  }
231
296
  }
@@ -1,6 +1,9 @@
1
1
  import type { PeerId, IPeerNetwork, ICluster, ClusterRecord } from '@optimystic/db-core';
2
+ import { blockIdToBytes, blockIdsForTransforms } from '@optimystic/db-core';
2
3
  import { ProtocolClient } from '../protocol-client.js';
3
4
  import { peerIdFromString } from '@libp2p/peer-id';
5
+ import { isClusterErrorEnvelope, clusterErrorFromEnvelope } from './cluster-error.js';
6
+ import { withRpcDeadlineDefaults, type RpcDeadlineOptions } from '../rpc-deadline.js';
4
7
 
5
8
  export class ClusterClient extends ProtocolClient implements ICluster {
6
9
  private constructor(peerId: PeerId, peerNetwork: IPeerNetwork, readonly protocolPrefix?: string) {
@@ -12,56 +15,72 @@ export class ClusterClient extends ProtocolClient implements ICluster {
12
15
  return new ClusterClient(peerId, peerNetwork, protocolPrefix);
13
16
  }
14
17
 
15
- async update(record: ClusterRecord, hop: number = 0): Promise<ClusterRecord> {
18
+ async update(record: ClusterRecord, hop: number = 0, options?: RpcDeadlineOptions): Promise<ClusterRecord> {
16
19
  const message = {
17
20
  operation: 'update',
18
21
  record
19
22
  };
20
- const preferred = (this.protocolPrefix ?? '/db-p2p') + '/cluster/1.0.0'
21
- let response: any
22
- try {
23
- response = await this.processMessage<any>(message, preferred)
24
- } catch (err) {
25
- if (preferred !== '/db-p2p/cluster/1.0.0') {
26
- try {
27
- response = await this.processMessage<any>(message, '/db-p2p/cluster/1.0.0')
28
- } catch (fallbackErr) {
29
- // Throw original error - fallback protocol is likely not registered
30
- throw err
31
- }
32
- } else {
33
- throw err
34
- }
35
- }
36
- if (response?.redirect?.peers?.length) {
37
- if (hop >= 2) {
38
- throw new Error('Redirect loop detected in ClusterClient (max hops reached)')
39
- }
40
- const currentIdStr = this.peerId.toString()
41
- const next = response.redirect.peers.find((p: any) => p.id !== currentIdStr) ?? response.redirect.peers[0]
42
- const nextId = peerIdFromString(next.id)
43
- if (next.id === currentIdStr) {
44
- throw new Error('Redirect loop detected in ClusterClient (same peer)')
45
- }
46
- this.recordCoordinatorForRecordIfSupported(record, nextId)
47
- const nextClient = ClusterClient.create(nextId, this.peerNetwork, this.protocolPrefix)
48
- return await nextClient.update(record, hop + 1)
49
- }
50
- return response as ClusterRecord;
23
+ // Every node registers the cluster service under its network-prefixed
24
+ // protocol id (`/optimystic/<network>/cluster/1.0.0`); the bare
25
+ // `/db-p2p/cluster/1.0.0` is never registered, so there is no legacy
26
+ // fallback to attempt — a single dial whose error propagates directly.
27
+ const protocol = (this.protocolPrefix ?? '/db-p2p') + '/cluster/1.0.0';
28
+ // Apply the client-level dial/response deadline so a silent cluster peer
29
+ // can't hang the coordinator forever; an explicit caller override wins.
30
+ const response = await this.processMessage<unknown>(message, protocol, withRpcDeadlineDefaults(options));
31
+
32
+ // A member that threw inside `update` replies with a structured error
33
+ // envelope rather than aborting the stream; rethrow the server's real
34
+ // error (preserving name/code) so the coordinator sees the true cause.
35
+ if (isClusterErrorEnvelope(response)) {
36
+ throw clusterErrorFromEnvelope(response);
37
+ }
38
+
39
+ const redirectResponse = response as { redirect?: { peers?: Array<{ id: string }> } };
40
+ if (redirectResponse?.redirect?.peers?.length) {
41
+ if (hop >= 2) {
42
+ throw new Error('Redirect loop detected in ClusterClient (max hops reached)')
43
+ }
44
+ const currentIdStr = this.peerId.toString()
45
+ const next = redirectResponse.redirect.peers.find((p) => p.id !== currentIdStr) ?? redirectResponse.redirect.peers[0]!
46
+ const nextId = peerIdFromString(next.id)
47
+ if (next.id === currentIdStr) {
48
+ throw new Error('Redirect loop detected in ClusterClient (same peer)')
49
+ }
50
+ await this.recordCoordinatorForRecordIfSupported(record, nextId)
51
+ const nextClient = ClusterClient.create(nextId, this.peerNetwork, this.protocolPrefix)
52
+ // Thread the caller's *original* options through the redirect hop (the
53
+ // recursive call re-applies its own defaults) so the deadline survives a redirect.
54
+ return await nextClient.update(record, hop + 1, options)
55
+ }
56
+ return response as ClusterRecord;
51
57
  }
52
58
 
53
- private recordCoordinatorForRecordIfSupported(record: ClusterRecord, peerId: PeerId): void {
54
- const rmsg: any = (record as any)?.message
55
- let tailId: string | undefined
56
- if (rmsg?.commit?.tailId) tailId = rmsg.commit.tailId
57
- else if (rmsg?.pend?.transforms) {
58
- const keys = Object.keys(rmsg.pend.transforms)
59
- if (keys.length > 0) tailId = keys[0]
60
- }
61
- if (tailId) {
62
- const kbytes = new TextEncoder().encode(tailId)
63
- const pn: any = this.peerNetwork as any
64
- if (typeof pn?.recordCoordinator === 'function') pn.recordCoordinator(kbytes, peerId)
65
- }
59
+ /**
60
+ * Record a coordinator-affinity hint for the block this record's op is
61
+ * coordinated on, so a follow-up op can dial `peerId` directly.
62
+ *
63
+ * The op lives at `record.message.operations[0]` — `record.message` is a
64
+ * RepoMessage `{ operations: [...] }`, NOT a bare `{ commit }`/`{ pend }`.
65
+ * Reading `record.message.commit`/`.pend` (the old code) always saw
66
+ * `undefined`, so this hint was dead code and never recorded anything.
67
+ *
68
+ * The key is `blockIdToBytes(<the coordinated block id>)` — the sha256 digest
69
+ * findCoordinator/recordCoordinator key the cache on — NOT raw utf8 of the id
70
+ * (which would never be retrieved). Commit anchors on blockIds[0] (where
71
+ * CoordinatorRepo runs consensus + verifyResponsibility), not tailId. Pend
72
+ * anchors on a real block id (blockIdsForTransforms), not a structural
73
+ * transforms field name. ClusterClient only ever carries commit/pend.
74
+ */
75
+ private async recordCoordinatorForRecordIfSupported(record: ClusterRecord, peerId: PeerId): Promise<void> {
76
+ const op = record.message.operations[0]
77
+ if (!op) return
78
+ let id: string | undefined
79
+ if ('commit' in op) id = op.commit.blockIds[0]
80
+ else if ('pend' in op) id = blockIdsForTransforms(op.pend.transforms)[0]
81
+ if (id == null) return
82
+ const kbytes = await blockIdToBytes(id)
83
+ const pn: any = this.peerNetwork as any
84
+ if (typeof pn?.recordCoordinator === 'function') pn.recordCoordinator(kbytes, peerId)
66
85
  }
67
86
  }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Structured error envelope for the cluster protocol.
3
+ *
4
+ * When a cluster member throws while processing an `update` (validation,
5
+ * signature, merge, or consensus failure), the service serializes the error as
6
+ * this envelope and closes the stream normally instead of aborting it. The
7
+ * coordinator's {@link ClusterClient} detects the envelope and rethrows a real
8
+ * `Error` carrying the server's message/name/code — so the genuine cause is
9
+ * visible on the coordinator side (which already enables `optimystic:*` debug)
10
+ * rather than collapsing into an opaque `StreamResetError`.
11
+ *
12
+ * The marker key `__clusterError` cannot collide with a successful response: a
13
+ * {@link ClusterRecord} never carries a top-level field by this name, and the
14
+ * redirect payload is keyed under `redirect`.
15
+ */
16
+
17
+ /** Top-level key that marks a response as a structured cluster error. */
18
+ export const CLUSTER_ERROR_KEY = '__clusterError';
19
+
20
+ /** Serializable error detail carried in a {@link ClusterErrorEnvelope}. */
21
+ export interface ClusterErrorDetail {
22
+ message: string;
23
+ name: string;
24
+ /** Stable error code (e.g. libp2p `ERR_*`) when the source error carries one. */
25
+ code?: string;
26
+ }
27
+
28
+ /** Wire shape of a structured cluster error response. */
29
+ export interface ClusterErrorEnvelope {
30
+ __clusterError: ClusterErrorDetail;
31
+ }
32
+
33
+ /** Build a {@link ClusterErrorEnvelope} from any thrown value. */
34
+ export function toClusterErrorEnvelope(err: unknown): ClusterErrorEnvelope {
35
+ const error = err instanceof Error ? err : new Error(String(err));
36
+ const rawCode = (error as { code?: unknown }).code;
37
+ const detail: ClusterErrorDetail = {
38
+ message: error.message,
39
+ name: error.name
40
+ };
41
+ if (typeof rawCode === 'string' && rawCode.length > 0) {
42
+ detail.code = rawCode;
43
+ }
44
+ return { __clusterError: detail };
45
+ }
46
+
47
+ /** Type guard: is `value` a structured cluster error envelope (not a record/redirect)? */
48
+ export function isClusterErrorEnvelope(value: unknown): value is ClusterErrorEnvelope {
49
+ if (typeof value !== 'object' || value === null) return false;
50
+ const detail = (value as { [CLUSTER_ERROR_KEY]?: unknown })[CLUSTER_ERROR_KEY];
51
+ return typeof detail === 'object' && detail !== null;
52
+ }
53
+
54
+ /**
55
+ * Reconstruct a real `Error` from a cluster error envelope, preserving `name`
56
+ * and `code` so the coordinator's reputation/penalty classification still works.
57
+ */
58
+ export function clusterErrorFromEnvelope(envelope: ClusterErrorEnvelope): Error {
59
+ const detail = envelope[CLUSTER_ERROR_KEY];
60
+ const error = new Error(detail.message || 'cluster update failed');
61
+ if (detail.name) error.name = detail.name;
62
+ if (detail.code) (error as { code?: string }).code = detail.code;
63
+ return error;
64
+ }