@xyo-network/xl1-cli 1.7.5 → 1.7.7

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 (301) hide show
  1. package/README.md +29 -6
  2. package/dist/cli-min.mjs +96 -96
  3. package/package.json +22 -18
  4. package/lib/node/commands/api/index.d.ts +0 -2
  5. package/lib/node/commands/api/index.d.ts.map +0 -1
  6. package/lib/node/commands/api/runApi.d.ts +0 -9
  7. package/lib/node/commands/api/runApi.d.ts.map +0 -1
  8. package/lib/node/commands/index.d.ts +0 -4
  9. package/lib/node/commands/index.d.ts.map +0 -1
  10. package/lib/node/commands/producer/createDeclaration.d.ts +0 -3
  11. package/lib/node/commands/producer/createDeclaration.d.ts.map +0 -1
  12. package/lib/node/commands/producer/index.d.ts +0 -3
  13. package/lib/node/commands/producer/index.d.ts.map +0 -1
  14. package/lib/node/commands/producer/runProducer.d.ts +0 -11
  15. package/lib/node/commands/producer/runProducer.d.ts.map +0 -1
  16. package/lib/node/commands/validator/index.d.ts +0 -2
  17. package/lib/node/commands/validator/index.d.ts.map +0 -1
  18. package/lib/node/commands/validator/runValidator.d.ts +0 -9
  19. package/lib/node/commands/validator/runValidator.d.ts.map +0 -1
  20. package/lib/node/images.d.ts +0 -2
  21. package/lib/node/images.d.ts.map +0 -1
  22. package/lib/node/index.d.ts +0 -4
  23. package/lib/node/index.d.ts.map +0 -1
  24. package/lib/node/index.mjs +0 -1610
  25. package/lib/node/index.mjs.map +0 -1
  26. package/lib/node/initConfig.d.ts +0 -3
  27. package/lib/node/initConfig.d.ts.map +0 -1
  28. package/lib/node/initEnv.d.ts +0 -2
  29. package/lib/node/initEnv.d.ts.map +0 -1
  30. package/lib/node/initLogger.d.ts +0 -4
  31. package/lib/node/initLogger.d.ts.map +0 -1
  32. package/lib/node/optionsFromZodSchema.d.ts +0 -4
  33. package/lib/node/optionsFromZodSchema.d.ts.map +0 -1
  34. package/lib/node/orchestration/ChainInitializableParams.d.ts +0 -9
  35. package/lib/node/orchestration/ChainInitializableParams.d.ts.map +0 -1
  36. package/lib/node/orchestration/actor/implementation/BalanceActor.d.ts +0 -17
  37. package/lib/node/orchestration/actor/implementation/BalanceActor.d.ts.map +0 -1
  38. package/lib/node/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts +0 -17
  39. package/lib/node/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts.map +0 -1
  40. package/lib/node/orchestration/actor/implementation/ProducerActor.d.ts +0 -26
  41. package/lib/node/orchestration/actor/implementation/ProducerActor.d.ts.map +0 -1
  42. package/lib/node/orchestration/actor/implementation/index.d.ts +0 -4
  43. package/lib/node/orchestration/actor/implementation/index.d.ts.map +0 -1
  44. package/lib/node/orchestration/actor/index.d.ts +0 -3
  45. package/lib/node/orchestration/actor/index.d.ts.map +0 -1
  46. package/lib/node/orchestration/actor/model/Actor.d.ts +0 -37
  47. package/lib/node/orchestration/actor/model/Actor.d.ts.map +0 -1
  48. package/lib/node/orchestration/actor/model/Orchestrator.d.ts +0 -27
  49. package/lib/node/orchestration/actor/model/Orchestrator.d.ts.map +0 -1
  50. package/lib/node/orchestration/actor/model/index.d.ts +0 -3
  51. package/lib/node/orchestration/actor/model/index.d.ts.map +0 -1
  52. package/lib/node/orchestration/archivists/ChainFinalized/archivist.d.ts +0 -4
  53. package/lib/node/orchestration/archivists/ChainFinalized/archivist.d.ts.map +0 -1
  54. package/lib/node/orchestration/archivists/ChainFinalized/index.d.ts +0 -2
  55. package/lib/node/orchestration/archivists/ChainFinalized/index.d.ts.map +0 -1
  56. package/lib/node/orchestration/archivists/ChainFinalized/local.d.ts +0 -4
  57. package/lib/node/orchestration/archivists/ChainFinalized/local.d.ts.map +0 -1
  58. package/lib/node/orchestration/archivists/ChainFinalized/remote.d.ts +0 -4
  59. package/lib/node/orchestration/archivists/ChainFinalized/remote.d.ts.map +0 -1
  60. package/lib/node/orchestration/archivists/ChainSubmissions/archivist.d.ts +0 -4
  61. package/lib/node/orchestration/archivists/ChainSubmissions/archivist.d.ts.map +0 -1
  62. package/lib/node/orchestration/archivists/ChainSubmissions/index.d.ts +0 -2
  63. package/lib/node/orchestration/archivists/ChainSubmissions/index.d.ts.map +0 -1
  64. package/lib/node/orchestration/archivists/ChainSubmissions/remote.d.ts +0 -4
  65. package/lib/node/orchestration/archivists/ChainSubmissions/remote.d.ts.map +0 -1
  66. package/lib/node/orchestration/archivists/PendingTransactions/archivist.d.ts +0 -4
  67. package/lib/node/orchestration/archivists/PendingTransactions/archivist.d.ts.map +0 -1
  68. package/lib/node/orchestration/archivists/PendingTransactions/index.d.ts +0 -2
  69. package/lib/node/orchestration/archivists/PendingTransactions/index.d.ts.map +0 -1
  70. package/lib/node/orchestration/archivists/PendingTransactions/local.d.ts +0 -4
  71. package/lib/node/orchestration/archivists/PendingTransactions/local.d.ts.map +0 -1
  72. package/lib/node/orchestration/archivists/PendingTransactions/remote.d.ts +0 -4
  73. package/lib/node/orchestration/archivists/PendingTransactions/remote.d.ts.map +0 -1
  74. package/lib/node/orchestration/archivists/RejectedTransactions/archivist.d.ts +0 -4
  75. package/lib/node/orchestration/archivists/RejectedTransactions/archivist.d.ts.map +0 -1
  76. package/lib/node/orchestration/archivists/RejectedTransactions/index.d.ts +0 -2
  77. package/lib/node/orchestration/archivists/RejectedTransactions/index.d.ts.map +0 -1
  78. package/lib/node/orchestration/archivists/RejectedTransactions/local.d.ts +0 -4
  79. package/lib/node/orchestration/archivists/RejectedTransactions/local.d.ts.map +0 -1
  80. package/lib/node/orchestration/archivists/StakeIntentState/archivist.d.ts +0 -5
  81. package/lib/node/orchestration/archivists/StakeIntentState/archivist.d.ts.map +0 -1
  82. package/lib/node/orchestration/archivists/StakeIntentState/index.d.ts +0 -2
  83. package/lib/node/orchestration/archivists/StakeIntentState/index.d.ts.map +0 -1
  84. package/lib/node/orchestration/archivists/StakeIntentState/local.d.ts +0 -4
  85. package/lib/node/orchestration/archivists/StakeIntentState/local.d.ts.map +0 -1
  86. package/lib/node/orchestration/archivists/index.d.ts +0 -6
  87. package/lib/node/orchestration/archivists/index.d.ts.map +0 -1
  88. package/lib/node/orchestration/archivists/lib/index.d.ts +0 -2
  89. package/lib/node/orchestration/archivists/lib/index.d.ts.map +0 -1
  90. package/lib/node/orchestration/archivists/lib/localPersistentArchivist.d.ts +0 -12
  91. package/lib/node/orchestration/archivists/lib/localPersistentArchivist.d.ts.map +0 -1
  92. package/lib/node/orchestration/health/index.d.ts +0 -2
  93. package/lib/node/orchestration/health/index.d.ts.map +0 -1
  94. package/lib/node/orchestration/health/initHealthEndpoints.d.ts +0 -7
  95. package/lib/node/orchestration/health/initHealthEndpoints.d.ts.map +0 -1
  96. package/lib/node/orchestration/host/implementation/DefaultHost.d.ts +0 -12
  97. package/lib/node/orchestration/host/implementation/DefaultHost.d.ts.map +0 -1
  98. package/lib/node/orchestration/host/implementation/DefaultServiceCollection.d.ts +0 -24
  99. package/lib/node/orchestration/host/implementation/DefaultServiceCollection.d.ts.map +0 -1
  100. package/lib/node/orchestration/host/implementation/DefaultServiceProvider.d.ts +0 -7
  101. package/lib/node/orchestration/host/implementation/DefaultServiceProvider.d.ts.map +0 -1
  102. package/lib/node/orchestration/host/implementation/index.d.ts +0 -3
  103. package/lib/node/orchestration/host/implementation/index.d.ts.map +0 -1
  104. package/lib/node/orchestration/host/index.d.ts +0 -3
  105. package/lib/node/orchestration/host/index.d.ts.map +0 -1
  106. package/lib/node/orchestration/host/model/Host.d.ts +0 -19
  107. package/lib/node/orchestration/host/model/Host.d.ts.map +0 -1
  108. package/lib/node/orchestration/host/model/ServiceCollection.d.ts +0 -20
  109. package/lib/node/orchestration/host/model/ServiceCollection.d.ts.map +0 -1
  110. package/lib/node/orchestration/host/model/ServiceProvider.d.ts +0 -4
  111. package/lib/node/orchestration/host/model/ServiceProvider.d.ts.map +0 -1
  112. package/lib/node/orchestration/host/model/index.d.ts +0 -4
  113. package/lib/node/orchestration/host/model/index.d.ts.map +0 -1
  114. package/lib/node/orchestration/index.d.ts +0 -6
  115. package/lib/node/orchestration/index.d.ts.map +0 -1
  116. package/lib/node/orchestration/initServices.d.ts +0 -10
  117. package/lib/node/orchestration/initServices.d.ts.map +0 -1
  118. package/lib/node/orchestration/map/BalanceSummary/index.d.ts +0 -2
  119. package/lib/node/orchestration/map/BalanceSummary/index.d.ts.map +0 -1
  120. package/lib/node/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts +0 -7
  121. package/lib/node/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts.map +0 -1
  122. package/lib/node/orchestration/map/BalanceSummary/local.d.ts +0 -7
  123. package/lib/node/orchestration/map/BalanceSummary/local.d.ts.map +0 -1
  124. package/lib/node/orchestration/map/driver/index.d.ts +0 -2
  125. package/lib/node/orchestration/map/driver/index.d.ts.map +0 -1
  126. package/lib/node/orchestration/map/driver/lmdb/Params.d.ts +0 -7
  127. package/lib/node/orchestration/map/driver/lmdb/Params.d.ts.map +0 -1
  128. package/lib/node/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts +0 -32
  129. package/lib/node/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts.map +0 -1
  130. package/lib/node/orchestration/map/driver/lmdb/index.d.ts +0 -2
  131. package/lib/node/orchestration/map/driver/lmdb/index.d.ts.map +0 -1
  132. package/lib/node/orchestration/map/driver/lmdb/spec/SynchronousLmdbMap.spec.d.ts +0 -2
  133. package/lib/node/orchestration/map/driver/lmdb/spec/SynchronousLmdbMap.spec.d.ts.map +0 -1
  134. package/lib/node/orchestration/map/index.d.ts +0 -3
  135. package/lib/node/orchestration/map/index.d.ts.map +0 -1
  136. package/lib/node/orchestration/map/localPersistentMap.d.ts +0 -12
  137. package/lib/node/orchestration/map/localPersistentMap.d.ts.map +0 -1
  138. package/lib/node/orchestration/repository/index.d.ts +0 -2
  139. package/lib/node/orchestration/repository/index.d.ts.map +0 -1
  140. package/lib/node/orchestration/repository/lib/index.d.ts +0 -2
  141. package/lib/node/orchestration/repository/lib/index.d.ts.map +0 -1
  142. package/lib/node/orchestration/repository/lib/repositoryFromArchivist.d.ts +0 -6
  143. package/lib/node/orchestration/repository/lib/repositoryFromArchivist.d.ts.map +0 -1
  144. package/lib/node/orchestration/services/implementation/account.d.ts +0 -4
  145. package/lib/node/orchestration/services/implementation/account.d.ts.map +0 -1
  146. package/lib/node/orchestration/services/implementation/balance.d.ts +0 -4
  147. package/lib/node/orchestration/services/implementation/balance.d.ts.map +0 -1
  148. package/lib/node/orchestration/services/implementation/chain/evm.d.ts +0 -6
  149. package/lib/node/orchestration/services/implementation/chain/evm.d.ts.map +0 -1
  150. package/lib/node/orchestration/services/implementation/chain/index.d.ts +0 -4
  151. package/lib/node/orchestration/services/implementation/chain/index.d.ts.map +0 -1
  152. package/lib/node/orchestration/services/implementation/evm/index.d.ts +0 -2
  153. package/lib/node/orchestration/services/implementation/evm/index.d.ts.map +0 -1
  154. package/lib/node/orchestration/services/implementation/evm/initChainId.d.ts +0 -3
  155. package/lib/node/orchestration/services/implementation/evm/initChainId.d.ts.map +0 -1
  156. package/lib/node/orchestration/services/implementation/evm/initEvmProvider.d.ts +0 -4
  157. package/lib/node/orchestration/services/implementation/evm/initEvmProvider.d.ts.map +0 -1
  158. package/lib/node/orchestration/services/implementation/evm/initGanacheProvider.d.ts +0 -5
  159. package/lib/node/orchestration/services/implementation/evm/initGanacheProvider.d.ts.map +0 -1
  160. package/lib/node/orchestration/services/implementation/evm/initInfuraProvider.d.ts +0 -5
  161. package/lib/node/orchestration/services/implementation/evm/initInfuraProvider.d.ts.map +0 -1
  162. package/lib/node/orchestration/services/implementation/head.d.ts +0 -10
  163. package/lib/node/orchestration/services/implementation/head.d.ts.map +0 -1
  164. package/lib/node/orchestration/services/implementation/index.d.ts +0 -11
  165. package/lib/node/orchestration/services/implementation/index.d.ts.map +0 -1
  166. package/lib/node/orchestration/services/implementation/iterator.d.ts +0 -6
  167. package/lib/node/orchestration/services/implementation/iterator.d.ts.map +0 -1
  168. package/lib/node/orchestration/services/implementation/pendingTransactions.d.ts +0 -4
  169. package/lib/node/orchestration/services/implementation/pendingTransactions.d.ts.map +0 -1
  170. package/lib/node/orchestration/services/implementation/producer.d.ts +0 -4
  171. package/lib/node/orchestration/services/implementation/producer.d.ts.map +0 -1
  172. package/lib/node/orchestration/services/implementation/reward.d.ts +0 -4
  173. package/lib/node/orchestration/services/implementation/reward.d.ts.map +0 -1
  174. package/lib/node/orchestration/services/implementation/validator.d.ts +0 -4
  175. package/lib/node/orchestration/services/implementation/validator.d.ts.map +0 -1
  176. package/lib/node/orchestration/services/index.d.ts +0 -2
  177. package/lib/node/orchestration/services/index.d.ts.map +0 -1
  178. package/lib/node/orchestration/status/RuntimeStatusMonitor.d.ts +0 -31
  179. package/lib/node/orchestration/status/RuntimeStatusMonitor.d.ts.map +0 -1
  180. package/lib/node/orchestration/status/ServiceStatus.d.ts +0 -9
  181. package/lib/node/orchestration/status/ServiceStatus.d.ts.map +0 -1
  182. package/lib/node/orchestration/status/index.d.ts +0 -3
  183. package/lib/node/orchestration/status/index.d.ts.map +0 -1
  184. package/lib/node/orchestration/store/StoreKind.d.ts +0 -2
  185. package/lib/node/orchestration/store/StoreKind.d.ts.map +0 -1
  186. package/lib/node/orchestration/store/getStoreDirectory.d.ts +0 -9
  187. package/lib/node/orchestration/store/getStoreDirectory.d.ts.map +0 -1
  188. package/lib/node/orchestration/store/index.d.ts +0 -3
  189. package/lib/node/orchestration/store/index.d.ts.map +0 -1
  190. package/lib/node/runCLI.d.ts +0 -2
  191. package/lib/node/runCLI.d.ts.map +0 -1
  192. package/lib/node/spec/BootstrapChain.spec.d.ts +0 -2
  193. package/lib/node/spec/BootstrapChain.spec.d.ts.map +0 -1
  194. package/lib/node/start.d.ts +0 -2
  195. package/lib/node/start.d.ts.map +0 -1
  196. package/lib/node/waitForHostPort.d.ts +0 -2
  197. package/lib/node/waitForHostPort.d.ts.map +0 -1
  198. package/lib/node/xl1.d.ts +0 -2
  199. package/lib/node/xl1.d.ts.map +0 -1
  200. package/lib/node/xl1.mjs +0 -1582
  201. package/lib/node/xl1.mjs.map +0 -1
  202. package/nodemon.json +0 -9
  203. package/rollup.config.mjs +0 -79
  204. package/src/commands/api/index.ts +0 -1
  205. package/src/commands/api/runApi.ts +0 -12
  206. package/src/commands/index.ts +0 -3
  207. package/src/commands/producer/createDeclaration.ts +0 -18
  208. package/src/commands/producer/index.ts +0 -2
  209. package/src/commands/producer/runProducer.ts +0 -35
  210. package/src/commands/validator/index.ts +0 -1
  211. package/src/commands/validator/runValidator.ts +0 -22
  212. package/src/images.ts +0 -19
  213. package/src/index.ts +0 -3
  214. package/src/initConfig.ts +0 -6
  215. package/src/initEnv.ts +0 -8
  216. package/src/initLogger.ts +0 -16
  217. package/src/optionsFromZodSchema.ts +0 -69
  218. package/src/orchestration/ChainInitializableParams.ts +0 -10
  219. package/src/orchestration/actor/implementation/BalanceActor.ts +0 -51
  220. package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +0 -65
  221. package/src/orchestration/actor/implementation/ProducerActor.ts +0 -250
  222. package/src/orchestration/actor/implementation/index.ts +0 -3
  223. package/src/orchestration/actor/index.ts +0 -2
  224. package/src/orchestration/actor/model/Actor.ts +0 -112
  225. package/src/orchestration/actor/model/Orchestrator.ts +0 -71
  226. package/src/orchestration/actor/model/index.ts +0 -2
  227. package/src/orchestration/archivists/ChainFinalized/archivist.ts +0 -27
  228. package/src/orchestration/archivists/ChainFinalized/index.ts +0 -1
  229. package/src/orchestration/archivists/ChainFinalized/local.ts +0 -16
  230. package/src/orchestration/archivists/ChainFinalized/remote.ts +0 -18
  231. package/src/orchestration/archivists/ChainSubmissions/archivist.ts +0 -19
  232. package/src/orchestration/archivists/ChainSubmissions/index.ts +0 -1
  233. package/src/orchestration/archivists/ChainSubmissions/remote.ts +0 -18
  234. package/src/orchestration/archivists/PendingTransactions/archivist.ts +0 -29
  235. package/src/orchestration/archivists/PendingTransactions/index.ts +0 -1
  236. package/src/orchestration/archivists/PendingTransactions/local.ts +0 -20
  237. package/src/orchestration/archivists/PendingTransactions/remote.ts +0 -18
  238. package/src/orchestration/archivists/RejectedTransactions/archivist.ts +0 -18
  239. package/src/orchestration/archivists/RejectedTransactions/index.ts +0 -1
  240. package/src/orchestration/archivists/RejectedTransactions/local.ts +0 -20
  241. package/src/orchestration/archivists/StakeIntentState/archivist.ts +0 -21
  242. package/src/orchestration/archivists/StakeIntentState/index.ts +0 -1
  243. package/src/orchestration/archivists/StakeIntentState/local.ts +0 -17
  244. package/src/orchestration/archivists/index.ts +0 -5
  245. package/src/orchestration/archivists/lib/index.ts +0 -1
  246. package/src/orchestration/archivists/lib/localPersistentArchivist.ts +0 -44
  247. package/src/orchestration/health/index.ts +0 -1
  248. package/src/orchestration/health/initHealthEndpoints.ts +0 -70
  249. package/src/orchestration/host/implementation/DefaultHost.ts +0 -25
  250. package/src/orchestration/host/implementation/DefaultServiceCollection.ts +0 -60
  251. package/src/orchestration/host/implementation/DefaultServiceProvider.ts +0 -12
  252. package/src/orchestration/host/implementation/index.ts +0 -2
  253. package/src/orchestration/host/index.ts +0 -2
  254. package/src/orchestration/host/model/Host.ts +0 -21
  255. package/src/orchestration/host/model/ServiceCollection.ts +0 -22
  256. package/src/orchestration/host/model/ServiceProvider.ts +0 -3
  257. package/src/orchestration/host/model/index.ts +0 -3
  258. package/src/orchestration/index.ts +0 -5
  259. package/src/orchestration/initServices.ts +0 -241
  260. package/src/orchestration/map/BalanceSummary/index.ts +0 -1
  261. package/src/orchestration/map/BalanceSummary/initBalanceSummaryMap.ts +0 -22
  262. package/src/orchestration/map/BalanceSummary/local.ts +0 -20
  263. package/src/orchestration/map/driver/index.ts +0 -1
  264. package/src/orchestration/map/driver/lmdb/Params.ts +0 -7
  265. package/src/orchestration/map/driver/lmdb/SynchronousLmdbMap.ts +0 -67
  266. package/src/orchestration/map/driver/lmdb/index.ts +0 -1
  267. package/src/orchestration/map/index.ts +0 -2
  268. package/src/orchestration/map/localPersistentMap.ts +0 -39
  269. package/src/orchestration/repository/index.ts +0 -1
  270. package/src/orchestration/repository/lib/index.ts +0 -1
  271. package/src/orchestration/repository/lib/repositoryFromArchivist.ts +0 -27
  272. package/src/orchestration/services/implementation/account.ts +0 -23
  273. package/src/orchestration/services/implementation/balance.ts +0 -13
  274. package/src/orchestration/services/implementation/chain/evm.ts +0 -35
  275. package/src/orchestration/services/implementation/chain/index.ts +0 -27
  276. package/src/orchestration/services/implementation/evm/index.ts +0 -1
  277. package/src/orchestration/services/implementation/evm/initChainId.ts +0 -18
  278. package/src/orchestration/services/implementation/evm/initEvmProvider.ts +0 -21
  279. package/src/orchestration/services/implementation/evm/initGanacheProvider.ts +0 -19
  280. package/src/orchestration/services/implementation/evm/initInfuraProvider.ts +0 -25
  281. package/src/orchestration/services/implementation/head.ts +0 -44
  282. package/src/orchestration/services/implementation/index.ts +0 -10
  283. package/src/orchestration/services/implementation/iterator.ts +0 -36
  284. package/src/orchestration/services/implementation/pendingTransactions.ts +0 -14
  285. package/src/orchestration/services/implementation/producer.ts +0 -13
  286. package/src/orchestration/services/implementation/reward.ts +0 -37
  287. package/src/orchestration/services/implementation/validator.ts +0 -14
  288. package/src/orchestration/services/index.ts +0 -1
  289. package/src/orchestration/status/RuntimeStatusMonitor.ts +0 -117
  290. package/src/orchestration/status/ServiceStatus.ts +0 -21
  291. package/src/orchestration/status/index.ts +0 -2
  292. package/src/orchestration/store/StoreKind.ts +0 -1
  293. package/src/orchestration/store/getStoreDirectory.ts +0 -15
  294. package/src/orchestration/store/index.ts +0 -2
  295. package/src/runCLI.ts +0 -111
  296. package/src/spec/MultiProducer.ChainOutput.json +0 -864
  297. package/src/start.ts +0 -7
  298. package/src/waitForHostPort.ts +0 -26
  299. package/src/xl1.ts +0 -7
  300. package/vitest.config.ts +0 -11
  301. package/xy.config.ts +0 -23
package/src/initLogger.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Base } from '@xylabs/base'
2
- import type { Logger, LogLevelValue } from '@xylabs/logger'
3
- import { ConsoleLogger, LogLevel } from '@xylabs/logger'
4
- import { isDefined } from '@xylabs/typeof'
5
- import type { Config } from '@xyo-network/chain-protocol'
6
-
7
- export const initLogger = (config: Config): Logger => {
8
- let level: LogLevelValue | undefined
9
- if (isDefined(config?.log?.level)) {
10
- const parsed = LogLevel[config.log.level.toLowerCase() as keyof typeof LogLevel]
11
- if (isDefined(parsed)) level = parsed
12
- }
13
- const logger = new ConsoleLogger(level)
14
- Base.defaultLogger = logger
15
- return logger
16
- }
@@ -1,69 +0,0 @@
1
- import type { Options } from 'yargs'
2
- import type { ZodTypeAny } from 'zod'
3
- import {
4
- ZodBoolean, ZodDefault, ZodEnum, ZodNumber, ZodObject, ZodOptional,
5
- } from 'zod'
6
-
7
- const collectOptions = (
8
- zodType: ZodTypeAny,
9
- path: string[] = [],
10
- out: Record<string, Options> = {},
11
- ): Record<string, Options> => {
12
- // Handle objects by descending into their shape
13
- if (zodType instanceof ZodObject) {
14
- const shape = (zodType as ZodObject<{}>).shape
15
- for (const [k, v] of Object.entries(shape)) {
16
- collectOptions(v as ZodTypeAny, [...path, k], out)
17
- }
18
- return out
19
- }
20
-
21
- // Handle defaults and optionals by descending into the inner type
22
- // TODO: Less brittle
23
- const def = zodType._def
24
- if (def?.innerType instanceof ZodObject) {
25
- const shape = def.innerType.shape
26
- for (const [k, v] of Object.entries(shape)) {
27
- collectOptions(v as ZodTypeAny, [...path, k], out)
28
- }
29
- return out
30
- }
31
-
32
- // Construct the Yargs Options
33
- const options: Options = {}
34
-
35
- // Assign the description
36
- options.describe = def.description
37
-
38
- // Assign the default value
39
- options.default = typeof def.defaultValue === 'function'
40
- ? def.defaultValue()
41
- : def.defaultValue
42
-
43
- // Assign the type
44
- let type: 'string' | 'number' | 'boolean' = 'string'
45
- const typeName = def.typeName === ZodDefault.name || def.typeName === ZodOptional.name
46
- ? def.innerType._def.typeName
47
- : def.typeName
48
- if (typeName === ZodBoolean.name) type = 'boolean'
49
- if (typeName === ZodNumber.name || def.coerce) type = 'number'
50
- if (typeName === ZodEnum.name) {
51
- options.choices = Object.values(def.innerType.enum)
52
- }
53
- options.type = type
54
-
55
- // Build argument path e.g. "db.host" or "producer.port"
56
- const key = path.join('.')
57
- out[key] = options
58
- return out
59
- }
60
-
61
- export const optionsFromZodSchema = (
62
- schema: Record<string, ZodTypeAny>,
63
- ): Record<string, Options> => {
64
- const opts: Record<string, Options> = {}
65
- for (const [rootKey, zodType] of Object.entries(schema)) {
66
- collectOptions(zodType, [rootKey], opts)
67
- }
68
- return opts
69
- }
@@ -1,10 +0,0 @@
1
- import type { MeterProvider, TracerProvider } from '@opentelemetry/api'
2
- import type { InitializableParams } from '@xyo-network/xl1-protocol'
3
-
4
- import type { RuntimeStatusMonitor } from './status/index.ts'
5
-
6
- export type ChainInitializableParams = InitializableParams<{
7
- meterProvider: MeterProvider
8
- statusReporter: RuntimeStatusMonitor
9
- traceProvider: TracerProvider
10
- }>
@@ -1,51 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import type { BaseParams } from '@xylabs/base'
3
- import type { Promisable } from '@xylabs/promise'
4
- import { PayloadBuilder } from '@xyo-network/payload-builder'
5
- import type { OpenTelemetryProviders } from '@xyo-network/xl1-protocol'
6
- import type { ChainServiceCollectionV2 } from '@xyo-network/xl1-protocol-sdk'
7
- import { Mutex } from 'async-mutex'
8
-
9
- import { Actor } from '../model/index.ts'
10
-
11
- export type BalanceActorParams = BaseParams<
12
- Pick<ChainServiceCollectionV2, 'balanceService' | 'chainIterator'>
13
- & OpenTelemetryProviders>
14
-
15
- export class BalanceActor extends Actor<BalanceActorParams> {
16
- protected _updateMutex = new Mutex()
17
-
18
- protected constructor(params: BalanceActorParams) {
19
- super('BalanceActor', 'Balance', params)
20
- }
21
-
22
- protected get balanceService() {
23
- return assertEx(this.params.balanceService, () => 'balanceService not set')
24
- }
25
-
26
- protected get chainIterator() {
27
- return assertEx(this.params.chainIterator, () => 'chainIterator not set')
28
- }
29
-
30
- static create(params: BalanceActorParams): Promisable<BalanceActor> {
31
- return new BalanceActor(params)
32
- }
33
-
34
- override async start(): Promise<void> {
35
- await super.start()
36
- this.chainIterator.on('headUpdate', async () => {
37
- await this.updateBalance()
38
- })
39
- this.registerTimer('BalanceTimer', async () => {
40
- await this.updateBalance()
41
- }, 1000, 1000)
42
- }
43
-
44
- protected async updateBalance(): Promise<void> {
45
- if (this._updateMutex.isLocked()) return
46
- await this._updateMutex.runExclusive(async () => {
47
- const head = await PayloadBuilder.hash(await this.chainIterator.head())
48
- await this.balanceService.balances(head, [])
49
- })
50
- }
51
- }
@@ -1,65 +0,0 @@
1
- import { filterAs } from '@xylabs/array'
2
- import { assertEx } from '@xylabs/assert'
3
- import type { BaseParams } from '@xylabs/base'
4
- import { toHex } from '@xylabs/hex'
5
- import type { Promisable } from '@xylabs/promise'
6
- import { findMostRecentBlock, sortBlocks } from '@xyo-network/chain-protocol'
7
- import type { Payload } from '@xyo-network/payload-model'
8
- import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
9
- import { asBlockBoundWitness } from '@xyo-network/xl1-protocol'
10
- import type { ChainServiceCollection } from '@xyo-network/xl1-protocol-sdk'
11
-
12
- import { Actor } from '../model/index.ts'
13
-
14
- export type ChainHeadUpdateActorParams = BaseParams<Pick<ChainServiceCollection, 'chainIterator' | 'chainArchivist'>>
15
-
16
- export class ChainHeadUpdateActor extends Actor<ChainHeadUpdateActorParams> {
17
- protected constructor(params: ChainHeadUpdateActorParams) {
18
- super('ChainHeadUpdate', 'ChainHeadUpdate', params)
19
- }
20
-
21
- protected get chainFinalizedArchivist() {
22
- return assertEx(this.params.chainArchivist, () => 'ChainArchivist not set')
23
- }
24
-
25
- protected get chainIterator() {
26
- return assertEx(this.params.chainIterator, () => 'chainIterator not set')
27
- }
28
-
29
- static create(params: ChainHeadUpdateActorParams): Promisable<ChainHeadUpdateActor> {
30
- return new ChainHeadUpdateActor(params)
31
- }
32
-
33
- override async start(): Promise<void> {
34
- await super.start()
35
- // Register event handler on all insert event to check for new head
36
- this.chainFinalizedArchivist.on('inserted', async (data: { payloads: Payload[] }) => {
37
- await this.checkInsertedForNewHead(data)
38
- })
39
- // Poll in case we missed an event
40
- this.registerTimer('ChainHeadUpdateTimer', async () => await this.pollForNewHead(), 0, 250)
41
- }
42
-
43
- private async checkInsertedForNewHead(data: { payloads: Payload[] }) {
44
- const candidateBlock = sortBlocks(filterAs(data.payloads, asBlockBoundWitness)).at(-1)
45
- await this.updateHeadIfNewer(candidateBlock)
46
- }
47
-
48
- private async pollForNewHead() {
49
- const candidateBlock = await findMostRecentBlock(this.chainFinalizedArchivist)
50
- await this.updateHeadIfNewer(candidateBlock)
51
- }
52
-
53
- private async updateHeadIfNewer(candidateBlock?: BlockBoundWitness) {
54
- if (!candidateBlock) return
55
- const currentHead = await this.chainIterator.head()
56
- const candidateBlockNumber = candidateBlock.block
57
- const candidateBlockNumberDisplay = `0x${toHex(candidateBlockNumber)}`
58
- const currentBlockNumber = currentHead?.block ?? -1
59
- if (candidateBlockNumber > currentBlockNumber) {
60
- this.logger?.log('Found more recent head:', candidateBlockNumberDisplay)
61
- await this.chainIterator.updateHead(candidateBlock)
62
- this.logger?.log('Updated head:', candidateBlockNumberDisplay)
63
- }
64
- }
65
- }
@@ -1,250 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import type { BaseParams } from '@xylabs/base'
3
- import { toHex } from '@xylabs/hex'
4
- import type { Promisable } from '@xylabs/promise'
5
- import { isDefined, isUndefined } from '@xylabs/typeof'
6
- import { createDeclarationIntent } from '@xyo-network/chain-protocol'
7
- import { BaseBlockProducerService } from '@xyo-network/chain-services'
8
- import { PayloadBuilder } from '@xyo-network/payload-builder'
9
- import type { PayloadBundle } from '@xyo-network/payload-model'
10
- import { PayloadBundleSchema } from '@xyo-network/payload-model'
11
- import type {
12
- ChainStakeIntent,
13
- HydratedBlock, OpenTelemetryProviders,
14
- } from '@xyo-network/xl1-protocol'
15
- import type { ChainServiceCollectionV2 } from '@xyo-network/xl1-protocol-sdk'
16
- import {
17
- buildTransaction, flattenHydratedBlock, flattenHydratedTransaction,
18
- } from '@xyo-network/xl1-protocol-sdk'
19
-
20
- import { Actor } from '../model/index.ts'
21
-
22
- export type ProducerActorParams = BaseParams<
23
- Pick<ChainServiceCollectionV2,
24
- 'account'
25
- | 'balanceService'
26
- | 'chainIterator'
27
- | 'chainStakeViewer'
28
- | 'chainSubmissionsArchivistWrite'
29
- | 'pendingBundledTransactionsArchivistWrite'
30
- | 'producer'
31
- | 'stakeIntentService'
32
- >
33
- & OpenTelemetryProviders>
34
-
35
- const SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true
36
- const TEN_MINUTES = 10 * 60 * 1000 // 10 minutes in milliseconds
37
-
38
- export class ProducerActor extends Actor<ProducerActorParams> {
39
- protected _lastProducedBlock: HydratedBlock | undefined
40
- protected _lastRedeclarationIntent: ChainStakeIntent | undefined
41
-
42
- protected constructor(params: ProducerActorParams) {
43
- super(params.producer.address, 'Producer', params)
44
- }
45
-
46
- protected get account() {
47
- return assertEx(this.params.account, () => 'account not set')
48
- }
49
-
50
- protected get balanceService() {
51
- return assertEx(this.params.balanceService, () => 'balanceService not set')
52
- }
53
-
54
- protected get chainIterator() {
55
- return assertEx(this.params.chainIterator, () => 'chainIterator not set')
56
- }
57
-
58
- protected get chainStakeViewer() {
59
- return assertEx(this.params.chainStakeViewer, () => 'chainStakeViewer not set')
60
- }
61
-
62
- protected get chainSubmissionsArchivistWrite() {
63
- return assertEx(this.params.chainSubmissionsArchivistWrite, () => 'chainSubmissionsArchivistWrite not set')
64
- }
65
-
66
- protected get pendingBundledTransactionsArchivistWrite() {
67
- return assertEx(this.params.pendingBundledTransactionsArchivistWrite, () => 'pendingBundledTransactionsArchivistWrite not set')
68
- }
69
-
70
- protected get producer() {
71
- return assertEx(this.params.producer, () => 'producer not set')
72
- }
73
-
74
- protected get stakeIntentService() {
75
- return assertEx(this.params.stakeIntentService, () => 'stakeIntentService not set')
76
- }
77
-
78
- static create(params: ProducerActorParams): Promisable<ProducerActor> {
79
- return new ProducerActor(params)
80
- }
81
-
82
- override async start(): Promise<void> {
83
- await super.start()
84
- // Register a timer to check if we should produce a block
85
- this.registerTimer('BlockProductionTimer', async () => {
86
- await this.spanAsync('produceBlock', async () => {
87
- // Get the updated head
88
- const head = await this.chainIterator.head()
89
- // Check if we've already produced the next block for this head
90
- const headHash = await PayloadBuilder.hash(head)
91
- // If our last produced block was the next block for the current head, we do not
92
- // need to produce another. This prevents duplicate blocks from being produced
93
- if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {
94
- this.logger?.log('Block already produced:', `0x${toHex(this._lastProducedBlock[0].block)}`)
95
- } else {
96
- // Produce the next block
97
- const nextBlock = await this.producer.next(head)
98
- // If it was produced
99
- if (nextBlock) {
100
- const displayBlockNumber = `0x${toHex(nextBlock[0].block)}`
101
- this.logger?.log('Produced block:', displayBlockNumber)
102
- // Insert the block into the chain
103
- await this.chainSubmissionsArchivistWrite.insert(flattenHydratedBlock(nextBlock))
104
- this.logger?.log('Published block:', displayBlockNumber)
105
- // Record that we have produced a block so we do not produce it again
106
- this._lastProducedBlock = nextBlock
107
- }
108
- }
109
- })
110
- }, 100, 500)
111
-
112
- if (SHOULD_REGISTER_REDECLARATION_INTENT_TIMER) {
113
- // Register a timer to check if we should redeclare the producer
114
- this.registerTimer('ProducerRedeclarationTimer', async () => {
115
- await this.spanAsync('producerRedeclarationTimer', async () => {
116
- // Decide if we should redeclare intent
117
- if (!BaseBlockProducerService.RedeclareIntent) return
118
-
119
- // Get the current block
120
- const head = await this.chainIterator.head()
121
- if (isUndefined(head)) return
122
- const currentBlock = head.block
123
-
124
- // Calculate the time until the producer's declaration expires
125
- const blocksUntilExpiration = await this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock)
126
-
127
- // Allow the producer time to redeclare itself via block production
128
- // (for free) before submitting a redeclaration intent transaction.
129
- if (blocksUntilExpiration > BaseBlockProducerService.RedeclarationWindow * 0.1) {
130
- // Clear any previous redeclaration intent
131
- this._lastRedeclarationIntent = undefined
132
- // No need to redeclare yet
133
- return
134
- }
135
-
136
- // If we already have a valid redeclaration intent, do not create another
137
- // unless it has expired.
138
- if (this._lastRedeclarationIntent) {
139
- // Check if the last redeclaration intent is still valid
140
- if (this._lastRedeclarationIntent.exp > currentBlock) return
141
- // If it has expired, clear the last redeclaration intent
142
- this._lastRedeclarationIntent = undefined
143
- }
144
-
145
- // Check if we have a valid balance before declaring intent
146
- if (!await this.validateCurrentBalance()) {
147
- this.logger?.error(
148
- `Add balance to address ${this.account.address} for the producer to declare it's intent.`,
149
- )
150
- return
151
- }
152
-
153
- // Check if we have a valid stake before declaring intent
154
- if (!(await this.validateCurrentStake())) {
155
- this.logger?.error(
156
- `Add stake to contract address ${process.env.XYO_EVM_STAKING_CONTRACT_ADDRESS}`
157
- + ' for the producer to declare it\'s intent.',
158
- )
159
- return
160
- }
161
-
162
- // Create a redeclaration intent
163
- this.logger?.log('Creating redeclaration intent for producer:', this.account.address)
164
- const redeclarationIntent = createDeclarationIntent(
165
- this.account.address,
166
- 'producer',
167
- currentBlock,
168
- currentBlock + BaseBlockProducerService.RedeclarationDuration,
169
- )
170
-
171
- // Submit the redeclaration intent
172
- await this.submitRedeclarationIntent(currentBlock, redeclarationIntent)
173
-
174
- // On successful submission, save the redeclaration intent
175
- this._lastRedeclarationIntent = redeclarationIntent
176
- })
177
- }, 10_000, TEN_MINUTES)
178
- }
179
- }
180
-
181
- protected async calculateBlocksUntilProducerDeclarationExpiration(currentBlock: number): Promise<number> {
182
- // Decide if we need to redeclare intent
183
- const ranges = await this.stakeIntentService.getDeclaredCandidateRanges(this.account.address, 'producer')
184
- // TODO: This doesn't handle the case where the producer had declared a range for the future
185
- // but we're in a range that's not the future
186
- // Sort in ascending order based on ending range to get range with highest ending block
187
- const lastRange = ranges.toSorted((a, b) => a[1] > b[1] ? 1 : -1).at(-1)
188
-
189
- // Use the most recent range's end block as the current declaration end OR
190
- const [, currentDeclarationEnd] = lastRange
191
- // If we have no ranges, we need to declare intent, so use the current block
192
- || [undefined, currentBlock]
193
-
194
- // Calculate the time until the producer's declaration expires
195
- const timeToProducerExpiration = currentDeclarationEnd - currentBlock
196
- return timeToProducerExpiration
197
- }
198
-
199
- protected async submitRedeclarationIntent(currentBlock: number, redeclarationIntent: ChainStakeIntent): Promise<void> {
200
- this.logger?.log('Submitting redeclaration intent for producer:', this.account.address)
201
- // Create a transaction to submit the redeclaration intent
202
- const tx = await buildTransaction(
203
- this.chainIterator.chainId,
204
- [redeclarationIntent],
205
- [],
206
- this.account,
207
- currentBlock,
208
- currentBlock + 1000,
209
- )
210
- const payloads = flattenHydratedTransaction(tx)
211
- const root = tx[0]._hash
212
- const payloadBundle = new PayloadBuilder<PayloadBundle>({ schema: PayloadBundleSchema }).fields({ payloads, root }).build()
213
-
214
- // Submit the redeclaration intent
215
- await this.pendingBundledTransactionsArchivistWrite.insert([payloadBundle])
216
-
217
- this.logger?.log('Submitted redeclaration intent for producer:', this.account.address)
218
- }
219
-
220
- protected async validateCurrentBalance(): Promise<boolean> {
221
- // Check if we have a valid balance before declaring intent
222
- const head = this._lastProducedBlock?.[0]._hash
223
- if (isDefined(head)) {
224
- const balances = await this.balanceService.balances(head, [this.account.address])
225
- const currentBalance = balances[this.account.address] ?? 0n
226
- if (currentBalance <= 0n) {
227
- this.logger?.error(`Producer ${this.account.address} has no balance.`)
228
- return false
229
- }
230
- return true
231
- }
232
- return true
233
- }
234
-
235
- protected async validateCurrentStake(): Promise<boolean> {
236
- // TODO: Use StakeIntentService to get the required minimum stake for
237
- // the intent once services is published
238
- // const requiredMinimumStake = this.stakeIntentService.getRequiredMinimumStakeForIntent('producer')
239
- const requiredMinimumStake = isDefined(process.env.XYO_PRODUCER_MIN_STAKE)
240
- ? BigInt(process.env.XYO_PRODUCER_MIN_STAKE)
241
- : 1n
242
- // Check if we have a valid stake before declaring intent
243
- const currentStake = await this.chainStakeViewer.activeByAddressStaked(this.account.address)
244
- if (currentStake < requiredMinimumStake) {
245
- this.logger?.error(`Producer ${this.account.address} has insufficient stake.`)
246
- return false
247
- }
248
- return true
249
- }
250
- }
@@ -1,3 +0,0 @@
1
- export * from './BalanceActor.ts'
2
- export * from './ChainHeadUpdateActor.ts'
3
- export * from './ProducerActor.ts'
@@ -1,2 +0,0 @@
1
- export * from './implementation/index.ts'
2
- export * from './model/index.ts'
@@ -1,112 +0,0 @@
1
- import type { TracerProvider } from '@opentelemetry/api'
2
- import { Base, type BaseParams } from '@xylabs/base'
3
- import { forget } from '@xylabs/forget'
4
- import { IdLogger } from '@xylabs/logger'
5
- import type { Promisable } from '@xylabs/promise'
6
- import { span, spanAsync } from '@xylabs/telemetry'
7
-
8
- export interface IActor {
9
- start(): Promise<void>
10
- stop(): Promise<void>
11
- }
12
-
13
- export type ActorParams = BaseParams<{
14
- traceProvider?: TracerProvider
15
- }>
16
-
17
- export class Actor<TParams extends ActorParams = ActorParams> extends Base<TParams> implements IActor {
18
- protected readonly _timers: Map<string, ReturnType<typeof setTimeout>> = new Map()
19
- private _active = false
20
- private readonly _displayName: string
21
- private readonly _id: string
22
-
23
- constructor(id: string, displayName: string = 'Actor', params: TParams) {
24
- const logger = params.logger ?? new IdLogger(Base.defaultLogger ?? console, () => `[${displayName} (${id})] `)
25
- super({ ...params, logger })
26
- this._displayName = displayName
27
- this._id = id
28
- }
29
-
30
- get displayName() {
31
- return this._displayName
32
- }
33
-
34
- get id() {
35
- return this._id
36
- }
37
-
38
- get name() {
39
- return this.constructor.name
40
- }
41
-
42
- protected get logPrefix() {
43
- return `[${this.displayName} (${this.id})] `
44
- }
45
-
46
- /**
47
- * The timer runs until the actor is deactivated (or you manually stop it).
48
- */
49
- registerTimer(timerName: string, callback: () => Promisable<void>, dueTimeMs: number, periodMs: number) {
50
- if (!this._active) {
51
- this.logger?.warn(
52
- `Cannot register timer '${timerName}' because actor is not active.`,
53
- )
54
- return
55
- }
56
-
57
- // Function to handle recursive scheduling
58
- const schedulePeriodicRun = async () => {
59
- // Stop if actor is deactivated or timer is removed
60
- if (!this._active || !this._timers.has(timerName)) return
61
- try {
62
- // Run the callback
63
- await callback()
64
- } catch (error) {
65
- // Catch and log any errors
66
- this.logger?.error(`Error in timer '${this.name}:${timerName}': ${error}`)
67
- } finally {
68
- // Always schedule subsequent executions based on the desired period
69
- this._timers.set(timerName, setTimeout(() => forget(schedulePeriodicRun(), { name: `schedulePeriodicRun:${this.name}:${timerName}` }), periodMs))
70
- }
71
- }
72
-
73
- // Schedule the 1st execution after the desired initial delay
74
- this._timers.set(timerName, setTimeout(() => forget(schedulePeriodicRun(), { name: `schedulePeriodicRun(initial):${this.name}:${timerName}` }), dueTimeMs))
75
-
76
- this.logger?.log(
77
- `Timer '${this.name}:${timerName}' registered: first call after ${dueTimeMs}ms, recurring every ${periodMs}ms.`,
78
- )
79
- }
80
-
81
- span<T>(name: string, fn: () => T): T {
82
- return span(`${this.name}:${name}`, fn, this.tracer)
83
- }
84
-
85
- async spanAsync<T>(name: string, fn: () => Promise<T>): Promise<T> {
86
- return await spanAsync(`${this.name}:${name}`, fn, this.tracer)
87
- }
88
-
89
- /**
90
- * Called by the Orchestrator when the actor is activated.
91
- */
92
- async start() {
93
- await Promise.resolve()
94
- this._active = true
95
- this.logger?.log('Started.')
96
- }
97
-
98
- /**
99
- * Called by the Orchestrator when the actor is deactivated.
100
- * Stop all running timers.
101
- */
102
- async stop() {
103
- await Promise.resolve()
104
- this._active = false
105
- this.logger?.log('Stopping all timers...')
106
- for (const [, timerRef] of this._timers.entries()) {
107
- clearTimeout(timerRef)
108
- }
109
- this._timers.clear()
110
- this.logger?.log('Stopped.')
111
- }
112
- }
@@ -1,71 +0,0 @@
1
- import type { Logger } from '@xylabs/logger'
2
-
3
- import type { IActor } from './Actor.ts'
4
-
5
- export interface IOrchestrator {
6
- start(): Promise<void>
7
- stop(): Promise<void>
8
- }
9
-
10
- export class Orchestrator implements IOrchestrator {
11
- protected actors: IActor[] = []
12
- protected keepAliveHandle: NodeJS.Timeout | null = null
13
- protected readonly logger?: Logger
14
- protected running = false
15
-
16
- constructor(logger?: Logger) {
17
- this.logger = logger
18
- }
19
-
20
- /**
21
- * Registers an actor.
22
- * (We won't activate the actor until `start()` is called.)
23
- */
24
- async registerActor(actor: IActor) {
25
- if (this.running) {
26
- // If the orchestrator is already running, activate the actor immediately
27
- await actor.start()
28
- }
29
- this.actors.push(actor)
30
- }
31
-
32
- /**
33
- * Starts the orchestrator: activates all actors.
34
- */
35
- async start() {
36
- await Promise.resolve()
37
- if (this.running) {
38
- this.logger?.warn('[Orchestrator] Already started.')
39
- return
40
- }
41
-
42
- this.logger?.log('[Orchestrator] Starting...')
43
- this.running = true
44
- for (const actor of this.actors) {
45
- await actor.start()
46
- }
47
- // This interval will fire every 24.8 days (2^31 - 1 ms), effectively never finishing
48
- this.keepAliveHandle = setInterval(() => {
49
- // No-op
50
- }, 2_147_483_647)
51
- }
52
-
53
- /**
54
- * Stops the orchestrator: deactivates all actors.
55
- */
56
- async stop() {
57
- await Promise.resolve()
58
- if (!this.running) {
59
- this.logger?.log('[Orchestrator] Already stopped.')
60
- return
61
- }
62
-
63
- this.logger?.log('[Orchestrator] Stopping...')
64
- for (const actor of this.actors) {
65
- await actor.stop()
66
- }
67
- this.running = false
68
- if (this.keepAliveHandle) clearInterval(this.keepAliveHandle)
69
- this.logger?.log('[Orchestrator] Stopped...')
70
- }
71
- }
@@ -1,2 +0,0 @@
1
- export * from './Actor.ts'
2
- export * from './Orchestrator.ts'