@xyo-network/xl1-cli 1.19.0 → 1.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli-min.mjs +81 -30
  2. package/package.json +3 -3
package/dist/cli-min.mjs CHANGED
@@ -87435,7 +87435,7 @@ async function withContextCacheResponse(context, name, key, func, { max = 1e4 }
87435
87435
  if (isDefined(cacheResult)) {
87436
87436
  return cacheResult;
87437
87437
  }
87438
- const result = timeBudgetLimit > 0 ? await timeBudget(name, context.logger, func, timeBudgetLimit) : await func();
87438
+ const result = timeBudgetLimit > 0 ? timeBudget(name, context.logger, func, timeBudgetLimit) : func();
87439
87439
  await cache.set(key, result);
87440
87440
  return result;
87441
87441
  }
@@ -96760,6 +96760,7 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
96760
96760
  _tracer;
96761
96761
  _accountBalanceViewer;
96762
96762
  _blockViewer;
96763
+ _chainContractViewer;
96763
96764
  _finalizedPayloadMap;
96764
96765
  _mempoolViewer;
96765
96766
  _networkStakeViewer;
@@ -96776,6 +96777,9 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
96776
96777
  get block() {
96777
96778
  return this._blockViewer;
96778
96779
  }
96780
+ get chainContractViewer() {
96781
+ return this._chainContractViewer;
96782
+ }
96779
96783
  get mempool() {
96780
96784
  return this._mempoolViewer;
96781
96785
  }
@@ -96830,12 +96834,12 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
96830
96834
  return await this.block.blocksByNumber(blockNumber, limit);
96831
96835
  }
96832
96836
  async chainId(blockNumber = "latest") {
96833
- return await this.spanAsync("chainIdAtBlock", async () => {
96834
- const block = assertEx(
96835
- blockNumber === "latest" ? await this.currentBlock() : await this.blockByNumber(blockNumber),
96837
+ return await this.spanAsync("SimpleXyoViewer:chainId", async () => {
96838
+ const chainId = assertEx(
96839
+ blockNumber === "latest" ? await this.chainContractViewer.chainId() : await this.chainContractViewer.chainIdAtBlockNumber(blockNumber),
96836
96840
  () => `Could not find block for chainId at block ${blockNumber}`
96837
96841
  );
96838
- return block[0].chain;
96842
+ return chainId;
96839
96843
  }, this.context);
96840
96844
  }
96841
96845
  async createHandler() {
@@ -96843,6 +96847,7 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
96843
96847
  this._finalizedPayloadMap = readPayloadMapFromStore(this.params.finalizedArchivist);
96844
96848
  this._accountBalanceViewer = await this.locator.getInstance(AccountBalanceViewerMoniker);
96845
96849
  this._blockViewer = await this.locator.getInstance(BlockViewerMoniker);
96850
+ this._chainContractViewer = await this.locator.getInstance(ChainContractViewerMoniker);
96846
96851
  this._mempoolViewer = await this.locator.getInstance(MempoolViewerMoniker);
96847
96852
  this._networkStakeViewer = await this.locator.getInstance(NetworkStakeViewerMoniker);
96848
96853
  this._networkStepRewardsByPositionViewer = await this.locator.getInstance(NetworkStakeStepRewardsByPositionViewerMoniker);
@@ -96875,7 +96880,8 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
96875
96880
  throw new Error("Method [networkStakeStepRewardClaimedByAddress] not implemented.");
96876
96881
  }
96877
96882
  async networkStakeStepRewardForPosition(position, range) {
96878
- return await this.spanAsync("networkStakeStepRewardForPosition", async () => {
96883
+ const cacheKey = `${position}|${range[0]}-${range[1]}`;
96884
+ return await withContextCacheResponse(this.context, "SimpleXyoViewer:networkStakeStepRewardForPosition", cacheKey, async () => {
96879
96885
  const externalRange = await externalBlockRangeFromXL1BlockRange(this.context, this.block, range);
96880
96886
  const positionCount = await this.stake.stakeEvents.positionCount(externalRange);
96881
96887
  if (positionCount === 0) {
@@ -96886,7 +96892,7 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
96886
96892
  const positionReward = asAttoXL1(rewards.reduce((a, b) => a + b[0], 0n));
96887
96893
  const totalReward = asAttoXL1(rewards.reduce((a, b) => a + b[1], 0n));
96888
96894
  return [positionReward, totalReward];
96889
- }, this.context);
96895
+ });
96890
96896
  }
96891
96897
  async networkStakeStepRewardForStep(stepContext) {
96892
96898
  return await stepRewardTotal(await this.getStakedChainContext(), stepContext, this.rewardMultipliers);
@@ -96895,7 +96901,7 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
96895
96901
  const stepIdentityString = toStepIdentityString(stepIdentity);
96896
96902
  const cacheKey = `${stepIdentityString}|${position}`;
96897
96903
  const stakedChainContext = await this.getStakedChainContext();
96898
- return await withContextCacheResponse(stakedChainContext, "NodeXyoViewer-networkStakeStepRewardForStepForPosition", cacheKey, async () => {
96904
+ return await withContextCacheResponse(stakedChainContext, "SimpleXyoViewer:networkStakeStepRewardForStepForPosition", cacheKey, async () => {
96899
96905
  const range = await externalBlockRangeFromStep(stakedChainContext, this.block, stepIdentity);
96900
96906
  const stake = await this.stakeById(position);
96901
96907
  const numerator = stake.staked === XYO_NETWORK_STAKING_ADDRESS ? await weightedStakeForRangeByPosition(stakedChainContext, this.block, range, XYO_NETWORK_STAKING_ADDRESS, position) : 0n;
@@ -97090,7 +97096,8 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
97090
97096
  },
97091
97097
  store,
97092
97098
  chainId: await this.chainId(),
97093
- stake
97099
+ stake,
97100
+ timeBudgetLimit: this.context.timeBudgetLimit
97094
97101
  };
97095
97102
  }
97096
97103
  async startHandler() {
@@ -97104,14 +97111,23 @@ var SimpleXyoViewer = class extends AbstractCreatableProvider {
97104
97111
  asXL1BlockRange([0, currentBlockNumber], { name: "startHandler" })
97105
97112
  );
97106
97113
  const positionCount = await this.stake.stakeEvents.positionCount(externalRange);
97107
- this.logger?.log(`NodeXyoViewer: Precomputing networkStakeStepRewardForPosition up to position ${positionCount - 1}`);
97108
- for (let position = 0; position < positionCount; position++) {
97109
- await this.networkStakeStepRewardForPosition(position, asXL1BlockRange([0, currentBlockNumber], { name: "startHandler" }));
97114
+ this.logger?.log(`SimpleXyoViewer: Precomputing networkStakeStepRewardForPosition up to position ${positionCount - 1}`);
97115
+ const positions = Array.from(
97116
+ { length: positionCount },
97117
+ (_, i) => i
97118
+ );
97119
+ while (positions.length > 0) {
97120
+ const batch = positions.splice(0, 10);
97121
+ this.logger?.log(`SimpleXyoViewer: Precomputing networkStakeStepRewardForPosition for positions ${batch.at(0)} - ${batch.at(-1)}`);
97122
+ await Promise.all(batch.map(async (_, position) => await this.networkStakeStepRewardForPosition(
97123
+ position,
97124
+ asXL1BlockRange([0, currentBlockNumber], { name: "startHandler" })
97125
+ )));
97110
97126
  }
97111
- this.logger?.log(`NodeXyoViewer: Precomputed networkStakeStepRewardForPosition up to position ${positionCount - 1}`);
97127
+ this.logger?.log(`SimpleXyoViewer: Precomputed networkStakeStepRewardForPosition up to position ${positionCount - 1}`);
97112
97128
  }
97113
97129
  } catch (ex) {
97114
- this.logger?.error(`NodeXyoViewer: Error during startHandler initialization: ${ex.message}`);
97130
+ this.logger?.error(`SimpleXyoViewer: Error during startHandler initialization: ${ex.message}`);
97115
97131
  this.logger?.error(ex.stack ?? "<No Stack>");
97116
97132
  throw ex;
97117
97133
  }
@@ -298452,6 +298468,7 @@ async function getServer$3(params) {
298452
298468
  config,
298453
298469
  logger,
298454
298470
  statusReporter,
298471
+ timeBudgetLimit: 1e3,
298455
298472
  meterProvider,
298456
298473
  traceProvider,
298457
298474
  singletons: {},
@@ -298571,6 +298588,8 @@ async function getServer$3(params) {
298571
298588
  assertEx(blk, () => "No blocks found after initialization");
298572
298589
  const accountBalanceViewer = await locator.getInstance(AccountBalanceViewerMoniker);
298573
298590
  assertEx(await accountBalanceViewer.start(), () => "Failed to start AccountBalanceViewer");
298591
+ const xyoViewer = await locator.getInstance(XyoViewerMoniker);
298592
+ assertEx(await xyoViewer.start(), () => "Failed to start XyoViewer");
298574
298593
  console.info(`[API] Current block after initialization: #${blk[0].block} (${blk[0]._hash})`);
298575
298594
  const actor = config.mempool.enabled ? void 0 : await ValidatorActor.create({
298576
298595
  id: "validator-mempool-server",
@@ -298669,10 +298688,26 @@ function _ts_decorate(decorators, target, key, desc) {
298669
298688
  }
298670
298689
  __name$4(_ts_decorate, "_ts_decorate");
298671
298690
  var TEN_MINUTES = 10 * 60 * 1e3;
298691
+ var toFormattedBlockReference = /* @__PURE__ */ __name$4((blockBoundWitness) => {
298692
+ return `${blockBoundWitness.block} [${toHex(blockBoundWitness._hash, {
298693
+ prefix: true
298694
+ })}]`;
298695
+ }, "toFormattedBlockReference");
298672
298696
  var ProducerActor = class _ProducerActor extends Actor {
298673
298697
  static {
298674
298698
  __name$4(this, "ProducerActor");
298675
298699
  }
298700
+ /**
298701
+ * The interval time (in MS) between block production attempts.
298702
+ */
298703
+ static BlockSubmissionCheckInterval = 1500;
298704
+ /**
298705
+ * The threshold time (in MS) for resubmitting the same block number if the head has not changed.
298706
+ */
298707
+ static HeadResubmissionThreshold = _ProducerActor.BlockSubmissionCheckInterval * 30;
298708
+ /**
298709
+ * The window (in blocks) before expiration to attempt redeclaration of producer intent.
298710
+ */
298676
298711
  static RedeclarationWindow = 1e4;
298677
298712
  _lastProducedBlock;
298678
298713
  _lastRedeclarationIntent;
@@ -298685,6 +298720,8 @@ var ProducerActor = class _ProducerActor extends Actor {
298685
298720
  _blockRunner;
298686
298721
  _blockViewer;
298687
298722
  _chainId;
298723
+ _lastHeadChangeTime;
298724
+ _lastHeadHash;
298688
298725
  _mempoolRunner;
298689
298726
  _mempoolViewer;
298690
298727
  _produceBlockMutex = new Mutex$1();
@@ -298795,15 +298832,9 @@ var ProducerActor = class _ProducerActor extends Actor {
298795
298832
  }
298796
298833
  async startHandler() {
298797
298834
  await super.startHandler();
298798
- this.registerTimer(
298799
- "BlockProductionTimer",
298800
- async () => {
298801
- await this.produceBlock();
298802
- },
298803
- 2e3,
298804
- 1500
298805
- /* 500 */
298806
- );
298835
+ this.registerTimer("BlockProductionTimer", async () => {
298836
+ await this.produceBlock();
298837
+ }, 2e3, _ProducerActor.BlockSubmissionCheckInterval);
298807
298838
  {
298808
298839
  this.registerTimer("ProducerRedeclarationTimer", async () => {
298809
298840
  await this.redeclareIntent();
@@ -298823,24 +298854,44 @@ var ProducerActor = class _ProducerActor extends Actor {
298823
298854
  await this._produceBlockMutex.runExclusive(async () => {
298824
298855
  const head = (await this.blockViewer.currentBlock())[0];
298825
298856
  const headHash = head._hash;
298826
- if (this._lastProducedBlock && this._lastProducedBlock[0].previous === headHash) {
298827
- this.logger?.log("Block already produced:", `0x${toHex(this._lastProducedBlock[0].block)}`, this._lastProducedBlock[0].block);
298828
- } else {
298857
+ const currentTime = Date.now();
298858
+ if (this._lastHeadHash !== headHash) {
298859
+ const lastHeadHashHex = isDefined(this._lastHeadHash) ? `0x${this._lastHeadHash}` : "undefined";
298860
+ const currentHeadHashHex = `0x${headHash}`;
298861
+ this.logger?.log(`Found updated head ${lastHeadHashHex} -> ${currentHeadHashHex}`);
298862
+ this._lastHeadHash = headHash;
298863
+ this._lastHeadChangeTime = currentTime;
298864
+ }
298865
+ const timeSinceHeadChange = isDefined(this._lastHeadChangeTime) ? currentTime - this._lastHeadChangeTime : 0;
298866
+ const shouldSubmit = !this._lastProducedBlock || this._lastProducedBlock[0].previous !== headHash;
298867
+ const shouldResubmit = timeSinceHeadChange > _ProducerActor.HeadResubmissionThreshold;
298868
+ const shouldSubmitBlock = shouldSubmit || shouldResubmit;
298869
+ if (shouldSubmitBlock) {
298870
+ if (shouldResubmit) {
298871
+ this.logger?.log(`Resubmitting block due to stale head. Head ${toFormattedBlockReference(head)} unchanged for ${timeSinceHeadChange}ms`);
298872
+ this._lastHeadChangeTime = currentTime;
298873
+ }
298829
298874
  this._producerActorBlockProductionAttempts?.add(1, this._metricAttributes);
298830
298875
  const nextBlock = await this.blockRunner.next(head);
298831
298876
  if (nextBlock) {
298832
- const displayBlockNumber = `0x${toHex(nextBlock[0].block)}`;
298877
+ const displayBlockNumber = toFormattedBlockReference(nextBlock[0]);
298833
298878
  this.logger?.log("Produced block:", displayBlockNumber);
298834
298879
  this._producerActorBlocksProduced?.add(1, this._metricAttributes);
298835
298880
  await this.mempoolRunner.submitBlocks([
298836
298881
  nextBlock
298837
298882
  ]);
298838
- this.logger?.log("Published block:", displayBlockNumber, nextBlock[0].block);
298883
+ this.logger?.log("Published block:", displayBlockNumber);
298839
298884
  this._producerActorBlocksPublished?.add(1, this._metricAttributes);
298840
298885
  this._lastProducedBlock = nextBlock;
298841
298886
  } else {
298842
- this.logger?.log("No block produced at this time.");
298887
+ this.logger?.log("No block produced for submission.");
298888
+ }
298889
+ } else {
298890
+ let nonSubmissionMessage = "No block submission required at this time";
298891
+ if (isDefined(this._lastProducedBlock)) {
298892
+ nonSubmissionMessage = nonSubmissionMessage + `, already produced: ${toFormattedBlockReference(this._lastProducedBlock[0])}`;
298843
298893
  }
298894
+ this.logger?.log(`${nonSubmissionMessage}.`);
298844
298895
  }
298845
298896
  });
298846
298897
  }, {
@@ -350163,7 +350214,7 @@ var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
350163
350214
 
350164
350215
  // src/runCLI.ts
350165
350216
  var configuration;
350166
- var version = isDefined("1.18.5") ? "1.18.5" : "unknown";
350217
+ var version = isDefined("1.19.1") ? "1.19.1" : "unknown";
350167
350218
  var getContextFromConfig = /* @__PURE__ */ __name(async (configuration2) => {
350168
350219
  const logger = initLogger(configuration2);
350169
350220
  const orchestrator = await Orchestrator.create({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/xl1-cli",
3
- "version": "1.19.0",
3
+ "version": "1.19.2",
4
4
  "description": "XYO Layer One CLI",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -75,8 +75,8 @@
75
75
  "@xyo-network/payload-model": "~5.3.2",
76
76
  "@xyo-network/wallet": "~5.3.2",
77
77
  "@xyo-network/wallet-model": "~5.3.2",
78
- "@xyo-network/xl1-cli-lib": "~1.19.0",
79
- "@xyo-network/xl1-sdk": "~1.20.2",
78
+ "@xyo-network/xl1-cli-lib": "~1.19.2",
79
+ "@xyo-network/xl1-sdk": "~1.20.9",
80
80
  "async-mutex": "~0.5.0",
81
81
  "dotenv": "~17.2.3",
82
82
  "eslint": "^9.39.2",