@xyo-network/xl1-cli-lib 1.15.21 → 1.15.23

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.
@@ -25,6 +25,8 @@ export declare class ProducerActor extends Actor<ProducerActorParams> {
25
25
  static create(params: ProducerActorParams): Promisable<ProducerActor>;
26
26
  start(): Promise<void>;
27
27
  protected calculateBlocksUntilProducerDeclarationExpiration(currentBlock: number): Promise<number>;
28
+ protected produceBlock(): Promise<void>;
29
+ protected redeclareIntent(): Promise<void>;
28
30
  protected submitRedeclarationIntent(currentBlock: number, redeclarationIntent: ChainStakeIntent): Promise<void>;
29
31
  protected validateCurrentBalance(): Promise<boolean>;
30
32
  protected validateCurrentStake(): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"ProducerActor.d.ts","sourceRoot":"","sources":["../../../../../src/orchestration/actor/implementation/ProducerActor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAMjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAChF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAKrF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAC1C,IAAI,CAAC,wBAAwB,EAC7B,SAAS,GACP,SAAS,GACT,eAAe,GACf,kBAAkB,GAClB,gCAAgC,GAChC,0CAA0C,GAC1C,UAAU,GACV,aAAa,CACd,GAAG;IACF,MAAM,EAAE,MAAM,CAAA;CACf,CAAC,CAAA;AAKJ,qBAAa,aAAc,SAAQ,KAAK,CAAC,mBAAmB,CAAC;IAC3D,SAAS,CAAC,kBAAkB,EAAE,aAAa,GAAG,SAAS,CAAA;IACvD,SAA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P,SAAS,GACT,eAAe,GACf,kBAAkB,GAClB,gCAAgC,GAChC,0CAA0C,GAC1C,UAAU,GACV,aAAa,CACd,GAAG;IACF,MAAM,EAAE,MAAM,CAAA;CACf,CAAC,CAAA;AAKJ,qBAAa,aAAc,SAAQ,KAAK,CAAC,mBAAmB,CAAC;IAC3D,SAAS,CAAC,kBAAkB,EAAE,aAAa,GAAG,SAAS,CAAA;IACvD,SAAS,CAAC,wBAAwB,EAAE,gBAAgB,GAAG,SAAS,CAAA;IAEhE,SAAS,aAAa,MAAM,EAAE,mBAAmB;IAIjD,SAAS,KAAK,OAAO,uDAEpB;IAED,SAAS,KAAK,cAAc,6DAE3B;IAED,SAAS,KAAK,aAAa,6EAE1B;IAED,SAAS,KAAK,gBAAgB,sDAE7B;IAED,SAAS,KAAK,8BAA8B;;;;QAE3C;IAED,SAAS,KAAK,wCAAwC,iVAErD;IAED,SAAS,KAAK,QAAQ,0DAErB;IAED,SAAS,KAAK,kBAAkB,wDAE/B;IAED,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,UAAU,CAAC,aAAa,CAAC;IAItD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;cAerB,iDAAiD,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;cAkBxF,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cAqC7B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;cAiEhC,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;cAqBrG,sBAAsB,IAAI,OAAO,CAAC,OAAO,CAAC;cAe1C,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;CAWzD"}
@@ -1,6 +1,7 @@
1
1
  import type { TracerProvider } from '@opentelemetry/api';
2
2
  import { Base, type BaseParams } from '@xylabs/base';
3
3
  import type { Config } from '@xyo-network/xl1-protocol-sdk';
4
+ import { Semaphore } from 'async-mutex';
4
5
  export interface IActor {
5
6
  start(): Promise<void>;
6
7
  stop(): Promise<void>;
@@ -11,6 +12,7 @@ export type ActorParams = BaseParams<{
11
12
  }>;
12
13
  export declare class Actor<TParams extends ActorParams = ActorParams> extends Base<TParams> implements IActor {
13
14
  protected readonly _intervals: Map<string, ReturnType<typeof setInterval>>;
15
+ protected readonly _semaphores: Map<string, Semaphore>;
14
16
  protected readonly _timeouts: Map<string, ReturnType<typeof setTimeout>>;
15
17
  private _active;
16
18
  private readonly _displayName;
@@ -1 +1 @@
1
- {"version":3,"file":"Actor.d.ts","sourceRoot":"","sources":["../../../../../src/orchestration/actor/model/Actor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAGpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAE3D,MAAM,WAAW,MAAM;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,cAAc,CAAA;CAC/B,CAAC,CAAA;AAEF,qBAAa,KAAK,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,IAAI,CAAC,OAAO,CAAE,YAAW,MAAM;IACnG,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAY;IACtF,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAY;IACpF,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO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34
  // src/orchestration/actor/model/Actor.ts
35
35
  import { Base } from "@xylabs/base";
36
+ import { delay } from "@xylabs/delay";
36
37
  import { IdLogger } from "@xylabs/logger";
37
38
  import { span, spanRootAsync } from "@xylabs/telemetry";
39
+ import { Semaphore } from "async-mutex";
38
40
  var Actor = class extends Base {
39
41
  static {
40
42
  __name(this, "Actor");
41
43
  }
42
44
  _intervals = /* @__PURE__ */ new Map();
45
+ _semaphores = /* @__PURE__ */ new Map();
43
46
  _timeouts = /* @__PURE__ */ new Map();
44
47
  _active = false;
45
48
  _displayName;
@@ -74,14 +77,33 @@ var Actor = class extends Base {
74
77
  return;
75
78
  }
76
79
  let running = false;
80
+ this._semaphores.set(timerName, new Semaphore(1));
77
81
  const timeoutId = setTimeout(() => {
78
82
  const intervalId = setInterval(() => {
79
- if (!this._active || !this._intervals.has(timerName) || running) return;
80
- running = true;
81
- callback().catch((error) => {
82
- this.logger?.error(`Error in timer '${this.name}:${timerName}': ${error}`);
83
- }).finally(() => {
84
- running = false;
83
+ const semaphore = this._semaphores.get(timerName);
84
+ if (!this._active || !this._intervals.has(timerName) || !semaphore || running) return;
85
+ if (semaphore.isLocked()) {
86
+ this.logger?.warn(`Skipping timer '${this.name}:${timerName}' execution because previous execution is still running.`);
87
+ return;
88
+ }
89
+ semaphore.acquire().then(([, release]) => {
90
+ const startTime = Date.now();
91
+ running = true;
92
+ callback().then(() => {
93
+ const duration = Date.now() - startTime;
94
+ if (duration > periodMs) {
95
+ this.logger?.warn(`Timer '${this.name}:${timerName}' execution took longer (${duration}ms) than the period (${periodMs}ms).`);
96
+ } else if (duration > 5e3) {
97
+ this.logger?.warn(`Timer '${this.name}:${timerName}' execution took longer (${duration}ms) than 5000ms.`);
98
+ }
99
+ }).catch((error) => {
100
+ this.logger?.error(`Error in timer '${this.name}:${timerName}': ${error}`);
101
+ }).finally(() => {
102
+ release();
103
+ running = false;
104
+ });
105
+ }).catch((error) => {
106
+ this.logger?.error(`Error acquiring semaphore for timer '${this.name}:${timerName}': ${error}`);
85
107
  });
86
108
  }, periodMs);
87
109
  this._intervals.set(timerName, intervalId);
@@ -111,6 +133,16 @@ var Actor = class extends Base {
111
133
  await Promise.resolve();
112
134
  this._active = false;
113
135
  this.logger?.log("Stopping all timers...");
136
+ await Promise.all([
137
+ ...this._semaphores.values()
138
+ ].map(async (semaphore) => {
139
+ while (semaphore.isLocked()) {
140
+ this.logger?.log("Waiting for running timer task to complete...");
141
+ await delay(500);
142
+ }
143
+ await semaphore.acquire();
144
+ }));
145
+ this._semaphores.clear();
114
146
  for (const [, timeoutRef] of this._timeouts.entries()) {
115
147
  clearTimeout(timeoutRef);
116
148
  }
@@ -204,9 +236,15 @@ var BalanceActor = class _BalanceActor extends Actor {
204
236
  this.chainIterator.on("headUpdate", async () => {
205
237
  await this.updateBalance();
206
238
  });
207
- this.registerTimer("BalanceTimer", async () => {
208
- await this.updateBalance();
209
- }, 1e3, 1e3);
239
+ this.registerTimer(
240
+ "BalanceTimer",
241
+ async () => {
242
+ await this.updateBalance();
243
+ },
244
+ 1e3,
245
+ 1e4
246
+ /* 1000 */
247
+ );
210
248
  }
211
249
  async updateBalance() {
212
250
  if (this._updateMutex.isLocked()) return;
@@ -244,7 +282,13 @@ var ChainHeadUpdateActor = class _ChainHeadUpdateActor extends Actor {
244
282
  this.chainFinalizedArchivist.on("inserted", async (data) => {
245
283
  await this.checkInsertedForNewHead(data);
246
284
  });
247
- this.registerTimer("ChainHeadUpdateTimer", async () => await this.pollForNewHead(), 0, 250);
285
+ this.registerTimer(
286
+ "ChainHeadUpdateTimer",
287
+ async () => await this.pollForNewHead(),
288
+ 0,
289
+ 2500
290
+ /* 250 */
291
+ );
248
292
  }
249
293
  async checkInsertedForNewHead(data) {
250
294
  const candidateBlock = sortBlocks(filterAs(data.payloads, asBlockBoundWitness)).at(-1);
@@ -316,54 +360,19 @@ var ProducerActor = class _ProducerActor extends Actor {
316
360
  }
317
361
  async start() {
318
362
  await super.start();
319
- this.registerTimer("BlockProductionTimer", async () => {
320
- await this.spanAsync("produceBlock", async () => {
321
- const head = await this.chainIterator.head();
322
- const headHash = await PayloadBuilder2.hash(head);
323
- if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {
324
- this.logger?.log("Block already produced:", `0x${toHex2(this._lastProducedBlock[0].block)}`);
325
- } else {
326
- const nextBlock = await this.producer.next(head);
327
- if (nextBlock) {
328
- const displayBlockNumber = `0x${toHex2(nextBlock[0].block)}`;
329
- this.logger?.log("Produced block:", displayBlockNumber);
330
- await this.chainSubmissionsArchivistWrite.insert(flattenHydratedBlock(nextBlock));
331
- this.logger?.log("Published block:", displayBlockNumber);
332
- this._lastProducedBlock = nextBlock;
333
- }
334
- }
335
- });
336
- }, 100, 500);
363
+ this.registerTimer(
364
+ "BlockProductionTimer",
365
+ async () => {
366
+ await this.produceBlock();
367
+ },
368
+ 100,
369
+ 1500
370
+ /* 500 */
371
+ );
337
372
  if (SHOULD_REGISTER_REDECLARATION_INTENT_TIMER) {
338
373
  this.registerTimer("ProducerRedeclarationTimer", async () => {
339
- await this.spanAsync("producerRedeclarationTimer", async () => {
340
- if (this.params.config.producer.disableIntentRedeclaration) return;
341
- const head = await this.chainIterator.head();
342
- if (isUndefined(head)) return;
343
- const currentBlock = head.block;
344
- const blocksUntilExpiration = await this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock);
345
- if (blocksUntilExpiration > BaseBlockProducerService.RedeclarationWindow * 0.1) {
346
- this._lastRedeclarationIntent = void 0;
347
- return;
348
- }
349
- if (this._lastRedeclarationIntent) {
350
- if (this._lastRedeclarationIntent.exp > currentBlock) return;
351
- this._lastRedeclarationIntent = void 0;
352
- }
353
- if (!await this.validateCurrentBalance()) {
354
- this.logger?.error(`Add balance to address ${this.account.address} for the producer to declare it's intent.`);
355
- return;
356
- }
357
- if (!await this.validateCurrentStake()) {
358
- this.logger?.error(`Add stake to contract address ${this.params.config.chain.id} for the producer to declare it's intent.`);
359
- return;
360
- }
361
- this.logger?.log("Creating redeclaration intent for producer:", this.account.address);
362
- const redeclarationIntent = createDeclarationIntent(this.account.address, "producer", currentBlock, currentBlock + BaseBlockProducerService.RedeclarationDuration);
363
- await this.submitRedeclarationIntent(currentBlock, redeclarationIntent);
364
- this._lastRedeclarationIntent = redeclarationIntent;
365
- });
366
- }, 1e4, TEN_MINUTES);
374
+ await this.redeclareIntent();
375
+ }, TEN_MINUTES, TEN_MINUTES);
367
376
  }
368
377
  }
369
378
  async calculateBlocksUntilProducerDeclarationExpiration(currentBlock) {
@@ -376,6 +385,63 @@ var ProducerActor = class _ProducerActor extends Actor {
376
385
  const timeToProducerExpiration = currentDeclarationEnd - currentBlock;
377
386
  return timeToProducerExpiration;
378
387
  }
388
+ async produceBlock() {
389
+ await this.spanAsync("produceBlock", async () => {
390
+ const headStart = Date.now();
391
+ const head = await this.chainIterator.head();
392
+ const headDuration = Date.now() - headStart;
393
+ if (headDuration > 500) {
394
+ this.logger?.warn(`[Slow] Fetched head in ${headDuration}ms: 0x${toHex2(head._hash)}`);
395
+ }
396
+ const headHash = head._hash;
397
+ if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {
398
+ this.logger?.log("Block already produced:", `0x${toHex2(this._lastProducedBlock[0].block)}`);
399
+ } else {
400
+ const nextStart = Date.now();
401
+ const nextBlock = await this.producer.next(head);
402
+ const nextDuration = Date.now() - nextStart;
403
+ if (nextDuration > 1e3) {
404
+ this.logger?.warn(`[Slow] Generated next block in ${nextDuration}ms, block: ${nextBlock?.[0]._hash}`);
405
+ }
406
+ if (nextBlock) {
407
+ const displayBlockNumber = `0x${toHex2(nextBlock[0].block)}`;
408
+ this.logger?.log("Produced block:", displayBlockNumber);
409
+ await this.chainSubmissionsArchivistWrite.insert(flattenHydratedBlock(nextBlock));
410
+ this.logger?.log("Published block:", displayBlockNumber);
411
+ this._lastProducedBlock = nextBlock;
412
+ }
413
+ }
414
+ });
415
+ }
416
+ async redeclareIntent() {
417
+ await this.spanAsync("redeclareIntent", async () => {
418
+ if (this.params.config.producer.disableIntentRedeclaration) return;
419
+ const head = await this.chainIterator.head();
420
+ if (isUndefined(head)) return;
421
+ const currentBlock = head.block;
422
+ const blocksUntilExpiration = await this.calculateBlocksUntilProducerDeclarationExpiration(currentBlock);
423
+ if (blocksUntilExpiration > BaseBlockProducerService.RedeclarationWindow * 0.1) {
424
+ this._lastRedeclarationIntent = void 0;
425
+ return;
426
+ }
427
+ if (this._lastRedeclarationIntent) {
428
+ if (this._lastRedeclarationIntent.exp > currentBlock) return;
429
+ this._lastRedeclarationIntent = void 0;
430
+ }
431
+ if (!await this.validateCurrentBalance()) {
432
+ this.logger?.error(`Add balance to address ${this.account.address} for the producer to declare it's intent.`);
433
+ return;
434
+ }
435
+ if (!await this.validateCurrentStake()) {
436
+ this.logger?.error(`Add stake to contract address ${this.params.config.chain.id} for the producer to declare it's intent.`);
437
+ return;
438
+ }
439
+ this.logger?.log("Creating redeclaration intent for producer:", this.account.address);
440
+ const redeclarationIntent = createDeclarationIntent(this.account.address, "producer", currentBlock, currentBlock + BaseBlockProducerService.RedeclarationDuration);
441
+ await this.submitRedeclarationIntent(currentBlock, redeclarationIntent);
442
+ this._lastRedeclarationIntent = redeclarationIntent;
443
+ });
444
+ }
379
445
  async submitRedeclarationIntent(currentBlock, redeclarationIntent) {
380
446
  this.logger?.log("Submitting redeclaration intent for producer:", this.account.address);
381
447
  const tx = await buildTransaction(this.chainIterator.chainId, [
@@ -484,7 +550,7 @@ import { initTelemetry, startupSpanAsync as startupSpanAsync8, StepSizes, valida
484
550
  import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
485
551
  import { readPayloadMapFromStore } from "@xyo-network/xl1-protocol-sdk";
486
552
  import { CompletedStepRewardAddressValidatorFactory, DerivedReceiveAddressValidatorFactory, SelfSignerValidator, TransactionTransfersValidatorFactory } from "@xyo-network/xl1-validation";
487
- import { Semaphore } from "async-mutex";
553
+ import { Semaphore as Semaphore2 } from "async-mutex";
488
554
 
489
555
  // src/orchestration/archivists/ChainFinalized/archivist.ts
490
556
  import { initArchivistSync, startupSpanAsync } from "@xyo-network/chain-sdk";
@@ -1180,7 +1246,7 @@ var getForkFromBlock = /* @__PURE__ */ __name(async (head, chainService, chainAr
1180
1246
  }, "getForkFromBlock");
1181
1247
 
1182
1248
  // src/orchestration/services/implementation/head/submitNewChain.ts
1183
- import { delay } from "@xylabs/delay";
1249
+ import { delay as delay2 } from "@xylabs/delay";
1184
1250
  import { flattenHydratedBlock as flattenHydratedBlock2 } from "@xyo-network/xl1-protocol-sdk";
1185
1251
  var submitNewChain = /* @__PURE__ */ __name(async (chain, chainArchivist, chainSubmissionsArchivistWrite) => {
1186
1252
  for (const block of chain) {
@@ -1191,7 +1257,7 @@ var submitNewChain = /* @__PURE__ */ __name(async (chain, chainArchivist, chainS
1191
1257
  bw._hash
1192
1258
  ]);
1193
1259
  if (result.length > 0) break;
1194
- await delay(1e3);
1260
+ await delay2(1e3);
1195
1261
  }
1196
1262
  }
1197
1263
  }, "submitNewChain");
@@ -1520,7 +1586,7 @@ var initServices = /* @__PURE__ */ __name(async (context) => {
1520
1586
  startupSpanAsync8("BalanceService", () => initBalanceService({
1521
1587
  name: "BalanceService",
1522
1588
  context: {
1523
- stepSemaphores: StepSizes.map(() => new Semaphore(20)),
1589
+ stepSemaphores: StepSizes.map(() => new Semaphore2(20)),
1524
1590
  store: {
1525
1591
  chainMap
1526
1592
  },
@@ -1533,7 +1599,7 @@ var initServices = /* @__PURE__ */ __name(async (context) => {
1533
1599
  startupSpanAsync8("TransferService", () => initTransferService({
1534
1600
  name: "TransferService",
1535
1601
  context: {
1536
- stepSemaphores: StepSizes.map(() => new Semaphore(20)),
1602
+ stepSemaphores: StepSizes.map(() => new Semaphore2(20)),
1537
1603
  store: {
1538
1604
  chainMap
1539
1605
  },
@@ -1747,7 +1813,7 @@ var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
1747
1813
 
1748
1814
  // src/runCLI.ts
1749
1815
  var config;
1750
- var version = isDefined16("1.15.20") ? "1.15.20" : "unknown";
1816
+ var version = isDefined16("1.15.22") ? "1.15.22" : "unknown";
1751
1817
  var getContextFromConfig = /* @__PURE__ */ __name((config3) => {
1752
1818
  const logger = initLogger(config3);
1753
1819
  const orchestrator = new Orchestrator(logger);