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