@xyo-network/xl1-cli-lib 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +46 -0
- package/dist/node/commands/api/index.d.ts +2 -0
- package/dist/node/commands/api/index.d.ts.map +1 -0
- package/dist/node/commands/api/runApi.d.ts +9 -0
- package/dist/node/commands/api/runApi.d.ts.map +1 -0
- package/dist/node/commands/index.d.ts +4 -0
- package/dist/node/commands/index.d.ts.map +1 -0
- package/dist/node/commands/producer/index.d.ts +2 -0
- package/dist/node/commands/producer/index.d.ts.map +1 -0
- package/dist/node/commands/producer/runProducer.d.ts +11 -0
- package/dist/node/commands/producer/runProducer.d.ts.map +1 -0
- package/dist/node/commands/validator/index.d.ts +2 -0
- package/dist/node/commands/validator/index.d.ts.map +1 -0
- package/dist/node/commands/validator/runValidator.d.ts +11 -0
- package/dist/node/commands/validator/runValidator.d.ts.map +1 -0
- package/dist/node/images.d.ts +2 -0
- package/dist/node/images.d.ts.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.mjs +1712 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/node/initConfig.d.ts +3 -0
- package/dist/node/initConfig.d.ts.map +1 -0
- package/dist/node/initLogger.d.ts +4 -0
- package/dist/node/initLogger.d.ts.map +1 -0
- package/dist/node/optionsFromZodSchema.d.ts +4 -0
- package/dist/node/optionsFromZodSchema.d.ts.map +1 -0
- package/dist/node/orchestration/ChainInitializableParams.d.ts +11 -0
- package/dist/node/orchestration/ChainInitializableParams.d.ts.map +1 -0
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts +18 -0
- package/dist/node/orchestration/actor/implementation/BalanceActor.d.ts.map +1 -0
- package/dist/node/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts +19 -0
- package/dist/node/orchestration/actor/implementation/ChainHeadUpdateActor.d.ts.map +1 -0
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts +28 -0
- package/dist/node/orchestration/actor/implementation/ProducerActor.d.ts.map +1 -0
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts +26 -0
- package/dist/node/orchestration/actor/implementation/ValidatorActor.d.ts.map +1 -0
- package/dist/node/orchestration/actor/implementation/index.d.ts +5 -0
- package/dist/node/orchestration/actor/implementation/index.d.ts.map +1 -0
- package/dist/node/orchestration/actor/index.d.ts +3 -0
- package/dist/node/orchestration/actor/index.d.ts.map +1 -0
- package/dist/node/orchestration/actor/model/Actor.d.ts +39 -0
- package/dist/node/orchestration/actor/model/Actor.d.ts.map +1 -0
- package/dist/node/orchestration/actor/model/Orchestrator.d.ts +27 -0
- package/dist/node/orchestration/actor/model/Orchestrator.d.ts.map +1 -0
- package/dist/node/orchestration/actor/model/index.d.ts +3 -0
- package/dist/node/orchestration/actor/model/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/ChainFinalized/archivist.d.ts +4 -0
- package/dist/node/orchestration/archivists/ChainFinalized/archivist.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/ChainFinalized/index.d.ts +2 -0
- package/dist/node/orchestration/archivists/ChainFinalized/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/ChainFinalized/local.d.ts +7 -0
- package/dist/node/orchestration/archivists/ChainFinalized/local.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/ChainFinalized/remote.d.ts +7 -0
- package/dist/node/orchestration/archivists/ChainFinalized/remote.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/ChainSubmissions/archivist.d.ts +7 -0
- package/dist/node/orchestration/archivists/ChainSubmissions/archivist.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/ChainSubmissions/index.d.ts +2 -0
- package/dist/node/orchestration/archivists/ChainSubmissions/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/ChainSubmissions/remote.d.ts +7 -0
- package/dist/node/orchestration/archivists/ChainSubmissions/remote.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/PendingTransactions/archivist.d.ts +6 -0
- package/dist/node/orchestration/archivists/PendingTransactions/archivist.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/PendingTransactions/index.d.ts +2 -0
- package/dist/node/orchestration/archivists/PendingTransactions/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/PendingTransactions/local.d.ts +7 -0
- package/dist/node/orchestration/archivists/PendingTransactions/local.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/PendingTransactions/remote.d.ts +7 -0
- package/dist/node/orchestration/archivists/PendingTransactions/remote.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/RejectedTransactions/archivist.d.ts +4 -0
- package/dist/node/orchestration/archivists/RejectedTransactions/archivist.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/RejectedTransactions/index.d.ts +2 -0
- package/dist/node/orchestration/archivists/RejectedTransactions/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/RejectedTransactions/local.d.ts +4 -0
- package/dist/node/orchestration/archivists/RejectedTransactions/local.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/StakeIntentState/archivist.d.ts +5 -0
- package/dist/node/orchestration/archivists/StakeIntentState/archivist.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/StakeIntentState/index.d.ts +2 -0
- package/dist/node/orchestration/archivists/StakeIntentState/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/StakeIntentState/local.d.ts +7 -0
- package/dist/node/orchestration/archivists/StakeIntentState/local.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/index.d.ts +6 -0
- package/dist/node/orchestration/archivists/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/lib/index.d.ts +2 -0
- package/dist/node/orchestration/archivists/lib/index.d.ts.map +1 -0
- package/dist/node/orchestration/archivists/lib/localPersistentArchivist.d.ts +20 -0
- package/dist/node/orchestration/archivists/lib/localPersistentArchivist.d.ts.map +1 -0
- package/dist/node/orchestration/health/index.d.ts +2 -0
- package/dist/node/orchestration/health/index.d.ts.map +1 -0
- package/dist/node/orchestration/health/initHealthEndpoints.d.ts +11 -0
- package/dist/node/orchestration/health/initHealthEndpoints.d.ts.map +1 -0
- package/dist/node/orchestration/host/implementation/DefaultHost.d.ts +12 -0
- package/dist/node/orchestration/host/implementation/DefaultHost.d.ts.map +1 -0
- package/dist/node/orchestration/host/implementation/DefaultServiceCollection.d.ts +24 -0
- package/dist/node/orchestration/host/implementation/DefaultServiceCollection.d.ts.map +1 -0
- package/dist/node/orchestration/host/implementation/DefaultServiceProvider.d.ts +7 -0
- package/dist/node/orchestration/host/implementation/DefaultServiceProvider.d.ts.map +1 -0
- package/dist/node/orchestration/host/implementation/index.d.ts +3 -0
- package/dist/node/orchestration/host/implementation/index.d.ts.map +1 -0
- package/dist/node/orchestration/host/index.d.ts +3 -0
- package/dist/node/orchestration/host/index.d.ts.map +1 -0
- package/dist/node/orchestration/host/model/Host.d.ts +19 -0
- package/dist/node/orchestration/host/model/Host.d.ts.map +1 -0
- package/dist/node/orchestration/host/model/ServiceCollection.d.ts +20 -0
- package/dist/node/orchestration/host/model/ServiceCollection.d.ts.map +1 -0
- package/dist/node/orchestration/host/model/ServiceProvider.d.ts +4 -0
- package/dist/node/orchestration/host/model/ServiceProvider.d.ts.map +1 -0
- package/dist/node/orchestration/host/model/index.d.ts +4 -0
- package/dist/node/orchestration/host/model/index.d.ts.map +1 -0
- package/dist/node/orchestration/index.d.ts +6 -0
- package/dist/node/orchestration/index.d.ts.map +1 -0
- package/dist/node/orchestration/initServices.d.ts +9 -0
- package/dist/node/orchestration/initServices.d.ts.map +1 -0
- package/dist/node/orchestration/map/BalanceSummary/index.d.ts +2 -0
- package/dist/node/orchestration/map/BalanceSummary/index.d.ts.map +1 -0
- package/dist/node/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts +7 -0
- package/dist/node/orchestration/map/BalanceSummary/initBalanceSummaryMap.d.ts.map +1 -0
- package/dist/node/orchestration/map/BalanceSummary/local.d.ts +7 -0
- package/dist/node/orchestration/map/BalanceSummary/local.d.ts.map +1 -0
- package/dist/node/orchestration/map/driver/index.d.ts +2 -0
- package/dist/node/orchestration/map/driver/index.d.ts.map +1 -0
- package/dist/node/orchestration/map/driver/lmdb/Params.d.ts +7 -0
- package/dist/node/orchestration/map/driver/lmdb/Params.d.ts.map +1 -0
- package/dist/node/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts +32 -0
- package/dist/node/orchestration/map/driver/lmdb/SynchronousLmdbMap.d.ts.map +1 -0
- package/dist/node/orchestration/map/driver/lmdb/index.d.ts +2 -0
- package/dist/node/orchestration/map/driver/lmdb/index.d.ts.map +1 -0
- package/dist/node/orchestration/map/driver/lmdb/spec/SynchronousLmdbMap.spec.d.ts +2 -0
- package/dist/node/orchestration/map/driver/lmdb/spec/SynchronousLmdbMap.spec.d.ts.map +1 -0
- package/dist/node/orchestration/map/index.d.ts +3 -0
- package/dist/node/orchestration/map/index.d.ts.map +1 -0
- package/dist/node/orchestration/map/localPersistentMap.d.ts +13 -0
- package/dist/node/orchestration/map/localPersistentMap.d.ts.map +1 -0
- package/dist/node/orchestration/repository/index.d.ts +2 -0
- package/dist/node/orchestration/repository/index.d.ts.map +1 -0
- package/dist/node/orchestration/repository/lib/index.d.ts +2 -0
- package/dist/node/orchestration/repository/lib/index.d.ts.map +1 -0
- package/dist/node/orchestration/repository/lib/repositoryFromArchivist.d.ts +6 -0
- package/dist/node/orchestration/repository/lib/repositoryFromArchivist.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/account.d.ts +7 -0
- package/dist/node/orchestration/services/implementation/account.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/balance.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/balance.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/chain/evm.d.ts +7 -0
- package/dist/node/orchestration/services/implementation/chain/evm.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/chain/index.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/chain/index.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/evm/index.d.ts +2 -0
- package/dist/node/orchestration/services/implementation/evm/index.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/evm/initChainId.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/evm/initChainId.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/evm/initEvmProvider.d.ts +11 -0
- package/dist/node/orchestration/services/implementation/evm/initEvmProvider.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/evm/initInfuraProvider.d.ts +6 -0
- package/dist/node/orchestration/services/implementation/evm/initInfuraProvider.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/evm/initJsonRpcProvider.d.ts +6 -0
- package/dist/node/orchestration/services/implementation/evm/initJsonRpcProvider.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/head.d.ts +10 -0
- package/dist/node/orchestration/services/implementation/head.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/index.d.ts +11 -0
- package/dist/node/orchestration/services/implementation/index.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/iterator.d.ts +6 -0
- package/dist/node/orchestration/services/implementation/iterator.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/pendingTransactions.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/pendingTransactions.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/producer.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/producer.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/reward.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/reward.d.ts.map +1 -0
- package/dist/node/orchestration/services/implementation/validator.d.ts +4 -0
- package/dist/node/orchestration/services/implementation/validator.d.ts.map +1 -0
- package/dist/node/orchestration/services/index.d.ts +2 -0
- package/dist/node/orchestration/services/index.d.ts.map +1 -0
- package/dist/node/orchestration/status/RuntimeStatusMonitor.d.ts +31 -0
- package/dist/node/orchestration/status/RuntimeStatusMonitor.d.ts.map +1 -0
- package/dist/node/orchestration/status/ServiceStatus.d.ts +9 -0
- package/dist/node/orchestration/status/ServiceStatus.d.ts.map +1 -0
- package/dist/node/orchestration/status/index.d.ts +3 -0
- package/dist/node/orchestration/status/index.d.ts.map +1 -0
- package/dist/node/orchestration/store/StoreKind.d.ts +2 -0
- package/dist/node/orchestration/store/StoreKind.d.ts.map +1 -0
- package/dist/node/orchestration/store/getStoreDirectory.d.ts +10 -0
- package/dist/node/orchestration/store/getStoreDirectory.d.ts.map +1 -0
- package/dist/node/orchestration/store/index.d.ts +3 -0
- package/dist/node/orchestration/store/index.d.ts.map +1 -0
- package/dist/node/runCLI.d.ts +2 -0
- package/dist/node/runCLI.d.ts.map +1 -0
- package/dist/node/spec/BootstrapChain.spec.d.ts +2 -0
- package/dist/node/spec/BootstrapChain.spec.d.ts.map +1 -0
- package/dist/node/start.d.ts +2 -0
- package/dist/node/start.d.ts.map +1 -0
- package/dist/node/waitForHostPort.d.ts +2 -0
- package/dist/node/waitForHostPort.d.ts.map +1 -0
- package/dist/node/xl1.d.ts +2 -0
- package/dist/node/xl1.d.ts.map +1 -0
- package/dist/node/xl1.mjs +1610 -0
- package/dist/node/xl1.mjs.map +1 -0
- package/package.json +96 -0
- package/src/commands/api/index.ts +1 -0
- package/src/commands/api/runApi.ts +12 -0
- package/src/commands/index.ts +3 -0
- package/src/commands/producer/index.ts +1 -0
- package/src/commands/producer/runProducer.ts +38 -0
- package/src/commands/validator/index.ts +1 -0
- package/src/commands/validator/runValidator.ts +38 -0
- package/src/images.ts +19 -0
- package/src/index.ts +3 -0
- package/src/initConfig.ts +6 -0
- package/src/initLogger.ts +23 -0
- package/src/optionsFromZodSchema.ts +69 -0
- package/src/orchestration/ChainInitializableParams.ts +12 -0
- package/src/orchestration/actor/implementation/BalanceActor.ts +50 -0
- package/src/orchestration/actor/implementation/ChainHeadUpdateActor.ts +65 -0
- package/src/orchestration/actor/implementation/ProducerActor.ts +244 -0
- package/src/orchestration/actor/implementation/ValidatorActor.ts +113 -0
- package/src/orchestration/actor/implementation/index.ts +4 -0
- package/src/orchestration/actor/index.ts +2 -0
- package/src/orchestration/actor/model/Actor.ts +114 -0
- package/src/orchestration/actor/model/Orchestrator.ts +71 -0
- package/src/orchestration/actor/model/index.ts +2 -0
- package/src/orchestration/archivists/ChainFinalized/archivist.ts +29 -0
- package/src/orchestration/archivists/ChainFinalized/index.ts +1 -0
- package/src/orchestration/archivists/ChainFinalized/local.ts +18 -0
- package/src/orchestration/archivists/ChainFinalized/remote.ts +20 -0
- package/src/orchestration/archivists/ChainSubmissions/archivist.ts +20 -0
- package/src/orchestration/archivists/ChainSubmissions/index.ts +1 -0
- package/src/orchestration/archivists/ChainSubmissions/remote.ts +20 -0
- package/src/orchestration/archivists/PendingTransactions/archivist.ts +29 -0
- package/src/orchestration/archivists/PendingTransactions/index.ts +1 -0
- package/src/orchestration/archivists/PendingTransactions/local.ts +21 -0
- package/src/orchestration/archivists/PendingTransactions/remote.ts +20 -0
- package/src/orchestration/archivists/RejectedTransactions/archivist.ts +18 -0
- package/src/orchestration/archivists/RejectedTransactions/index.ts +1 -0
- package/src/orchestration/archivists/RejectedTransactions/local.ts +20 -0
- package/src/orchestration/archivists/StakeIntentState/archivist.ts +21 -0
- package/src/orchestration/archivists/StakeIntentState/index.ts +1 -0
- package/src/orchestration/archivists/StakeIntentState/local.ts +19 -0
- package/src/orchestration/archivists/index.ts +5 -0
- package/src/orchestration/archivists/lib/index.ts +1 -0
- package/src/orchestration/archivists/lib/localPersistentArchivist.ts +57 -0
- package/src/orchestration/health/index.ts +1 -0
- package/src/orchestration/health/initHealthEndpoints.ts +72 -0
- package/src/orchestration/host/implementation/DefaultHost.ts +25 -0
- package/src/orchestration/host/implementation/DefaultServiceCollection.ts +60 -0
- package/src/orchestration/host/implementation/DefaultServiceProvider.ts +12 -0
- package/src/orchestration/host/implementation/index.ts +2 -0
- package/src/orchestration/host/index.ts +2 -0
- package/src/orchestration/host/model/Host.ts +21 -0
- package/src/orchestration/host/model/ServiceCollection.ts +22 -0
- package/src/orchestration/host/model/ServiceProvider.ts +3 -0
- package/src/orchestration/host/model/index.ts +3 -0
- package/src/orchestration/index.ts +5 -0
- package/src/orchestration/initServices.ts +240 -0
- package/src/orchestration/map/BalanceSummary/index.ts +1 -0
- package/src/orchestration/map/BalanceSummary/initBalanceSummaryMap.ts +22 -0
- package/src/orchestration/map/BalanceSummary/local.ts +21 -0
- package/src/orchestration/map/driver/index.ts +1 -0
- package/src/orchestration/map/driver/lmdb/Params.ts +7 -0
- package/src/orchestration/map/driver/lmdb/SynchronousLmdbMap.ts +66 -0
- package/src/orchestration/map/driver/lmdb/index.ts +1 -0
- package/src/orchestration/map/driver/lmdb/spec/SynchronousLmdbMap.spec.ts +97 -0
- package/src/orchestration/map/index.ts +2 -0
- package/src/orchestration/map/localPersistentMap.ts +52 -0
- package/src/orchestration/repository/index.ts +1 -0
- package/src/orchestration/repository/lib/index.ts +1 -0
- package/src/orchestration/repository/lib/repositoryFromArchivist.ts +27 -0
- package/src/orchestration/services/implementation/account.ts +24 -0
- package/src/orchestration/services/implementation/balance.ts +13 -0
- package/src/orchestration/services/implementation/chain/evm.ts +38 -0
- package/src/orchestration/services/implementation/chain/index.ts +22 -0
- package/src/orchestration/services/implementation/evm/index.ts +1 -0
- package/src/orchestration/services/implementation/evm/initChainId.ts +20 -0
- package/src/orchestration/services/implementation/evm/initEvmProvider.ts +23 -0
- package/src/orchestration/services/implementation/evm/initInfuraProvider.ts +27 -0
- package/src/orchestration/services/implementation/evm/initJsonRpcProvider.ts +21 -0
- package/src/orchestration/services/implementation/head.ts +44 -0
- package/src/orchestration/services/implementation/index.ts +10 -0
- package/src/orchestration/services/implementation/iterator.ts +36 -0
- package/src/orchestration/services/implementation/pendingTransactions.ts +14 -0
- package/src/orchestration/services/implementation/producer.ts +13 -0
- package/src/orchestration/services/implementation/reward.ts +41 -0
- package/src/orchestration/services/implementation/validator.ts +14 -0
- package/src/orchestration/services/index.ts +1 -0
- package/src/orchestration/status/RuntimeStatusMonitor.ts +117 -0
- package/src/orchestration/status/ServiceStatus.ts +21 -0
- package/src/orchestration/status/index.ts +2 -0
- package/src/orchestration/store/StoreKind.ts +1 -0
- package/src/orchestration/store/getStoreDirectory.ts +14 -0
- package/src/orchestration/store/index.ts +2 -0
- package/src/runCLI.ts +111 -0
- package/src/spec/BootstrapChain.spec.ts +133 -0
- package/src/spec/MultiProducer.ChainOutput.json +864 -0
- package/src/start.ts +8 -0
- package/src/waitForHostPort.ts +26 -0
- package/src/xl1.ts +8 -0
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
8
|
+
|
|
9
|
+
export interface IActor {
|
|
10
|
+
start(): Promise<void>
|
|
11
|
+
stop(): Promise<void>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ActorParams = BaseParams<{
|
|
15
|
+
config: Config
|
|
16
|
+
traceProvider?: TracerProvider
|
|
17
|
+
}>
|
|
18
|
+
|
|
19
|
+
export class Actor<TParams extends ActorParams = ActorParams> extends Base<TParams> implements IActor {
|
|
20
|
+
protected readonly _timers: Map<string, ReturnType<typeof setTimeout>> = new Map()
|
|
21
|
+
private _active = false
|
|
22
|
+
private readonly _displayName: string
|
|
23
|
+
private readonly _id: string
|
|
24
|
+
|
|
25
|
+
constructor(id: string, displayName: string = 'Actor', params: TParams) {
|
|
26
|
+
const logger = params.logger ?? new IdLogger(Base.defaultLogger ?? console, () => `[${displayName} (${id})] `)
|
|
27
|
+
super({ ...params, logger })
|
|
28
|
+
this._displayName = displayName
|
|
29
|
+
this._id = id
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get displayName() {
|
|
33
|
+
return this._displayName
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get id() {
|
|
37
|
+
return this._id
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get name() {
|
|
41
|
+
return this.constructor.name
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected get logPrefix() {
|
|
45
|
+
return `[${this.displayName} (${this.id})] `
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The timer runs until the actor is deactivated (or you manually stop it).
|
|
50
|
+
*/
|
|
51
|
+
registerTimer(timerName: string, callback: () => Promisable<void>, dueTimeMs: number, periodMs: number) {
|
|
52
|
+
if (!this._active) {
|
|
53
|
+
this.logger?.warn(
|
|
54
|
+
`Cannot register timer '${timerName}' because actor is not active.`,
|
|
55
|
+
)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Function to handle recursive scheduling
|
|
60
|
+
const schedulePeriodicRun = async () => {
|
|
61
|
+
// Stop if actor is deactivated or timer is removed
|
|
62
|
+
if (!this._active || !this._timers.has(timerName)) return
|
|
63
|
+
try {
|
|
64
|
+
// Run the callback
|
|
65
|
+
await callback()
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Catch and log any errors
|
|
68
|
+
this.logger?.error(`Error in timer '${this.name}:${timerName}': ${error}`)
|
|
69
|
+
} finally {
|
|
70
|
+
// Always schedule subsequent executions based on the desired period
|
|
71
|
+
this._timers.set(timerName, setTimeout(() => forget(schedulePeriodicRun(), { name: `schedulePeriodicRun:${this.name}:${timerName}` }), periodMs))
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Schedule the 1st execution after the desired initial delay
|
|
76
|
+
this._timers.set(timerName, setTimeout(() => forget(schedulePeriodicRun(), { name: `schedulePeriodicRun(initial):${this.name}:${timerName}` }), dueTimeMs))
|
|
77
|
+
|
|
78
|
+
this.logger?.log(
|
|
79
|
+
`Timer '${this.name}:${timerName}' registered: first call after ${dueTimeMs}ms, recurring every ${periodMs}ms.`,
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
span<T>(name: string, fn: () => T): T {
|
|
84
|
+
return span(`${this.name}:${name}`, fn, this.tracer)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async spanAsync<T>(name: string, fn: () => Promise<T>): Promise<T> {
|
|
88
|
+
return await spanAsync(`${this.name}:${name}`, fn, this.tracer)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Called by the Orchestrator when the actor is activated.
|
|
93
|
+
*/
|
|
94
|
+
async start() {
|
|
95
|
+
await Promise.resolve()
|
|
96
|
+
this._active = true
|
|
97
|
+
this.logger?.log('Started.')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Called by the Orchestrator when the actor is deactivated.
|
|
102
|
+
* Stop all running timers.
|
|
103
|
+
*/
|
|
104
|
+
async stop() {
|
|
105
|
+
await Promise.resolve()
|
|
106
|
+
this._active = false
|
|
107
|
+
this.logger?.log('Stopping all timers...')
|
|
108
|
+
for (const [, timerRef] of this._timers.entries()) {
|
|
109
|
+
clearTimeout(timerRef)
|
|
110
|
+
}
|
|
111
|
+
this._timers.clear()
|
|
112
|
+
this.logger?.log('Stopped.')
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
+
import { initArchivistSync } from '@xyo-network/chain-orchestration'
|
|
3
|
+
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
4
|
+
import { Mutex } from 'async-mutex'
|
|
5
|
+
|
|
6
|
+
import type { ChainInitializableParams } from '../../ChainInitializableParams.ts'
|
|
7
|
+
import { initLocalChainFinalizedArchivist } from './local.ts'
|
|
8
|
+
import { initRemoteChainFinalizedArchivist } from './remote.ts'
|
|
9
|
+
|
|
10
|
+
const mutex = new Mutex()
|
|
11
|
+
let singleton: ArchivistInstance | undefined
|
|
12
|
+
|
|
13
|
+
export async function initChainFinalizedArchivist({
|
|
14
|
+
config, logger, traceProvider,
|
|
15
|
+
}: ChainInitializableParams) {
|
|
16
|
+
return await mutex.runExclusive(async () => {
|
|
17
|
+
if (singleton) return singleton
|
|
18
|
+
const [remote, local] = await Promise.all([
|
|
19
|
+
startupSpanAsync('ChainFinalizedArchivist:initRemote', () => initRemoteChainFinalizedArchivist({ config, logger })),
|
|
20
|
+
startupSpanAsync('ChainFinalizedArchivist:initLocal', () => initLocalChainFinalizedArchivist({ config, logger })),
|
|
21
|
+
])
|
|
22
|
+
await startupSpanAsync(
|
|
23
|
+
'ChainFinalizedArchivist:initArchivistSync',
|
|
24
|
+
() => initArchivistSync('ChainFinalizedArchivist', remote, local, 200, Number.MAX_SAFE_INTEGER, traceProvider),
|
|
25
|
+
)
|
|
26
|
+
singleton = local
|
|
27
|
+
return singleton
|
|
28
|
+
})
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './archivist.ts'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
3
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
4
|
+
import { Mutex } from 'async-mutex'
|
|
5
|
+
|
|
6
|
+
import { getLocalPersistentArchivist } from '../lib/index.ts'
|
|
7
|
+
|
|
8
|
+
const mutex = new Mutex()
|
|
9
|
+
let singleton: ArchivistInstance | undefined
|
|
10
|
+
|
|
11
|
+
export const initLocalChainFinalizedArchivist: Initializable<{ config: Config }, ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
12
|
+
return await mutex.runExclusive(async () => {
|
|
13
|
+
if (singleton) return singleton
|
|
14
|
+
const { root } = config.storage
|
|
15
|
+
singleton = await getLocalPersistentArchivist('chain', 'finalized', root)
|
|
16
|
+
return singleton
|
|
17
|
+
})
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import { initBridge, initBridgedArchivistModule } from '@xyo-network/chain-orchestration'
|
|
4
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { type Config, getUrl } from '@xyo-network/xl1-protocol-sdk'
|
|
6
|
+
import { Mutex } from 'async-mutex'
|
|
7
|
+
|
|
8
|
+
const mutex = new Mutex()
|
|
9
|
+
let singleton: ArchivistInstance | undefined
|
|
10
|
+
|
|
11
|
+
export const initRemoteChainFinalizedArchivist: Initializable<{ config: Config }, ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
12
|
+
return await mutex.runExclusive(async () => {
|
|
13
|
+
if (singleton) return singleton
|
|
14
|
+
const { host, port } = config.api
|
|
15
|
+
const nodeUrl = getUrl(host, port)
|
|
16
|
+
const bridge = await initBridge(nodeUrl)
|
|
17
|
+
singleton = await initBridgedArchivistModule({ bridge, moduleName: 'XYOChain:Chain:Finalized' })
|
|
18
|
+
return assertEx(singleton, () => 'Error: RemoteChainFinalizedArchivist failed to initialize')
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
4
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
6
|
+
import { Mutex } from 'async-mutex'
|
|
7
|
+
|
|
8
|
+
import { initRemoteChainSubmissionsArchivist } from './remote.ts'
|
|
9
|
+
|
|
10
|
+
const mutex = new Mutex()
|
|
11
|
+
let singleton: ArchivistInstance | undefined
|
|
12
|
+
|
|
13
|
+
export const initChainSubmissionsArchivist: Initializable<{ config: Config }, ArchivistInstance> = async (params): Promise<ArchivistInstance> => {
|
|
14
|
+
return await mutex.runExclusive(async () => {
|
|
15
|
+
if (singleton) return singleton
|
|
16
|
+
const remote = await startupSpanAsync('ChainSubmissionsArchivist:initRemote', () => initRemoteChainSubmissionsArchivist(params))
|
|
17
|
+
singleton = remote
|
|
18
|
+
return assertEx(singleton, () => new Error('Failed to initialize ChainSubmissionsArchivist'))
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './archivist.ts'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import { initBridge, initBridgedArchivistModule } from '@xyo-network/chain-orchestration'
|
|
4
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { type Config, getUrl } from '@xyo-network/xl1-protocol-sdk'
|
|
6
|
+
import { Mutex } from 'async-mutex'
|
|
7
|
+
|
|
8
|
+
const mutex = new Mutex()
|
|
9
|
+
let singleton: ArchivistInstance | undefined
|
|
10
|
+
|
|
11
|
+
export const initRemoteChainSubmissionsArchivist: Initializable<{ config: Config }, ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
12
|
+
return await mutex.runExclusive(async () => {
|
|
13
|
+
if (singleton) return singleton
|
|
14
|
+
const { host, port } = config.api
|
|
15
|
+
const nodeUrl = getUrl(host, port)
|
|
16
|
+
const bridge = await initBridge(nodeUrl)
|
|
17
|
+
singleton = await initBridgedArchivistModule({ bridge, moduleName: 'XYOChain:Chain:Submissions' })
|
|
18
|
+
return assertEx(singleton, () => new Error('Failed to initialize RemoteChainSubmissionsArchivist'))
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
+
import { initArchivistSync } from '@xyo-network/chain-orchestration'
|
|
3
|
+
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
4
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
+
import { Mutex } from 'async-mutex'
|
|
6
|
+
|
|
7
|
+
import { initLocalPendingTransactionsArchivist } from './local.ts'
|
|
8
|
+
import { initRemotePendingTransactionsArchivist } from './remote.ts'
|
|
9
|
+
|
|
10
|
+
const mutex = new Mutex()
|
|
11
|
+
let singleton: [local: ArchivistInstance, remote: ArchivistInstance] | undefined
|
|
12
|
+
|
|
13
|
+
export const initPendingBundledTransactionsArchivist = async (params: { config: Config }): Promise<[local: ArchivistInstance, remote: ArchivistInstance]> => {
|
|
14
|
+
return await mutex.runExclusive(async () => {
|
|
15
|
+
if (singleton) return singleton
|
|
16
|
+
const remote = await startupSpanAsync('PendingBundledTransactionsArchivist:initRemote', () => initRemotePendingTransactionsArchivist(params))
|
|
17
|
+
const local = await startupSpanAsync('PendingBundledTransactionsArchivist:initLocal', () => initLocalPendingTransactionsArchivist(params))
|
|
18
|
+
// Grab the most recent payload from the remote archivist
|
|
19
|
+
const start = await remote.next({ limit: 1, order: 'desc' })
|
|
20
|
+
// Write it locally so we have a starting point for syncing
|
|
21
|
+
await local.insert(start)
|
|
22
|
+
await startupSpanAsync(
|
|
23
|
+
'PendingBundledTransactionsArchivist:initArchivistSync',
|
|
24
|
+
() => initArchivistSync('PendingBundledTransactionsArchivist', remote, local),
|
|
25
|
+
)
|
|
26
|
+
singleton = [local, remote]
|
|
27
|
+
return singleton
|
|
28
|
+
})
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './archivist.ts'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
4
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
+
import { Mutex } from 'async-mutex'
|
|
6
|
+
|
|
7
|
+
const mutex = new Mutex()
|
|
8
|
+
let singleton: ArchivistInstance | undefined
|
|
9
|
+
|
|
10
|
+
export const initLocalPendingTransactionsArchivist: Initializable<{ config: Config }, ArchivistInstance> = async (): Promise<ArchivistInstance> => {
|
|
11
|
+
return await mutex.runExclusive(async () => {
|
|
12
|
+
if (singleton) return singleton
|
|
13
|
+
singleton = await MemoryArchivist.create({
|
|
14
|
+
account: 'random',
|
|
15
|
+
config: {
|
|
16
|
+
schema: MemoryArchivistConfigSchema, max: 1000, name: 'localPendingTransactions',
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
return singleton
|
|
20
|
+
})
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import { initBridge, initBridgedArchivistModule } from '@xyo-network/chain-orchestration'
|
|
4
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { type Config, getUrl } from '@xyo-network/xl1-protocol-sdk'
|
|
6
|
+
import { Mutex } from 'async-mutex'
|
|
7
|
+
|
|
8
|
+
const mutex = new Mutex()
|
|
9
|
+
let singleton: ArchivistInstance | undefined
|
|
10
|
+
|
|
11
|
+
export const initRemotePendingTransactionsArchivist: Initializable<{ config: Config }, ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
12
|
+
return await mutex.runExclusive(async () => {
|
|
13
|
+
if (singleton) return singleton
|
|
14
|
+
const { host, port } = config.api
|
|
15
|
+
const nodeUrl = getUrl(host, port)
|
|
16
|
+
const bridge = await initBridge(nodeUrl)
|
|
17
|
+
singleton = await initBridgedArchivistModule({ bridge, moduleName: 'XYOChain:Pending:PendingTransactions' })
|
|
18
|
+
return assertEx(singleton, () => 'Error: RemotePendingBundledTransactionsArchivist is undefined')
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
2
|
+
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
3
|
+
import type { InitializableParams } from '@xyo-network/xl1-protocol'
|
|
4
|
+
import { Mutex } from 'async-mutex'
|
|
5
|
+
|
|
6
|
+
import { initLocalRejectedTransactionsArchivist } from './local.ts'
|
|
7
|
+
|
|
8
|
+
const mutex = new Mutex()
|
|
9
|
+
let singleton: ArchivistInstance | undefined
|
|
10
|
+
|
|
11
|
+
export async function initRejectedTransactionsArchivist(params: InitializableParams) {
|
|
12
|
+
return await mutex.runExclusive(async () => {
|
|
13
|
+
if (singleton) return singleton
|
|
14
|
+
const local = await startupSpanAsync('RejectedTransactionsArchivist:initLocal', () => initLocalRejectedTransactionsArchivist(params))
|
|
15
|
+
singleton = local
|
|
16
|
+
return singleton
|
|
17
|
+
})
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './archivist.ts'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MemoryArchivist, MemoryArchivistConfigSchema } from '@xyo-network/archivist-memory'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
4
|
+
import { Mutex } from 'async-mutex'
|
|
5
|
+
|
|
6
|
+
const mutex = new Mutex()
|
|
7
|
+
let singleton: ArchivistInstance | undefined
|
|
8
|
+
|
|
9
|
+
export const initLocalRejectedTransactionsArchivist: Initializable<{}, ArchivistInstance> = async (): Promise<ArchivistInstance> => {
|
|
10
|
+
return await mutex.runExclusive(async () => {
|
|
11
|
+
if (singleton) return singleton
|
|
12
|
+
singleton = await MemoryArchivist.create({
|
|
13
|
+
account: 'random',
|
|
14
|
+
config: {
|
|
15
|
+
schema: MemoryArchivistConfigSchema, max: 1000, name: 'localRejectedTransactions',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
return singleton
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import { startupSpanAsync } from '@xyo-network/chain-utils'
|
|
4
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
5
|
+
import { Mutex } from 'async-mutex'
|
|
6
|
+
|
|
7
|
+
import type { ChainInitializableParams } from '../../ChainInitializableParams.ts'
|
|
8
|
+
import { initLocalStakeIntentStateArchivist } from './local.ts'
|
|
9
|
+
|
|
10
|
+
const mutex = new Mutex()
|
|
11
|
+
let singleton: ArchivistInstance | undefined
|
|
12
|
+
|
|
13
|
+
export const initStakeIntentStateArchivist: Initializable<ChainInitializableParams, ArchivistInstance>
|
|
14
|
+
= async (params: ChainInitializableParams): Promise<ArchivistInstance> => {
|
|
15
|
+
return await mutex.runExclusive(async () => {
|
|
16
|
+
if (singleton) return singleton
|
|
17
|
+
const local = await startupSpanAsync('StakeIntentStateArchivist:initLocal', () => initLocalStakeIntentStateArchivist(params))
|
|
18
|
+
singleton = local
|
|
19
|
+
return assertEx(singleton, () => 'Error: StakeIntentStateArchivist is undefined')
|
|
20
|
+
})
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './archivist.ts'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
3
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
4
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
5
|
+
import { Mutex } from 'async-mutex'
|
|
6
|
+
|
|
7
|
+
import { getLocalPersistentArchivist } from '../lib/index.ts'
|
|
8
|
+
|
|
9
|
+
const mutex = new Mutex()
|
|
10
|
+
let singleton: ArchivistInstance | undefined
|
|
11
|
+
|
|
12
|
+
export const initLocalStakeIntentStateArchivist: Initializable<{ config: Config }, ArchivistInstance> = async ({ config }): Promise<ArchivistInstance> => {
|
|
13
|
+
return await mutex.runExclusive(async () => {
|
|
14
|
+
if (singleton) return singleton
|
|
15
|
+
const { root } = config.storage
|
|
16
|
+
singleton = await getLocalPersistentArchivist('stakeIntent', 'state', root)
|
|
17
|
+
return assertEx(singleton, () => new Error('Failed to initialize stake intent state archivist'))
|
|
18
|
+
})
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './localPersistentArchivist.ts'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises'
|
|
2
|
+
import Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { LmdbArchivist, LmdbArchivistConfigSchema } from '@xyo-network/archivist-lmdb'
|
|
5
|
+
import type { ArchivistInstance } from '@xyo-network/archivist-model'
|
|
6
|
+
|
|
7
|
+
import type { StoreKind } from '../../store/index.ts'
|
|
8
|
+
import { getStoreDirectory } from '../../store/index.ts'
|
|
9
|
+
|
|
10
|
+
const DEFAULT_STORAGE_ROOT = Path.join(process.cwd(), '.store')
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns a local persistent archivist
|
|
14
|
+
* @param dbName The name of the database
|
|
15
|
+
* @param storeName The name of the store
|
|
16
|
+
* @param storageRoot The root directory for storage (default is '.store' in the current working directory)
|
|
17
|
+
* @param kind The kind of the archivist
|
|
18
|
+
* @returns an archivist instance
|
|
19
|
+
*/
|
|
20
|
+
export const getLocalPersistentArchivist = (dbName: string, storeName: string, storageRoot?: string, kind: StoreKind = 'lmdb'): Promise<ArchivistInstance> => {
|
|
21
|
+
switch (kind) {
|
|
22
|
+
case 'lmdb': {
|
|
23
|
+
const root = storageRoot ?? DEFAULT_STORAGE_ROOT
|
|
24
|
+
return LmdbArchivist.create({
|
|
25
|
+
account: 'random',
|
|
26
|
+
config: {
|
|
27
|
+
clearStoreOnStart: false,
|
|
28
|
+
dbName,
|
|
29
|
+
location: getStoreDirectory(dbName, root, 'lmdb'),
|
|
30
|
+
schema: LmdbArchivistConfigSchema,
|
|
31
|
+
storeName,
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Deletes a local persistent archivist
|
|
40
|
+
* @param dbName The name of the database
|
|
41
|
+
* @param storageRoot The root directory for storage (default is '.store' in the current working directory)
|
|
42
|
+
* @param kind The kind of the archivist
|
|
43
|
+
* @returns A promise that resolves when the archivist is deleted
|
|
44
|
+
*/
|
|
45
|
+
export const deleteLocalPersistentArchivist = async (dbName: string, storageRoot?: string, kind: StoreKind = 'lmdb'): Promise<void> => {
|
|
46
|
+
await Promise.resolve()
|
|
47
|
+
console.warn(`Deleting local persistent archivist for ${dbName} of kind ${kind}.`)
|
|
48
|
+
let location = ''
|
|
49
|
+
switch (kind) {
|
|
50
|
+
case 'lmdb': {
|
|
51
|
+
const root = storageRoot ?? DEFAULT_STORAGE_ROOT
|
|
52
|
+
location = getStoreDirectory(dbName, root, 'lmdb')
|
|
53
|
+
break
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
await rm(location, { recursive: true, force: true })
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './initHealthEndpoints.ts'
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IncomingMessage, Server, ServerResponse,
|
|
3
|
+
} from 'node:http'
|
|
4
|
+
import http from 'node:http'
|
|
5
|
+
|
|
6
|
+
import type { CreatableStatus } from '@xylabs/creatable'
|
|
7
|
+
import type { Logger } from '@xylabs/logger'
|
|
8
|
+
import { isDefined } from '@xylabs/typeof'
|
|
9
|
+
import type { Initializable } from '@xyo-network/xl1-protocol'
|
|
10
|
+
import type { Config } from '@xyo-network/xl1-protocol-sdk'
|
|
11
|
+
|
|
12
|
+
import type { RuntimeStatusMonitor } from '../status/index.ts'
|
|
13
|
+
|
|
14
|
+
const sendStatus = (res: ServerResponse, status: CreatableStatus, errorCode: number) => {
|
|
15
|
+
const statusCode = status === 'started' ? 200 : errorCode
|
|
16
|
+
res.writeHead(statusCode, { 'Content-Type': 'application/json' })
|
|
17
|
+
res.end(JSON.stringify({ status }))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const notFound = (res: ServerResponse) => {
|
|
21
|
+
res.writeHead(404, { 'Content-Type': 'application/json' })
|
|
22
|
+
res.end(JSON.stringify({ status: 'not found' }))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Starts an HTTP server with Kubernetes health endpoints:
|
|
27
|
+
* - /healthz
|
|
28
|
+
* - /livez
|
|
29
|
+
* - /readyz
|
|
30
|
+
* @param port The port to listen on (default: 8080)
|
|
31
|
+
*/
|
|
32
|
+
const createHealthServer = (port: number, statusMonitor: RuntimeStatusMonitor, logger: Logger) => {
|
|
33
|
+
const server = http.createServer((req: IncomingMessage, res: ServerResponse) => {
|
|
34
|
+
const url = req.url ?? ''
|
|
35
|
+
|
|
36
|
+
const status = statusMonitor.getGlobalStatus()
|
|
37
|
+
|
|
38
|
+
switch (url) {
|
|
39
|
+
case '/healthz': {
|
|
40
|
+
sendStatus(res, status, 500)
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
case '/livez': {
|
|
44
|
+
sendStatus(res, status, 503)
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
case '/readyz': {
|
|
48
|
+
sendStatus(res, status, 503)
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
default: {
|
|
52
|
+
notFound(res)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
server.listen(port, () => {
|
|
58
|
+
logger.log(`Health server running on http://localhost:${port}`)
|
|
59
|
+
logger.log(' - /healthz')
|
|
60
|
+
logger.log(' - /livez')
|
|
61
|
+
logger.log(' - /readyz')
|
|
62
|
+
})
|
|
63
|
+
return server
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const initHealthEndpoints: Initializable<{ config: Config; logger: Logger; statusReporter: RuntimeStatusMonitor }, Server | undefined> = (params) => {
|
|
67
|
+
const {
|
|
68
|
+
config, logger, statusReporter,
|
|
69
|
+
} = params
|
|
70
|
+
const { healthCheckPort } = config.producer
|
|
71
|
+
return isDefined(healthCheckPort) ? createHealthServer(healthCheckPort, statusReporter, logger) : undefined
|
|
72
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Host, ServiceProvider } from '../model/index.ts'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A generic host implementation that can be used as a starting point for
|
|
5
|
+
* more complex host implementations.
|
|
6
|
+
*/
|
|
7
|
+
export class GenericHost implements Host {
|
|
8
|
+
services: ServiceProvider
|
|
9
|
+
|
|
10
|
+
constructor(services: ServiceProvider) {
|
|
11
|
+
this.services = services
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async start(): Promise<void> {
|
|
15
|
+
await Promise.resolve()
|
|
16
|
+
// Initialize or start your services here
|
|
17
|
+
console.log('Host is starting...')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async stop(): Promise<void> {
|
|
21
|
+
await Promise.resolve()
|
|
22
|
+
// Stop or clean up services here
|
|
23
|
+
console.log('Host is stopping...')
|
|
24
|
+
}
|
|
25
|
+
}
|