@xyo-network/chain-orchestration 1.20.28 → 1.20.29
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/dist/browser/index.mjs +357 -77
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/neutral/config/locators/basicRemoteViewerLocator.d.ts +1 -1
- package/dist/browser/neutral/config/locators/basicRemoteViewerLocator.d.ts.map +1 -1
- package/dist/browser/node/config/capabilities/Capability.d.ts +36 -0
- package/dist/browser/node/config/capabilities/Capability.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/ProcessSharedResources.d.ts +30 -0
- package/dist/browser/node/config/capabilities/ProcessSharedResources.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/Provider.d.ts +50 -0
- package/dist/browser/node/config/capabilities/Provider.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/XL1ResolutionContext.d.ts +18 -0
- package/dist/browser/node/config/capabilities/XL1ResolutionContext.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/defaultCapabilityRegistry.d.ts +8 -0
- package/dist/browser/node/config/capabilities/defaultCapabilityRegistry.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/descriptors.d.ts +15 -0
- package/dist/browser/node/config/capabilities/descriptors.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/index.d.ts +9 -0
- package/dist/browser/node/config/capabilities/index.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/locatorFromActorNeeds.d.ts +36 -0
- package/dist/browser/node/config/capabilities/locatorFromActorNeeds.d.ts.map +1 -0
- package/dist/browser/node/config/capabilities/resolveProviders.d.ts +30 -0
- package/dist/browser/node/config/capabilities/resolveProviders.d.ts.map +1 -0
- package/dist/browser/node/config/index.d.ts +1 -0
- package/dist/browser/node/config/index.d.ts.map +1 -1
- package/dist/browser/node/config/locators/actors/producerLocatorFromConfig.d.ts.map +1 -1
- package/dist/browser/node/config/locators/basicRemoteViewerLocator.d.ts +1 -1
- package/dist/browser/node/config/locators/basicRemoteViewerLocator.d.ts.map +1 -1
- package/dist/browser/node/config/locators/localLocatorFromConfig.d.ts +10 -2
- package/dist/browser/node/config/locators/localLocatorFromConfig.d.ts.map +1 -1
- package/dist/browser/shared/actor/FinalizerActor.d.ts +6 -2
- package/dist/browser/shared/actor/FinalizerActor.d.ts.map +1 -1
- package/dist/browser/shared/actor/index.d.ts +1 -0
- package/dist/browser/shared/actor/index.d.ts.map +1 -1
- package/dist/browser/shared/actor/v3/ActorV3.d.ts +85 -0
- package/dist/browser/shared/actor/v3/ActorV3.d.ts.map +1 -0
- package/dist/browser/shared/actor/v3/index.d.ts +2 -0
- package/dist/browser/shared/actor/v3/index.d.ts.map +1 -0
- package/dist/browser/shared/config/actors/Api.d.ts +4 -4
- package/dist/browser/shared/config/actors/Bridge.d.ts +4 -4
- package/dist/browser/shared/config/actors/Finalizer.d.ts +10 -4
- package/dist/browser/shared/config/actors/Finalizer.d.ts.map +1 -1
- package/dist/browser/shared/config/actors/Mempool.d.ts +4 -4
- package/dist/browser/shared/config/actors/Producer.d.ts +6 -6
- package/dist/browser/shared/config/actors/Producer.d.ts.map +1 -1
- package/dist/browser/shared/config/actors/RewardRedemption.d.ts +4 -4
- package/dist/browser/shared/orchestrator/Orchestrator.d.ts +16 -2
- package/dist/browser/shared/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/neutral/index.mjs +357 -77
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/neutral/config/locators/basicRemoteViewerLocator.d.ts +1 -1
- package/dist/neutral/neutral/config/locators/basicRemoteViewerLocator.d.ts.map +1 -1
- package/dist/neutral/node/config/capabilities/Capability.d.ts +36 -0
- package/dist/neutral/node/config/capabilities/Capability.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/ProcessSharedResources.d.ts +30 -0
- package/dist/neutral/node/config/capabilities/ProcessSharedResources.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/Provider.d.ts +50 -0
- package/dist/neutral/node/config/capabilities/Provider.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/XL1ResolutionContext.d.ts +18 -0
- package/dist/neutral/node/config/capabilities/XL1ResolutionContext.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/defaultCapabilityRegistry.d.ts +8 -0
- package/dist/neutral/node/config/capabilities/defaultCapabilityRegistry.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/descriptors.d.ts +15 -0
- package/dist/neutral/node/config/capabilities/descriptors.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/index.d.ts +9 -0
- package/dist/neutral/node/config/capabilities/index.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/locatorFromActorNeeds.d.ts +36 -0
- package/dist/neutral/node/config/capabilities/locatorFromActorNeeds.d.ts.map +1 -0
- package/dist/neutral/node/config/capabilities/resolveProviders.d.ts +30 -0
- package/dist/neutral/node/config/capabilities/resolveProviders.d.ts.map +1 -0
- package/dist/neutral/node/config/index.d.ts +1 -0
- package/dist/neutral/node/config/index.d.ts.map +1 -1
- package/dist/neutral/node/config/locators/actors/producerLocatorFromConfig.d.ts.map +1 -1
- package/dist/neutral/node/config/locators/basicRemoteViewerLocator.d.ts +1 -1
- package/dist/neutral/node/config/locators/basicRemoteViewerLocator.d.ts.map +1 -1
- package/dist/neutral/node/config/locators/localLocatorFromConfig.d.ts +10 -2
- package/dist/neutral/node/config/locators/localLocatorFromConfig.d.ts.map +1 -1
- package/dist/neutral/shared/actor/FinalizerActor.d.ts +6 -2
- package/dist/neutral/shared/actor/FinalizerActor.d.ts.map +1 -1
- package/dist/neutral/shared/actor/index.d.ts +1 -0
- package/dist/neutral/shared/actor/index.d.ts.map +1 -1
- package/dist/neutral/shared/actor/v3/ActorV3.d.ts +85 -0
- package/dist/neutral/shared/actor/v3/ActorV3.d.ts.map +1 -0
- package/dist/neutral/shared/actor/v3/index.d.ts +2 -0
- package/dist/neutral/shared/actor/v3/index.d.ts.map +1 -0
- package/dist/neutral/shared/config/actors/Api.d.ts +4 -4
- package/dist/neutral/shared/config/actors/Bridge.d.ts +4 -4
- package/dist/neutral/shared/config/actors/Finalizer.d.ts +10 -4
- package/dist/neutral/shared/config/actors/Finalizer.d.ts.map +1 -1
- package/dist/neutral/shared/config/actors/Mempool.d.ts +4 -4
- package/dist/neutral/shared/config/actors/Producer.d.ts +6 -6
- package/dist/neutral/shared/config/actors/Producer.d.ts.map +1 -1
- package/dist/neutral/shared/config/actors/RewardRedemption.d.ts +4 -4
- package/dist/neutral/shared/orchestrator/Orchestrator.d.ts +16 -2
- package/dist/neutral/shared/orchestrator/Orchestrator.d.ts.map +1 -1
- package/dist/node/index.mjs +1036 -223
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/neutral/config/locators/basicRemoteViewerLocator.d.ts +1 -1
- package/dist/node/neutral/config/locators/basicRemoteViewerLocator.d.ts.map +1 -1
- package/dist/node/node/config/capabilities/Capability.d.ts +36 -0
- package/dist/node/node/config/capabilities/Capability.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/ProcessSharedResources.d.ts +30 -0
- package/dist/node/node/config/capabilities/ProcessSharedResources.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/Provider.d.ts +50 -0
- package/dist/node/node/config/capabilities/Provider.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/XL1ResolutionContext.d.ts +18 -0
- package/dist/node/node/config/capabilities/XL1ResolutionContext.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/defaultCapabilityRegistry.d.ts +8 -0
- package/dist/node/node/config/capabilities/defaultCapabilityRegistry.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/descriptors.d.ts +15 -0
- package/dist/node/node/config/capabilities/descriptors.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/index.d.ts +9 -0
- package/dist/node/node/config/capabilities/index.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/locatorFromActorNeeds.d.ts +36 -0
- package/dist/node/node/config/capabilities/locatorFromActorNeeds.d.ts.map +1 -0
- package/dist/node/node/config/capabilities/resolveProviders.d.ts +30 -0
- package/dist/node/node/config/capabilities/resolveProviders.d.ts.map +1 -0
- package/dist/node/node/config/index.d.ts +1 -0
- package/dist/node/node/config/index.d.ts.map +1 -1
- package/dist/node/node/config/locators/actors/producerLocatorFromConfig.d.ts.map +1 -1
- package/dist/node/node/config/locators/basicRemoteViewerLocator.d.ts +1 -1
- package/dist/node/node/config/locators/basicRemoteViewerLocator.d.ts.map +1 -1
- package/dist/node/node/config/locators/localLocatorFromConfig.d.ts +10 -2
- package/dist/node/node/config/locators/localLocatorFromConfig.d.ts.map +1 -1
- package/dist/node/shared/actor/FinalizerActor.d.ts +6 -2
- package/dist/node/shared/actor/FinalizerActor.d.ts.map +1 -1
- package/dist/node/shared/actor/index.d.ts +1 -0
- package/dist/node/shared/actor/index.d.ts.map +1 -1
- package/dist/node/shared/actor/v3/ActorV3.d.ts +85 -0
- package/dist/node/shared/actor/v3/ActorV3.d.ts.map +1 -0
- package/dist/node/shared/actor/v3/index.d.ts +2 -0
- package/dist/node/shared/actor/v3/index.d.ts.map +1 -0
- package/dist/node/shared/config/actors/Api.d.ts +4 -4
- package/dist/node/shared/config/actors/Bridge.d.ts +4 -4
- package/dist/node/shared/config/actors/Finalizer.d.ts +10 -4
- package/dist/node/shared/config/actors/Finalizer.d.ts.map +1 -1
- package/dist/node/shared/config/actors/Mempool.d.ts +4 -4
- package/dist/node/shared/config/actors/Producer.d.ts +6 -6
- package/dist/node/shared/config/actors/Producer.d.ts.map +1 -1
- package/dist/node/shared/config/actors/RewardRedemption.d.ts +4 -4
- package/dist/node/shared/orchestrator/Orchestrator.d.ts +16 -2
- package/dist/node/shared/orchestrator/Orchestrator.d.ts.map +1 -1
- package/package.json +80 -80
package/dist/node/index.mjs
CHANGED
|
@@ -4,7 +4,201 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/shared/actor/FinalizerActor.ts
|
|
5
5
|
import { creatable } from "@xylabs/sdk-js";
|
|
6
6
|
import { processPendingBlocks } from "@xyo-network/chain-sdk";
|
|
7
|
-
import {
|
|
7
|
+
import { BlockValidationViewerMoniker, BlockViewerMoniker, DeadLetterQueueRunnerMoniker, FinalizationRunnerMoniker, MempoolViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
8
|
+
|
|
9
|
+
// src/shared/actor/v3/ActorV3.ts
|
|
10
|
+
import { AbstractCreatable, assertEx, delay, IdLogger } from "@xylabs/sdk-js";
|
|
11
|
+
import { Semaphore } from "async-mutex";
|
|
12
|
+
import z from "zod";
|
|
13
|
+
var CreatableNameZod = z.custom((val) => typeof val === "string" && val.length > 0);
|
|
14
|
+
var StatusReporterInstanceZod = z.custom((val) => val !== null && typeof val === "object" && "report" in val);
|
|
15
|
+
var AccountInstanceZod = z.custom((val) => val !== null && typeof val === "object" && "address" in val);
|
|
16
|
+
var ActorParamsV3Zod = z.object({
|
|
17
|
+
account: AccountInstanceZod,
|
|
18
|
+
locator: z.unknown(),
|
|
19
|
+
name: CreatableNameZod,
|
|
20
|
+
statusReporter: StatusReporterInstanceZod.optional()
|
|
21
|
+
});
|
|
22
|
+
function createDeferred() {
|
|
23
|
+
let resolve;
|
|
24
|
+
let reject;
|
|
25
|
+
const promise = new Promise((res, rej) => {
|
|
26
|
+
resolve = res;
|
|
27
|
+
reject = rej;
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
promise,
|
|
31
|
+
resolve,
|
|
32
|
+
reject
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
__name(createDeferred, "createDeferred");
|
|
36
|
+
var ActorV3 = class extends AbstractCreatable {
|
|
37
|
+
static {
|
|
38
|
+
__name(this, "ActorV3");
|
|
39
|
+
}
|
|
40
|
+
_intervals = /* @__PURE__ */ new Map();
|
|
41
|
+
_semaphores = /* @__PURE__ */ new Map();
|
|
42
|
+
_timeouts = /* @__PURE__ */ new Map();
|
|
43
|
+
_logger;
|
|
44
|
+
_readyDeferred = createDeferred();
|
|
45
|
+
_readyError;
|
|
46
|
+
_readyState = "pending";
|
|
47
|
+
get logger() {
|
|
48
|
+
this._logger = new IdLogger(assertEx(this.context.logger, () => `Logger is required in context for actor ${this.name}.`), () => this.name);
|
|
49
|
+
return this._logger;
|
|
50
|
+
}
|
|
51
|
+
get readyError() {
|
|
52
|
+
return this._readyError;
|
|
53
|
+
}
|
|
54
|
+
get readyState() {
|
|
55
|
+
return this._readyState;
|
|
56
|
+
}
|
|
57
|
+
get account() {
|
|
58
|
+
return this.params.account;
|
|
59
|
+
}
|
|
60
|
+
get context() {
|
|
61
|
+
return this.locator.context;
|
|
62
|
+
}
|
|
63
|
+
get locator() {
|
|
64
|
+
return this.params.locator;
|
|
65
|
+
}
|
|
66
|
+
static async paramsHandler(params) {
|
|
67
|
+
const baseParams = await super.paramsHandler({
|
|
68
|
+
...params,
|
|
69
|
+
name: params.name ?? "UnknownActor"
|
|
70
|
+
});
|
|
71
|
+
const account = assertEx(params.account, () => `params.account is required for actor ${baseParams.name}.`);
|
|
72
|
+
const locator = assertEx(params.locator, () => `params.locator is required for actor ${baseParams.name}.`);
|
|
73
|
+
return {
|
|
74
|
+
...baseParams,
|
|
75
|
+
account,
|
|
76
|
+
locator
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The timer runs until the actor is deactivated (or you manually stop it).
|
|
81
|
+
*/
|
|
82
|
+
registerTimer(timerName, callback, dueTimeMs, periodMs) {
|
|
83
|
+
if (this.status !== "starting") {
|
|
84
|
+
this.logger?.warn(`Cannot register timer '${timerName}' because actor is not starting.`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
let running = false;
|
|
88
|
+
this._semaphores.set(timerName, new Semaphore(1));
|
|
89
|
+
const timeoutId = setTimeout(() => {
|
|
90
|
+
const intervalId = setInterval(() => {
|
|
91
|
+
const semaphore = this._semaphores.get(timerName);
|
|
92
|
+
if (this.status !== "started" || !this._intervals.has(timerName) || !semaphore || running) return;
|
|
93
|
+
if (semaphore.isLocked()) {
|
|
94
|
+
this.logger?.warn(`Skipping timer '${this.name}:${timerName}' execution because previous execution is still running.`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
semaphore.acquire().then(([, release]) => {
|
|
98
|
+
const startTime = Date.now();
|
|
99
|
+
running = true;
|
|
100
|
+
callback().then(() => {
|
|
101
|
+
const duration = Date.now() - startTime;
|
|
102
|
+
if (duration > periodMs) {
|
|
103
|
+
this.logger?.warn(`Timer '${this.name}:${timerName}' execution took longer (${duration}ms) than the period (${periodMs}ms).`);
|
|
104
|
+
} else if (duration > 5e3) {
|
|
105
|
+
this.logger?.warn(`Timer '${this.name}:${timerName}' execution took longer (${duration}ms) than 5000ms.`);
|
|
106
|
+
}
|
|
107
|
+
}).catch((error) => {
|
|
108
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
109
|
+
this.logger?.error(`Error in timer '${this.name}:${timerName}': ${err.message}`);
|
|
110
|
+
if (err.stack) this.logger?.error(err.stack);
|
|
111
|
+
}).finally(() => {
|
|
112
|
+
release();
|
|
113
|
+
running = false;
|
|
114
|
+
});
|
|
115
|
+
}).catch((error) => {
|
|
116
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
117
|
+
this.logger?.error(`Error acquiring semaphore for timer '${this.name}:${timerName}': ${err.message}`);
|
|
118
|
+
});
|
|
119
|
+
}, periodMs);
|
|
120
|
+
this._intervals.set(timerName, intervalId);
|
|
121
|
+
}, dueTimeMs);
|
|
122
|
+
this._timeouts.set(timerName, timeoutId);
|
|
123
|
+
this.logger?.debug(`Timer '${this.name}:${timerName}' registered: first call after ${dueTimeMs}ms, recurring every ${periodMs}ms.`);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Invoked by the Orchestrator after `start()` to run the warm-pass.
|
|
127
|
+
* Idempotent: returns immediately if already invoked.
|
|
128
|
+
* Throws if `readyHandler` throws; resolves once `readyHandler` resolves.
|
|
129
|
+
*/
|
|
130
|
+
async runReadyHandler() {
|
|
131
|
+
if (this._readyState !== "pending") return;
|
|
132
|
+
try {
|
|
133
|
+
await this.readyHandler();
|
|
134
|
+
this._readyState = "ready";
|
|
135
|
+
this._readyDeferred.resolve();
|
|
136
|
+
} catch (err) {
|
|
137
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
138
|
+
this._readyState = "failed";
|
|
139
|
+
this._readyError = error;
|
|
140
|
+
this._readyDeferred.reject(error);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async stopHandler() {
|
|
145
|
+
await super.stopHandler();
|
|
146
|
+
this.logger?.debug("Stopping all timers...");
|
|
147
|
+
await Promise.all([
|
|
148
|
+
...this._semaphores.values()
|
|
149
|
+
].map(async (semaphore) => {
|
|
150
|
+
while (semaphore.isLocked()) {
|
|
151
|
+
this.logger?.debug("Waiting for running timer task to complete...");
|
|
152
|
+
await delay(500);
|
|
153
|
+
}
|
|
154
|
+
await semaphore.acquire();
|
|
155
|
+
}));
|
|
156
|
+
this._semaphores.clear();
|
|
157
|
+
for (const [, timeoutRef] of this._timeouts.entries()) {
|
|
158
|
+
clearTimeout(timeoutRef);
|
|
159
|
+
}
|
|
160
|
+
this._timeouts.clear();
|
|
161
|
+
for (const [, intervalRef] of this._intervals.entries()) {
|
|
162
|
+
clearInterval(intervalRef);
|
|
163
|
+
}
|
|
164
|
+
this._intervals.clear();
|
|
165
|
+
this.logger?.debug("Stopped.");
|
|
166
|
+
}
|
|
167
|
+
async whenReady(timeoutMs) {
|
|
168
|
+
if (timeoutMs === void 0) {
|
|
169
|
+
await this._readyDeferred.promise;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
let timer;
|
|
173
|
+
const timeout = new Promise((_, reject) => {
|
|
174
|
+
timer = setTimeout(() => {
|
|
175
|
+
reject(new Error(`Actor ${this.name} did not become ready within ${timeoutMs}ms`));
|
|
176
|
+
}, timeoutMs);
|
|
177
|
+
});
|
|
178
|
+
try {
|
|
179
|
+
await Promise.race([
|
|
180
|
+
this._readyDeferred.promise,
|
|
181
|
+
timeout
|
|
182
|
+
]);
|
|
183
|
+
} finally {
|
|
184
|
+
if (timer) clearTimeout(timer);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Override in subclasses to prove the actor can do useful work.
|
|
189
|
+
* Default: no-op (the actor declares itself ready as soon as `start()` returns).
|
|
190
|
+
*/
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
192
|
+
async readyHandler() {
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var Actor = class extends ActorV3 {
|
|
196
|
+
static {
|
|
197
|
+
__name(this, "Actor");
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/shared/actor/FinalizerActor.ts
|
|
8
202
|
function _ts_decorate(decorators, target, key, desc) {
|
|
9
203
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
204
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -16,6 +210,17 @@ var FinalizerActor = class extends ActorV3 {
|
|
|
16
210
|
static {
|
|
17
211
|
__name(this, "FinalizerActor");
|
|
18
212
|
}
|
|
213
|
+
static needs = {
|
|
214
|
+
required: [
|
|
215
|
+
BlockValidationViewerMoniker,
|
|
216
|
+
BlockViewerMoniker,
|
|
217
|
+
FinalizationRunnerMoniker,
|
|
218
|
+
MempoolViewerMoniker
|
|
219
|
+
],
|
|
220
|
+
optional: [
|
|
221
|
+
DeadLetterQueueRunnerMoniker
|
|
222
|
+
]
|
|
223
|
+
};
|
|
19
224
|
_blockValidationViewer;
|
|
20
225
|
_blockViewer;
|
|
21
226
|
_deadLetterQueueRunner;
|
|
@@ -49,25 +254,32 @@ var FinalizerActor = class extends ActorV3 {
|
|
|
49
254
|
}
|
|
50
255
|
async startHandler() {
|
|
51
256
|
await super.startHandler();
|
|
257
|
+
const interval = this.params.config.finalizationCheckInterval ?? 500;
|
|
52
258
|
this.registerTimer("FinalizerActor", async () => {
|
|
53
|
-
await this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
259
|
+
await this.runFinalizationPass();
|
|
260
|
+
}, 2e3, interval);
|
|
261
|
+
}
|
|
262
|
+
async readyHandler() {
|
|
263
|
+
await this.runFinalizationPass();
|
|
264
|
+
}
|
|
265
|
+
async runFinalizationPass() {
|
|
266
|
+
await this.spanAsync("processPendingBlocks", async () => {
|
|
267
|
+
this.logger?.debug("FinalizerActor: Processing pending blocks...");
|
|
268
|
+
await processPendingBlocks({
|
|
269
|
+
blockValidationViewer: this.blockValidationViewer,
|
|
270
|
+
context: this.context,
|
|
271
|
+
logger: this.logger,
|
|
272
|
+
mempoolViewer: this.mempoolViewer,
|
|
273
|
+
blockViewer: this.blockViewer,
|
|
274
|
+
finalizationRunner: this.finalizationRunner,
|
|
275
|
+
allowedProducers: this.allowedProducers,
|
|
276
|
+
minCandidates: this.minCandidates,
|
|
277
|
+
deadLetterQueueRunner: this._deadLetterQueueRunner
|
|
69
278
|
});
|
|
70
|
-
},
|
|
279
|
+
}, {
|
|
280
|
+
...this.context,
|
|
281
|
+
timeBudgetLimit: 1500
|
|
282
|
+
});
|
|
71
283
|
}
|
|
72
284
|
};
|
|
73
285
|
FinalizerActor = _ts_decorate([
|
|
@@ -96,12 +308,12 @@ __name(buildTelemetryConfig, "buildTelemetryConfig");
|
|
|
96
308
|
// src/shared/config/actors/Api.ts
|
|
97
309
|
import { zodAsFactory, zodIsFactory, zodToFactory } from "@xylabs/sdk-js";
|
|
98
310
|
import { BaseConfigContextZod, HostActorConfigZod } from "@xyo-network/xl1-sdk";
|
|
99
|
-
import { globalRegistry, z } from "zod";
|
|
100
|
-
var ApiConfigZod = HostActorConfigZod.extend(
|
|
101
|
-
initRewardsCache:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
311
|
+
import { globalRegistry, z as z2 } from "zod";
|
|
312
|
+
var ApiConfigZod = HostActorConfigZod.extend(z2.object({
|
|
313
|
+
initRewardsCache: z2.union([
|
|
314
|
+
z2.number(),
|
|
315
|
+
z2.string(),
|
|
316
|
+
z2.boolean()
|
|
105
317
|
]).transform((v) => v !== "0" && v !== "false" && v !== false && v != 0).default(true).register(globalRegistry, {
|
|
106
318
|
description: "Whether to initialize the rewards cache on startup",
|
|
107
319
|
title: "api.initRewardsCache",
|
|
@@ -121,7 +333,7 @@ var toApiConfigContext = zodToFactory(ApiConfigContext, "toApiConfigContext");
|
|
|
121
333
|
// src/shared/config/actors/Bridge.ts
|
|
122
334
|
import { AddressZod, HexZod, toAddress, toHex, zodAsFactory as zodAsFactory2, zodIsFactory as zodIsFactory2, zodToFactory as zodToFactory2 } from "@xylabs/sdk-js";
|
|
123
335
|
import { AttoXL1ConvertFactor, BaseConfigContextZod as BaseConfigContextZod2, HostActorConfigZod as HostActorConfigZod2, XL1 } from "@xyo-network/xl1-sdk";
|
|
124
|
-
import { globalRegistry as globalRegistry2, z as
|
|
336
|
+
import { globalRegistry as globalRegistry2, z as z3 } from "zod";
|
|
125
337
|
var DEFAULT_FIXED_FEE = toHex(XL1(1000n) * AttoXL1ConvertFactor.xl1);
|
|
126
338
|
var DEFAULT_VARIABLE_FEE_BASIS_POINTS = 300;
|
|
127
339
|
var DEFAULT_HARDHAT_BRIDGE_CONTRACT = toAddress("2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6");
|
|
@@ -130,7 +342,7 @@ var DEFAULT_HARDHAT_REMOTE_CHAIN_WALLET_PRIVATE_KEY = toHex("0xac0974bec39a17e36
|
|
|
130
342
|
var DEFAULT_HARDHAT_TOKEN_CONTRACT = toAddress("5FbDB2315678afecb367f032d93F642f64180aa3");
|
|
131
343
|
var DEFAULT_MAX_BRIDGE_AMOUNT = toHex(XL1(1000000n) * AttoXL1ConvertFactor.xl1);
|
|
132
344
|
var DEFAULT_MIN_BRIDGE_AMOUNT = toHex(XL1(1500n) * AttoXL1ConvertFactor.xl1);
|
|
133
|
-
var BasisPointsZod =
|
|
345
|
+
var BasisPointsZod = z3.coerce.number().int().nonnegative().max(1e4);
|
|
134
346
|
var BridgeConfigZod = HostActorConfigZod2.extend({
|
|
135
347
|
escrowAddress: AddressZod.optional().register(globalRegistry2, {
|
|
136
348
|
description: "Address to which bridge escrow will be sent",
|
|
@@ -166,13 +378,13 @@ var BridgeConfigZod = HostActorConfigZod2.extend({
|
|
|
166
378
|
title: "bridge.minBridgeAmount",
|
|
167
379
|
type: "string"
|
|
168
380
|
}),
|
|
169
|
-
redisHost:
|
|
381
|
+
redisHost: z3.string().default("localhost").register(globalRegistry2, {
|
|
170
382
|
default: "localhost",
|
|
171
383
|
description: "Host for the Bridge Redis instance",
|
|
172
384
|
title: "bridge.redisHost",
|
|
173
385
|
type: "string"
|
|
174
386
|
}),
|
|
175
|
-
redisPort:
|
|
387
|
+
redisPort: z3.coerce.number().int().positive().default(6379).register(globalRegistry2, {
|
|
176
388
|
default: 6379,
|
|
177
389
|
description: "Port for the Bridge Redis instance",
|
|
178
390
|
title: "bridge.redisPort",
|
|
@@ -237,10 +449,14 @@ var toBridgeConfigContext = zodToFactory2(BridgeConfigContext, "toBridgeConfigCo
|
|
|
237
449
|
// src/shared/config/actors/Finalizer.ts
|
|
238
450
|
import { AddressZod as AddressZod2, zodAsFactory as zodAsFactory3, zodIsFactory as zodIsFactory3, zodToFactory as zodToFactory3 } from "@xylabs/sdk-js";
|
|
239
451
|
import { BaseConfigContextZod as BaseConfigContextZod3, DEFAULT_MIN_CANDIDATES, HostActorConfigZod as HostActorConfigZod3 } from "@xyo-network/xl1-sdk";
|
|
240
|
-
import { z as
|
|
452
|
+
import { z as z4 } from "zod";
|
|
241
453
|
var FinalizerConfigZod = HostActorConfigZod3.extend({
|
|
242
|
-
allowedProducers:
|
|
243
|
-
|
|
454
|
+
allowedProducers: z4.array(AddressZod2).optional(),
|
|
455
|
+
// Period (ms) between finalizer ticks. Default matches the historical
|
|
456
|
+
// hardcoded value in FinalizerActor; tests can lower it to drive faster
|
|
457
|
+
// block finalization.
|
|
458
|
+
finalizationCheckInterval: z4.coerce.number().default(500),
|
|
459
|
+
minCandidates: z4.number().int().min(0).default(DEFAULT_MIN_CANDIDATES)
|
|
244
460
|
});
|
|
245
461
|
var isFinalizerConfig = zodIsFactory3(FinalizerConfigZod);
|
|
246
462
|
var asFinalizerConfig = zodAsFactory3(FinalizerConfigZod, "asFinalizerConfig");
|
|
@@ -255,13 +471,13 @@ var toFinalizerConfigContext = zodToFactory3(FinalizerConfigContext, "toFinalize
|
|
|
255
471
|
// src/shared/config/actors/Mempool.ts
|
|
256
472
|
import { zodAsFactory as zodAsFactory4, zodIsFactory as zodIsFactory4, zodToFactory as zodToFactory4 } from "@xylabs/sdk-js";
|
|
257
473
|
import { BaseConfigContextZod as BaseConfigContextZod4, HostActorConfigZod as HostActorConfigZod4 } from "@xyo-network/xl1-sdk";
|
|
258
|
-
import { globalRegistry as globalRegistry3, z as
|
|
474
|
+
import { globalRegistry as globalRegistry3, z as z5 } from "zod";
|
|
259
475
|
var DEFAULT_MEMPOOL_BLOCK_PRUNE_INTERVAL = 1e3;
|
|
260
476
|
var DEFAULT_MEMPOOL_TRANSACTION_PRUNE_INTERVAL = 1e3;
|
|
261
477
|
var MempoolConfigZod = HostActorConfigZod4.extend({
|
|
262
|
-
enabled:
|
|
263
|
-
|
|
264
|
-
|
|
478
|
+
enabled: z5.union([
|
|
479
|
+
z5.string(),
|
|
480
|
+
z5.boolean()
|
|
265
481
|
]).default("false").transform((val, ctx) => {
|
|
266
482
|
if (typeof val === "boolean") return val;
|
|
267
483
|
const normalized = val.toLowerCase().trim();
|
|
@@ -282,19 +498,19 @@ var MempoolConfigZod = HostActorConfigZod4.extend({
|
|
|
282
498
|
expected: "boolean",
|
|
283
499
|
message: `Invalid boolean value: "${val}". Use true/false, 1/0, yes/no.`
|
|
284
500
|
});
|
|
285
|
-
return
|
|
501
|
+
return z5.NEVER;
|
|
286
502
|
}).register(globalRegistry3, {
|
|
287
503
|
default: "false",
|
|
288
504
|
description: "Enable the Mempool",
|
|
289
505
|
title: "mempool.enabled",
|
|
290
506
|
type: "boolean"
|
|
291
507
|
}),
|
|
292
|
-
blockPruneInterval:
|
|
508
|
+
blockPruneInterval: z5.coerce.number().default(DEFAULT_MEMPOOL_BLOCK_PRUNE_INTERVAL).register(globalRegistry3, {
|
|
293
509
|
description: "The interval time (in milliseconds) between pending block prune attempts",
|
|
294
510
|
title: "mempool.blockPruneInterval",
|
|
295
511
|
type: "number"
|
|
296
512
|
}),
|
|
297
|
-
transactionPruneInterval:
|
|
513
|
+
transactionPruneInterval: z5.coerce.number().default(DEFAULT_MEMPOOL_TRANSACTION_PRUNE_INTERVAL).register(globalRegistry3, {
|
|
298
514
|
description: "The interval time (in milliseconds) between pending transaction prune attempts",
|
|
299
515
|
title: "mempool.transactionPruneInterval",
|
|
300
516
|
type: "number"
|
|
@@ -311,44 +527,39 @@ var asMempoolConfigContext = zodAsFactory4(MempoolConfigContext, "asMempoolConfi
|
|
|
311
527
|
var toMempoolConfigContext = zodToFactory4(MempoolConfigContext, "toMempoolConfigContext");
|
|
312
528
|
|
|
313
529
|
// src/shared/config/actors/Producer.ts
|
|
314
|
-
import { AddressZod as AddressZod3,
|
|
530
|
+
import { AddressZod as AddressZod3, zodAsFactory as zodAsFactory5, zodIsFactory as zodIsFactory5, zodToFactory as zodToFactory5 } from "@xylabs/sdk-js";
|
|
315
531
|
import { ActorConfigZod, BaseConfigContextZod as BaseConfigContextZod5 } from "@xyo-network/xl1-sdk";
|
|
316
|
-
import { globalRegistry as globalRegistry4, z as
|
|
532
|
+
import { globalRegistry as globalRegistry4, z as z6 } from "zod";
|
|
317
533
|
var DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL = 1e4;
|
|
318
|
-
var ProducerConfigZod = ActorConfigZod.extend(
|
|
319
|
-
allowlist:
|
|
320
|
-
if (typeof val === "string") {
|
|
321
|
-
return val.split(",").map((s) => asAddress(s.trim()));
|
|
322
|
-
}
|
|
323
|
-
return val;
|
|
324
|
-
}, z5.array(AddressZod3).optional().register(globalRegistry4, {
|
|
534
|
+
var ProducerConfigZod = ActorConfigZod.extend(z6.object({
|
|
535
|
+
allowlist: z6.array(AddressZod3).optional().register(globalRegistry4, {
|
|
325
536
|
description: "List of allowed producer addresses, if undefined anyone can participate",
|
|
326
537
|
title: "allowlist",
|
|
327
538
|
type: "array"
|
|
328
|
-
})
|
|
329
|
-
blockProductionCheckInterval:
|
|
539
|
+
}),
|
|
540
|
+
blockProductionCheckInterval: z6.coerce.number().default(DEFAULT_BLOCK_PRODUCTION_CHECK_INTERVAL).register(globalRegistry4, {
|
|
330
541
|
description: "The interval time (in milliseconds) between block production attempts",
|
|
331
542
|
title: "producer.blockProductionCheckInterval",
|
|
332
543
|
type: "number"
|
|
333
544
|
}),
|
|
334
|
-
disableIntentRedeclaration:
|
|
545
|
+
disableIntentRedeclaration: z6.boolean().optional().register(globalRegistry4, {
|
|
335
546
|
description: "Should the producer skip redeclaring their intent to continue producing blocks",
|
|
336
547
|
title: "producer.disableIntentRedeclaration",
|
|
337
548
|
type: "boolean"
|
|
338
549
|
}),
|
|
339
|
-
heartbeatInterval:
|
|
550
|
+
heartbeatInterval: z6.coerce.number().default(36e5).register(globalRegistry4, {
|
|
340
551
|
description: "The number of milliseconds between heartbeats if no blocks are produced",
|
|
341
552
|
title: "producer.heartbeatInterval",
|
|
342
553
|
type: "number"
|
|
343
554
|
}),
|
|
344
555
|
// TODO: BigInt schema
|
|
345
|
-
minStake:
|
|
556
|
+
minStake: z6.coerce.number().default(1).register(globalRegistry4, {
|
|
346
557
|
description: "Minimum stake required to be a Producer",
|
|
347
558
|
title: "producer.minStake",
|
|
348
559
|
type: "number"
|
|
349
560
|
}),
|
|
350
561
|
// TODO: Address schema
|
|
351
|
-
rewardAddress:
|
|
562
|
+
rewardAddress: z6.string().optional().register(globalRegistry4, {
|
|
352
563
|
description: "Address to receive block rewards",
|
|
353
564
|
title: "producer.rewardAddress",
|
|
354
565
|
type: "string"
|
|
@@ -765,7 +976,7 @@ async function initActorAccount({ config, logger }) {
|
|
|
765
976
|
__name(initActorAccount, "initActorAccount");
|
|
766
977
|
|
|
767
978
|
// src/shared/init/initActorSeedPhrase.ts
|
|
768
|
-
import { assertEx, isString } from "@xylabs/sdk-js";
|
|
979
|
+
import { assertEx as assertEx2, isString } from "@xylabs/sdk-js";
|
|
769
980
|
async function initActorSeedPhrase(context, bios) {
|
|
770
981
|
const { logger, config } = context;
|
|
771
982
|
const walletKind = config.name;
|
|
@@ -774,12 +985,12 @@ async function initActorSeedPhrase(context, bios) {
|
|
|
774
985
|
if (isString(report?.root.mnemonic)) return report.root.mnemonic;
|
|
775
986
|
const fallback = getBuiltInDevMnemonic();
|
|
776
987
|
logger?.debug(`[${walletKind}] Falling back to built-in development mnemonic`);
|
|
777
|
-
return
|
|
988
|
+
return assertEx2(fallback, () => "Unable to resolve mnemonic");
|
|
778
989
|
}
|
|
779
990
|
__name(initActorSeedPhrase, "initActorSeedPhrase");
|
|
780
991
|
|
|
781
992
|
// src/shared/init/initBridgedModule.ts
|
|
782
|
-
import { assertEx as
|
|
993
|
+
import { assertEx as assertEx3 } from "@xylabs/sdk-js";
|
|
783
994
|
import { asAttachableArchivistInstance, asAttachableModuleInstance } from "@xyo-network/sdk-js";
|
|
784
995
|
import { Mutex } from "async-mutex";
|
|
785
996
|
var initMutex = new Mutex();
|
|
@@ -788,8 +999,8 @@ async function initBridgedModule({ bridge, moduleName }) {
|
|
|
788
999
|
return await initMutex.runExclusive(async () => {
|
|
789
1000
|
const existing = bridgedModuleDictionary?.[bridge.address]?.[moduleName];
|
|
790
1001
|
if (existing) return existing;
|
|
791
|
-
const mod =
|
|
792
|
-
const moduleInstance =
|
|
1002
|
+
const mod = assertEx3(await bridge.resolve(moduleName), () => `Could not resolve ${moduleName}`);
|
|
1003
|
+
const moduleInstance = assertEx3(asAttachableModuleInstance(mod), () => `Could not convert ${moduleName} to attachable module instance`);
|
|
793
1004
|
let moduleMap = bridgedModuleDictionary[bridge.address];
|
|
794
1005
|
if (moduleMap === void 0) {
|
|
795
1006
|
moduleMap = {};
|
|
@@ -801,7 +1012,7 @@ async function initBridgedModule({ bridge, moduleName }) {
|
|
|
801
1012
|
}
|
|
802
1013
|
__name(initBridgedModule, "initBridgedModule");
|
|
803
1014
|
async function initBridgedArchivistModule({ bridge, moduleName }) {
|
|
804
|
-
return
|
|
1015
|
+
return assertEx3(asAttachableArchivistInstance(await initBridgedModule({
|
|
805
1016
|
bridge,
|
|
806
1017
|
moduleName
|
|
807
1018
|
})), () => `Could not convert ${moduleName} to attachable archivist instance`);
|
|
@@ -836,7 +1047,7 @@ async function initActorWallet(context) {
|
|
|
836
1047
|
__name(initActorWallet, "initActorWallet");
|
|
837
1048
|
|
|
838
1049
|
// src/shared/orchestrator/Orchestrator.ts
|
|
839
|
-
import { AbstractCreatable, creatable as creatable2 } from "@xylabs/sdk-js";
|
|
1050
|
+
import { AbstractCreatable as AbstractCreatable2, creatable as creatable2 } from "@xylabs/sdk-js";
|
|
840
1051
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
841
1052
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
842
1053
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -844,25 +1055,43 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
844
1055
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
845
1056
|
}
|
|
846
1057
|
__name(_ts_decorate2, "_ts_decorate");
|
|
847
|
-
var Orchestrator = class extends
|
|
1058
|
+
var Orchestrator = class extends AbstractCreatable2 {
|
|
848
1059
|
static {
|
|
849
1060
|
__name(this, "Orchestrator");
|
|
850
1061
|
}
|
|
851
1062
|
actors = [];
|
|
852
|
-
keepAliveHandle = null;
|
|
853
1063
|
running = false;
|
|
1064
|
+
shuttingDown = false;
|
|
1065
|
+
get readyState() {
|
|
1066
|
+
if (this.actors.length === 0) return "pending";
|
|
1067
|
+
if (this.actors.some((a) => isLocalActor(a) && a.readyState === "failed")) return "failed";
|
|
1068
|
+
if (this.actors.every((a) => isLocalActor(a) && a.readyState === "ready")) return "ready";
|
|
1069
|
+
return "pending";
|
|
1070
|
+
}
|
|
1071
|
+
isReady() {
|
|
1072
|
+
return this.readyState === "ready" && !this.shuttingDown;
|
|
1073
|
+
}
|
|
1074
|
+
isShuttingDown() {
|
|
1075
|
+
return this.shuttingDown;
|
|
1076
|
+
}
|
|
854
1077
|
/**
|
|
855
1078
|
* Registers an actor.
|
|
856
1079
|
* (We won't activate the actor until `start()` is called.)
|
|
857
1080
|
*/
|
|
858
1081
|
async registerActor(actor) {
|
|
1082
|
+
this.actors.push(actor);
|
|
859
1083
|
if (this.running) {
|
|
860
1084
|
await actor.start();
|
|
1085
|
+
if (isLocalActor(actor)) {
|
|
1086
|
+
actor.runReadyHandler().catch((err) => {
|
|
1087
|
+
this.logger?.error(`[Orchestrator] Actor [${actor.name}] readyHandler failed: ${formatError(err)}`);
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
861
1090
|
}
|
|
862
|
-
this.actors.push(actor);
|
|
863
1091
|
}
|
|
864
1092
|
/**
|
|
865
|
-
* Starts the orchestrator: activates all actors.
|
|
1093
|
+
* Starts the orchestrator: activates all actors in parallel and kicks off their warm-pass.
|
|
1094
|
+
* `whenReady()` resolves once every actor's `readyHandler` has succeeded.
|
|
866
1095
|
*/
|
|
867
1096
|
async startHandler() {
|
|
868
1097
|
await super.startHandler();
|
|
@@ -870,13 +1099,26 @@ var Orchestrator = class extends AbstractCreatable {
|
|
|
870
1099
|
this.logger?.warn("[Orchestrator] Already started.");
|
|
871
1100
|
return;
|
|
872
1101
|
}
|
|
873
|
-
this.logger?.log(
|
|
1102
|
+
this.logger?.log(`[Orchestrator] Starting ${this.actors.length} actor(s) in parallel...`);
|
|
874
1103
|
this.running = true;
|
|
1104
|
+
const startResults = await Promise.allSettled(this.actors.map((a) => a.start()));
|
|
1105
|
+
const startFailures = startResults.flatMap((r, i) => r.status === "rejected" ? [
|
|
1106
|
+
{
|
|
1107
|
+
actor: this.actors[i],
|
|
1108
|
+
reason: r.reason
|
|
1109
|
+
}
|
|
1110
|
+
] : []);
|
|
1111
|
+
if (startFailures.length > 0) {
|
|
1112
|
+
for (const f of startFailures) this.logger?.error(`[Orchestrator] Actor [${f.actor?.name ?? "?"}] failed to start: ${formatError(f.reason)}`);
|
|
1113
|
+
throw new Error(`[Orchestrator] ${startFailures.length} actor(s) failed to start`);
|
|
1114
|
+
}
|
|
875
1115
|
for (const actor of this.actors) {
|
|
876
|
-
|
|
1116
|
+
if (isLocalActor(actor)) {
|
|
1117
|
+
actor.runReadyHandler().catch((err) => {
|
|
1118
|
+
this.logger?.error(`[Orchestrator] Actor [${actor.name}] readyHandler failed: ${formatError(err)}`);
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
877
1121
|
}
|
|
878
|
-
this.keepAliveHandle = setInterval(() => {
|
|
879
|
-
}, 2147483647);
|
|
880
1122
|
}
|
|
881
1123
|
/**
|
|
882
1124
|
* Stops the orchestrator: deactivates all actors.
|
|
@@ -888,20 +1130,55 @@ var Orchestrator = class extends AbstractCreatable {
|
|
|
888
1130
|
return;
|
|
889
1131
|
}
|
|
890
1132
|
this.logger?.log("[Orchestrator] Stopping...");
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
1133
|
+
this.shuttingDown = true;
|
|
1134
|
+
await Promise.allSettled(this.actors.map((a) => a.stop()));
|
|
894
1135
|
this.running = false;
|
|
895
|
-
|
|
896
|
-
this.logger?.log("[Orchestrator] Stopped
|
|
1136
|
+
this.shuttingDown = false;
|
|
1137
|
+
this.logger?.log("[Orchestrator] Stopped.");
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Resolves once every actor reports ready. Rejects if any actor's `readyHandler` throws,
|
|
1141
|
+
* or after `timeoutMs` if provided.
|
|
1142
|
+
*/
|
|
1143
|
+
async whenReady(timeoutMs) {
|
|
1144
|
+
const localActors = this.actors.filter(isLocalActor);
|
|
1145
|
+
if (localActors.length === 0) return;
|
|
1146
|
+
if (timeoutMs === void 0) {
|
|
1147
|
+
await Promise.all(localActors.map((a) => a.whenReady()));
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
let timer;
|
|
1151
|
+
const timeout = new Promise((_, reject) => {
|
|
1152
|
+
timer = setTimeout(() => {
|
|
1153
|
+
reject(new Error(`[Orchestrator] Not ready within ${timeoutMs}ms`));
|
|
1154
|
+
}, timeoutMs);
|
|
1155
|
+
});
|
|
1156
|
+
try {
|
|
1157
|
+
await Promise.race([
|
|
1158
|
+
Promise.all(localActors.map((a) => a.whenReady())),
|
|
1159
|
+
timeout
|
|
1160
|
+
]);
|
|
1161
|
+
} finally {
|
|
1162
|
+
if (timer) clearTimeout(timer);
|
|
1163
|
+
}
|
|
897
1164
|
}
|
|
898
1165
|
};
|
|
899
1166
|
Orchestrator = _ts_decorate2([
|
|
900
1167
|
creatable2()
|
|
901
1168
|
], Orchestrator);
|
|
1169
|
+
function isLocalActor(actor) {
|
|
1170
|
+
return actor instanceof ActorV3;
|
|
1171
|
+
}
|
|
1172
|
+
__name(isLocalActor, "isLocalActor");
|
|
1173
|
+
function formatError(err) {
|
|
1174
|
+
if (err instanceof Error) return `${err.message}${err.stack ? `
|
|
1175
|
+
${err.stack}` : ""}`;
|
|
1176
|
+
return String(err);
|
|
1177
|
+
}
|
|
1178
|
+
__name(formatError, "formatError");
|
|
902
1179
|
|
|
903
1180
|
// src/shared/provider/SimpleRejectedTransactionsArchivistProvider.ts
|
|
904
|
-
import { assertEx as
|
|
1181
|
+
import { assertEx as assertEx4 } from "@xylabs/sdk-js";
|
|
905
1182
|
import { AbstractCreatableProvider, creatableProvider } from "@xyo-network/xl1-sdk";
|
|
906
1183
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
907
1184
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -927,7 +1204,7 @@ var SimpleRejectedTransactionsArchivistProvider = class _SimpleRejectedTransacti
|
|
|
927
1204
|
static async paramsHandler(params) {
|
|
928
1205
|
return {
|
|
929
1206
|
...await super.paramsHandler(params),
|
|
930
|
-
archivist:
|
|
1207
|
+
archivist: assertEx4(params?.archivist, () => "archivist is required")
|
|
931
1208
|
};
|
|
932
1209
|
}
|
|
933
1210
|
};
|
|
@@ -935,91 +1212,346 @@ SimpleRejectedTransactionsArchivistProvider = _ts_decorate3([
|
|
|
935
1212
|
creatableProvider()
|
|
936
1213
|
], SimpleRejectedTransactionsArchivistProvider);
|
|
937
1214
|
|
|
938
|
-
// src/node/config/
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
if (isAccountInstance(signer)) {
|
|
943
|
-
return SimpleXyoSigner.factory(SimpleXyoSigner.dependencies, {
|
|
944
|
-
account: signer
|
|
945
|
-
});
|
|
1215
|
+
// src/node/config/capabilities/Capability.ts
|
|
1216
|
+
var CapabilityRegistry = class CapabilityRegistry2 {
|
|
1217
|
+
static {
|
|
1218
|
+
__name(this, "CapabilityRegistry");
|
|
946
1219
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
1220
|
+
_entries = /* @__PURE__ */ new Map();
|
|
1221
|
+
get(id) {
|
|
1222
|
+
const cap = this._entries.get(id);
|
|
1223
|
+
if (!cap) throw new Error(`Capability not found: ${id}`);
|
|
1224
|
+
return cap;
|
|
1225
|
+
}
|
|
1226
|
+
register(cap) {
|
|
1227
|
+
if (this._entries.has(cap.id)) {
|
|
1228
|
+
throw new Error(`Capability already registered: ${cap.id}`);
|
|
1229
|
+
}
|
|
1230
|
+
this._entries.set(cap.id, cap);
|
|
1231
|
+
return this;
|
|
1232
|
+
}
|
|
1233
|
+
toJson() {
|
|
1234
|
+
const result = {};
|
|
1235
|
+
for (const [id, cap] of this._entries.entries()) {
|
|
1236
|
+
const { id: _, ...rest } = cap;
|
|
1237
|
+
result[id] = rest;
|
|
1238
|
+
}
|
|
1239
|
+
return result;
|
|
1240
|
+
}
|
|
1241
|
+
tryGet(id) {
|
|
1242
|
+
return this._entries.get(id);
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
function createCapabilityRegistry() {
|
|
1246
|
+
return new CapabilityRegistry();
|
|
950
1247
|
}
|
|
951
|
-
__name(
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1248
|
+
__name(createCapabilityRegistry, "createCapabilityRegistry");
|
|
1249
|
+
|
|
1250
|
+
// src/node/config/capabilities/defaultCapabilityRegistry.ts
|
|
1251
|
+
import { AccountBalanceViewerMoniker, BlockRunnerMoniker, BlockValidationViewerMoniker as BlockValidationViewerMoniker2, BlockViewerMoniker as BlockViewerMoniker2, ChainContractViewerMoniker, DeadLetterQueueRunnerMoniker as DeadLetterQueueRunnerMoniker2, DeadLetterQueueViewerMoniker, FinalizationRunnerMoniker as FinalizationRunnerMoniker2, FinalizationViewerMoniker, MempoolRunnerMoniker, MempoolViewerMoniker as MempoolViewerMoniker2, StakeTotalsViewerMoniker, TimeSyncViewerMoniker, TransactionValidationViewerMoniker, TransactionViewerMoniker, WindowedBlockViewerMoniker, XyoViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
1252
|
+
var XyoConnectionMoniker = "XyoConnection";
|
|
1253
|
+
var XyoGatewayRunnerMoniker = "XyoGatewayRunner";
|
|
1254
|
+
var capabilities = [
|
|
1255
|
+
{
|
|
1256
|
+
id: BlockViewerMoniker2,
|
|
1257
|
+
label: "Block viewer",
|
|
1258
|
+
kind: "viewer"
|
|
1259
|
+
},
|
|
1260
|
+
{
|
|
1261
|
+
id: WindowedBlockViewerMoniker,
|
|
1262
|
+
label: "Windowed block viewer",
|
|
1263
|
+
kind: "viewer"
|
|
1264
|
+
},
|
|
1265
|
+
{
|
|
1266
|
+
id: MempoolViewerMoniker2,
|
|
1267
|
+
label: "Mempool viewer",
|
|
1268
|
+
kind: "viewer"
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
id: MempoolRunnerMoniker,
|
|
1272
|
+
label: "Mempool runner",
|
|
1273
|
+
kind: "runner"
|
|
1274
|
+
},
|
|
1275
|
+
{
|
|
1276
|
+
id: AccountBalanceViewerMoniker,
|
|
1277
|
+
label: "Account balance viewer",
|
|
1278
|
+
kind: "viewer"
|
|
1279
|
+
},
|
|
1280
|
+
{
|
|
1281
|
+
id: FinalizationViewerMoniker,
|
|
1282
|
+
label: "Finalization viewer",
|
|
1283
|
+
kind: "viewer"
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
id: FinalizationRunnerMoniker2,
|
|
1287
|
+
label: "Finalization runner",
|
|
1288
|
+
kind: "runner"
|
|
1289
|
+
},
|
|
1290
|
+
{
|
|
1291
|
+
id: TransactionViewerMoniker,
|
|
1292
|
+
label: "Transaction viewer",
|
|
1293
|
+
kind: "viewer"
|
|
1294
|
+
},
|
|
1295
|
+
{
|
|
1296
|
+
id: BlockValidationViewerMoniker2,
|
|
1297
|
+
label: "Block validation viewer",
|
|
1298
|
+
kind: "viewer"
|
|
1299
|
+
},
|
|
1300
|
+
{
|
|
1301
|
+
id: TransactionValidationViewerMoniker,
|
|
1302
|
+
label: "Transaction validation viewer",
|
|
1303
|
+
kind: "viewer"
|
|
1304
|
+
},
|
|
1305
|
+
{
|
|
1306
|
+
id: DeadLetterQueueViewerMoniker,
|
|
1307
|
+
label: "Dead-letter queue viewer",
|
|
1308
|
+
kind: "viewer"
|
|
1309
|
+
},
|
|
1310
|
+
{
|
|
1311
|
+
id: DeadLetterQueueRunnerMoniker2,
|
|
1312
|
+
label: "Dead-letter queue runner",
|
|
1313
|
+
kind: "runner"
|
|
1314
|
+
},
|
|
1315
|
+
{
|
|
1316
|
+
id: ChainContractViewerMoniker,
|
|
1317
|
+
label: "Chain contract viewer",
|
|
1318
|
+
kind: "viewer"
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
id: StakeTotalsViewerMoniker,
|
|
1322
|
+
label: "Stake totals viewer",
|
|
1323
|
+
kind: "viewer"
|
|
1324
|
+
},
|
|
1325
|
+
{
|
|
1326
|
+
id: TimeSyncViewerMoniker,
|
|
1327
|
+
label: "Time sync viewer",
|
|
1328
|
+
kind: "viewer"
|
|
1329
|
+
},
|
|
1330
|
+
{
|
|
1331
|
+
id: XyoViewerMoniker,
|
|
1332
|
+
label: "XYO viewer",
|
|
1333
|
+
kind: "viewer"
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
id: XyoConnectionMoniker,
|
|
1337
|
+
label: "XYO connection",
|
|
1338
|
+
kind: "gateway"
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
id: XyoGatewayRunnerMoniker,
|
|
1342
|
+
label: "XYO gateway runner",
|
|
1343
|
+
kind: "gateway"
|
|
1344
|
+
},
|
|
1345
|
+
{
|
|
1346
|
+
id: RejectedTransactionsArchivistProviderMoniker,
|
|
1347
|
+
label: "Rejected transactions archivist provider",
|
|
1348
|
+
kind: "archivist"
|
|
1349
|
+
},
|
|
1350
|
+
{
|
|
1351
|
+
id: BlockRunnerMoniker,
|
|
1352
|
+
label: "Block runner",
|
|
1353
|
+
kind: "runner",
|
|
1354
|
+
implies: [
|
|
1355
|
+
AccountBalanceViewerMoniker,
|
|
1356
|
+
BlockValidationViewerMoniker2,
|
|
1357
|
+
ChainContractViewerMoniker,
|
|
1358
|
+
FinalizationViewerMoniker,
|
|
1359
|
+
MempoolRunnerMoniker,
|
|
1360
|
+
MempoolViewerMoniker2,
|
|
1361
|
+
TimeSyncViewerMoniker
|
|
1362
|
+
]
|
|
1363
|
+
}
|
|
1364
|
+
];
|
|
1365
|
+
function createDefaultCapabilityRegistry() {
|
|
1366
|
+
const registry = createCapabilityRegistry();
|
|
1367
|
+
for (const cap of capabilities) registry.register(cap);
|
|
1368
|
+
return registry;
|
|
962
1369
|
}
|
|
963
|
-
__name(
|
|
1370
|
+
__name(createDefaultCapabilityRegistry, "createDefaultCapabilityRegistry");
|
|
964
1371
|
|
|
965
|
-
// src/node/config/
|
|
966
|
-
import {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1372
|
+
// src/node/config/capabilities/descriptors.ts
|
|
1373
|
+
import { SimpleAccountBalanceViewer, SimpleBlockValidationViewer, SimpleBlockViewer, SimpleDeadLetterQueueRunner, SimpleDeadLetterQueueViewer, SimpleFinalizationRunner, SimpleFinalizationViewer, SimpleMempoolRunner, SimpleMempoolViewer, SimpleTransactionValidationViewer, SimpleTransactionViewer, SimpleWindowedBlockViewer, SimpleXyoConnectionViewer, SimpleXyoViewer } from "@xyo-network/xl1-sdk";
|
|
1374
|
+
var passes = /* @__PURE__ */ __name(() => true, "passes");
|
|
1375
|
+
var localTier1Descriptors = [
|
|
1376
|
+
{
|
|
1377
|
+
id: "SimpleMempoolViewer",
|
|
1378
|
+
satisfies: [
|
|
1379
|
+
SimpleMempoolViewer.defaultMoniker
|
|
971
1380
|
],
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1381
|
+
tier: 1,
|
|
1382
|
+
preconditions: passes,
|
|
1383
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleMempoolViewer.factory(SimpleMempoolViewer.dependencies, {
|
|
1384
|
+
pendingTransactionsArchivist: ctx.process.pendingTransactionsArchivist,
|
|
1385
|
+
pendingBlocksArchivist: ctx.process.pendingBlocksArchivist
|
|
1386
|
+
}), "build")
|
|
1387
|
+
},
|
|
1388
|
+
{
|
|
1389
|
+
id: "SimpleMempoolRunner",
|
|
1390
|
+
satisfies: [
|
|
1391
|
+
SimpleMempoolRunner.defaultMoniker
|
|
1392
|
+
],
|
|
1393
|
+
tier: 1,
|
|
1394
|
+
preconditions: passes,
|
|
1395
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleMempoolRunner.factory(SimpleMempoolRunner.dependencies, {
|
|
1396
|
+
pendingTransactionsArchivist: ctx.process.pendingTransactionsArchivist,
|
|
1397
|
+
pendingBlocksArchivist: ctx.process.pendingBlocksArchivist
|
|
1398
|
+
}), "build")
|
|
1399
|
+
},
|
|
1400
|
+
{
|
|
1401
|
+
id: "SimpleAccountBalanceViewer",
|
|
1402
|
+
satisfies: [
|
|
1403
|
+
SimpleAccountBalanceViewer.defaultMoniker
|
|
1404
|
+
],
|
|
1405
|
+
tier: 1,
|
|
1406
|
+
preconditions: passes,
|
|
1407
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleAccountBalanceViewer.factory(SimpleAccountBalanceViewer.dependencies, {
|
|
1408
|
+
balancesSummaryMap: ctx.process.balancesSummaryMap,
|
|
1409
|
+
transfersSummaryMap: ctx.process.transfersSummaryMap
|
|
1410
|
+
}), "build")
|
|
1411
|
+
},
|
|
1412
|
+
{
|
|
1413
|
+
id: "SimpleFinalizationViewer",
|
|
1414
|
+
satisfies: [
|
|
1415
|
+
SimpleFinalizationViewer.defaultMoniker
|
|
1416
|
+
],
|
|
1417
|
+
tier: 1,
|
|
1418
|
+
preconditions: passes,
|
|
1419
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleFinalizationViewer.factory(SimpleFinalizationViewer.dependencies, {
|
|
1420
|
+
finalizedArchivist: ctx.process.readonlyChainArchivist
|
|
1421
|
+
}), "build")
|
|
1422
|
+
},
|
|
1423
|
+
{
|
|
1424
|
+
id: "SimpleBlockViewer",
|
|
1425
|
+
satisfies: [
|
|
1426
|
+
SimpleBlockViewer.defaultMoniker
|
|
1427
|
+
],
|
|
1428
|
+
tier: 1,
|
|
1429
|
+
preconditions: passes,
|
|
1430
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleBlockViewer.factory(SimpleBlockViewer.dependencies, {
|
|
1431
|
+
finalizedArchivist: ctx.process.readonlyChainArchivist
|
|
1432
|
+
}), "build")
|
|
1433
|
+
},
|
|
1434
|
+
{
|
|
1435
|
+
id: "SimpleWindowedBlockViewer",
|
|
1436
|
+
satisfies: [
|
|
1437
|
+
SimpleWindowedBlockViewer.defaultMoniker
|
|
1438
|
+
],
|
|
1439
|
+
tier: 1,
|
|
1440
|
+
preconditions: passes,
|
|
1441
|
+
build: /* @__PURE__ */ __name(() => SimpleWindowedBlockViewer.factory(SimpleWindowedBlockViewer.dependencies, {
|
|
1442
|
+
maxWindowSize: 1e3,
|
|
1443
|
+
syncInterval: 1e4
|
|
1444
|
+
}), "build")
|
|
1445
|
+
},
|
|
1446
|
+
{
|
|
1447
|
+
id: "SimpleXyoConnectionViewer",
|
|
1448
|
+
satisfies: [
|
|
1449
|
+
SimpleXyoConnectionViewer.defaultMoniker
|
|
1450
|
+
],
|
|
1451
|
+
tier: 1,
|
|
1452
|
+
preconditions: passes,
|
|
1453
|
+
build: /* @__PURE__ */ __name(() => SimpleXyoConnectionViewer.factory(SimpleXyoConnectionViewer.dependencies, {}), "build")
|
|
1454
|
+
},
|
|
1455
|
+
{
|
|
1456
|
+
id: "SimpleTransactionViewer",
|
|
1457
|
+
satisfies: [
|
|
1458
|
+
SimpleTransactionViewer.defaultMoniker
|
|
1459
|
+
],
|
|
1460
|
+
tier: 1,
|
|
1461
|
+
preconditions: passes,
|
|
1462
|
+
build: /* @__PURE__ */ __name(() => SimpleTransactionViewer.factory(SimpleTransactionViewer.dependencies, {}), "build")
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
id: "SimpleXyoViewer",
|
|
1466
|
+
satisfies: [
|
|
1467
|
+
SimpleXyoViewer.defaultMoniker
|
|
1468
|
+
],
|
|
1469
|
+
tier: 1,
|
|
1470
|
+
preconditions: passes,
|
|
1471
|
+
build: /* @__PURE__ */ __name(() => SimpleXyoViewer.factory(SimpleXyoViewer.dependencies, {}), "build")
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
id: "SimpleFinalizationRunner",
|
|
1475
|
+
satisfies: [
|
|
1476
|
+
SimpleFinalizationRunner.defaultMoniker
|
|
1477
|
+
],
|
|
1478
|
+
tier: 1,
|
|
1479
|
+
preconditions: passes,
|
|
1480
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleFinalizationRunner.factory(SimpleFinalizationRunner.dependencies, {
|
|
1481
|
+
finalizedArchivist: ctx.process.writableChainArchivist
|
|
1482
|
+
}), "build")
|
|
1483
|
+
},
|
|
1484
|
+
{
|
|
1485
|
+
id: "SimpleBlockValidationViewer",
|
|
1486
|
+
satisfies: [
|
|
1487
|
+
SimpleBlockValidationViewer.defaultMoniker
|
|
1488
|
+
],
|
|
1489
|
+
tier: 1,
|
|
1490
|
+
preconditions: passes,
|
|
1491
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleBlockValidationViewer.factory(SimpleBlockValidationViewer.dependencies, {
|
|
1492
|
+
state: ctx.process.blockStateValidator,
|
|
1493
|
+
protocol: ctx.process.blockProtocolValidator
|
|
1494
|
+
}), "build")
|
|
1495
|
+
},
|
|
1496
|
+
{
|
|
1497
|
+
id: "SimpleTransactionValidationViewer",
|
|
1498
|
+
satisfies: [
|
|
1499
|
+
SimpleTransactionValidationViewer.defaultMoniker
|
|
1500
|
+
],
|
|
1501
|
+
tier: 1,
|
|
1502
|
+
preconditions: passes,
|
|
1503
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleTransactionValidationViewer.factory(SimpleTransactionValidationViewer.dependencies, {
|
|
1504
|
+
protocol: ctx.process.transactionProtocolValidator,
|
|
1505
|
+
state: ctx.process.transactionStateValidator
|
|
1506
|
+
}), "build")
|
|
1507
|
+
},
|
|
1508
|
+
{
|
|
1509
|
+
id: "SimpleDeadLetterQueueRunner",
|
|
1510
|
+
satisfies: [
|
|
1511
|
+
SimpleDeadLetterQueueRunner.defaultMoniker
|
|
1512
|
+
],
|
|
1513
|
+
tier: 1,
|
|
1514
|
+
preconditions: passes,
|
|
1515
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleDeadLetterQueueRunner.factory(SimpleDeadLetterQueueRunner.dependencies, {
|
|
1516
|
+
rejectedBlocksArchivist: ctx.process.rejectedBlocksArchivist,
|
|
1517
|
+
rejectedTransactionsArchivist: ctx.process.rejectedTransactionsArchivist
|
|
1518
|
+
}), "build")
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
id: "SimpleDeadLetterQueueViewer",
|
|
1522
|
+
satisfies: [
|
|
1523
|
+
SimpleDeadLetterQueueViewer.defaultMoniker
|
|
1524
|
+
],
|
|
1525
|
+
tier: 1,
|
|
1526
|
+
preconditions: passes,
|
|
1527
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleDeadLetterQueueViewer.factory(SimpleDeadLetterQueueViewer.dependencies, {
|
|
1528
|
+
rejectedBlocksArchivist: ctx.process.rejectedBlocksArchivist,
|
|
1529
|
+
rejectedTransactionsArchivist: ctx.process.rejectedTransactionsArchivist
|
|
1530
|
+
}), "build")
|
|
1531
|
+
},
|
|
1532
|
+
{
|
|
1533
|
+
id: "SimpleRejectedTransactionsArchivistProvider",
|
|
1534
|
+
satisfies: [
|
|
1535
|
+
SimpleRejectedTransactionsArchivistProvider.defaultMoniker
|
|
1536
|
+
],
|
|
1537
|
+
tier: 1,
|
|
1538
|
+
preconditions: passes,
|
|
1539
|
+
build: /* @__PURE__ */ __name((ctx) => SimpleRejectedTransactionsArchivistProvider.factory(SimpleRejectedTransactionsArchivistProvider.dependencies, {
|
|
1540
|
+
archivist: ctx.process.rejectedTransactionsArchivist
|
|
1541
|
+
}), "build")
|
|
1542
|
+
}
|
|
1543
|
+
];
|
|
976
1544
|
|
|
977
|
-
// src/node/config/
|
|
978
|
-
import {
|
|
979
|
-
async function telemetryContextFromConfig(config, serviceName, serviceVersion) {
|
|
980
|
-
const { otlpEndpoint } = config.telemetry?.otel ?? {};
|
|
981
|
-
const { path: endpoint = "/metrics", port = 9466 } = config.telemetry?.metrics?.scrape ?? {};
|
|
982
|
-
return await initTelemetry({
|
|
983
|
-
attributes: {
|
|
984
|
-
serviceName,
|
|
985
|
-
serviceVersion
|
|
986
|
-
},
|
|
987
|
-
otlpEndpoint,
|
|
988
|
-
metricsConfig: {
|
|
989
|
-
endpoint,
|
|
990
|
-
port
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
__name(telemetryContextFromConfig, "telemetryContextFromConfig");
|
|
1545
|
+
// src/node/config/capabilities/locatorFromActorNeeds.ts
|
|
1546
|
+
import { ProviderFactoryLocator } from "@xyo-network/xl1-sdk";
|
|
995
1547
|
|
|
996
|
-
// src/node/config/
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
const caches = {};
|
|
1000
|
-
const telemetryConfig = await telemetryContextFromConfig(config, serviceName, serviceVersion);
|
|
1001
|
-
const statusReporter = initStatusReporter({
|
|
1002
|
-
logger
|
|
1003
|
-
});
|
|
1004
|
-
return {
|
|
1005
|
-
...telemetryConfig,
|
|
1006
|
-
config,
|
|
1007
|
-
singletons,
|
|
1008
|
-
caches,
|
|
1009
|
-
logger,
|
|
1010
|
-
statusReporter
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
__name(contextFromConfigWithoutLocator, "contextFromConfigWithoutLocator");
|
|
1014
|
-
|
|
1015
|
-
// src/node/config/locators/localLocatorFromConfig.ts
|
|
1016
|
-
import { assertEx as assertEx8 } from "@xylabs/sdk-js";
|
|
1017
|
-
import { validateHydratedBlock, validateHydratedBlockState } from "@xyo-network/chain-validation";
|
|
1018
|
-
import { BlockCumulativeBalanceValidatorFactory, ProviderFactoryLocator, SimpleAccountBalanceViewer, SimpleBlockValidationViewer, SimpleBlockViewer, SimpleDeadLetterQueueRunner, SimpleDeadLetterQueueViewer, SimpleFinalizationRunner, SimpleFinalizationViewer, SimpleMempoolRunner, SimpleMempoolViewer, SimpleTransactionValidationViewer, SimpleTransactionViewer, SimpleWindowedBlockViewer, SimpleXyoConnectionViewer, SimpleXyoViewer, validateTransaction } from "@xyo-network/xl1-sdk";
|
|
1548
|
+
// src/node/config/capabilities/ProcessSharedResources.ts
|
|
1549
|
+
import { validateHydratedBlock, validateHydratedBlockState, validateHydratedTransactionState } from "@xyo-network/chain-validation";
|
|
1550
|
+
import { BlockCumulativeBalanceValidatorFactory, validateTransaction } from "@xyo-network/xl1-sdk";
|
|
1019
1551
|
|
|
1020
1552
|
// src/node/init/initBalanceSummaryMap.ts
|
|
1021
1553
|
import { BaseMongoSdk } from "@xylabs/mongo";
|
|
1022
|
-
import { assertEx as
|
|
1554
|
+
import { assertEx as assertEx5 } from "@xylabs/sdk-js";
|
|
1023
1555
|
import { MongoMap } from "@xyo-network/chain-protocol-driver-mongodb";
|
|
1024
1556
|
import { hasMongoConfig, MemoryMap } from "@xyo-network/xl1-sdk";
|
|
1025
1557
|
async function initBalanceSummaryMap({ logger, config }) {
|
|
@@ -1044,7 +1576,7 @@ async function initBalanceSummaryMap({ logger, config }) {
|
|
|
1044
1576
|
maxEntries: 5e3
|
|
1045
1577
|
}
|
|
1046
1578
|
});
|
|
1047
|
-
|
|
1579
|
+
assertEx5(await result.start(), () => "Failed to start transfer summary map");
|
|
1048
1580
|
return result;
|
|
1049
1581
|
} else {
|
|
1050
1582
|
logger?.warn("[API] Mongo configuration not found. Using MemoryMap for BalanceSummaryMap.");
|
|
@@ -1106,7 +1638,7 @@ async function initEvmProvidersIfAvailable(locator) {
|
|
|
1106
1638
|
__name(initEvmProvidersIfAvailable, "initEvmProvidersIfAvailable");
|
|
1107
1639
|
|
|
1108
1640
|
// src/node/init/initFinalizationArchivistIfNeeded.ts
|
|
1109
|
-
import { assertEx as
|
|
1641
|
+
import { assertEx as assertEx6 } from "@xylabs/sdk-js";
|
|
1110
1642
|
import { createBootstrapHead } from "@xyo-network/chain-sdk";
|
|
1111
1643
|
import { Account } from "@xyo-network/sdk-js";
|
|
1112
1644
|
import { asAttoXL1, findMostRecentBlock, flattenHydratedBlock } from "@xyo-network/xl1-sdk";
|
|
@@ -1129,8 +1661,8 @@ async function initFinalizationArchivistIfNeeded(archivist, config, account, opt
|
|
|
1129
1661
|
const payloads = chain.flatMap((block) => flattenHydratedBlock(block));
|
|
1130
1662
|
await archivist.insert(payloads);
|
|
1131
1663
|
}
|
|
1132
|
-
const head = possibleHead ??
|
|
1133
|
-
const chainId =
|
|
1664
|
+
const head = possibleHead ?? assertEx6(await findMostRecentBlock(archivist), () => "No blocks found in chain archivist");
|
|
1665
|
+
const chainId = assertEx6(possibleChainId, () => "Chain ID could not be determined");
|
|
1134
1666
|
return [
|
|
1135
1667
|
head,
|
|
1136
1668
|
chainId
|
|
@@ -1157,7 +1689,7 @@ async function initFinalizedArchivist(config) {
|
|
|
1157
1689
|
__name(initFinalizedArchivist, "initFinalizedArchivist");
|
|
1158
1690
|
|
|
1159
1691
|
// src/node/init/initServerNode.ts
|
|
1160
|
-
import { assertEx as
|
|
1692
|
+
import { assertEx as assertEx7 } from "@xylabs/sdk-js";
|
|
1161
1693
|
import { asArchivistInstance } from "@xyo-network/sdk-js";
|
|
1162
1694
|
|
|
1163
1695
|
// src/node/manifest/getLocator.ts
|
|
@@ -1165,7 +1697,7 @@ import { isDefined as isDefined2 } from "@xylabs/sdk-js";
|
|
|
1165
1697
|
import { LmdbArchivistConfigSchema } from "@xyo-network/archivist-lmdb";
|
|
1166
1698
|
import { MongoDBArchivistV2 as MongoDBArchivistV22, MongoDBArchivistV2Deletable } from "@xyo-network/archivist-mongodb";
|
|
1167
1699
|
import { ViewArchivist } from "@xyo-network/archivist-view";
|
|
1168
|
-
import { initTelemetry
|
|
1700
|
+
import { initTelemetry } from "@xyo-network/chain-telemetry";
|
|
1169
1701
|
import { AbstractModule, LoggerModuleStatusReporter, MemoryArchivist, MemorySentinel, ModuleFactoryLocator } from "@xyo-network/sdk-js";
|
|
1170
1702
|
import { hasMongoConfig as hasMongoConfig2 } from "@xyo-network/xl1-sdk";
|
|
1171
1703
|
|
|
@@ -1197,7 +1729,7 @@ var NamedLmdbArchivist = class extends LmdbArchivist {
|
|
|
1197
1729
|
var getLocator = /* @__PURE__ */ __name(async ({ logger, config }) => {
|
|
1198
1730
|
const { otlpEndpoint } = config.telemetry?.otel ?? {};
|
|
1199
1731
|
const { path: endpoint = "/metrics", port = 9465 } = config.telemetry?.metrics?.scrape ?? {};
|
|
1200
|
-
const { traceProvider, meterProvider } = await
|
|
1732
|
+
const { traceProvider, meterProvider } = await initTelemetry({
|
|
1201
1733
|
attributes: {
|
|
1202
1734
|
serviceName: "xl1-api",
|
|
1203
1735
|
serviceVersion: "1.0.0"
|
|
@@ -1484,7 +2016,7 @@ async function writableChainArchivistFromNode(node) {
|
|
|
1484
2016
|
}
|
|
1485
2017
|
__name(writableChainArchivistFromNode, "writableChainArchivistFromNode");
|
|
1486
2018
|
async function readonlyChainArchivistFromNode(node) {
|
|
1487
|
-
return
|
|
2019
|
+
return assertEx7(asArchivistInstance(await node.resolve("Chain:Validated"), {
|
|
1488
2020
|
required: true
|
|
1489
2021
|
}));
|
|
1490
2022
|
}
|
|
@@ -1515,7 +2047,7 @@ async function rejectedTransactionsArchivistFromNode(node) {
|
|
|
1515
2047
|
__name(rejectedTransactionsArchivistFromNode, "rejectedTransactionsArchivistFromNode");
|
|
1516
2048
|
async function initServerNode(context, wallet, providedNode) {
|
|
1517
2049
|
const node = providedNode ?? await loadNode(context, wallet);
|
|
1518
|
-
|
|
2050
|
+
assertEx7(await node.start(), () => "Failed to start node");
|
|
1519
2051
|
const writableChainArchivist = await writableChainArchivistFromNode(node);
|
|
1520
2052
|
const readonlyChainArchivist = await readonlyChainArchivistFromNode(node);
|
|
1521
2053
|
const pendingTransactionsArchivist = await pendingTransactionsArchivistFromNode(node);
|
|
@@ -1536,7 +2068,7 @@ __name(initServerNode, "initServerNode");
|
|
|
1536
2068
|
|
|
1537
2069
|
// src/node/init/initTransferSummaryMap.ts
|
|
1538
2070
|
import { BaseMongoSdk as BaseMongoSdk2 } from "@xylabs/mongo";
|
|
1539
|
-
import { assertEx as
|
|
2071
|
+
import { assertEx as assertEx8 } from "@xylabs/sdk-js";
|
|
1540
2072
|
import { MongoMap as MongoMap2 } from "@xyo-network/chain-protocol-driver-mongodb";
|
|
1541
2073
|
import { hasMongoConfig as hasMongoConfig3, MemoryMap as MemoryMap2 } from "@xyo-network/xl1-sdk";
|
|
1542
2074
|
async function initTransferSummaryMap({ logger, config }) {
|
|
@@ -1561,7 +2093,7 @@ async function initTransferSummaryMap({ logger, config }) {
|
|
|
1561
2093
|
maxEntries: 5e3
|
|
1562
2094
|
}
|
|
1563
2095
|
});
|
|
1564
|
-
|
|
2096
|
+
assertEx8(await result.start(), () => "Failed to start transfer summary map");
|
|
1565
2097
|
return result;
|
|
1566
2098
|
} else {
|
|
1567
2099
|
logger?.warn("[API] Mongo configuration not found. Using MemoryMap for TransferSummaryMap.");
|
|
@@ -1570,7 +2102,7 @@ async function initTransferSummaryMap({ logger, config }) {
|
|
|
1570
2102
|
}
|
|
1571
2103
|
__name(initTransferSummaryMap, "initTransferSummaryMap");
|
|
1572
2104
|
|
|
1573
|
-
// src/node/config/
|
|
2105
|
+
// src/node/config/capabilities/ProcessSharedResources.ts
|
|
1574
2106
|
var cumulativeBalanceValidator = BlockCumulativeBalanceValidatorFactory();
|
|
1575
2107
|
var validateHydratedBlockStateWithCumulativeBalance = /* @__PURE__ */ __name(async (context, block) => {
|
|
1576
2108
|
const [stateErrors, cumulativeErrors] = await Promise.all([
|
|
@@ -1582,68 +2114,335 @@ var validateHydratedBlockStateWithCumulativeBalance = /* @__PURE__ */ __name(asy
|
|
|
1582
2114
|
...cumulativeErrors
|
|
1583
2115
|
];
|
|
1584
2116
|
}, "validateHydratedBlockStateWithCumulativeBalance");
|
|
1585
|
-
async function
|
|
1586
|
-
const balancesSummaryMap =
|
|
1587
|
-
|
|
2117
|
+
async function buildProcessSharedResources(context, options) {
|
|
2118
|
+
const balancesSummaryMap = await initBalanceSummaryMap(context);
|
|
2119
|
+
if (!balancesSummaryMap) throw new Error("Balance Summary Map not initialized");
|
|
2120
|
+
const transfersSummaryMap = await initTransferSummaryMap(context);
|
|
2121
|
+
if (!transfersSummaryMap) throw new Error("Transfer Summary Map not initialized");
|
|
1588
2122
|
const wallet = await initActorWallet(context);
|
|
1589
|
-
const
|
|
2123
|
+
const serverNode = await initServerNode(context, wallet);
|
|
2124
|
+
const { writableChainArchivist, readonlyChainArchivist, pendingTransactionsArchivist, pendingBlocksArchivist, rejectedBlocksArchivist, rejectedTransactionsArchivist } = serverNode;
|
|
1590
2125
|
await initFinalizationArchivistIfNeeded(writableChainArchivist, context.config, wallet, {
|
|
1591
2126
|
logger: context.logger,
|
|
1592
|
-
onInsecureGenesisConfirm
|
|
2127
|
+
onInsecureGenesisConfirm: options?.onInsecureGenesisConfirm
|
|
1593
2128
|
});
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
2129
|
+
return {
|
|
2130
|
+
balancesSummaryMap,
|
|
2131
|
+
transfersSummaryMap,
|
|
2132
|
+
wallet,
|
|
2133
|
+
node: serverNode.node,
|
|
2134
|
+
writableChainArchivist,
|
|
2135
|
+
readonlyChainArchivist,
|
|
2136
|
+
pendingTransactionsArchivist,
|
|
2137
|
+
pendingBlocksArchivist,
|
|
2138
|
+
rejectedBlocksArchivist,
|
|
2139
|
+
rejectedTransactionsArchivist,
|
|
2140
|
+
blockProtocolValidator: validateHydratedBlock,
|
|
2141
|
+
blockStateValidator: validateHydratedBlockStateWithCumulativeBalance,
|
|
2142
|
+
transactionProtocolValidator: validateTransaction,
|
|
2143
|
+
transactionStateValidator: validateHydratedTransactionState
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2146
|
+
__name(buildProcessSharedResources, "buildProcessSharedResources");
|
|
2147
|
+
|
|
2148
|
+
// src/node/config/capabilities/resolveProviders.ts
|
|
2149
|
+
var MissingCapabilityError = class extends Error {
|
|
2150
|
+
static {
|
|
2151
|
+
__name(this, "MissingCapabilityError");
|
|
2152
|
+
}
|
|
2153
|
+
moniker;
|
|
2154
|
+
reasons;
|
|
2155
|
+
constructor(moniker, reasons) {
|
|
2156
|
+
const detail = reasons.length === 0 ? "(no candidates registered)" : reasons.join("; ");
|
|
2157
|
+
super(`No provider satisfies capability '${moniker}': ${detail}`);
|
|
2158
|
+
this.name = "MissingCapabilityError";
|
|
2159
|
+
this.moniker = moniker;
|
|
2160
|
+
this.reasons = reasons;
|
|
2161
|
+
}
|
|
2162
|
+
};
|
|
2163
|
+
function resolveProviders(needs, candidates, ctx) {
|
|
2164
|
+
const wanted = expandNeeds(needs, ctx);
|
|
2165
|
+
const { surviving, rejected } = filterByPreconditions(candidates, ctx);
|
|
2166
|
+
const byCapability = groupByCapability(surviving, wanted);
|
|
2167
|
+
const { bindings, selectedById } = pickWinners(wanted, byCapability, rejected, candidates);
|
|
2168
|
+
const selected = topoSort([
|
|
2169
|
+
...selectedById.values()
|
|
2170
|
+
], ctx);
|
|
2171
|
+
return {
|
|
2172
|
+
bindings,
|
|
2173
|
+
rejected,
|
|
2174
|
+
selected
|
|
2175
|
+
};
|
|
2176
|
+
}
|
|
2177
|
+
__name(resolveProviders, "resolveProviders");
|
|
2178
|
+
function expandNeeds(needs, ctx) {
|
|
2179
|
+
const wanted = new Set(needs);
|
|
2180
|
+
const stack = [
|
|
2181
|
+
...needs
|
|
2182
|
+
];
|
|
2183
|
+
while (stack.length > 0) {
|
|
2184
|
+
const moniker = stack.pop();
|
|
2185
|
+
const cap = ctx.capabilities.tryGet(moniker);
|
|
2186
|
+
if (!cap?.implies) continue;
|
|
2187
|
+
for (const dep of cap.implies) {
|
|
2188
|
+
if (!wanted.has(dep)) {
|
|
2189
|
+
wanted.add(dep);
|
|
2190
|
+
stack.push(dep);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
return wanted;
|
|
2195
|
+
}
|
|
2196
|
+
__name(expandNeeds, "expandNeeds");
|
|
2197
|
+
function filterByPreconditions(candidates, ctx) {
|
|
2198
|
+
const surviving = [];
|
|
2199
|
+
const rejected = [];
|
|
2200
|
+
for (const descriptor of candidates) {
|
|
2201
|
+
try {
|
|
2202
|
+
if (descriptor.preconditions(ctx)) {
|
|
2203
|
+
surviving.push(descriptor);
|
|
2204
|
+
} else {
|
|
2205
|
+
rejected.push({
|
|
2206
|
+
descriptor,
|
|
2207
|
+
reason: "preconditions returned false"
|
|
2208
|
+
});
|
|
2209
|
+
}
|
|
2210
|
+
} catch (err) {
|
|
2211
|
+
rejected.push({
|
|
2212
|
+
descriptor,
|
|
2213
|
+
reason: `preconditions threw: ${err instanceof Error ? err.message : String(err)}`
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
return {
|
|
2218
|
+
surviving,
|
|
2219
|
+
rejected
|
|
2220
|
+
};
|
|
2221
|
+
}
|
|
2222
|
+
__name(filterByPreconditions, "filterByPreconditions");
|
|
2223
|
+
function groupByCapability(surviving, wanted) {
|
|
2224
|
+
const byCapability = /* @__PURE__ */ new Map();
|
|
2225
|
+
for (const descriptor of surviving) {
|
|
2226
|
+
for (const moniker of descriptor.satisfies) {
|
|
2227
|
+
if (!wanted.has(moniker)) continue;
|
|
2228
|
+
const list = byCapability.get(moniker) ?? [];
|
|
2229
|
+
list.push(descriptor);
|
|
2230
|
+
byCapability.set(moniker, list);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
return byCapability;
|
|
2234
|
+
}
|
|
2235
|
+
__name(groupByCapability, "groupByCapability");
|
|
2236
|
+
function pickWinners(wanted, byCapability, rejected, allCandidates) {
|
|
2237
|
+
const bindings = {};
|
|
2238
|
+
const selectedById = /* @__PURE__ */ new Map();
|
|
2239
|
+
for (const moniker of wanted) {
|
|
2240
|
+
const group = byCapability.get(moniker);
|
|
2241
|
+
if (!group || group.length === 0) {
|
|
2242
|
+
throw new MissingCapabilityError(moniker, reasonsFor(moniker, rejected, allCandidates));
|
|
2243
|
+
}
|
|
2244
|
+
const sorted = group.toSorted(compareDescriptors);
|
|
2245
|
+
const winner = sorted[0];
|
|
2246
|
+
bindings[moniker] = winner.id;
|
|
2247
|
+
selectedById.set(winner.id, winner);
|
|
2248
|
+
for (const loser of sorted.slice(1)) {
|
|
2249
|
+
rejected.push({
|
|
2250
|
+
descriptor: loser,
|
|
2251
|
+
reason: `tier ${loser.tier} lost to ${winner.id} (tier ${winner.tier}) for ${moniker}`
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
return {
|
|
2256
|
+
bindings,
|
|
2257
|
+
selectedById
|
|
2258
|
+
};
|
|
2259
|
+
}
|
|
2260
|
+
__name(pickWinners, "pickWinners");
|
|
2261
|
+
function reasonsFor(moniker, rejected, allCandidates) {
|
|
2262
|
+
const candidatesForMoniker = allCandidates.filter((c) => c.satisfies.includes(moniker));
|
|
2263
|
+
if (candidatesForMoniker.length === 0) return [];
|
|
2264
|
+
return rejected.filter((r) => r.descriptor.satisfies.includes(moniker)).map((r) => `${r.descriptor.id}: ${r.reason}`);
|
|
2265
|
+
}
|
|
2266
|
+
__name(reasonsFor, "reasonsFor");
|
|
2267
|
+
function compareDescriptors(a, b) {
|
|
2268
|
+
if (a.tier !== b.tier) return a.tier - b.tier;
|
|
2269
|
+
const pa = a.priority ?? 0;
|
|
2270
|
+
const pb = b.priority ?? 0;
|
|
2271
|
+
if (pa !== pb) return pb - pa;
|
|
2272
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
2273
|
+
}
|
|
2274
|
+
__name(compareDescriptors, "compareDescriptors");
|
|
2275
|
+
function topoSort(descriptors, ctx) {
|
|
2276
|
+
const byMoniker = /* @__PURE__ */ new Map();
|
|
2277
|
+
for (const d of descriptors) for (const m of d.satisfies) byMoniker.set(m, d);
|
|
2278
|
+
const order = [];
|
|
2279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2280
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
2281
|
+
const visit = /* @__PURE__ */ __name((d) => {
|
|
2282
|
+
if (seen.has(d.id)) return;
|
|
2283
|
+
if (visiting.has(d.id)) {
|
|
2284
|
+
throw new Error(`Cycle detected through provider ${d.id}`);
|
|
2285
|
+
}
|
|
2286
|
+
visiting.add(d.id);
|
|
2287
|
+
for (const moniker of d.satisfies) {
|
|
2288
|
+
const cap = ctx.capabilities.tryGet(moniker);
|
|
2289
|
+
if (!cap?.implies) continue;
|
|
2290
|
+
for (const dep of cap.implies) {
|
|
2291
|
+
const depDesc = byMoniker.get(dep);
|
|
2292
|
+
if (depDesc) visit(depDesc);
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
visiting.delete(d.id);
|
|
2296
|
+
seen.add(d.id);
|
|
2297
|
+
order.push(d);
|
|
2298
|
+
}, "visit");
|
|
2299
|
+
for (const d of descriptors) visit(d);
|
|
2300
|
+
return order;
|
|
2301
|
+
}
|
|
2302
|
+
__name(topoSort, "topoSort");
|
|
2303
|
+
|
|
2304
|
+
// src/node/config/capabilities/locatorFromActorNeeds.ts
|
|
2305
|
+
async function locatorFromActorNeeds(context, actorNeeds, options = {}) {
|
|
2306
|
+
const process2 = await buildProcessSharedResources(context, options);
|
|
2307
|
+
const capabilities2 = createDefaultCapabilityRegistry();
|
|
2308
|
+
const resolutionContext = {
|
|
2309
|
+
actorContext: context,
|
|
2310
|
+
capabilities: capabilities2,
|
|
2311
|
+
process: process2
|
|
2312
|
+
};
|
|
2313
|
+
const needs = unionNeeds(actorNeeds);
|
|
2314
|
+
const candidates = [
|
|
2315
|
+
...localTier1Descriptors,
|
|
2316
|
+
...options.extraDescriptors ?? []
|
|
2317
|
+
];
|
|
2318
|
+
const plan = resolveProviders(needs, candidates, resolutionContext);
|
|
2319
|
+
const locator = new ProviderFactoryLocator(context, {}, options.validateDepsOnRegister ?? false);
|
|
2320
|
+
const factories = plan.selected.map((d) => d.build(resolutionContext)).filter((f) => f !== void 0);
|
|
2321
|
+
locator.registerMany(factories);
|
|
2322
|
+
return {
|
|
2323
|
+
locator,
|
|
2324
|
+
plan,
|
|
2325
|
+
process: process2
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
__name(locatorFromActorNeeds, "locatorFromActorNeeds");
|
|
2329
|
+
function unionNeeds(actorNeeds) {
|
|
2330
|
+
const result = /* @__PURE__ */ new Set();
|
|
2331
|
+
for (const needs of actorNeeds) {
|
|
2332
|
+
for (const moniker of needs.required) result.add(moniker);
|
|
2333
|
+
if (needs.optional) for (const moniker of needs.optional) result.add(moniker);
|
|
2334
|
+
}
|
|
2335
|
+
return result;
|
|
2336
|
+
}
|
|
2337
|
+
__name(unionNeeds, "unionNeeds");
|
|
2338
|
+
|
|
2339
|
+
// src/node/config/locators/basicRemoteRunnerLocator.ts
|
|
2340
|
+
import { isAccountInstance } from "@xyo-network/sdk-js";
|
|
2341
|
+
import { basicRemoteRunnerLocator as sdkBasicRemoteRunnerLocator, JsonRpcAccountBalanceViewer, JsonRpcXyoSigner, SimpleXyoSigner } from "@xyo-network/xl1-sdk";
|
|
2342
|
+
function signerFactoryFromParam(signer) {
|
|
2343
|
+
if (isAccountInstance(signer)) {
|
|
2344
|
+
return SimpleXyoSigner.factory(SimpleXyoSigner.dependencies, {
|
|
2345
|
+
account: signer
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
return JsonRpcXyoSigner.factory(JsonRpcXyoSigner.dependencies, {
|
|
2349
|
+
transport: signer
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2352
|
+
__name(signerFactoryFromParam, "signerFactoryFromParam");
|
|
2353
|
+
function basicRemoteRunnerLocator(name, remoteConfig, signer, dataLakeEndpoint, validators) {
|
|
2354
|
+
const transport = isAccountInstance(signer) ? void 0 : signer;
|
|
2355
|
+
return sdkBasicRemoteRunnerLocator(name, remoteConfig, transport, dataLakeEndpoint, {
|
|
2356
|
+
additionalProviders: [
|
|
2357
|
+
JsonRpcAccountBalanceViewer.factory(JsonRpcAccountBalanceViewer.dependencies, {})
|
|
2358
|
+
],
|
|
2359
|
+
signerFactory: signerFactoryFromParam(signer),
|
|
2360
|
+
skipGatewayRunner: true,
|
|
2361
|
+
validators
|
|
2362
|
+
});
|
|
2363
|
+
}
|
|
2364
|
+
__name(basicRemoteRunnerLocator, "basicRemoteRunnerLocator");
|
|
2365
|
+
|
|
2366
|
+
// src/node/config/locators/basicRemoteViewerLocator.ts
|
|
2367
|
+
import { basicRemoteViewerLocator as sdkBasicRemoteViewerLocator, JsonRpcAccountBalanceViewer as JsonRpcAccountBalanceViewer2 } from "@xyo-network/xl1-sdk";
|
|
2368
|
+
function basicRemoteViewerLocator(name, remoteConfig, dataLakeEndpoint, validators) {
|
|
2369
|
+
return sdkBasicRemoteViewerLocator(name, remoteConfig, dataLakeEndpoint, {
|
|
2370
|
+
additionalProviders: [
|
|
2371
|
+
JsonRpcAccountBalanceViewer2.factory(JsonRpcAccountBalanceViewer2.dependencies, {})
|
|
2372
|
+
],
|
|
2373
|
+
validators
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
__name(basicRemoteViewerLocator, "basicRemoteViewerLocator");
|
|
2377
|
+
|
|
2378
|
+
// src/node/config/locators/telemetryContextFromConfig.ts
|
|
2379
|
+
import { initTelemetry as initTelemetry2 } from "@xyo-network/chain-telemetry";
|
|
2380
|
+
async function telemetryContextFromConfig(config, serviceName, serviceVersion) {
|
|
2381
|
+
const { otlpEndpoint } = config.telemetry?.otel ?? {};
|
|
2382
|
+
const { path: endpoint = "/metrics", port = 9466 } = config.telemetry?.metrics?.scrape ?? {};
|
|
2383
|
+
return await initTelemetry2({
|
|
2384
|
+
attributes: {
|
|
2385
|
+
serviceName,
|
|
2386
|
+
serviceVersion
|
|
2387
|
+
},
|
|
2388
|
+
otlpEndpoint,
|
|
2389
|
+
metricsConfig: {
|
|
2390
|
+
endpoint,
|
|
2391
|
+
port
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2395
|
+
__name(telemetryContextFromConfig, "telemetryContextFromConfig");
|
|
2396
|
+
|
|
2397
|
+
// src/node/config/locators/contextFromConfigWithoutLocator.ts
|
|
2398
|
+
async function contextFromConfigWithoutLocator(config, logger, serviceName, serviceVersion) {
|
|
2399
|
+
const singletons = {};
|
|
2400
|
+
const caches = {};
|
|
2401
|
+
const telemetryConfig = await telemetryContextFromConfig(config, serviceName, serviceVersion);
|
|
2402
|
+
const statusReporter = initStatusReporter({
|
|
2403
|
+
logger
|
|
2404
|
+
});
|
|
2405
|
+
return {
|
|
2406
|
+
...telemetryConfig,
|
|
2407
|
+
config,
|
|
2408
|
+
singletons,
|
|
2409
|
+
caches,
|
|
2410
|
+
logger,
|
|
2411
|
+
statusReporter
|
|
2412
|
+
};
|
|
2413
|
+
}
|
|
2414
|
+
__name(contextFromConfigWithoutLocator, "contextFromConfigWithoutLocator");
|
|
2415
|
+
|
|
2416
|
+
// src/node/config/locators/localLocatorFromConfig.ts
|
|
2417
|
+
import { AccountBalanceViewerMoniker as AccountBalanceViewerMoniker2, BlockValidationViewerMoniker as BlockValidationViewerMoniker3, BlockViewerMoniker as BlockViewerMoniker3, DeadLetterQueueRunnerMoniker as DeadLetterQueueRunnerMoniker3, DeadLetterQueueViewerMoniker as DeadLetterQueueViewerMoniker2, FinalizationRunnerMoniker as FinalizationRunnerMoniker3, FinalizationViewerMoniker as FinalizationViewerMoniker2, MempoolRunnerMoniker as MempoolRunnerMoniker2, MempoolViewerMoniker as MempoolViewerMoniker3, TransactionValidationViewerMoniker as TransactionValidationViewerMoniker2, TransactionViewerMoniker as TransactionViewerMoniker2, WindowedBlockViewerMoniker as WindowedBlockViewerMoniker2, XyoViewerMoniker as XyoViewerMoniker2 } from "@xyo-network/xl1-sdk";
|
|
2418
|
+
var XyoConnectionMoniker2 = "XyoConnection";
|
|
2419
|
+
var LOCAL_LEGACY_NEEDS = {
|
|
2420
|
+
required: [
|
|
2421
|
+
AccountBalanceViewerMoniker2,
|
|
2422
|
+
BlockValidationViewerMoniker3,
|
|
2423
|
+
BlockViewerMoniker3,
|
|
2424
|
+
DeadLetterQueueRunnerMoniker3,
|
|
2425
|
+
DeadLetterQueueViewerMoniker2,
|
|
2426
|
+
FinalizationRunnerMoniker3,
|
|
2427
|
+
FinalizationViewerMoniker2,
|
|
2428
|
+
MempoolRunnerMoniker2,
|
|
2429
|
+
MempoolViewerMoniker3,
|
|
2430
|
+
RejectedTransactionsArchivistProviderMoniker,
|
|
2431
|
+
TransactionValidationViewerMoniker2,
|
|
2432
|
+
TransactionViewerMoniker2,
|
|
2433
|
+
WindowedBlockViewerMoniker2,
|
|
2434
|
+
XyoConnectionMoniker2,
|
|
2435
|
+
XyoViewerMoniker2
|
|
2436
|
+
]
|
|
2437
|
+
};
|
|
2438
|
+
async function localLocatorFromConfig(context, validateDepsOnRegister = false, onInsecureGenesisConfirm) {
|
|
2439
|
+
const result = await locatorFromActorNeeds(context, [
|
|
2440
|
+
LOCAL_LEGACY_NEEDS
|
|
2441
|
+
], {
|
|
2442
|
+
onInsecureGenesisConfirm,
|
|
2443
|
+
validateDepsOnRegister
|
|
2444
|
+
});
|
|
2445
|
+
return result.locator;
|
|
1647
2446
|
}
|
|
1648
2447
|
__name(localLocatorFromConfig, "localLocatorFromConfig");
|
|
1649
2448
|
|
|
@@ -1752,7 +2551,7 @@ function mempoolLocatorFromConfig(context, parent) {
|
|
|
1752
2551
|
__name(mempoolLocatorFromConfig, "mempoolLocatorFromConfig");
|
|
1753
2552
|
|
|
1754
2553
|
// src/node/config/locators/actors/producerLocatorFromConfig.ts
|
|
1755
|
-
import { asAddress
|
|
2554
|
+
import { asAddress } from "@xylabs/sdk-js";
|
|
1756
2555
|
import { SimpleBlockRunner } from "@xyo-network/chain-services";
|
|
1757
2556
|
import { ProviderFactoryLocator as ProviderFactoryLocator6 } from "@xyo-network/xl1-sdk";
|
|
1758
2557
|
async function producerLocatorFromConfig(context, parent) {
|
|
@@ -1762,7 +2561,7 @@ async function producerLocatorFromConfig(context, parent) {
|
|
|
1762
2561
|
...context,
|
|
1763
2562
|
locator: parent
|
|
1764
2563
|
});
|
|
1765
|
-
const rewardAddress =
|
|
2564
|
+
const rewardAddress = asAddress(config.rewardAddress ?? account.address, true);
|
|
1766
2565
|
logger?.info(`Using reward address ${rewardAddress}`);
|
|
1767
2566
|
if (rewardAddress === account.address) {
|
|
1768
2567
|
logger?.warn(`Using producer account address as reward address: ${account.address}`);
|
|
@@ -1773,7 +2572,11 @@ async function producerLocatorFromConfig(context, parent) {
|
|
|
1773
2572
|
SimpleBlockRunner.factory(SimpleBlockRunner.dependencies, {
|
|
1774
2573
|
account,
|
|
1775
2574
|
rewardAddress,
|
|
1776
|
-
rejectedTransactionsArchivist
|
|
2575
|
+
rejectedTransactionsArchivist,
|
|
2576
|
+
// ProducerConfigZod has always exposed `heartbeatInterval`, but until now
|
|
2577
|
+
// it was not wired anywhere. Threading it into the BlockRunner lets tests
|
|
2578
|
+
// (and operators who want denser heartbeat blocks) override the 1-h default.
|
|
2579
|
+
heartbeatInterval: config.heartbeatInterval
|
|
1777
2580
|
})
|
|
1778
2581
|
]);
|
|
1779
2582
|
locator.freeze();
|
|
@@ -1959,7 +2762,10 @@ export * from "@xyo-network/chain-orchestration-evm";
|
|
|
1959
2762
|
export * from "@xyo-network/chain-orchestration-express";
|
|
1960
2763
|
export * from "@xyo-network/chain-orchestration-storage";
|
|
1961
2764
|
export {
|
|
2765
|
+
Actor,
|
|
1962
2766
|
ActorMnemonicNotAllowedError,
|
|
2767
|
+
ActorParamsV3Zod,
|
|
2768
|
+
ActorV3,
|
|
1963
2769
|
ApiConfigContext,
|
|
1964
2770
|
ApiConfigZod,
|
|
1965
2771
|
BUILT_IN_DEV_MNEMONIC,
|
|
@@ -1982,6 +2788,7 @@ export {
|
|
|
1982
2788
|
INSECURE_GENESIS_REWARD_MNEMONIC,
|
|
1983
2789
|
MempoolConfigContext,
|
|
1984
2790
|
MempoolConfigZod,
|
|
2791
|
+
MissingCapabilityError,
|
|
1985
2792
|
NodeManifest,
|
|
1986
2793
|
Orchestrator,
|
|
1987
2794
|
PrivateChildManifests,
|
|
@@ -2011,9 +2818,12 @@ export {
|
|
|
2011
2818
|
basicRemoteRunnerLocator,
|
|
2012
2819
|
basicRemoteViewerLocator,
|
|
2013
2820
|
buildInsecureGenesisRewardAccounts,
|
|
2821
|
+
buildProcessSharedResources,
|
|
2014
2822
|
buildTelemetryConfig,
|
|
2015
2823
|
clearResolvedWalletReport,
|
|
2016
2824
|
contextFromConfigWithoutLocator,
|
|
2825
|
+
createCapabilityRegistry,
|
|
2826
|
+
createDefaultCapabilityRegistry,
|
|
2017
2827
|
createProducerChainStakeIntentBlock,
|
|
2018
2828
|
detectDerivationPathCollisions,
|
|
2019
2829
|
expandAccountPath,
|
|
@@ -2051,11 +2861,14 @@ export {
|
|
|
2051
2861
|
isRewardRedemptionConfigContext,
|
|
2052
2862
|
loadNode,
|
|
2053
2863
|
localLocatorFromConfig,
|
|
2864
|
+
localTier1Descriptors,
|
|
2865
|
+
locatorFromActorNeeds,
|
|
2054
2866
|
locatorsFromConfig,
|
|
2055
2867
|
mergeConfig,
|
|
2056
2868
|
resolveActorAccountPath,
|
|
2057
2869
|
resolveActorWallet,
|
|
2058
2870
|
resolveGenesisRewardAddress,
|
|
2871
|
+
resolveProviders,
|
|
2059
2872
|
resolveRootWallet,
|
|
2060
2873
|
resolveWalletForActor,
|
|
2061
2874
|
resolveWalletReport,
|