@xyo-network/xl1-protocol-sdk 1.26.2 → 1.26.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"blockFromBlockNumber.d.ts","sourceRoot":"","sources":["../../../../src/block/primitives/blockFromBlockNumber.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EACpD,MAAM,+BAA+B,CAAA;AAOtC,4CAA4C;AAC5C,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,gBAAgB,EACzB,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CA+ClD"}
1
+ {"version":3,"file":"blockFromBlockNumber.d.ts","sourceRoot":"","sources":["../../../../src/block/primitives/blockFromBlockNumber.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EACpD,MAAM,+BAA+B,CAAA;AAOtC,4CAA4C;AAC5C,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,gBAAgB,EACzB,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAiDlD"}
@@ -406,7 +406,8 @@ var tryHydrateBlock = async (archivist, hash, maxDepth = 1) => {
406
406
  // src/block/primitives/blockFromBlockNumber.ts
407
407
  import {
408
408
  asHash,
409
- isDefined as isDefined3
409
+ isDefined as isDefined3,
410
+ spanAsync
410
411
  } from "@xylabs/sdk-js";
411
412
  import { toSafeJsonString } from "@xylabs/sdk-js";
412
413
  import {
@@ -529,52 +530,54 @@ async function withContextCacheResponse(context, name, key, func, { max = 1e4 }
529
530
 
530
531
  // src/block/primitives/blockFromBlockNumber.ts
531
532
  async function blockFromBlockNumber(context, blockNumber) {
532
- const cacheKey = `${blockNumber}`;
533
- const { chainMap, head } = context;
534
- return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
535
- const [result] = await chainMap.get([head._hash]);
536
- if (!isDefined3(result)) {
537
- throw new Error(`Head block not found for hash: ${head._hash}`);
538
- }
539
- let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
540
- result,
541
- () => `Found Payload is not a Signed<BlockBoundWitness>: ${JSON.stringify(result, null, 2)}`
542
- );
543
- if (currentBlock.block < blockNumber) {
544
- throw new Error(`Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
545
- }
546
- while (currentBlock.block > blockNumber) {
547
- let jumpHash = currentBlock.previous;
548
- let jumpBlockNumber = currentBlock.block - 1;
549
- for (const [step, stepSize2] of StepSizes.entries()) {
550
- const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize2 - 1;
551
- if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
552
- jumpBlockNumber = possibleJumpBlockNumber;
553
- jumpHash = asHash(currentBlock.step_hashes?.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
554
- }
533
+ return await spanAsync("blockFromBlockNumber", async () => {
534
+ const cacheKey = `${blockNumber}`;
535
+ const { chainMap, head } = context;
536
+ return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
537
+ const [result] = await chainMap.get([head._hash]);
538
+ if (!isDefined3(result)) {
539
+ throw new Error(`Head block not found for hash: ${head._hash}`);
555
540
  }
556
- const [newBlock] = await chainMap.get([
557
- asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
558
- ]);
559
- if (!isDefined3(newBlock)) {
560
- throw new Error(`Block not found for jump hash: ${jumpHash}`);
561
- }
562
- currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
563
- newBlock,
564
- () => {
565
- const result2 = SignedBlockBoundWitnessWithHashMetaZod.safeParse(newBlock);
566
- return `Found Payload [jump hash] is not a Signed<BlockBoundWitness>: ${result2.error}`;
567
- }
541
+ let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
542
+ result,
543
+ () => `Found Payload is not a Signed<BlockBoundWitness>: ${JSON.stringify(result, null, 2)}`
568
544
  );
569
- if (currentBlock.block === blockNumber) {
570
- break;
571
- }
572
545
  if (currentBlock.block < blockNumber) {
573
- throw new Error(`Block number ${blockNumber} is not a valid step block number for block ${head._hash}.`);
546
+ throw new Error(`Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
574
547
  }
575
- }
576
- return currentBlock;
577
- });
548
+ while (currentBlock.block > blockNumber) {
549
+ let jumpHash = currentBlock.previous;
550
+ let jumpBlockNumber = currentBlock.block - 1;
551
+ for (const [step, stepSize2] of StepSizes.entries()) {
552
+ const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize2 - 1;
553
+ if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
554
+ jumpBlockNumber = possibleJumpBlockNumber;
555
+ jumpHash = asHash(currentBlock.step_hashes?.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
556
+ }
557
+ }
558
+ const [newBlock] = await chainMap.get([
559
+ asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
560
+ ]);
561
+ if (!isDefined3(newBlock)) {
562
+ throw new Error(`Block not found for jump hash: ${jumpHash}`);
563
+ }
564
+ currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
565
+ newBlock,
566
+ () => {
567
+ const result2 = SignedBlockBoundWitnessWithHashMetaZod.safeParse(newBlock);
568
+ return `Found Payload [jump hash] is not a Signed<BlockBoundWitness>: ${result2.error}`;
569
+ }
570
+ );
571
+ if (currentBlock.block === blockNumber) {
572
+ break;
573
+ }
574
+ if (currentBlock.block < blockNumber) {
575
+ throw new Error(`Block number ${blockNumber} is not a valid step block number for block ${head._hash}.`);
576
+ }
577
+ }
578
+ return currentBlock;
579
+ });
580
+ }, { ...context, timeBudgetLimit: 500 });
578
581
  }
579
582
 
580
583
  // src/block/primitives/frames/calculateFramesFromRange.ts
@@ -2967,19 +2970,21 @@ var findMostRecentBlock = async (chainArchivist, nextOptions = DEFAULT_NEXT_OPTI
2967
2970
  };
2968
2971
 
2969
2972
  // src/primitives/state/hydratedBlockByNumber.ts
2970
- import { assertEx as assertEx24 } from "@xylabs/sdk-js";
2973
+ import { assertEx as assertEx24, spanAsync as spanAsync2 } from "@xylabs/sdk-js";
2971
2974
  async function hydratedBlockByNumber(context, blockNumber) {
2972
- if (blockNumber < 0) throw new Error(`Block number ${blockNumber} is less than 0`);
2973
- if (blockNumber > Number.MAX_SAFE_INTEGER) throw new Error(`Block number ${blockNumber} is greater than the maximum safe integer`);
2974
- if (blockNumber % 1 !== 0) throw new Error(`Block number ${blockNumber} is not an integer`);
2975
- const cacheKey = `${blockNumber}`;
2976
- return await withContextCacheResponse(context, "hydratedBlockByNumber", cacheKey, async () => {
2977
- const block = assertEx24(
2978
- await blockFromBlockNumber(context, blockNumber),
2979
- () => `Could not find block for block number ${blockNumber}`
2980
- );
2981
- return await hydrateBlock(context, block._hash);
2982
- });
2975
+ return await spanAsync2("hydratedBlockByNumber", async () => {
2976
+ if (blockNumber < 0) throw new Error(`Block number ${blockNumber} is less than 0`);
2977
+ if (blockNumber > Number.MAX_SAFE_INTEGER) throw new Error(`Block number ${blockNumber} is greater than the maximum safe integer`);
2978
+ if (blockNumber % 1 !== 0) throw new Error(`Block number ${blockNumber} is not an integer`);
2979
+ const cacheKey = `${blockNumber}`;
2980
+ return await withContextCacheResponse(context, "hydratedBlockByNumber", cacheKey, async () => {
2981
+ const block = assertEx24(
2982
+ await blockFromBlockNumber(context, blockNumber),
2983
+ () => `Could not find block for block number ${blockNumber}`
2984
+ );
2985
+ return await hydrateBlock(context, block._hash);
2986
+ }, { max: 2e4 });
2987
+ }, { ...context, timeBudgetLimit: 500 });
2983
2988
  }
2984
2989
 
2985
2990
  // src/primitives/transaction/elevatedPayloads.ts
@@ -3784,7 +3789,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3784
3789
  this._signedHydratedBlockCache = new HydratedCache(context, async (context2, hash, maxDepth, minDepth) => {
3785
3790
  const result = await hydrateBlock(context2, hash, maxDepth, minDepth);
3786
3791
  return asSignedHydratedBlockWithStorageMeta(result, true);
3787
- }, 2e3);
3792
+ }, 2e4);
3788
3793
  return this._signedHydratedBlockCache;
3789
3794
  }
3790
3795
  get store() {
@@ -3809,7 +3814,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3809
3814
  this.signedHydratedBlockWithDataLakePayloadsCache.set(hash, result);
3810
3815
  }
3811
3816
  return result;
3812
- }, this.context);
3817
+ }, { ...this.context, timeBudgetLimit: 100 });
3813
3818
  }
3814
3819
  async blockByNumber(blockNumber) {
3815
3820
  return await this.spanAsync("blockByNumber", async () => {
@@ -3820,7 +3825,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3820
3825
  const block = asSignedHydratedBlockWithHashMeta(await hydratedBlockByNumber(await this.getChainContextRead(), blockNumber)) ?? null;
3821
3826
  const [result] = block ? await addDataLakePayloads(block, this.dataLakeViewer) : [null, []];
3822
3827
  return result;
3823
- }, this.context);
3828
+ }, { ...this.context, timeBudgetLimit: 100 });
3824
3829
  }
3825
3830
  async blocksByHash(hash, limit = 50) {
3826
3831
  return await this.spanAsync("blocksByHash", async () => {
@@ -3835,7 +3840,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3835
3840
  current = await this.blockByHash(previousHash);
3836
3841
  }
3837
3842
  return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
3838
- }, this.context);
3843
+ }, { ...this.context, timeBudgetLimit: 300 });
3839
3844
  }
3840
3845
  async blocksByNumber(blockNumber, limit = 50) {
3841
3846
  return await this.spanAsync("blocksByNumber", async () => {