@xyo-network/xl1-protocol-sdk 1.24.12 → 1.24.13

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.
@@ -3340,10 +3340,10 @@ var HydratedCache = class {
3340
3340
  cache;
3341
3341
  context;
3342
3342
  hydrateFunction;
3343
- constructor(context, hydrateFunction, maxSize = 200) {
3343
+ constructor(context, hydrateFunction, maxCount = 2e3, ttl = Number.MAX_SAFE_INTEGER) {
3344
3344
  this.context = context;
3345
3345
  this.hydrateFunction = hydrateFunction;
3346
- this.cache = new LRUCache2({ max: maxSize });
3346
+ this.cache = new LRUCache2({ max: maxCount, ttl });
3347
3347
  }
3348
3348
  async get(hash) {
3349
3349
  const existing = this.cache.get(hash);
@@ -3373,7 +3373,8 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3373
3373
  chainContractViewer;
3374
3374
  dataLakeViewer;
3375
3375
  finalizationViewer;
3376
- _payloadCache;
3376
+ payloadCache = new LruCacheMap({ max: 1e4 });
3377
+ signedHydratedBlockWithDataLakePayloadsCache = new LruCacheMap({ max: 2e3, ttl: 1e3 * 60 * 60 });
3377
3378
  _signedHydratedBlockCache;
3378
3379
  get finalizedArchivist() {
3379
3380
  return this.params.finalizedArchivist;
@@ -3384,14 +3385,9 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3384
3385
  this._signedHydratedBlockCache = new HydratedCache(context, async (context2, hash, maxDepth, minDepth) => {
3385
3386
  const result = await hydrateBlock(context2, hash, maxDepth, minDepth);
3386
3387
  return asSignedHydratedBlockWithStorageMeta(result, true);
3387
- }, 200);
3388
+ }, 2e3);
3388
3389
  return this._signedHydratedBlockCache;
3389
3390
  }
3390
- get payloadCache() {
3391
- if (this._payloadCache) return this._payloadCache;
3392
- this._payloadCache = new LruCacheMap({ max: 1e4 });
3393
- return this._payloadCache;
3394
- }
3395
3391
  get store() {
3396
3392
  return this._store;
3397
3393
  }
@@ -3403,9 +3399,17 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3403
3399
  }
3404
3400
  async blockByHash(hash) {
3405
3401
  return await this.spanAsync("blockByHash", async () => {
3402
+ const cachedBlock = this.signedHydratedBlockWithDataLakePayloadsCache.get(hash);
3403
+ if (cachedBlock) {
3404
+ return cachedBlock;
3405
+ }
3406
3406
  const cache = this.hydratedBlockCache;
3407
3407
  const block = await cache.get(hash);
3408
- return block ? await this.addDataLakePayloadsToBlock(block) : null;
3408
+ const result = block ? await this.addDataLakePayloadsToBlock(block) : null;
3409
+ if (result) {
3410
+ this.signedHydratedBlockWithDataLakePayloadsCache.set(hash, result);
3411
+ }
3412
+ return result;
3409
3413
  }, this.context);
3410
3414
  }
3411
3415
  async blockByNumber(blockNumber) {
@@ -3478,16 +3482,15 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3478
3482
  }
3479
3483
  async payloadsByHash(hashes) {
3480
3484
  let remainingHashes = [...hashes];
3481
- const cachedPayloads = await this.payloadCache.getMany(remainingHashes);
3485
+ const cachedPayloads = this.payloadCache.getMany(remainingHashes);
3482
3486
  const cachedHashes = new Set(cachedPayloads.map((p) => p._hash));
3483
3487
  remainingHashes = remainingHashes.filter((h) => !cachedHashes.has(h));
3484
3488
  const finalizedPayloads = remainingHashes.length > 0 ? await this.finalizedArchivist.get(remainingHashes) : [];
3485
- await Promise.all(finalizedPayloads.map(async (payload) => {
3486
- await this.payloadCache.set(payload._hash, payload);
3487
- }));
3488
- const finalizedHashes = new Set(finalizedPayloads.map((p) => p._hash));
3489
- remainingHashes = remainingHashes.filter((h) => !finalizedHashes.has(h));
3490
- return await this.addDataLakePayloadsToPayloads(hashes, [...cachedPayloads, ...finalizedPayloads.filter(exists4)]);
3489
+ const resultPayloads = await this.addDataLakePayloadsToPayloads(hashes, [...cachedPayloads, ...finalizedPayloads.filter(exists4)]);
3490
+ resultPayloads.map((payload) => {
3491
+ this.payloadCache.set(payload._hash, payload);
3492
+ });
3493
+ return resultPayloads;
3491
3494
  }
3492
3495
  async rate(range, timeUnit) {
3493
3496
  return await calculateBlockRate(this, range, timeUnit);