@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,1610 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/start.ts
|
|
5
|
+
import { config as config2 } from "dotenv";
|
|
6
|
+
|
|
7
|
+
// src/runCLI.ts
|
|
8
|
+
import { isDefined as isDefined11 } from "@xylabs/typeof";
|
|
9
|
+
import { ConfigSchema } from "@xyo-network/xl1-protocol-sdk";
|
|
10
|
+
import yargs from "yargs";
|
|
11
|
+
import { hideBin } from "yargs/helpers";
|
|
12
|
+
import { ZodError } from "zod";
|
|
13
|
+
|
|
14
|
+
// src/commands/api/runApi.ts
|
|
15
|
+
import { getServer } from "@xyo-network/chain-api";
|
|
16
|
+
function runApi(context) {
|
|
17
|
+
void getServer(context);
|
|
18
|
+
}
|
|
19
|
+
__name(runApi, "runApi");
|
|
20
|
+
|
|
21
|
+
// src/orchestration/actor/implementation/BalanceActor.ts
|
|
22
|
+
import { assertEx } from "@xylabs/assert";
|
|
23
|
+
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
24
|
+
import { Mutex } from "async-mutex";
|
|
25
|
+
|
|
26
|
+
// src/orchestration/actor/model/Actor.ts
|
|
27
|
+
import { Base } from "@xylabs/base";
|
|
28
|
+
import { forget } from "@xylabs/forget";
|
|
29
|
+
import { IdLogger } from "@xylabs/logger";
|
|
30
|
+
import { span, spanAsync } from "@xylabs/telemetry";
|
|
31
|
+
var Actor = class extends Base {
|
|
32
|
+
static {
|
|
33
|
+
__name(this, "Actor");
|
|
34
|
+
}
|
|
35
|
+
_timers = /* @__PURE__ */ new Map();
|
|
36
|
+
_active = false;
|
|
37
|
+
_displayName;
|
|
38
|
+
_id;
|
|
39
|
+
constructor(id, displayName = "Actor", params) {
|
|
40
|
+
const logger = params.logger ?? new IdLogger(Base.defaultLogger ?? console, () => `[${displayName} (${id})] `);
|
|
41
|
+
super({
|
|
42
|
+
...params,
|
|
43
|
+
logger
|
|
44
|
+
});
|
|
45
|
+
this._displayName = displayName;
|
|
46
|
+
this._id = id;
|
|
47
|
+
}
|
|
48
|
+
get displayName() {
|
|
49
|
+
return this._displayName;
|
|
50
|
+
}
|
|
51
|
+
get id() {
|
|
52
|
+
return this._id;
|
|
53
|
+
}
|
|
54
|
+
get name() {
|
|
55
|
+
return this.constructor.name;
|
|
56
|
+
}
|
|
57
|
+
get logPrefix() {
|
|
58
|
+
return `[${this.displayName} (${this.id})] `;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The timer runs until the actor is deactivated (or you manually stop it).
|
|
62
|
+
*/
|
|
63
|
+
registerTimer(timerName, callback, dueTimeMs, periodMs) {
|
|
64
|
+
if (!this._active) {
|
|
65
|
+
this.logger?.warn(`Cannot register timer '${timerName}' because actor is not active.`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const schedulePeriodicRun = /* @__PURE__ */ __name(async () => {
|
|
69
|
+
if (!this._active || !this._timers.has(timerName)) return;
|
|
70
|
+
try {
|
|
71
|
+
await callback();
|
|
72
|
+
} catch (error) {
|
|
73
|
+
this.logger?.error(`Error in timer '${this.name}:${timerName}': ${error}`);
|
|
74
|
+
} finally {
|
|
75
|
+
this._timers.set(timerName, setTimeout(() => forget(schedulePeriodicRun(), {
|
|
76
|
+
name: `schedulePeriodicRun:${this.name}:${timerName}`
|
|
77
|
+
}), periodMs));
|
|
78
|
+
}
|
|
79
|
+
}, "schedulePeriodicRun");
|
|
80
|
+
this._timers.set(timerName, setTimeout(() => forget(schedulePeriodicRun(), {
|
|
81
|
+
name: `schedulePeriodicRun(initial):${this.name}:${timerName}`
|
|
82
|
+
}), dueTimeMs));
|
|
83
|
+
this.logger?.log(`Timer '${this.name}:${timerName}' registered: first call after ${dueTimeMs}ms, recurring every ${periodMs}ms.`);
|
|
84
|
+
}
|
|
85
|
+
span(name, fn) {
|
|
86
|
+
return span(`${this.name}:${name}`, fn, this.tracer);
|
|
87
|
+
}
|
|
88
|
+
async spanAsync(name, fn) {
|
|
89
|
+
return await spanAsync(`${this.name}:${name}`, fn, this.tracer);
|
|
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
|
+
* Called by the Orchestrator when the actor is deactivated.
|
|
101
|
+
* Stop all running timers.
|
|
102
|
+
*/
|
|
103
|
+
async stop() {
|
|
104
|
+
await Promise.resolve();
|
|
105
|
+
this._active = false;
|
|
106
|
+
this.logger?.log("Stopping all timers...");
|
|
107
|
+
for (const [, timerRef] of this._timers.entries()) {
|
|
108
|
+
clearTimeout(timerRef);
|
|
109
|
+
}
|
|
110
|
+
this._timers.clear();
|
|
111
|
+
this.logger?.log("Stopped.");
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/orchestration/actor/model/Orchestrator.ts
|
|
116
|
+
var Orchestrator = class {
|
|
117
|
+
static {
|
|
118
|
+
__name(this, "Orchestrator");
|
|
119
|
+
}
|
|
120
|
+
actors = [];
|
|
121
|
+
keepAliveHandle = null;
|
|
122
|
+
logger;
|
|
123
|
+
running = false;
|
|
124
|
+
constructor(logger) {
|
|
125
|
+
this.logger = logger;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Registers an actor.
|
|
129
|
+
* (We won't activate the actor until `start()` is called.)
|
|
130
|
+
*/
|
|
131
|
+
async registerActor(actor) {
|
|
132
|
+
if (this.running) {
|
|
133
|
+
await actor.start();
|
|
134
|
+
}
|
|
135
|
+
this.actors.push(actor);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Starts the orchestrator: activates all actors.
|
|
139
|
+
*/
|
|
140
|
+
async start() {
|
|
141
|
+
await Promise.resolve();
|
|
142
|
+
if (this.running) {
|
|
143
|
+
this.logger?.warn("[Orchestrator] Already started.");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
this.logger?.log("[Orchestrator] Starting...");
|
|
147
|
+
this.running = true;
|
|
148
|
+
for (const actor of this.actors) {
|
|
149
|
+
await actor.start();
|
|
150
|
+
}
|
|
151
|
+
this.keepAliveHandle = setInterval(() => {
|
|
152
|
+
}, 2147483647);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Stops the orchestrator: deactivates all actors.
|
|
156
|
+
*/
|
|
157
|
+
async stop() {
|
|
158
|
+
await Promise.resolve();
|
|
159
|
+
if (!this.running) {
|
|
160
|
+
this.logger?.log("[Orchestrator] Already stopped.");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.logger?.log("[Orchestrator] Stopping...");
|
|
164
|
+
for (const actor of this.actors) {
|
|
165
|
+
await actor.stop();
|
|
166
|
+
}
|
|
167
|
+
this.running = false;
|
|
168
|
+
if (this.keepAliveHandle) clearInterval(this.keepAliveHandle);
|
|
169
|
+
this.logger?.log("[Orchestrator] Stopped...");
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/orchestration/actor/implementation/BalanceActor.ts
|
|
174
|
+
var BalanceActor = class _BalanceActor extends Actor {
|
|
175
|
+
static {
|
|
176
|
+
__name(this, "BalanceActor");
|
|
177
|
+
}
|
|
178
|
+
_updateMutex = new Mutex();
|
|
179
|
+
constructor(params) {
|
|
180
|
+
super("BalanceActor", "Balance", params);
|
|
181
|
+
}
|
|
182
|
+
get balanceService() {
|
|
183
|
+
return assertEx(this.params.balanceService, () => "balanceService not set");
|
|
184
|
+
}
|
|
185
|
+
get chainIterator() {
|
|
186
|
+
return assertEx(this.params.chainIterator, () => "chainIterator not set");
|
|
187
|
+
}
|
|
188
|
+
static create(params) {
|
|
189
|
+
return new _BalanceActor(params);
|
|
190
|
+
}
|
|
191
|
+
async start() {
|
|
192
|
+
await super.start();
|
|
193
|
+
this.chainIterator.on("headUpdate", async () => {
|
|
194
|
+
await this.updateBalance();
|
|
195
|
+
});
|
|
196
|
+
this.registerTimer("BalanceTimer", async () => {
|
|
197
|
+
await this.updateBalance();
|
|
198
|
+
}, 1e3, 1e3);
|
|
199
|
+
}
|
|
200
|
+
async updateBalance() {
|
|
201
|
+
if (this._updateMutex.isLocked()) return;
|
|
202
|
+
await this._updateMutex.runExclusive(async () => {
|
|
203
|
+
const head = await PayloadBuilder.hash(await this.chainIterator.head());
|
|
204
|
+
await this.balanceService.balances(head, []);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/orchestration/actor/implementation/ChainHeadUpdateActor.ts
|
|
210
|
+
import { filterAs } from "@xylabs/array";
|
|
211
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
212
|
+
import { toHex } from "@xylabs/hex";
|
|
213
|
+
import { findMostRecentBlock, sortBlocks } from "@xyo-network/chain-protocol";
|
|
214
|
+
import { asBlockBoundWitness } from "@xyo-network/xl1-protocol";
|
|
215
|
+
var ChainHeadUpdateActor = class _ChainHeadUpdateActor extends Actor {
|
|
216
|
+
static {
|
|
217
|
+
__name(this, "ChainHeadUpdateActor");
|
|
218
|
+
}
|
|
219
|
+
constructor(params) {
|
|
220
|
+
super("ChainHeadUpdate", "ChainHeadUpdate", params);
|
|
221
|
+
}
|
|
222
|
+
get chainFinalizedArchivist() {
|
|
223
|
+
return assertEx2(this.params.chainArchivist, () => "ChainArchivist not set");
|
|
224
|
+
}
|
|
225
|
+
get chainIterator() {
|
|
226
|
+
return assertEx2(this.params.chainIterator, () => "chainIterator not set");
|
|
227
|
+
}
|
|
228
|
+
static create(params) {
|
|
229
|
+
return new _ChainHeadUpdateActor(params);
|
|
230
|
+
}
|
|
231
|
+
async start() {
|
|
232
|
+
await super.start();
|
|
233
|
+
this.chainFinalizedArchivist.on("inserted", async (data) => {
|
|
234
|
+
await this.checkInsertedForNewHead(data);
|
|
235
|
+
});
|
|
236
|
+
this.registerTimer("ChainHeadUpdateTimer", async () => await this.pollForNewHead(), 0, 250);
|
|
237
|
+
}
|
|
238
|
+
async checkInsertedForNewHead(data) {
|
|
239
|
+
const candidateBlock = sortBlocks(filterAs(data.payloads, asBlockBoundWitness)).at(-1);
|
|
240
|
+
await this.updateHeadIfNewer(candidateBlock);
|
|
241
|
+
}
|
|
242
|
+
async pollForNewHead() {
|
|
243
|
+
const candidateBlock = await findMostRecentBlock(this.chainFinalizedArchivist);
|
|
244
|
+
await this.updateHeadIfNewer(candidateBlock);
|
|
245
|
+
}
|
|
246
|
+
async updateHeadIfNewer(candidateBlock) {
|
|
247
|
+
if (!candidateBlock) return;
|
|
248
|
+
const currentHead = await this.chainIterator.head();
|
|
249
|
+
const candidateBlockNumber = candidateBlock.block;
|
|
250
|
+
const candidateBlockNumberDisplay = `0x${toHex(candidateBlockNumber)}`;
|
|
251
|
+
const currentBlockNumber = currentHead?.block ?? -1;
|
|
252
|
+
if (candidateBlockNumber > currentBlockNumber) {
|
|
253
|
+
this.logger?.log("Found more recent head:", candidateBlockNumberDisplay);
|
|
254
|
+
await this.chainIterator.updateHead(candidateBlock);
|
|
255
|
+
this.logger?.log("Updated head:", candidateBlockNumberDisplay);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// src/orchestration/actor/implementation/ProducerActor.ts
|
|
261
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
262
|
+
import { toHex as toHex2 } from "@xylabs/hex";
|
|
263
|
+
import { isDefined, isUndefined } from "@xylabs/typeof";
|
|
264
|
+
import { createDeclarationIntent } from "@xyo-network/chain-protocol";
|
|
265
|
+
import { BaseBlockProducerService } from "@xyo-network/chain-services";
|
|
266
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
267
|
+
import { PayloadBundleSchema } from "@xyo-network/payload-model";
|
|
268
|
+
import { buildTransaction, flattenHydratedBlock, flattenHydratedTransaction } from "@xyo-network/xl1-protocol-sdk";
|
|
269
|
+
var SHOULD_REGISTER_REDECLARATION_INTENT_TIMER = true;
|
|
270
|
+
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
271
|
+
var ProducerActor = class _ProducerActor extends Actor {
|
|
272
|
+
static {
|
|
273
|
+
__name(this, "ProducerActor");
|
|
274
|
+
}
|
|
275
|
+
_lastProducedBlock;
|
|
276
|
+
_lastRedeclarationIntent;
|
|
277
|
+
constructor(params) {
|
|
278
|
+
super(params.producer.address, "Producer", params);
|
|
279
|
+
}
|
|
280
|
+
get account() {
|
|
281
|
+
return assertEx3(this.params.account, () => "account not set");
|
|
282
|
+
}
|
|
283
|
+
get balanceService() {
|
|
284
|
+
return assertEx3(this.params.balanceService, () => "balanceService not set");
|
|
285
|
+
}
|
|
286
|
+
get chainIterator() {
|
|
287
|
+
return assertEx3(this.params.chainIterator, () => "chainIterator not set");
|
|
288
|
+
}
|
|
289
|
+
get chainStakeViewer() {
|
|
290
|
+
return assertEx3(this.params.chainStakeViewer, () => "chainStakeViewer not set");
|
|
291
|
+
}
|
|
292
|
+
get chainSubmissionsArchivistWrite() {
|
|
293
|
+
return assertEx3(this.params.chainSubmissionsArchivistWrite, () => "chainSubmissionsArchivistWrite not set");
|
|
294
|
+
}
|
|
295
|
+
get pendingBundledTransactionsArchivistWrite() {
|
|
296
|
+
return assertEx3(this.params.pendingBundledTransactionsArchivistWrite, () => "pendingBundledTransactionsArchivistWrite not set");
|
|
297
|
+
}
|
|
298
|
+
get producer() {
|
|
299
|
+
return assertEx3(this.params.producer, () => "producer not set");
|
|
300
|
+
}
|
|
301
|
+
get stakeIntentService() {
|
|
302
|
+
return assertEx3(this.params.stakeIntentService, () => "stakeIntentService not set");
|
|
303
|
+
}
|
|
304
|
+
static create(params) {
|
|
305
|
+
return new _ProducerActor(params);
|
|
306
|
+
}
|
|
307
|
+
async start() {
|
|
308
|
+
await super.start();
|
|
309
|
+
this.registerTimer("BlockProductionTimer", async () => {
|
|
310
|
+
await this.spanAsync("produceBlock", async () => {
|
|
311
|
+
const head = await this.chainIterator.head();
|
|
312
|
+
const headHash = await PayloadBuilder2.hash(head);
|
|
313
|
+
if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {
|
|
314
|
+
this.logger?.log("Block already produced:", `0x${toHex2(this._lastProducedBlock[0].block)}`);
|
|
315
|
+
} else {
|
|
316
|
+
const nextBlock = await this.producer.next(head);
|
|
317
|
+
if (nextBlock) {
|
|
318
|
+
const displayBlockNumber = `0x${toHex2(nextBlock[0].block)}`;
|
|
319
|
+
this.logger?.log("Produced block:", displayBlockNumber);
|
|
320
|
+
await this.chainSubmissionsArchivistWrite.insert(flattenHydratedBlock(nextBlock));
|
|
321
|
+
this.logger?.log("Published block:", displayBlockNumber);
|
|
322
|
+
this._lastProducedBlock = nextBlock;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}, 100, 500);
|
|
327
|
+
if (SHOULD_REGISTER_REDECLARATION_INTENT_TIMER) {
|
|
328
|
+
this.registerTimer("ProducerRedeclarationTimer", async () => {
|
|
329
|
+
await this.spanAsync("producerRedeclarationTimer", async () => {
|
|
330
|
+
if (this.params.config.producer.disableIntentRedeclaration) return;
|
|
331
|
+
const head = await this.chainIterator.head();
|
|
332
|
+
if (isUndefined(head)) return;
|
|
333
|
+
const currentBlock = head.block;
|
|
334
|
+
const blocksUntilExpiration = await this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock);
|
|
335
|
+
if (blocksUntilExpiration > BaseBlockProducerService.RedeclarationWindow * 0.1) {
|
|
336
|
+
this._lastRedeclarationIntent = void 0;
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (this._lastRedeclarationIntent) {
|
|
340
|
+
if (this._lastRedeclarationIntent.exp > currentBlock) return;
|
|
341
|
+
this._lastRedeclarationIntent = void 0;
|
|
342
|
+
}
|
|
343
|
+
if (!await this.validateCurrentBalance()) {
|
|
344
|
+
this.logger?.error(`Add balance to address ${this.account.address} for the producer to declare it's intent.`);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (!await this.validateCurrentStake()) {
|
|
348
|
+
this.logger?.error(`Add stake to contract address ${this.params.config.chain.id} for the producer to declare it's intent.`);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
this.logger?.log("Creating redeclaration intent for producer:", this.account.address);
|
|
352
|
+
const redeclarationIntent = createDeclarationIntent(this.account.address, "producer", currentBlock, currentBlock + BaseBlockProducerService.RedeclarationDuration);
|
|
353
|
+
await this.submitRedeclarationIntent(currentBlock, redeclarationIntent);
|
|
354
|
+
this._lastRedeclarationIntent = redeclarationIntent;
|
|
355
|
+
});
|
|
356
|
+
}, 1e4, TEN_MINUTES);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
async calculateBlocksUntilProducerDeclarationExpiration(currentBlock) {
|
|
360
|
+
const ranges = await this.stakeIntentService.getDeclaredCandidateRanges(this.account.address, "producer");
|
|
361
|
+
const lastRange = ranges.toSorted((a, b) => a[1] > b[1] ? 1 : -1).at(-1);
|
|
362
|
+
const [, currentDeclarationEnd] = lastRange || [
|
|
363
|
+
void 0,
|
|
364
|
+
currentBlock
|
|
365
|
+
];
|
|
366
|
+
const timeToProducerExpiration = currentDeclarationEnd - currentBlock;
|
|
367
|
+
return timeToProducerExpiration;
|
|
368
|
+
}
|
|
369
|
+
async submitRedeclarationIntent(currentBlock, redeclarationIntent) {
|
|
370
|
+
this.logger?.log("Submitting redeclaration intent for producer:", this.account.address);
|
|
371
|
+
const tx = await buildTransaction(this.chainIterator.chainId, [
|
|
372
|
+
redeclarationIntent
|
|
373
|
+
], [], this.account, currentBlock, currentBlock + 1e3);
|
|
374
|
+
const payloads = flattenHydratedTransaction(tx);
|
|
375
|
+
const root = tx[0]._hash;
|
|
376
|
+
const payloadBundle = new PayloadBuilder2({
|
|
377
|
+
schema: PayloadBundleSchema
|
|
378
|
+
}).fields({
|
|
379
|
+
payloads,
|
|
380
|
+
root
|
|
381
|
+
}).build();
|
|
382
|
+
await this.pendingBundledTransactionsArchivistWrite.insert([
|
|
383
|
+
payloadBundle
|
|
384
|
+
]);
|
|
385
|
+
this.logger?.log("Submitted redeclaration intent for producer:", this.account.address);
|
|
386
|
+
}
|
|
387
|
+
async validateCurrentBalance() {
|
|
388
|
+
const head = this._lastProducedBlock?.[0]._hash;
|
|
389
|
+
if (isDefined(head)) {
|
|
390
|
+
const balances = await this.balanceService.balances(head, [
|
|
391
|
+
this.account.address
|
|
392
|
+
]);
|
|
393
|
+
const currentBalance = balances[this.account.address] ?? 0n;
|
|
394
|
+
if (currentBalance <= 0n) {
|
|
395
|
+
this.logger?.error(`Producer ${this.account.address} has no balance.`);
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
async validateCurrentStake() {
|
|
403
|
+
const requiredMinimumStake = this.stakeIntentService.getRequiredMinimumStakeForIntent("producer");
|
|
404
|
+
const currentStake = await this.chainStakeViewer.activeByAddressStaked(this.account.address);
|
|
405
|
+
if (currentStake < requiredMinimumStake) {
|
|
406
|
+
this.logger?.error(`Producer ${this.account.address} has insufficient stake.`);
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// src/orchestration/health/initHealthEndpoints.ts
|
|
414
|
+
import http from "http";
|
|
415
|
+
import { isDefined as isDefined2 } from "@xylabs/typeof";
|
|
416
|
+
var sendStatus = /* @__PURE__ */ __name((res, status, errorCode) => {
|
|
417
|
+
const statusCode = status === "started" ? 200 : errorCode;
|
|
418
|
+
res.writeHead(statusCode, {
|
|
419
|
+
"Content-Type": "application/json"
|
|
420
|
+
});
|
|
421
|
+
res.end(JSON.stringify({
|
|
422
|
+
status
|
|
423
|
+
}));
|
|
424
|
+
}, "sendStatus");
|
|
425
|
+
var notFound = /* @__PURE__ */ __name((res) => {
|
|
426
|
+
res.writeHead(404, {
|
|
427
|
+
"Content-Type": "application/json"
|
|
428
|
+
});
|
|
429
|
+
res.end(JSON.stringify({
|
|
430
|
+
status: "not found"
|
|
431
|
+
}));
|
|
432
|
+
}, "notFound");
|
|
433
|
+
var createHealthServer = /* @__PURE__ */ __name((port, statusMonitor, logger) => {
|
|
434
|
+
const server = http.createServer((req, res) => {
|
|
435
|
+
const url = req.url ?? "";
|
|
436
|
+
const status = statusMonitor.getGlobalStatus();
|
|
437
|
+
switch (url) {
|
|
438
|
+
case "/healthz": {
|
|
439
|
+
sendStatus(res, status, 500);
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
case "/livez": {
|
|
443
|
+
sendStatus(res, status, 503);
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
case "/readyz": {
|
|
447
|
+
sendStatus(res, status, 503);
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
default: {
|
|
451
|
+
notFound(res);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
server.listen(port, () => {
|
|
456
|
+
logger.log(`Health server running on http://localhost:${port}`);
|
|
457
|
+
logger.log(" - /healthz");
|
|
458
|
+
logger.log(" - /livez");
|
|
459
|
+
logger.log(" - /readyz");
|
|
460
|
+
});
|
|
461
|
+
return server;
|
|
462
|
+
}, "createHealthServer");
|
|
463
|
+
var initHealthEndpoints = /* @__PURE__ */ __name((params) => {
|
|
464
|
+
const { config: config3, logger, statusReporter } = params;
|
|
465
|
+
const { healthCheckPort } = config3.producer;
|
|
466
|
+
return isDefined2(healthCheckPort) ? createHealthServer(healthCheckPort, statusReporter, logger) : void 0;
|
|
467
|
+
}, "initHealthEndpoints");
|
|
468
|
+
|
|
469
|
+
// src/orchestration/initServices.ts
|
|
470
|
+
import { assertEx as assertEx16 } from "@xylabs/assert";
|
|
471
|
+
import { asAddress as asAddress2 } from "@xylabs/hex";
|
|
472
|
+
import { isDefined as isDefined9 } from "@xylabs/typeof";
|
|
473
|
+
import { balanceSummaryRepositoryFromMap } from "@xyo-network/chain-modules";
|
|
474
|
+
import { initTelemetry } from "@xyo-network/chain-telemetry";
|
|
475
|
+
import { startupSpanAsync as startupSpanAsync7 } from "@xyo-network/chain-utils";
|
|
476
|
+
import { validateHydratedBlockState } from "@xyo-network/chain-validation";
|
|
477
|
+
|
|
478
|
+
// src/orchestration/archivists/ChainFinalized/archivist.ts
|
|
479
|
+
import { initArchivistSync } from "@xyo-network/chain-orchestration";
|
|
480
|
+
import { startupSpanAsync } from "@xyo-network/chain-utils";
|
|
481
|
+
import { Mutex as Mutex4 } from "async-mutex";
|
|
482
|
+
|
|
483
|
+
// src/orchestration/archivists/ChainFinalized/local.ts
|
|
484
|
+
import { Mutex as Mutex2 } from "async-mutex";
|
|
485
|
+
|
|
486
|
+
// src/orchestration/archivists/lib/localPersistentArchivist.ts
|
|
487
|
+
import { rm } from "fs/promises";
|
|
488
|
+
import Path2 from "path";
|
|
489
|
+
import { LmdbArchivist, LmdbArchivistConfigSchema } from "@xyo-network/archivist-lmdb";
|
|
490
|
+
|
|
491
|
+
// src/orchestration/store/getStoreDirectory.ts
|
|
492
|
+
import Path from "path";
|
|
493
|
+
var getStoreDirectory = /* @__PURE__ */ __name((name, storageRoot, kind) => {
|
|
494
|
+
return kind === void 0 ? Path.join(storageRoot, name) : Path.join(storageRoot, kind, name);
|
|
495
|
+
}, "getStoreDirectory");
|
|
496
|
+
|
|
497
|
+
// src/orchestration/archivists/lib/localPersistentArchivist.ts
|
|
498
|
+
var DEFAULT_STORAGE_ROOT = Path2.join(process.cwd(), ".store");
|
|
499
|
+
var getLocalPersistentArchivist = /* @__PURE__ */ __name((dbName, storeName, storageRoot, kind = "lmdb") => {
|
|
500
|
+
switch (kind) {
|
|
501
|
+
case "lmdb": {
|
|
502
|
+
const root = storageRoot ?? DEFAULT_STORAGE_ROOT;
|
|
503
|
+
return LmdbArchivist.create({
|
|
504
|
+
account: "random",
|
|
505
|
+
config: {
|
|
506
|
+
clearStoreOnStart: false,
|
|
507
|
+
dbName,
|
|
508
|
+
location: getStoreDirectory(dbName, root, "lmdb"),
|
|
509
|
+
schema: LmdbArchivistConfigSchema,
|
|
510
|
+
storeName
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}, "getLocalPersistentArchivist");
|
|
516
|
+
|
|
517
|
+
// src/orchestration/archivists/ChainFinalized/local.ts
|
|
518
|
+
var mutex = new Mutex2();
|
|
519
|
+
var singleton;
|
|
520
|
+
var initLocalChainFinalizedArchivist = /* @__PURE__ */ __name(async ({ config: config3 }) => {
|
|
521
|
+
return await mutex.runExclusive(async () => {
|
|
522
|
+
if (singleton) return singleton;
|
|
523
|
+
const { root } = config3.storage;
|
|
524
|
+
singleton = await getLocalPersistentArchivist("chain", "finalized", root);
|
|
525
|
+
return singleton;
|
|
526
|
+
});
|
|
527
|
+
}, "initLocalChainFinalizedArchivist");
|
|
528
|
+
|
|
529
|
+
// src/orchestration/archivists/ChainFinalized/remote.ts
|
|
530
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
531
|
+
import { initBridge, initBridgedArchivistModule } from "@xyo-network/chain-orchestration";
|
|
532
|
+
import { getUrl } from "@xyo-network/xl1-protocol-sdk";
|
|
533
|
+
import { Mutex as Mutex3 } from "async-mutex";
|
|
534
|
+
var mutex2 = new Mutex3();
|
|
535
|
+
var singleton2;
|
|
536
|
+
var initRemoteChainFinalizedArchivist = /* @__PURE__ */ __name(async ({ config: config3 }) => {
|
|
537
|
+
return await mutex2.runExclusive(async () => {
|
|
538
|
+
if (singleton2) return singleton2;
|
|
539
|
+
const { host, port } = config3.api;
|
|
540
|
+
const nodeUrl = getUrl(host, port);
|
|
541
|
+
const bridge = await initBridge(nodeUrl);
|
|
542
|
+
singleton2 = await initBridgedArchivistModule({
|
|
543
|
+
bridge,
|
|
544
|
+
moduleName: "XYOChain:Chain:Finalized"
|
|
545
|
+
});
|
|
546
|
+
return assertEx4(singleton2, () => "Error: RemoteChainFinalizedArchivist failed to initialize");
|
|
547
|
+
});
|
|
548
|
+
}, "initRemoteChainFinalizedArchivist");
|
|
549
|
+
|
|
550
|
+
// src/orchestration/archivists/ChainFinalized/archivist.ts
|
|
551
|
+
var mutex3 = new Mutex4();
|
|
552
|
+
var singleton3;
|
|
553
|
+
async function initChainFinalizedArchivist({ config: config3, logger, traceProvider }) {
|
|
554
|
+
return await mutex3.runExclusive(async () => {
|
|
555
|
+
if (singleton3) return singleton3;
|
|
556
|
+
const [remote, local] = await Promise.all([
|
|
557
|
+
startupSpanAsync("ChainFinalizedArchivist:initRemote", () => initRemoteChainFinalizedArchivist({
|
|
558
|
+
config: config3,
|
|
559
|
+
logger
|
|
560
|
+
})),
|
|
561
|
+
startupSpanAsync("ChainFinalizedArchivist:initLocal", () => initLocalChainFinalizedArchivist({
|
|
562
|
+
config: config3,
|
|
563
|
+
logger
|
|
564
|
+
}))
|
|
565
|
+
]);
|
|
566
|
+
await startupSpanAsync("ChainFinalizedArchivist:initArchivistSync", () => initArchivistSync("ChainFinalizedArchivist", remote, local, 200, Number.MAX_SAFE_INTEGER, traceProvider));
|
|
567
|
+
singleton3 = local;
|
|
568
|
+
return singleton3;
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
__name(initChainFinalizedArchivist, "initChainFinalizedArchivist");
|
|
572
|
+
|
|
573
|
+
// src/orchestration/archivists/ChainSubmissions/archivist.ts
|
|
574
|
+
import { assertEx as assertEx6 } from "@xylabs/assert";
|
|
575
|
+
import { startupSpanAsync as startupSpanAsync2 } from "@xyo-network/chain-utils";
|
|
576
|
+
import { Mutex as Mutex6 } from "async-mutex";
|
|
577
|
+
|
|
578
|
+
// src/orchestration/archivists/ChainSubmissions/remote.ts
|
|
579
|
+
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
580
|
+
import { initBridge as initBridge2, initBridgedArchivistModule as initBridgedArchivistModule2 } from "@xyo-network/chain-orchestration";
|
|
581
|
+
import { getUrl as getUrl2 } from "@xyo-network/xl1-protocol-sdk";
|
|
582
|
+
import { Mutex as Mutex5 } from "async-mutex";
|
|
583
|
+
var mutex4 = new Mutex5();
|
|
584
|
+
var singleton4;
|
|
585
|
+
var initRemoteChainSubmissionsArchivist = /* @__PURE__ */ __name(async ({ config: config3 }) => {
|
|
586
|
+
return await mutex4.runExclusive(async () => {
|
|
587
|
+
if (singleton4) return singleton4;
|
|
588
|
+
const { host, port } = config3.api;
|
|
589
|
+
const nodeUrl = getUrl2(host, port);
|
|
590
|
+
const bridge = await initBridge2(nodeUrl);
|
|
591
|
+
singleton4 = await initBridgedArchivistModule2({
|
|
592
|
+
bridge,
|
|
593
|
+
moduleName: "XYOChain:Chain:Submissions"
|
|
594
|
+
});
|
|
595
|
+
return assertEx5(singleton4, () => new Error("Failed to initialize RemoteChainSubmissionsArchivist"));
|
|
596
|
+
});
|
|
597
|
+
}, "initRemoteChainSubmissionsArchivist");
|
|
598
|
+
|
|
599
|
+
// src/orchestration/archivists/ChainSubmissions/archivist.ts
|
|
600
|
+
var mutex5 = new Mutex6();
|
|
601
|
+
var singleton5;
|
|
602
|
+
var initChainSubmissionsArchivist = /* @__PURE__ */ __name(async (params) => {
|
|
603
|
+
return await mutex5.runExclusive(async () => {
|
|
604
|
+
if (singleton5) return singleton5;
|
|
605
|
+
const remote = await startupSpanAsync2("ChainSubmissionsArchivist:initRemote", () => initRemoteChainSubmissionsArchivist(params));
|
|
606
|
+
singleton5 = remote;
|
|
607
|
+
return assertEx6(singleton5, () => new Error("Failed to initialize ChainSubmissionsArchivist"));
|
|
608
|
+
});
|
|
609
|
+
}, "initChainSubmissionsArchivist");
|
|
610
|
+
|
|
611
|
+
// src/orchestration/archivists/PendingTransactions/archivist.ts
|
|
612
|
+
import { initArchivistSync as initArchivistSync2 } from "@xyo-network/chain-orchestration";
|
|
613
|
+
import { startupSpanAsync as startupSpanAsync3 } from "@xyo-network/chain-utils";
|
|
614
|
+
import { Mutex as Mutex9 } from "async-mutex";
|
|
615
|
+
|
|
616
|
+
// src/orchestration/archivists/PendingTransactions/local.ts
|
|
617
|
+
import { MemoryArchivist, MemoryArchivistConfigSchema } from "@xyo-network/archivist-memory";
|
|
618
|
+
import { Mutex as Mutex7 } from "async-mutex";
|
|
619
|
+
var mutex6 = new Mutex7();
|
|
620
|
+
var singleton6;
|
|
621
|
+
var initLocalPendingTransactionsArchivist = /* @__PURE__ */ __name(async () => {
|
|
622
|
+
return await mutex6.runExclusive(async () => {
|
|
623
|
+
if (singleton6) return singleton6;
|
|
624
|
+
singleton6 = await MemoryArchivist.create({
|
|
625
|
+
account: "random",
|
|
626
|
+
config: {
|
|
627
|
+
schema: MemoryArchivistConfigSchema,
|
|
628
|
+
max: 1e3,
|
|
629
|
+
name: "localPendingTransactions"
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
return singleton6;
|
|
633
|
+
});
|
|
634
|
+
}, "initLocalPendingTransactionsArchivist");
|
|
635
|
+
|
|
636
|
+
// src/orchestration/archivists/PendingTransactions/remote.ts
|
|
637
|
+
import { assertEx as assertEx7 } from "@xylabs/assert";
|
|
638
|
+
import { initBridge as initBridge3, initBridgedArchivistModule as initBridgedArchivistModule3 } from "@xyo-network/chain-orchestration";
|
|
639
|
+
import { getUrl as getUrl3 } from "@xyo-network/xl1-protocol-sdk";
|
|
640
|
+
import { Mutex as Mutex8 } from "async-mutex";
|
|
641
|
+
var mutex7 = new Mutex8();
|
|
642
|
+
var singleton7;
|
|
643
|
+
var initRemotePendingTransactionsArchivist = /* @__PURE__ */ __name(async ({ config: config3 }) => {
|
|
644
|
+
return await mutex7.runExclusive(async () => {
|
|
645
|
+
if (singleton7) return singleton7;
|
|
646
|
+
const { host, port } = config3.api;
|
|
647
|
+
const nodeUrl = getUrl3(host, port);
|
|
648
|
+
const bridge = await initBridge3(nodeUrl);
|
|
649
|
+
singleton7 = await initBridgedArchivistModule3({
|
|
650
|
+
bridge,
|
|
651
|
+
moduleName: "XYOChain:Pending:PendingTransactions"
|
|
652
|
+
});
|
|
653
|
+
return assertEx7(singleton7, () => "Error: RemotePendingBundledTransactionsArchivist is undefined");
|
|
654
|
+
});
|
|
655
|
+
}, "initRemotePendingTransactionsArchivist");
|
|
656
|
+
|
|
657
|
+
// src/orchestration/archivists/PendingTransactions/archivist.ts
|
|
658
|
+
var mutex8 = new Mutex9();
|
|
659
|
+
var singleton8;
|
|
660
|
+
var initPendingBundledTransactionsArchivist = /* @__PURE__ */ __name(async (params) => {
|
|
661
|
+
return await mutex8.runExclusive(async () => {
|
|
662
|
+
if (singleton8) return singleton8;
|
|
663
|
+
const remote = await startupSpanAsync3("PendingBundledTransactionsArchivist:initRemote", () => initRemotePendingTransactionsArchivist(params));
|
|
664
|
+
const local = await startupSpanAsync3("PendingBundledTransactionsArchivist:initLocal", () => initLocalPendingTransactionsArchivist(params));
|
|
665
|
+
const start2 = await remote.next({
|
|
666
|
+
limit: 1,
|
|
667
|
+
order: "desc"
|
|
668
|
+
});
|
|
669
|
+
await local.insert(start2);
|
|
670
|
+
await startupSpanAsync3("PendingBundledTransactionsArchivist:initArchivistSync", () => initArchivistSync2("PendingBundledTransactionsArchivist", remote, local));
|
|
671
|
+
singleton8 = [
|
|
672
|
+
local,
|
|
673
|
+
remote
|
|
674
|
+
];
|
|
675
|
+
return singleton8;
|
|
676
|
+
});
|
|
677
|
+
}, "initPendingBundledTransactionsArchivist");
|
|
678
|
+
|
|
679
|
+
// src/orchestration/archivists/RejectedTransactions/archivist.ts
|
|
680
|
+
import { startupSpanAsync as startupSpanAsync4 } from "@xyo-network/chain-utils";
|
|
681
|
+
import { Mutex as Mutex11 } from "async-mutex";
|
|
682
|
+
|
|
683
|
+
// src/orchestration/archivists/RejectedTransactions/local.ts
|
|
684
|
+
import { MemoryArchivist as MemoryArchivist2, MemoryArchivistConfigSchema as MemoryArchivistConfigSchema2 } from "@xyo-network/archivist-memory";
|
|
685
|
+
import { Mutex as Mutex10 } from "async-mutex";
|
|
686
|
+
var mutex9 = new Mutex10();
|
|
687
|
+
var singleton9;
|
|
688
|
+
var initLocalRejectedTransactionsArchivist = /* @__PURE__ */ __name(async () => {
|
|
689
|
+
return await mutex9.runExclusive(async () => {
|
|
690
|
+
if (singleton9) return singleton9;
|
|
691
|
+
singleton9 = await MemoryArchivist2.create({
|
|
692
|
+
account: "random",
|
|
693
|
+
config: {
|
|
694
|
+
schema: MemoryArchivistConfigSchema2,
|
|
695
|
+
max: 1e3,
|
|
696
|
+
name: "localRejectedTransactions"
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
return singleton9;
|
|
700
|
+
});
|
|
701
|
+
}, "initLocalRejectedTransactionsArchivist");
|
|
702
|
+
|
|
703
|
+
// src/orchestration/archivists/RejectedTransactions/archivist.ts
|
|
704
|
+
var mutex10 = new Mutex11();
|
|
705
|
+
var singleton10;
|
|
706
|
+
async function initRejectedTransactionsArchivist(params) {
|
|
707
|
+
return await mutex10.runExclusive(async () => {
|
|
708
|
+
if (singleton10) return singleton10;
|
|
709
|
+
const local = await startupSpanAsync4("RejectedTransactionsArchivist:initLocal", () => initLocalRejectedTransactionsArchivist(params));
|
|
710
|
+
singleton10 = local;
|
|
711
|
+
return singleton10;
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
__name(initRejectedTransactionsArchivist, "initRejectedTransactionsArchivist");
|
|
715
|
+
|
|
716
|
+
// src/orchestration/archivists/StakeIntentState/archivist.ts
|
|
717
|
+
import { assertEx as assertEx9 } from "@xylabs/assert";
|
|
718
|
+
import { startupSpanAsync as startupSpanAsync5 } from "@xyo-network/chain-utils";
|
|
719
|
+
import { Mutex as Mutex13 } from "async-mutex";
|
|
720
|
+
|
|
721
|
+
// src/orchestration/archivists/StakeIntentState/local.ts
|
|
722
|
+
import { assertEx as assertEx8 } from "@xylabs/assert";
|
|
723
|
+
import { Mutex as Mutex12 } from "async-mutex";
|
|
724
|
+
var mutex11 = new Mutex12();
|
|
725
|
+
var singleton11;
|
|
726
|
+
var initLocalStakeIntentStateArchivist = /* @__PURE__ */ __name(async ({ config: config3 }) => {
|
|
727
|
+
return await mutex11.runExclusive(async () => {
|
|
728
|
+
if (singleton11) return singleton11;
|
|
729
|
+
const { root } = config3.storage;
|
|
730
|
+
singleton11 = await getLocalPersistentArchivist("stakeIntent", "state", root);
|
|
731
|
+
return assertEx8(singleton11, () => new Error("Failed to initialize stake intent state archivist"));
|
|
732
|
+
});
|
|
733
|
+
}, "initLocalStakeIntentStateArchivist");
|
|
734
|
+
|
|
735
|
+
// src/orchestration/archivists/StakeIntentState/archivist.ts
|
|
736
|
+
var mutex12 = new Mutex13();
|
|
737
|
+
var singleton12;
|
|
738
|
+
var initStakeIntentStateArchivist = /* @__PURE__ */ __name(async (params) => {
|
|
739
|
+
return await mutex12.runExclusive(async () => {
|
|
740
|
+
if (singleton12) return singleton12;
|
|
741
|
+
const local = await startupSpanAsync5("StakeIntentStateArchivist:initLocal", () => initLocalStakeIntentStateArchivist(params));
|
|
742
|
+
singleton12 = local;
|
|
743
|
+
return assertEx9(singleton12, () => "Error: StakeIntentStateArchivist is undefined");
|
|
744
|
+
});
|
|
745
|
+
}, "initStakeIntentStateArchivist");
|
|
746
|
+
|
|
747
|
+
// src/orchestration/map/BalanceSummary/initBalanceSummaryMap.ts
|
|
748
|
+
import { isDefined as isDefined4 } from "@xylabs/typeof";
|
|
749
|
+
import { startupSpanAsync as startupSpanAsync6 } from "@xyo-network/chain-utils";
|
|
750
|
+
import { Mutex as Mutex15 } from "async-mutex";
|
|
751
|
+
|
|
752
|
+
// src/orchestration/map/BalanceSummary/local.ts
|
|
753
|
+
import { isDefined as isDefined3 } from "@xylabs/typeof";
|
|
754
|
+
import { Mutex as Mutex14 } from "async-mutex";
|
|
755
|
+
|
|
756
|
+
// src/orchestration/map/localPersistentMap.ts
|
|
757
|
+
import { rm as rm2 } from "fs/promises";
|
|
758
|
+
import Path3 from "path";
|
|
759
|
+
|
|
760
|
+
// src/orchestration/map/driver/lmdb/SynchronousLmdbMap.ts
|
|
761
|
+
import { AbstractCreatable, creatable } from "@xylabs/creatable";
|
|
762
|
+
import { open } from "lmdb";
|
|
763
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
764
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
765
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
766
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
767
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
768
|
+
}
|
|
769
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
770
|
+
var SynchronousLmdbMap = class extends AbstractCreatable {
|
|
771
|
+
static {
|
|
772
|
+
__name(this, "SynchronousLmdbMap");
|
|
773
|
+
}
|
|
774
|
+
db;
|
|
775
|
+
rootDatabase;
|
|
776
|
+
/**
|
|
777
|
+
* The path to the LMDB folder where the database is stored.
|
|
778
|
+
* This is constructed from the location and dbName parameters
|
|
779
|
+
* allowing for multiple DBs within the root (by specifying a
|
|
780
|
+
* different storeName).
|
|
781
|
+
* @returns The folder path for the LMDB database.
|
|
782
|
+
*/
|
|
783
|
+
get folderPath() {
|
|
784
|
+
return `${this.params.location}/${this.params.dbName}`;
|
|
785
|
+
}
|
|
786
|
+
all() {
|
|
787
|
+
return [
|
|
788
|
+
...this.db.getRange({})
|
|
789
|
+
].map((entry) => entry.value);
|
|
790
|
+
}
|
|
791
|
+
clear() {
|
|
792
|
+
this.db.clearSync();
|
|
793
|
+
}
|
|
794
|
+
delete(id) {
|
|
795
|
+
return this.db.removeSync(id);
|
|
796
|
+
}
|
|
797
|
+
get(id) {
|
|
798
|
+
return this.db.get(id);
|
|
799
|
+
}
|
|
800
|
+
has(id) {
|
|
801
|
+
return this.db.doesExist(id);
|
|
802
|
+
}
|
|
803
|
+
set(id, data) {
|
|
804
|
+
this.db.putSync(id, data);
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
async startHandler() {
|
|
808
|
+
await super.startHandler();
|
|
809
|
+
this.rootDatabase = open({
|
|
810
|
+
path: this.folderPath
|
|
811
|
+
});
|
|
812
|
+
this.db = this.rootDatabase.openDB({
|
|
813
|
+
name: this.params.storeName
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
SynchronousLmdbMap = _ts_decorate([
|
|
818
|
+
creatable()
|
|
819
|
+
], SynchronousLmdbMap);
|
|
820
|
+
|
|
821
|
+
// src/orchestration/map/localPersistentMap.ts
|
|
822
|
+
var DEFAULT_STORAGE_ROOT2 = Path3.join(process.cwd(), ".store");
|
|
823
|
+
var getLocalPersistentMap = /* @__PURE__ */ __name(async (dbName, storeName, storageRoot, kind = "lmdb") => {
|
|
824
|
+
switch (kind) {
|
|
825
|
+
case "lmdb": {
|
|
826
|
+
const root = storageRoot ?? DEFAULT_STORAGE_ROOT2;
|
|
827
|
+
const location = getStoreDirectory(dbName, root, "lmdb");
|
|
828
|
+
const store = await SynchronousLmdbMap.create({
|
|
829
|
+
location,
|
|
830
|
+
dbName,
|
|
831
|
+
storeName
|
|
832
|
+
});
|
|
833
|
+
return store;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}, "getLocalPersistentMap");
|
|
837
|
+
|
|
838
|
+
// src/orchestration/map/BalanceSummary/local.ts
|
|
839
|
+
var mutex13 = new Mutex14();
|
|
840
|
+
var singleton13;
|
|
841
|
+
var initLocalBalanceSummaryMap = /* @__PURE__ */ __name(async (params) => {
|
|
842
|
+
return await mutex13.runExclusive(async () => {
|
|
843
|
+
if (isDefined3(singleton13)) return singleton13;
|
|
844
|
+
const { root } = params.config.storage;
|
|
845
|
+
singleton13 = await getLocalPersistentMap("balance", "summary", root);
|
|
846
|
+
return singleton13;
|
|
847
|
+
});
|
|
848
|
+
}, "initLocalBalanceSummaryMap");
|
|
849
|
+
|
|
850
|
+
// src/orchestration/map/BalanceSummary/initBalanceSummaryMap.ts
|
|
851
|
+
var mutex14 = new Mutex15();
|
|
852
|
+
var singleton14;
|
|
853
|
+
async function initBalanceSummaryMap(params) {
|
|
854
|
+
return await mutex14.runExclusive(async () => {
|
|
855
|
+
if (isDefined4(singleton14)) return singleton14;
|
|
856
|
+
const local = await startupSpanAsync6("BalanceSummaryMap:initLocal", () => initLocalBalanceSummaryMap(params));
|
|
857
|
+
singleton14 = local;
|
|
858
|
+
return singleton14;
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
__name(initBalanceSummaryMap, "initBalanceSummaryMap");
|
|
862
|
+
|
|
863
|
+
// src/orchestration/services/implementation/account.ts
|
|
864
|
+
import { isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
865
|
+
import { ADDRESS_INDEX, generateXyoBaseWalletFromPhrase } from "@xyo-network/chain-protocol";
|
|
866
|
+
import { HDWallet } from "@xyo-network/wallet";
|
|
867
|
+
var accountServiceSingleton;
|
|
868
|
+
var initAccount = /* @__PURE__ */ __name(async ({ config: config3, logger }) => {
|
|
869
|
+
if (accountServiceSingleton) return accountServiceSingleton;
|
|
870
|
+
let walletPhrase = config3.producer.mnemonic;
|
|
871
|
+
if (isUndefined2(walletPhrase)) {
|
|
872
|
+
logger?.log("No wallet mnemonic specified!");
|
|
873
|
+
const randomMnemonic = HDWallet.generateMnemonic();
|
|
874
|
+
logger?.log(`Using randomly generated mnemonic: ${randomMnemonic}`);
|
|
875
|
+
walletPhrase = randomMnemonic;
|
|
876
|
+
}
|
|
877
|
+
const wallet = await generateXyoBaseWalletFromPhrase(walletPhrase);
|
|
878
|
+
const account = await wallet.derivePath(ADDRESS_INDEX.XYO);
|
|
879
|
+
accountServiceSingleton = account;
|
|
880
|
+
return accountServiceSingleton;
|
|
881
|
+
}, "initAccount");
|
|
882
|
+
|
|
883
|
+
// src/orchestration/services/implementation/balance.ts
|
|
884
|
+
import { BaseAccountBalanceService } from "@xyo-network/chain-services";
|
|
885
|
+
var balanceServiceSingleton;
|
|
886
|
+
var initBalanceService = /* @__PURE__ */ __name(async (params) => {
|
|
887
|
+
if (balanceServiceSingleton) return balanceServiceSingleton;
|
|
888
|
+
balanceServiceSingleton = await BaseAccountBalanceService.create(params);
|
|
889
|
+
return balanceServiceSingleton;
|
|
890
|
+
}, "initBalanceService");
|
|
891
|
+
|
|
892
|
+
// src/orchestration/services/implementation/chain/index.ts
|
|
893
|
+
import { MemoryChainService } from "@xyo-network/chain-services";
|
|
894
|
+
|
|
895
|
+
// src/orchestration/services/implementation/chain/evm.ts
|
|
896
|
+
import { assertEx as assertEx14 } from "@xylabs/assert";
|
|
897
|
+
import { asAddress, ZERO_ADDRESS } from "@xylabs/hex";
|
|
898
|
+
import { isDefined as isDefined8 } from "@xylabs/typeof";
|
|
899
|
+
import { EvmChainService } from "@xyo-network/chain-services";
|
|
900
|
+
import { Wallet } from "ethers/wallet";
|
|
901
|
+
|
|
902
|
+
// src/orchestration/services/implementation/evm/initEvmProvider.ts
|
|
903
|
+
import { assertEx as assertEx13 } from "@xylabs/assert";
|
|
904
|
+
|
|
905
|
+
// src/orchestration/services/implementation/evm/initInfuraProvider.ts
|
|
906
|
+
import { assertEx as assertEx11 } from "@xylabs/assert";
|
|
907
|
+
import { isDefined as isDefined6 } from "@xylabs/typeof";
|
|
908
|
+
import { InfuraProvider } from "ethers/providers";
|
|
909
|
+
|
|
910
|
+
// src/orchestration/services/implementation/evm/initChainId.ts
|
|
911
|
+
import { assertEx as assertEx10 } from "@xylabs/assert";
|
|
912
|
+
import { hexFrom, isHex } from "@xylabs/hex";
|
|
913
|
+
import { isDefined as isDefined5 } from "@xylabs/typeof";
|
|
914
|
+
var canUseChainId = /* @__PURE__ */ __name((config3) => {
|
|
915
|
+
return isDefined5(config3.evm.chainId);
|
|
916
|
+
}, "canUseChainId");
|
|
917
|
+
var getChainId = /* @__PURE__ */ __name((config3) => {
|
|
918
|
+
const chainId = assertEx10(config3.evm.chainId, () => "Missing config.evm.chainId");
|
|
919
|
+
if (isHex(chainId, {
|
|
920
|
+
prefix: true
|
|
921
|
+
})) {
|
|
922
|
+
const hex = hexFrom(chainId);
|
|
923
|
+
const parsed = Number.parseInt(hex, 16);
|
|
924
|
+
return parsed;
|
|
925
|
+
} else {
|
|
926
|
+
const parsed = Number.parseInt(chainId, 10);
|
|
927
|
+
return parsed;
|
|
928
|
+
}
|
|
929
|
+
}, "getChainId");
|
|
930
|
+
|
|
931
|
+
// src/orchestration/services/implementation/evm/initInfuraProvider.ts
|
|
932
|
+
var instance;
|
|
933
|
+
var initInfuraProvider = /* @__PURE__ */ __name((config3) => {
|
|
934
|
+
if (instance) return instance;
|
|
935
|
+
const providerConfig = getInfuraProviderConfig(config3);
|
|
936
|
+
instance = Promise.resolve(new InfuraProvider(...providerConfig));
|
|
937
|
+
return instance;
|
|
938
|
+
}, "initInfuraProvider");
|
|
939
|
+
var canUseInfuraProvider = /* @__PURE__ */ __name((config3) => {
|
|
940
|
+
return canUseChainId(config3) && isDefined6(config3.evm?.infura?.projectId) && isDefined6(config3.evm?.infura?.projectSecret);
|
|
941
|
+
}, "canUseInfuraProvider");
|
|
942
|
+
var getInfuraProviderConfig = /* @__PURE__ */ __name((config3) => {
|
|
943
|
+
const projectId = assertEx11(config3.evm?.infura?.projectId, () => "Missing config.evm.infura.projectId");
|
|
944
|
+
const projectSecret = assertEx11(config3.evm?.infura?.projectSecret, () => "Missing config.evm.infura.projectSecret");
|
|
945
|
+
return [
|
|
946
|
+
getChainId(config3),
|
|
947
|
+
projectId,
|
|
948
|
+
projectSecret
|
|
949
|
+
];
|
|
950
|
+
}, "getInfuraProviderConfig");
|
|
951
|
+
|
|
952
|
+
// src/orchestration/services/implementation/evm/initJsonRpcProvider.ts
|
|
953
|
+
import { assertEx as assertEx12 } from "@xylabs/assert";
|
|
954
|
+
import { isDefined as isDefined7 } from "@xylabs/typeof";
|
|
955
|
+
import { JsonRpcProvider } from "ethers/providers";
|
|
956
|
+
var initJsonRpcProvider = /* @__PURE__ */ __name((config3) => {
|
|
957
|
+
const providerConfig = getJsonRpcProviderConfig(config3);
|
|
958
|
+
return Promise.resolve(new JsonRpcProvider(...providerConfig));
|
|
959
|
+
}, "initJsonRpcProvider");
|
|
960
|
+
var canUseJsonRpcProvider = /* @__PURE__ */ __name((config3) => {
|
|
961
|
+
return canUseChainId(config3) && isDefined7(config3.evm.jsonRpc?.url);
|
|
962
|
+
}, "canUseJsonRpcProvider");
|
|
963
|
+
var getJsonRpcProviderConfig = /* @__PURE__ */ __name((config3) => {
|
|
964
|
+
const jsonRpcUrl = assertEx12(config3.evm.jsonRpc?.url, () => "Missing config.evm.jsonRpc.url");
|
|
965
|
+
return [
|
|
966
|
+
jsonRpcUrl,
|
|
967
|
+
getChainId(config3)
|
|
968
|
+
];
|
|
969
|
+
}, "getJsonRpcProviderConfig");
|
|
970
|
+
|
|
971
|
+
// src/orchestration/services/implementation/evm/initEvmProvider.ts
|
|
972
|
+
var provider;
|
|
973
|
+
var initEvmProvider = /* @__PURE__ */ __name(async ({ config: config3 }) => {
|
|
974
|
+
if (provider) return provider;
|
|
975
|
+
if (canUseInfuraProvider(config3)) {
|
|
976
|
+
provider = initInfuraProvider(config3);
|
|
977
|
+
} else if (canUseJsonRpcProvider(config3)) {
|
|
978
|
+
provider = initJsonRpcProvider(config3);
|
|
979
|
+
}
|
|
980
|
+
return assertEx13(await provider, () => "Error: No provider available");
|
|
981
|
+
}, "initEvmProvider");
|
|
982
|
+
var canUseEvmProvider = /* @__PURE__ */ __name(({ config: config3 }) => {
|
|
983
|
+
return canUseInfuraProvider(config3) || canUseJsonRpcProvider(config3);
|
|
984
|
+
}, "canUseEvmProvider");
|
|
985
|
+
|
|
986
|
+
// src/orchestration/services/implementation/chain/evm.ts
|
|
987
|
+
var chainStakeServiceSingleton;
|
|
988
|
+
var canUseEvmContractChainService = /* @__PURE__ */ __name((config3) => {
|
|
989
|
+
const { id } = config3.chain;
|
|
990
|
+
return isDefined8(id) && id !== ZERO_ADDRESS && canUseEvmProvider({
|
|
991
|
+
config: config3
|
|
992
|
+
});
|
|
993
|
+
}, "canUseEvmContractChainService");
|
|
994
|
+
var initEvmContractChainService = /* @__PURE__ */ __name(async ({ account, config: config3, traceProvider, meterProvider, logger }) => {
|
|
995
|
+
if (chainStakeServiceSingleton) return chainStakeServiceSingleton;
|
|
996
|
+
const emvStakingContractAddress = assertEx14(config3.chain.id, () => "Error: config.chain.id is required");
|
|
997
|
+
const id = assertEx14(asAddress(emvStakingContractAddress), () => "Error: config.chain.id is not a valid address");
|
|
998
|
+
const provider2 = assertEx14(await initEvmProvider({
|
|
999
|
+
config: config3
|
|
1000
|
+
}));
|
|
1001
|
+
const privateKey = assertEx14(account.private?.hex, () => "Error: Account does not have a private key");
|
|
1002
|
+
const runner = new Wallet(privateKey, provider2);
|
|
1003
|
+
chainStakeServiceSingleton = EvmChainService.create({
|
|
1004
|
+
id,
|
|
1005
|
+
runner,
|
|
1006
|
+
traceProvider,
|
|
1007
|
+
meterProvider,
|
|
1008
|
+
logger
|
|
1009
|
+
});
|
|
1010
|
+
return await chainStakeServiceSingleton;
|
|
1011
|
+
}, "initEvmContractChainService");
|
|
1012
|
+
|
|
1013
|
+
// src/orchestration/services/implementation/chain/index.ts
|
|
1014
|
+
var chainStakeServiceSingleton2;
|
|
1015
|
+
var initChainService = /* @__PURE__ */ __name(({ account, config: config3 }) => init({
|
|
1016
|
+
config: config3,
|
|
1017
|
+
name: "ChainService",
|
|
1018
|
+
account
|
|
1019
|
+
}), "initChainService");
|
|
1020
|
+
var init = /* @__PURE__ */ __name((params) => {
|
|
1021
|
+
if (chainStakeServiceSingleton2) return chainStakeServiceSingleton2;
|
|
1022
|
+
const { config: config3 } = params;
|
|
1023
|
+
chainStakeServiceSingleton2 = canUseEvmContractChainService(config3) ? initEvmContractChainService({
|
|
1024
|
+
...params,
|
|
1025
|
+
name: "ChainStakeService"
|
|
1026
|
+
}) : MemoryChainService.create({
|
|
1027
|
+
...params,
|
|
1028
|
+
name: "ChainStakeService"
|
|
1029
|
+
});
|
|
1030
|
+
return chainStakeServiceSingleton2;
|
|
1031
|
+
}, "init");
|
|
1032
|
+
|
|
1033
|
+
// src/orchestration/services/implementation/head.ts
|
|
1034
|
+
import { delay } from "@xylabs/delay";
|
|
1035
|
+
import { ZERO_ADDRESS as ZERO_ADDRESS2 } from "@xylabs/hex";
|
|
1036
|
+
import { createGenesisBlock, findMostRecentBlock as findMostRecentBlock2 } from "@xyo-network/chain-protocol";
|
|
1037
|
+
import { flattenHydratedBlock as flattenHydratedBlock2 } from "@xyo-network/xl1-protocol-sdk";
|
|
1038
|
+
var headSingleton;
|
|
1039
|
+
var createBootstrapHead = /* @__PURE__ */ __name(async (chainSubmissionsArchivistWrite, chainArchivist, account) => {
|
|
1040
|
+
const block = await createGenesisBlock(account, ZERO_ADDRESS2, 10000000n, account.address);
|
|
1041
|
+
const [bw] = block;
|
|
1042
|
+
await chainSubmissionsArchivistWrite.insert(flattenHydratedBlock2(block));
|
|
1043
|
+
while (true) {
|
|
1044
|
+
const result = await chainArchivist.get([
|
|
1045
|
+
bw._hash
|
|
1046
|
+
]);
|
|
1047
|
+
if (result.length > 0) break;
|
|
1048
|
+
await delay(1e3);
|
|
1049
|
+
}
|
|
1050
|
+
return bw;
|
|
1051
|
+
}, "createBootstrapHead");
|
|
1052
|
+
var initHead = /* @__PURE__ */ __name(async (params) => {
|
|
1053
|
+
const { account, chainArchivist, chainSubmissionsArchivistWrite } = params;
|
|
1054
|
+
if (headSingleton) return headSingleton;
|
|
1055
|
+
let head = await findMostRecentBlock2(chainArchivist);
|
|
1056
|
+
if (!head) head = await createBootstrapHead(chainSubmissionsArchivistWrite, chainArchivist, account);
|
|
1057
|
+
headSingleton = head;
|
|
1058
|
+
return headSingleton;
|
|
1059
|
+
}, "initHead");
|
|
1060
|
+
|
|
1061
|
+
// src/orchestration/services/implementation/iterator.ts
|
|
1062
|
+
import { BaseElectionService, ChainBlockNumberIterationService, XyoStakeIntentService } from "@xyo-network/chain-services";
|
|
1063
|
+
var chainIteratorServiceSingleton;
|
|
1064
|
+
var stakeIntentServiceSingleton;
|
|
1065
|
+
var electionServiceSingleton;
|
|
1066
|
+
var initChainIterator = /* @__PURE__ */ __name((params) => {
|
|
1067
|
+
if (chainIteratorServiceSingleton) return chainIteratorServiceSingleton;
|
|
1068
|
+
chainIteratorServiceSingleton = ChainBlockNumberIterationService.create(params);
|
|
1069
|
+
return chainIteratorServiceSingleton;
|
|
1070
|
+
}, "initChainIterator");
|
|
1071
|
+
var initStakeIntentService = /* @__PURE__ */ __name((params) => {
|
|
1072
|
+
if (stakeIntentServiceSingleton) return stakeIntentServiceSingleton;
|
|
1073
|
+
stakeIntentServiceSingleton = XyoStakeIntentService.create(params);
|
|
1074
|
+
return stakeIntentServiceSingleton;
|
|
1075
|
+
}, "initStakeIntentService");
|
|
1076
|
+
var initElectionService = /* @__PURE__ */ __name((params) => {
|
|
1077
|
+
if (electionServiceSingleton) return electionServiceSingleton;
|
|
1078
|
+
electionServiceSingleton = BaseElectionService.create(params);
|
|
1079
|
+
return electionServiceSingleton;
|
|
1080
|
+
}, "initElectionService");
|
|
1081
|
+
|
|
1082
|
+
// src/orchestration/services/implementation/pendingTransactions.ts
|
|
1083
|
+
import { BasePendingTransactionsService } from "@xyo-network/chain-services";
|
|
1084
|
+
var serviceSingleton;
|
|
1085
|
+
var initPendingTransactions = /* @__PURE__ */ __name(async (params) => {
|
|
1086
|
+
if (serviceSingleton) return serviceSingleton;
|
|
1087
|
+
serviceSingleton = await BasePendingTransactionsService.create(params);
|
|
1088
|
+
return serviceSingleton;
|
|
1089
|
+
}, "initPendingTransactions");
|
|
1090
|
+
|
|
1091
|
+
// src/orchestration/services/implementation/producer.ts
|
|
1092
|
+
import { BaseBlockProducerService as BaseBlockProducerService2 } from "@xyo-network/chain-services";
|
|
1093
|
+
var serviceSingleton2;
|
|
1094
|
+
var initBlockProducer = /* @__PURE__ */ __name(async (params) => {
|
|
1095
|
+
if (serviceSingleton2) return serviceSingleton2;
|
|
1096
|
+
serviceSingleton2 = await BaseBlockProducerService2.create(params);
|
|
1097
|
+
return serviceSingleton2;
|
|
1098
|
+
}, "initBlockProducer");
|
|
1099
|
+
|
|
1100
|
+
// src/orchestration/services/implementation/reward.ts
|
|
1101
|
+
import { assertEx as assertEx15 } from "@xylabs/assert";
|
|
1102
|
+
import { EvmBlockRewardService, MemoryBlockRewardService } from "@xyo-network/chain-services";
|
|
1103
|
+
var rewardServiceSingleton;
|
|
1104
|
+
var initBlockRewardService = /* @__PURE__ */ __name((params) => {
|
|
1105
|
+
if (rewardServiceSingleton) return rewardServiceSingleton;
|
|
1106
|
+
const { config: config3 } = params;
|
|
1107
|
+
rewardServiceSingleton = canUseEvmBlockRewardService({
|
|
1108
|
+
config: config3
|
|
1109
|
+
}) ? initEvmBlockRewardService(params) : initXyoBlockRewardService(params);
|
|
1110
|
+
return rewardServiceSingleton;
|
|
1111
|
+
}, "initBlockRewardService");
|
|
1112
|
+
var initXyoBlockRewardService = /* @__PURE__ */ __name((params) => {
|
|
1113
|
+
if (rewardServiceSingleton) return rewardServiceSingleton;
|
|
1114
|
+
rewardServiceSingleton = MemoryBlockRewardService.create(params);
|
|
1115
|
+
return rewardServiceSingleton;
|
|
1116
|
+
}, "initXyoBlockRewardService");
|
|
1117
|
+
var canUseEvmBlockRewardService = /* @__PURE__ */ __name((params) => canUseEvmProvider({
|
|
1118
|
+
config: params.config
|
|
1119
|
+
}), "canUseEvmBlockRewardService");
|
|
1120
|
+
var initEvmBlockRewardService = /* @__PURE__ */ __name(async (params) => {
|
|
1121
|
+
if (rewardServiceSingleton) return rewardServiceSingleton;
|
|
1122
|
+
const { account: paramsAccount } = params;
|
|
1123
|
+
const account = assertEx15(paramsAccount, () => "Error: Account is required");
|
|
1124
|
+
const provider2 = assertEx15(await initEvmProvider(params));
|
|
1125
|
+
const evmBlockRewardServiceParams = {
|
|
1126
|
+
...params,
|
|
1127
|
+
provider: provider2,
|
|
1128
|
+
account
|
|
1129
|
+
};
|
|
1130
|
+
rewardServiceSingleton = EvmBlockRewardService.create(evmBlockRewardServiceParams);
|
|
1131
|
+
return rewardServiceSingleton;
|
|
1132
|
+
}, "initEvmBlockRewardService");
|
|
1133
|
+
|
|
1134
|
+
// src/orchestration/status/ServiceStatus.ts
|
|
1135
|
+
var LoggerStatusReporter = class {
|
|
1136
|
+
static {
|
|
1137
|
+
__name(this, "LoggerStatusReporter");
|
|
1138
|
+
}
|
|
1139
|
+
logger;
|
|
1140
|
+
statusMap = {};
|
|
1141
|
+
constructor(logger) {
|
|
1142
|
+
this.logger = logger;
|
|
1143
|
+
}
|
|
1144
|
+
report(name, status, progress) {
|
|
1145
|
+
this.statusMap[name] = status;
|
|
1146
|
+
const starting = Object.entries(this.statusMap).map(([, value]) => value === "starting" ? 1 : 0).reduce((a, b) => a + b, 0);
|
|
1147
|
+
const started = Object.entries(this.statusMap).map(([, value]) => value === "started" ? 1 : 0).reduce((a, b) => a + b, 0);
|
|
1148
|
+
this.logger.info(`${started}/${starting + started} ${name} status: ${status}`, {
|
|
1149
|
+
progress
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
// src/orchestration/status/RuntimeStatusMonitor.ts
|
|
1155
|
+
var statusPriority = {
|
|
1156
|
+
error: 0,
|
|
1157
|
+
stopped: 1,
|
|
1158
|
+
stopping: 2,
|
|
1159
|
+
creating: 3,
|
|
1160
|
+
created: 4,
|
|
1161
|
+
starting: 5,
|
|
1162
|
+
started: 6
|
|
1163
|
+
};
|
|
1164
|
+
var SENTINEL_STATUS = "starting";
|
|
1165
|
+
var reduceToMinimumStatus = /* @__PURE__ */ __name((statuses) => {
|
|
1166
|
+
let minStatus = SENTINEL_STATUS;
|
|
1167
|
+
let minPriority = Infinity;
|
|
1168
|
+
for (const status of statuses) {
|
|
1169
|
+
const priority = statusPriority[status];
|
|
1170
|
+
if (priority < minPriority) {
|
|
1171
|
+
minPriority = priority;
|
|
1172
|
+
minStatus = status;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return minStatus;
|
|
1176
|
+
}, "reduceToMinimumStatus");
|
|
1177
|
+
var RuntimeStatusMonitor = class extends LoggerStatusReporter {
|
|
1178
|
+
static {
|
|
1179
|
+
__name(this, "RuntimeStatusMonitor");
|
|
1180
|
+
}
|
|
1181
|
+
globalTransitions = [];
|
|
1182
|
+
transitions = [];
|
|
1183
|
+
getGlobalStatus() {
|
|
1184
|
+
if (Object.keys(this.statusMap).length === 0) return SENTINEL_STATUS;
|
|
1185
|
+
return reduceToMinimumStatus(Object.values(this.statusMap));
|
|
1186
|
+
}
|
|
1187
|
+
getStatus(name) {
|
|
1188
|
+
return this.statusMap[name];
|
|
1189
|
+
}
|
|
1190
|
+
onGlobalTransition(match, handler) {
|
|
1191
|
+
this.globalTransitions.push({
|
|
1192
|
+
...match,
|
|
1193
|
+
handler
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Register a callback to be called on a specific transition.
|
|
1198
|
+
*/
|
|
1199
|
+
onTransition(match, handler) {
|
|
1200
|
+
this.transitions.push({
|
|
1201
|
+
...match,
|
|
1202
|
+
handler
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
report(name, status, progress) {
|
|
1206
|
+
const previous = this.statusMap[name];
|
|
1207
|
+
const previousGlobal = this.getGlobalStatus();
|
|
1208
|
+
super.report(name, status, progress);
|
|
1209
|
+
if (previous === status) return;
|
|
1210
|
+
this.runTransitions(this.transitions, previous, status, name);
|
|
1211
|
+
const globalStatus = this.getGlobalStatus();
|
|
1212
|
+
if (previousGlobal === globalStatus) return;
|
|
1213
|
+
this.runTransitions(this.globalTransitions, previousGlobal, globalStatus);
|
|
1214
|
+
}
|
|
1215
|
+
runTransitions(transitions, prev, next, name) {
|
|
1216
|
+
for (const { from, to, name: matchName, handler } of transitions) {
|
|
1217
|
+
if ((matchName === void 0 || matchName === name) && (from === void 0 || from === prev) && (to === void 0 || to === next)) {
|
|
1218
|
+
handler(prev, next);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
// src/orchestration/initServices.ts
|
|
1225
|
+
var telemetryConfig = {
|
|
1226
|
+
attributes: {
|
|
1227
|
+
serviceName: "xl1-producer",
|
|
1228
|
+
serviceVersion: "1.0.0"
|
|
1229
|
+
},
|
|
1230
|
+
metricsConfig: {
|
|
1231
|
+
endpoint: "/metrics",
|
|
1232
|
+
port: 9464
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
var isStartable = /* @__PURE__ */ __name((value) => {
|
|
1236
|
+
return isDefined9(value.start) && typeof value.start === "function";
|
|
1237
|
+
}, "isStartable");
|
|
1238
|
+
var initServices = /* @__PURE__ */ __name(async (context) => {
|
|
1239
|
+
const { config: config3, logger } = context;
|
|
1240
|
+
const statusReporter = new RuntimeStatusMonitor(logger);
|
|
1241
|
+
statusReporter.onGlobalTransition({
|
|
1242
|
+
to: "started"
|
|
1243
|
+
}, () => {
|
|
1244
|
+
logger.log("All services started.");
|
|
1245
|
+
});
|
|
1246
|
+
statusReporter.onGlobalTransition({
|
|
1247
|
+
to: "error"
|
|
1248
|
+
}, () => {
|
|
1249
|
+
logger.error("Producer encountered an unhandled error!");
|
|
1250
|
+
process.exit(1);
|
|
1251
|
+
});
|
|
1252
|
+
await startupSpanAsync7("initHealthEndpoints", () => initHealthEndpoints({
|
|
1253
|
+
...context,
|
|
1254
|
+
statusReporter
|
|
1255
|
+
}));
|
|
1256
|
+
const [{ traceProvider, meterProvider }, account] = await Promise.all([
|
|
1257
|
+
startupSpanAsync7("initTelemetry", () => initTelemetry(telemetryConfig)),
|
|
1258
|
+
startupSpanAsync7("initAccount", () => initAccount(context))
|
|
1259
|
+
]);
|
|
1260
|
+
const initParams = {
|
|
1261
|
+
config: config3,
|
|
1262
|
+
logger,
|
|
1263
|
+
meterProvider,
|
|
1264
|
+
statusReporter,
|
|
1265
|
+
traceProvider
|
|
1266
|
+
};
|
|
1267
|
+
const [chainArchivist, [pendingBundledTransactionsArchivist, pendingBundledTransactionsArchivistWrite], rejectedTransactionsArchivist, chainSubmissionsArchivistWrite, stakeIntentStateArchivist, chainService, balanceSummaryMap] = await Promise.all([
|
|
1268
|
+
startupSpanAsync7("ChainFinalizedArchivist", () => initChainFinalizedArchivist(initParams)),
|
|
1269
|
+
startupSpanAsync7("PendingBundledTransactionsArchivist", () => initPendingBundledTransactionsArchivist(initParams)),
|
|
1270
|
+
startupSpanAsync7("RejectedTransactionsArchivist", () => initRejectedTransactionsArchivist(initParams)),
|
|
1271
|
+
startupSpanAsync7("ChainSubmissionsArchivist", () => initChainSubmissionsArchivist(initParams)),
|
|
1272
|
+
startupSpanAsync7("StakeIntentStateArchivist", () => initStakeIntentStateArchivist(initParams)),
|
|
1273
|
+
startupSpanAsync7("ChainService", () => initChainService({
|
|
1274
|
+
...initParams,
|
|
1275
|
+
account,
|
|
1276
|
+
name: "ChainService"
|
|
1277
|
+
})),
|
|
1278
|
+
startupSpanAsync7("BalanceSummaryMap", () => initBalanceSummaryMap(initParams))
|
|
1279
|
+
]);
|
|
1280
|
+
const chainId = chainService.chainId;
|
|
1281
|
+
const chainContractViewer = chainService;
|
|
1282
|
+
const chainStakeViewer = chainService;
|
|
1283
|
+
const chainStaker = chainService;
|
|
1284
|
+
const head = await startupSpanAsync7("initHead", () => initHead({
|
|
1285
|
+
...initParams,
|
|
1286
|
+
account,
|
|
1287
|
+
chainArchivist,
|
|
1288
|
+
chainSubmissionsArchivistWrite
|
|
1289
|
+
}));
|
|
1290
|
+
const [pendingTransactionsService, rewardService, chainIterator, balanceService] = await Promise.all([
|
|
1291
|
+
startupSpanAsync7("PendingTransactions", () => initPendingTransactions({
|
|
1292
|
+
name: "PendingTransactionsService",
|
|
1293
|
+
chainArchivist,
|
|
1294
|
+
chainId,
|
|
1295
|
+
pendingBundledTransactionsArchivist,
|
|
1296
|
+
rejectedTransactionsArchivist,
|
|
1297
|
+
...initParams
|
|
1298
|
+
})),
|
|
1299
|
+
startupSpanAsync7("RewardService", () => initBlockRewardService({
|
|
1300
|
+
name: "RewardService",
|
|
1301
|
+
account,
|
|
1302
|
+
chainService,
|
|
1303
|
+
...initParams
|
|
1304
|
+
})),
|
|
1305
|
+
startupSpanAsync7("ChainIterator", () => initChainIterator({
|
|
1306
|
+
name: "ChainIterator",
|
|
1307
|
+
chainArchivist,
|
|
1308
|
+
head,
|
|
1309
|
+
...initParams
|
|
1310
|
+
})),
|
|
1311
|
+
startupSpanAsync7("BalanceService", () => initBalanceService({
|
|
1312
|
+
name: "BalanceService",
|
|
1313
|
+
chainArchivist,
|
|
1314
|
+
summaryRepository: balanceSummaryRepositoryFromMap(balanceSummaryMap),
|
|
1315
|
+
...initParams
|
|
1316
|
+
}))
|
|
1317
|
+
]);
|
|
1318
|
+
const stakeIntentService = await startupSpanAsync7("StakeIntentService", () => initStakeIntentService({
|
|
1319
|
+
name: "StakeIntentService",
|
|
1320
|
+
chainArchivist,
|
|
1321
|
+
chainIterator,
|
|
1322
|
+
chainStakeViewer,
|
|
1323
|
+
stakeIntentStateArchivist,
|
|
1324
|
+
...initParams
|
|
1325
|
+
}));
|
|
1326
|
+
const electionService = await startupSpanAsync7("ElectionService", () => initElectionService({
|
|
1327
|
+
name: "ElectionService",
|
|
1328
|
+
chainIterator,
|
|
1329
|
+
chainStakeViewer,
|
|
1330
|
+
stakeIntentService,
|
|
1331
|
+
...initParams
|
|
1332
|
+
}));
|
|
1333
|
+
const validatorParams = {
|
|
1334
|
+
name: "Validator",
|
|
1335
|
+
account,
|
|
1336
|
+
chainId,
|
|
1337
|
+
pendingBundledTransactionsArchivist,
|
|
1338
|
+
chainArchivist,
|
|
1339
|
+
electionService,
|
|
1340
|
+
rewardService,
|
|
1341
|
+
stakeIntentService,
|
|
1342
|
+
validateHydratedBlockState,
|
|
1343
|
+
...initParams
|
|
1344
|
+
};
|
|
1345
|
+
const rewardAddress = isDefined9(config3.producer.rewardAddress) ? assertEx16(asAddress2(config3.producer.rewardAddress), () => "Invalid block reward address provided") : account.address;
|
|
1346
|
+
const producerParams = {
|
|
1347
|
+
...validatorParams,
|
|
1348
|
+
name: "Producer",
|
|
1349
|
+
balanceService,
|
|
1350
|
+
chainArchivist,
|
|
1351
|
+
pendingBundledTransactionsArchivist,
|
|
1352
|
+
pendingTransactionsService,
|
|
1353
|
+
rejectedTransactionsArchivist,
|
|
1354
|
+
rewardAddress,
|
|
1355
|
+
...initParams
|
|
1356
|
+
};
|
|
1357
|
+
const producer = await startupSpanAsync7("Producer", () => initBlockProducer(producerParams));
|
|
1358
|
+
const result = {
|
|
1359
|
+
account,
|
|
1360
|
+
balanceService,
|
|
1361
|
+
chainArchivist,
|
|
1362
|
+
chainContractViewer,
|
|
1363
|
+
chainIterator,
|
|
1364
|
+
chainStaker,
|
|
1365
|
+
chainStakeViewer,
|
|
1366
|
+
chainSubmissionsArchivistWrite,
|
|
1367
|
+
electionService,
|
|
1368
|
+
pendingBundledTransactionsArchivistWrite,
|
|
1369
|
+
pendingTransactionsService,
|
|
1370
|
+
producer,
|
|
1371
|
+
rewardService,
|
|
1372
|
+
stakeIntentService
|
|
1373
|
+
};
|
|
1374
|
+
logger?.log("All services created. Starting...");
|
|
1375
|
+
const startableServices = [
|
|
1376
|
+
balanceSummaryMap,
|
|
1377
|
+
...Object.values(result)
|
|
1378
|
+
].filter(isStartable);
|
|
1379
|
+
await Promise.all(startableServices.map((service) => service.start()));
|
|
1380
|
+
return result;
|
|
1381
|
+
}, "initServices");
|
|
1382
|
+
|
|
1383
|
+
// src/commands/producer/runProducer.ts
|
|
1384
|
+
var runProducer = /* @__PURE__ */ __name(async (context) => {
|
|
1385
|
+
const { config: config3, logger, orchestrator } = context;
|
|
1386
|
+
logger?.log("Services: Initializing...");
|
|
1387
|
+
const services = await initServices(context);
|
|
1388
|
+
logger?.log("Services: Initialized");
|
|
1389
|
+
const params = {
|
|
1390
|
+
...services,
|
|
1391
|
+
config: config3
|
|
1392
|
+
};
|
|
1393
|
+
const chainHeadUpdate = await ChainHeadUpdateActor.create(params);
|
|
1394
|
+
const balances = await BalanceActor.create(params);
|
|
1395
|
+
const producer = await ProducerActor.create(params);
|
|
1396
|
+
const actors = [
|
|
1397
|
+
chainHeadUpdate,
|
|
1398
|
+
balances,
|
|
1399
|
+
producer
|
|
1400
|
+
];
|
|
1401
|
+
for (const actor of actors) {
|
|
1402
|
+
await orchestrator.registerActor(actor);
|
|
1403
|
+
}
|
|
1404
|
+
await orchestrator.start();
|
|
1405
|
+
}, "runProducer");
|
|
1406
|
+
|
|
1407
|
+
// src/images.ts
|
|
1408
|
+
var XL1LogoColorizedAscii = `\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;118;111;144m_\x1B[0m
|
|
1409
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;72;32;223m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m
|
|
1410
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\u2560\u2560\x1B[0m\x1B[38;2;103;85;170m_\x1B[0m
|
|
1411
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;79;121;152m\u2566\x1B[0m\x1B[38;2;82;121;151m\u2566\x1B[0m\x1B[38;2;112;125;136m_\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;88;59;196m[\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;73;34;221m\u2592\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;121;121;127m_\x1B[0m\x1B[38;2;100;101;128m\u2554\x1B[0m\x1B[38;2;93;94;127m\u2566\x1B[0m
|
|
1412
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;82;121;151m\xB2\x1B[0m\x1B[38;2;44;116;170m\u2560\x1B[0m\x1B[38;2;44;116;171m\u2592\x1B[0m\x1B[38;2;51;117;167mD\x1B[0m\x1B[38;2;80;121;152m\u2566\x1B[0m\x1B[38;2;111;125;136m_\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;67;23;232m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;120;121;128m_\x1B[0m\x1B[38;2;100;101;127m\u2554\x1B[0m\x1B[38;2;79;81;127mR\x1B[0m\x1B[38;2;71;73;128m\u2592\x1B[0m\x1B[38;2;71;73;128m\u2592\x1B[0m\x1B[38;2;88;90;127m\u2559\x1B[0m
|
|
1413
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;55;117;165m\u255A\x1B[0m\x1B[38;2;44;116;171m\u2592\x1B[0m\x1B[38;2;44;116;171m\u2592\u2592\x1B[0m\x1B[38;2;50;116;167mD\x1B[0m\x1B[38;2;80;121;152m\u2566\xA0\x1B[0m\x1B[38;2;106;90;165mj\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\x1B[0m\x1B[38;2;89;61;194mH\xA0\x1B[0m\x1B[38;2;99;100;127m\u2554\x1B[0m\x1B[38;2;79;80;127mD\x1B[0m\x1B[38;2;71;73;128m\u2592\x1B[0m\x1B[38;2;71;73;128m\u2592\u2592\u2560\x1B[0m
|
|
1414
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;83;121;150m\xB2\x1B[0m\x1B[38;2;44;116;170m\u2592\x1B[0m\x1B[38;2;44;116;171m\u2592\u2592\u2592\xA0\x1B[0m\x1B[38;2;76;38;217m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\xA0\x1B[0m\x1B[38;2;74;76;128m\u2560\x1B[0m\x1B[38;2;71;73;128m\u2592\u2592\u2592\x1B[0m\x1B[38;2;89;90;128m\u2559\x1B[0m
|
|
1415
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;90;118;148m\`\x1B[0m\x1B[38;2;89;107;153m_\x1B[0m\x1B[38;2;93;97;154m,\x1B[0m\x1B[38;2;105;89;166m\u2553\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;95;72;183m\u2553\x1B[0m\x1B[38;2;106;96;152m_\x1B[0m\x1B[38;2;100;94;143m\`\x1B[0m\x1B[38;2;101;100;133m\`\x1B[0m
|
|
1416
|
+
\x1B[38;2;128;128;128m\xA0\x1B[0m\x1B[38;2;122;118;137m_\x1B[0m\x1B[38;2;113;102;153m,\x1B[0m\x1B[38;2;108;94;161m\u2553\x1B[0m\x1B[38;2;104;86;169m\u2553\x1B[0m\x1B[38;2;98;77;178m\u2554\x1B[0m\x1B[38;2;93;67;188m\u2557\x1B[0m\x1B[38;2;88;59;196m\u03C6\x1B[0m\x1B[38;2;83;51;204m@\x1B[0m\x1B[38;2;78;42;213mD\x1B[0m\x1B[38;2;72;32;223m\u2592\x1B[0m\x1B[38;2;68;24;231m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;71;30;225m\u2592\x1B[0m\x1B[38;2;77;40;215m\u2592\x1B[0m\x1B[38;2;82;49;206mK\x1B[0m\x1B[38;2;87;57;198m\u03C6\x1B[0m\x1B[38;2;91;65;190m\u2557\x1B[0m\x1B[38;2;97;75;180m\u2566\x1B[0m\x1B[38;2;103;84;171m\u2556\x1B[0m\x1B[38;2;107;92;163m\xB2\x1B[0m\x1B[38;2;112;101;154m_\x1B[0m\x1B[38;2;119;112;143m_\x1B[0m
|
|
1417
|
+
\x1B[38;2;128;128;128m\xA0\x1B[0m\x1B[38;2;106;91;164m\`\x1B[0m\x1B[38;2;94;70;185m^\x1B[0m\x1B[38;2;89;62;193m\u2559\x1B[0m\x1B[38;2;85;54;201m\u2559\x1B[0m\x1B[38;2;80;45;210m\u255A\x1B[0m\x1B[38;2;74;35;220m\u255D\x1B[0m\x1B[38;2;69;26;229m\u2560\x1B[0m\x1B[38;2;66;22;233m\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;73;33;222m\u255D\x1B[0m\x1B[38;2;79;43;212m\u2569\x1B[0m\x1B[38;2;84;52;203m\u255C\x1B[0m\x1B[38;2;88;60;195m\u2559\x1B[0m\x1B[38;2;93;68;187m^\x1B[0m\x1B[38;2;100;80;175m\`\x1B[0m
|
|
1418
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;113;84;152m\`\x1B[0m\x1B[38;2;103;79;169m'\x1B[0m\x1B[38;2;95;72;183m"\x1B[0m\x1B[38;2;87;57;198m\u2559\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\u2560\x1B[0m\x1B[38;2;80;46;209m\u255C\x1B[0m\x1B[38;2;94;70;185m^\x1B[0m\x1B[38;2;102;77;175m^\x1B[0m\x1B[38;2;112;81;162m\`\x1B[0m\x1B[38;2;115;92;155m\`\x1B[0m
|
|
1419
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;145;116;107m,\x1B[0m\x1B[38;2;199;82;45m\u2560\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;207;77;35m\u2592\u2560\xA0\x1B[0m\x1B[38;2;70;28;227m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\u2560\xA0\x1B[0m\x1B[38;2;189;49;97m\xE5\x1B[0m\x1B[38;2;203;32;90m\u2560\x1B[0m\x1B[38;2;203;32;90m\u2560\u2560\x1B[0m\x1B[38;2;155;92;114m,\x1B[0m
|
|
1420
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;175;98;73m\u2554\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;207;77;35m\u2592\u2592\u2592\x1B[0m\x1B[38;2;197;83;47m\u2569\xA0\x1B[0m\x1B[38;2;98;76;179m[\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\x1B[0m\x1B[38;2;81;48;207mH\xA0\x1B[0m\x1B[38;2;188;51;98m\u255A\x1B[0m\x1B[38;2;203;32;90m\u2560\x1B[0m\x1B[38;2;203;32;90m\u2560\u2560\u2560\x1B[0m\x1B[38;2;183;57;100mH\x1B[0m
|
|
1421
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;146;116;106m,\x1B[0m\x1B[38;2;199;82;44m\u2560\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;207;77;35m\u2592\x1B[0m\x1B[38;2;196;84;48m\u2569\x1B[0m\x1B[38;2;168;102;81m^\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\u2560\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;160;87;111m'\x1B[0m\x1B[38;2;187;52;98m\u255A\x1B[0m\x1B[38;2;203;32;90m\u2560\x1B[0m\x1B[38;2;203;32;90m\u2560\u2560\x1B[0m\x1B[38;2;156;91;113m,\x1B[0m
|
|
1422
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;198;83;46m\u2569\x1B[0m\x1B[38;2;194;85;50m\u2569\x1B[0m\x1B[38;2;167;102;82m^\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;81;46;209m\u255A\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\u2560\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;159;88;112m'\x1B[0m\x1B[38;2;186;53;98m\u255A\x1B[0m\x1B[38;2;197;40;93m\u2569\x1B[0m
|
|
1423
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;110;97;158m'\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m\x1B[38;2;94;69;186mH\x1B[0m
|
|
1424
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;68;25;230m\u2560\x1B[0m\x1B[38;2;66;21;234m\u2560\x1B[0m
|
|
1425
|
+
\x1B[38;2;128;128;128m\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\x1B[0m\x1B[38;2;108;93;162m\xB2\x1B[0m\x1B[38;2;99;79;176m^\x1B[0m`;
|
|
1426
|
+
|
|
1427
|
+
// src/initLogger.ts
|
|
1428
|
+
import { Base as Base2 } from "@xylabs/base";
|
|
1429
|
+
import { ConsoleLogger, LogLevel, SilentLogger } from "@xylabs/logger";
|
|
1430
|
+
import { isDefined as isDefined10 } from "@xylabs/typeof";
|
|
1431
|
+
var initLogger = /* @__PURE__ */ __name((config3) => {
|
|
1432
|
+
let logger;
|
|
1433
|
+
if (config3.silent) {
|
|
1434
|
+
logger = new SilentLogger();
|
|
1435
|
+
} else {
|
|
1436
|
+
let level;
|
|
1437
|
+
if (isDefined10(config3.logLevel)) {
|
|
1438
|
+
const parsed = LogLevel[config3.logLevel.toLowerCase()];
|
|
1439
|
+
if (isDefined10(parsed)) level = parsed;
|
|
1440
|
+
}
|
|
1441
|
+
logger = new ConsoleLogger(level);
|
|
1442
|
+
}
|
|
1443
|
+
Base2.defaultLogger = logger;
|
|
1444
|
+
return logger;
|
|
1445
|
+
}, "initLogger");
|
|
1446
|
+
|
|
1447
|
+
// src/optionsFromZodSchema.ts
|
|
1448
|
+
import { ZodBoolean, ZodDefault, ZodEnum, ZodNumber, ZodObject, ZodOptional } from "zod";
|
|
1449
|
+
var collectOptions = /* @__PURE__ */ __name((zodType, path = [], out = {}) => {
|
|
1450
|
+
if (zodType instanceof ZodObject) {
|
|
1451
|
+
const shape = zodType.shape;
|
|
1452
|
+
for (const [k, v] of Object.entries(shape)) {
|
|
1453
|
+
collectOptions(v, [
|
|
1454
|
+
...path,
|
|
1455
|
+
k
|
|
1456
|
+
], out);
|
|
1457
|
+
}
|
|
1458
|
+
return out;
|
|
1459
|
+
}
|
|
1460
|
+
const def = zodType._def;
|
|
1461
|
+
if (def?.innerType instanceof ZodObject) {
|
|
1462
|
+
const shape = def.innerType.shape;
|
|
1463
|
+
for (const [k, v] of Object.entries(shape)) {
|
|
1464
|
+
collectOptions(v, [
|
|
1465
|
+
...path,
|
|
1466
|
+
k
|
|
1467
|
+
], out);
|
|
1468
|
+
}
|
|
1469
|
+
return out;
|
|
1470
|
+
}
|
|
1471
|
+
const options = {};
|
|
1472
|
+
options.describe = def.description;
|
|
1473
|
+
options.default = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
|
|
1474
|
+
let type = "string";
|
|
1475
|
+
const typeName = def.typeName === ZodDefault.name || def.typeName === ZodOptional.name ? def.innerType._def.typeName : def.typeName;
|
|
1476
|
+
if (typeName === ZodBoolean.name) type = "boolean";
|
|
1477
|
+
if (typeName === ZodNumber.name || def.coerce) type = "number";
|
|
1478
|
+
if (typeName === ZodEnum.name) {
|
|
1479
|
+
options.choices = Object.values(def.innerType.enum);
|
|
1480
|
+
}
|
|
1481
|
+
options.type = type;
|
|
1482
|
+
const key = path.join(".");
|
|
1483
|
+
out[key] = options;
|
|
1484
|
+
return out;
|
|
1485
|
+
}, "collectOptions");
|
|
1486
|
+
var optionsFromZodSchema = /* @__PURE__ */ __name((schema) => {
|
|
1487
|
+
const opts = {};
|
|
1488
|
+
for (const [rootKey, zodType] of Object.entries(schema)) {
|
|
1489
|
+
collectOptions(zodType, [
|
|
1490
|
+
rootKey
|
|
1491
|
+
], opts);
|
|
1492
|
+
}
|
|
1493
|
+
return opts;
|
|
1494
|
+
}, "optionsFromZodSchema");
|
|
1495
|
+
|
|
1496
|
+
// src/waitForHostPort.ts
|
|
1497
|
+
import net from "net";
|
|
1498
|
+
var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
|
|
1499
|
+
return new Promise((resolve) => {
|
|
1500
|
+
const tryConnect = /* @__PURE__ */ __name(() => {
|
|
1501
|
+
const socket = new net.Socket();
|
|
1502
|
+
socket.setTimeout(1e3).once("error", () => {
|
|
1503
|
+
socket.destroy();
|
|
1504
|
+
setTimeout(tryConnect, 500);
|
|
1505
|
+
}).once("timeout", () => {
|
|
1506
|
+
socket.destroy();
|
|
1507
|
+
setTimeout(tryConnect, 500);
|
|
1508
|
+
}).connect(port, host, () => {
|
|
1509
|
+
socket.end();
|
|
1510
|
+
resolve();
|
|
1511
|
+
});
|
|
1512
|
+
}, "tryConnect");
|
|
1513
|
+
tryConnect();
|
|
1514
|
+
});
|
|
1515
|
+
}, "waitForHostPort");
|
|
1516
|
+
|
|
1517
|
+
// src/runCLI.ts
|
|
1518
|
+
var config;
|
|
1519
|
+
var version = isDefined11("1.7.3") ? "1.7.3" : "unknown";
|
|
1520
|
+
var getContextFromConfig = /* @__PURE__ */ __name((config3) => {
|
|
1521
|
+
const logger = initLogger(config3);
|
|
1522
|
+
const orchestrator = new Orchestrator(logger);
|
|
1523
|
+
process.on("SIGINT", () => {
|
|
1524
|
+
void (async () => {
|
|
1525
|
+
try {
|
|
1526
|
+
logger.log("\nSIGINT received. Attempting graceful shutdown...");
|
|
1527
|
+
await orchestrator?.stop();
|
|
1528
|
+
logger.log("Orchestrator stopped, exiting now.");
|
|
1529
|
+
process.exit(0);
|
|
1530
|
+
} catch (err) {
|
|
1531
|
+
logger.error("Error stopping orchestrator:", err);
|
|
1532
|
+
process.exit(1);
|
|
1533
|
+
}
|
|
1534
|
+
})();
|
|
1535
|
+
});
|
|
1536
|
+
return {
|
|
1537
|
+
logger,
|
|
1538
|
+
orchestrator
|
|
1539
|
+
};
|
|
1540
|
+
}, "getContextFromConfig");
|
|
1541
|
+
async function runCLI() {
|
|
1542
|
+
const y = yargs(hideBin(process.argv));
|
|
1543
|
+
const argv = y.usage(`
|
|
1544
|
+
\u{1F680} XL1 Node CLI (${version})
|
|
1545
|
+
${XL1LogoColorizedAscii}
|
|
1546
|
+
Run various components of the XL1 ecosystem.
|
|
1547
|
+
|
|
1548
|
+
Usage:
|
|
1549
|
+
$0 <command> [options]`).parserConfiguration({
|
|
1550
|
+
"dot-notation": true
|
|
1551
|
+
}).env("XL1").scriptName("xl1").config().version(version).middleware((argv2) => {
|
|
1552
|
+
try {
|
|
1553
|
+
config = ConfigSchema.parse(argv2);
|
|
1554
|
+
} catch (err) {
|
|
1555
|
+
if (err instanceof ZodError) {
|
|
1556
|
+
for (const issue of err.errors) {
|
|
1557
|
+
console.error(`${issue.path.join(".")} \u2192 ${issue.message}`);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
throw new Error("Invalid configuration");
|
|
1561
|
+
}
|
|
1562
|
+
}).options(optionsFromZodSchema(ConfigSchema.shape)).wrap(y.terminalWidth()).command("api", "Run a XL1 API Node", (yargs2) => {
|
|
1563
|
+
return yargs2.command("$0", "Run a XL1 API Node", () => {
|
|
1564
|
+
}, () => {
|
|
1565
|
+
const context = getContextFromConfig(config);
|
|
1566
|
+
runApi({
|
|
1567
|
+
...context,
|
|
1568
|
+
config
|
|
1569
|
+
});
|
|
1570
|
+
});
|
|
1571
|
+
}).command("producer", "Run a XL1 Producer Node", (yargs2) => {
|
|
1572
|
+
return yargs2.command("$0", "Run a XL1 Producer Node", () => {
|
|
1573
|
+
}, async () => {
|
|
1574
|
+
const context = getContextFromConfig(config);
|
|
1575
|
+
await runProducer({
|
|
1576
|
+
...context,
|
|
1577
|
+
config
|
|
1578
|
+
});
|
|
1579
|
+
});
|
|
1580
|
+
}).command("$0", "Run a full XL1 Node", () => {
|
|
1581
|
+
}, async () => {
|
|
1582
|
+
const context = getContextFromConfig(config);
|
|
1583
|
+
runApi({
|
|
1584
|
+
...context,
|
|
1585
|
+
config
|
|
1586
|
+
});
|
|
1587
|
+
await waitForHostPort("localhost", config.api.port);
|
|
1588
|
+
await runProducer({
|
|
1589
|
+
...context,
|
|
1590
|
+
config
|
|
1591
|
+
});
|
|
1592
|
+
}).help().alias("help", "h").argv;
|
|
1593
|
+
await argv;
|
|
1594
|
+
}
|
|
1595
|
+
__name(runCLI, "runCLI");
|
|
1596
|
+
|
|
1597
|
+
// src/start.ts
|
|
1598
|
+
var start = /* @__PURE__ */ __name(async () => {
|
|
1599
|
+
config2({
|
|
1600
|
+
quiet: true
|
|
1601
|
+
});
|
|
1602
|
+
await runCLI();
|
|
1603
|
+
}, "start");
|
|
1604
|
+
|
|
1605
|
+
// src/xl1.ts
|
|
1606
|
+
start().catch((err) => {
|
|
1607
|
+
if (process.env.NODE_ENV === "development") console.error("An error occurred during startup:", err);
|
|
1608
|
+
process.exit(1);
|
|
1609
|
+
});
|
|
1610
|
+
//# sourceMappingURL=xl1.mjs.map
|