@xyo-network/xl1-protocol-sdk 1.20.0 → 1.20.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 (31) hide show
  1. package/dist/neutral/index.mjs +29 -26
  2. package/dist/neutral/index.mjs.map +1 -1
  3. package/dist/neutral/model/ChainContext/ChainContext.d.ts +4 -2
  4. package/dist/neutral/model/ChainContext/ChainContext.d.ts.map +1 -1
  5. package/dist/neutral/primitives/chain/getWindowedChain.d.ts +2 -2
  6. package/dist/neutral/primitives/chain/getWindowedChain.d.ts.map +1 -1
  7. package/dist/neutral/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.d.ts +1 -1
  8. package/dist/neutral/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.d.ts.map +1 -1
  9. package/dist/neutral/simple/blockValidation/SimpleBlockValidationViewer.d.ts.map +1 -1
  10. package/dist/neutral/validation/block/BlockValidationFunction.d.ts +2 -1
  11. package/dist/neutral/validation/block/BlockValidationFunction.d.ts.map +1 -1
  12. package/dist/neutral/validation/block/HydratedBlockStateValidationFunction.d.ts +2 -2
  13. package/dist/neutral/validation/block/HydratedBlockStateValidationFunction.d.ts.map +1 -1
  14. package/dist/neutral/validation/block/HydratedBlockValidationFunction.d.ts +2 -1
  15. package/dist/neutral/validation/block/HydratedBlockValidationFunction.d.ts.map +1 -1
  16. package/package.json +2 -2
  17. package/src/model/ChainContext/ChainContext.ts +6 -3
  18. package/src/primitives/chain/getWindowedChain.ts +8 -3
  19. package/src/primitives/chain/time/externalBlockNumberFromXL1BlockNumber.ts +1 -2
  20. package/src/primitives/chain/time/externalBlockRangeFromStep.ts +1 -1
  21. package/src/simple/accountBalance/SimpleAccountBalanceViewer.ts +5 -5
  22. package/src/simple/block/SimpleBlockViewer.ts +5 -5
  23. package/src/simple/blockValidation/SimpleBlockValidationViewer.ts +3 -1
  24. package/src/simple/finalization/SimpleFinalizationViewer.ts +1 -1
  25. package/src/summary/primitives/balances/balancesStepSummaryFromRange.ts +4 -4
  26. package/src/summary/primitives/balances/balancesSummary.ts +1 -1
  27. package/src/summary/primitives/schemas/schemasSummary.ts +1 -1
  28. package/src/summary/primitives/transfers/transfersSummary.ts +1 -1
  29. package/src/validation/block/BlockValidationFunction.ts +2 -0
  30. package/src/validation/block/HydratedBlockStateValidationFunction.ts +2 -1
  31. package/src/validation/block/HydratedBlockValidationFunction.ts +2 -0
@@ -1474,7 +1474,7 @@ import {
1474
1474
  isNull,
1475
1475
  spanRootAsync
1476
1476
  } from "@xylabs/sdk-js";
1477
- async function getWindowedChain(blockViewer, maxWindowSize, previousChain = []) {
1477
+ async function getWindowedChain(context, blockViewer, maxWindowSize, previousChain = []) {
1478
1478
  return await spanRootAsync("getWindowedChain", async () => {
1479
1479
  const newChain = [];
1480
1480
  const previousChainByHash = new Map(previousChain.map((block) => [block[0]._hash, block]));
@@ -1501,7 +1501,7 @@ async function getWindowedChain(blockViewer, maxWindowSize, previousChain = [])
1501
1501
  currentBlock = previousChainByHash.get(previousBlockHash) ?? await blockViewer.blockByHash(previousBlockHash);
1502
1502
  }
1503
1503
  return newChain;
1504
- }, { timeBudgetLimit: 100 });
1504
+ }, context);
1505
1505
  }
1506
1506
 
1507
1507
  // src/primitives/chain/step/chainStepRewardAddress.ts
@@ -1799,7 +1799,7 @@ import {
1799
1799
  isTimePayload
1800
1800
  } from "@xyo-network/xl1-protocol";
1801
1801
  var functionName = "externalBlockNumberFromXL1BlockNumber";
1802
- async function externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockNumber, externalTimeName, externalGenesisTime, timeBudgetMs = 2e3) {
1802
+ async function externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1BlockNumber, externalTimeName, externalGenesisTime) {
1803
1803
  const cacheKey = `${xl1BlockNumber}-${externalTimeName}-${externalGenesisTime ?? "default"}`;
1804
1804
  return await withContextCacheResponse(context, functionName, cacheKey, async () => {
1805
1805
  const [, payloads = []] = await blockViewer.blockByNumber(xl1BlockNumber) ?? [];
@@ -1809,7 +1809,7 @@ async function externalBlockNumberFromXL1BlockNumber(context, blockViewer, xl1Bl
1809
1809
  timePayload?.[externalTimeName] ?? externalGenesisTime ?? 23372716,
1810
1810
  { name: functionName }
1811
1811
  );
1812
- }, { timeBudgetMs });
1812
+ });
1813
1813
  }
1814
1814
 
1815
1815
  // src/primitives/chain/time/externalBlockRangeFromXL1BlockRange.ts
@@ -1825,7 +1825,7 @@ async function externalBlockRangeFromStep(context, blockViewer, stepIdentity) {
1825
1825
  return await withContextCacheResponse(context, "externalBlockRangeFromStep", cacheKey, async () => {
1826
1826
  const xl1BlockRange = stepBlockRange(stepIdentity);
1827
1827
  return await externalBlockRangeFromXL1BlockRange(context, blockViewer, xl1BlockRange);
1828
- }, { timeBudgetMs: 1e3 });
1828
+ });
1829
1829
  }
1830
1830
 
1831
1831
  // src/primitives/mapToMapType.ts
@@ -2203,17 +2203,18 @@ function contextCache(context, name, create) {
2203
2203
  }
2204
2204
  return context.caches[name];
2205
2205
  }
2206
- async function withContextCacheResponse(context, name, key, func, { max = 1e4, timeBudgetMs = 0 } = {}) {
2206
+ async function withContextCacheResponse(context, name, key, func, { max = 1e4 } = {}) {
2207
2207
  const cache = contextCache(
2208
2208
  context,
2209
2209
  name,
2210
2210
  () => new LruCacheMap({ max })
2211
2211
  );
2212
+ const { timeBudgetLimit = 0 } = context;
2212
2213
  const cacheResult = await cache.get(key);
2213
2214
  if (isDefined13(cacheResult)) {
2214
2215
  return cacheResult;
2215
2216
  }
2216
- const result = timeBudgetMs > 0 ? await timeBudget(name, context.logger, func, timeBudgetMs) : await func();
2217
+ const result = timeBudgetLimit > 0 ? await timeBudget(name, context.logger, func, timeBudgetLimit) : await func();
2217
2218
  await cache.set(key, result);
2218
2219
  return result;
2219
2220
  }
@@ -3274,7 +3275,7 @@ async function balancesStepSummaryFromRange(context, range) {
3274
3275
  stepSize: -1,
3275
3276
  balances
3276
3277
  });
3277
- }, { timeBudgetLimit: 100 }) : await spanRootAsync2(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
3278
+ }, context) : await spanRootAsync2(`balancesStepSummaryFromRange.frameSize>1[${key}]`, async () => {
3278
3279
  const step = StepSizes9.indexOf(asXL1BlockNumber6(frameSize, true));
3279
3280
  assertEx25(step !== -1, () => `Invalid step size: ${frameSize}. Must be one of ${StepSizes9.join(", ")}`);
3280
3281
  const summaryResult = await context.summaryMap.get(key);
@@ -3311,9 +3312,9 @@ async function balancesStepSummaryFromRange(context, range) {
3311
3312
  context.stepSemaphores[step].release();
3312
3313
  }
3313
3314
  }
3314
- }, { timeBudgetLimit: 100 });
3315
- }, { timeBudgetLimit: 200 });
3316
- }, { max: 1e5, timeBudgetMs: 200 });
3315
+ }, context);
3316
+ }, context);
3317
+ }, { max: 1e5 });
3317
3318
  }
3318
3319
 
3319
3320
  // src/summary/primitives/balances/balancesSummary.ts
@@ -3338,7 +3339,7 @@ async function balancesSummary(context, config) {
3338
3339
  }
3339
3340
  }
3340
3341
  return [balances, { range, head: headHash }];
3341
- }, { timeBudgetLimit: 500 });
3342
+ }, context);
3342
3343
  }
3343
3344
 
3344
3345
  // src/summary/primitives/schemas/schemasStepSummaryFromRange.ts
@@ -3428,7 +3429,7 @@ async function schemasSummary(context, config) {
3428
3429
  }
3429
3430
  }
3430
3431
  return [results, { range, head: headHash }];
3431
- }, { timeBudgetLimit: 500 });
3432
+ }, context);
3432
3433
  }
3433
3434
 
3434
3435
  // src/summary/primitives/transfers/transfersStepSummaryFromRange.ts
@@ -3463,7 +3464,7 @@ async function transfersSummary(context, config) {
3463
3464
  }
3464
3465
  }
3465
3466
  return [transfers, { range, head: headHash }];
3466
- }, { timeBudgetLimit: 500 });
3467
+ }, context);
3467
3468
  }
3468
3469
  function transfersSummaryKey(frameHeadHash, frameSize) {
3469
3470
  return `${frameHeadHash}|${frameSize}`;
@@ -3592,7 +3593,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
3592
3593
  ]));
3593
3594
  }
3594
3595
  return result;
3595
- }, { timeBudgetLimit: 200 });
3596
+ }, this.context);
3596
3597
  }
3597
3598
  async accountBalances(address, config) {
3598
3599
  const [result] = await this.qualifiedAccountBalances(address, config ?? {});
@@ -3632,7 +3633,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
3632
3633
  );
3633
3634
  }
3634
3635
  return [Object.fromEntries(entries), { range: qualifiedRange, head: qualifiedHeadHash }];
3635
- }, { timeBudgetLimit: 200 });
3636
+ }, this.context);
3636
3637
  }
3637
3638
  async qualifiedAccountBalances(address, config) {
3638
3639
  return await this.spanAsync("qualifiedAccountsBalances", async () => {
@@ -3646,7 +3647,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
3646
3647
  result[addr] = AttoXL12(summaryBalance < 0n ? 0n : summaryBalance);
3647
3648
  }
3648
3649
  return [result, qualifiedSummary[1]];
3649
- }, { timeBudgetLimit: 200 });
3650
+ }, this.context);
3650
3651
  }
3651
3652
  async startHandler() {
3652
3653
  await super.startHandler();
@@ -3688,7 +3689,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
3688
3689
  }
3689
3690
  }
3690
3691
  return [...resultBlockNumbers].toSorted((a, b) => b - a).slice(0, max);
3691
- }, { timeBudgetLimit: 200 });
3692
+ }, this.context);
3692
3693
  }
3693
3694
  async qualifiedAccountBalanceHistory(address, headOrRange) {
3694
3695
  return await this.spanAsync("qualifiedAccountBalanceHistory", async () => {
@@ -3721,7 +3722,7 @@ var SimpleAccountBalanceViewer = class extends AbstractCreatableProvider {
3721
3722
  ]));
3722
3723
  }
3723
3724
  return [result, { range: startingRange, head: head._hash }];
3724
- }, { timeBudgetLimit: 200 });
3725
+ }, this.context);
3725
3726
  }
3726
3727
  };
3727
3728
  __publicField(SimpleAccountBalanceViewer, "defaultMoniker", AccountBalanceViewerMoniker);
@@ -3814,7 +3815,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3814
3815
  return await this.spanAsync("blockByHash", async () => {
3815
3816
  const cache = this.hydratedBlockCache;
3816
3817
  return await cache.get(hash);
3817
- }, { timeBudgetLimit: 200 });
3818
+ }, this.context);
3818
3819
  }
3819
3820
  async blockByNumber(blockNumber) {
3820
3821
  return await this.spanAsync("blockByNumber", async () => {
@@ -3830,7 +3831,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3830
3831
  },
3831
3832
  store: this.store
3832
3833
  }, blockNumber)) ?? null;
3833
- }, { timeBudgetLimit: 200 });
3834
+ }, this.context);
3834
3835
  }
3835
3836
  async blocksByHash(hash, limit = 50) {
3836
3837
  return await this.spanAsync("blocksByHash", async () => {
@@ -3845,7 +3846,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3845
3846
  current = await this.blockByHash(previousHash);
3846
3847
  }
3847
3848
  return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
3848
- }, { timeBudgetLimit: 200 });
3849
+ }, this.context);
3849
3850
  }
3850
3851
  async blocksByNumber(blockNumber, limit = 50) {
3851
3852
  return await this.spanAsync("blocksByNumber", async () => {
@@ -3860,12 +3861,12 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
3860
3861
  current = await this.blockByNumber(previousNumber);
3861
3862
  }
3862
3863
  return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
3863
- }, { timeBudgetLimit: 200 });
3864
+ }, this.context);
3864
3865
  }
3865
3866
  async chainId(blockNumber = "latest") {
3866
3867
  return await this.spanAsync("chainId", async () => {
3867
3868
  return blockNumber === "latest" ? await this.chainContractViewer.chainId() : await this.chainContractViewer.chainIdAtBlockNumber(blockNumber);
3868
- }, { timeBudgetLimit: 200 });
3869
+ }, this.context);
3869
3870
  }
3870
3871
  async createHandler() {
3871
3872
  await super.createHandler();
@@ -4014,6 +4015,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
4014
4015
  async doValidateProtocol(blocks, chainIdAtBlockNumber) {
4015
4016
  return (await Promise.all(blocks.map(async (block) => {
4016
4017
  return await this.params.protocol(
4018
+ this.context,
4017
4019
  block,
4018
4020
  chainIdAtBlockNumber
4019
4021
  );
@@ -4029,6 +4031,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
4029
4031
  }
4030
4032
  return (await Promise.all(uncles[0].map(async (block) => {
4031
4033
  return await this.params.state(
4034
+ this.context,
4032
4035
  block,
4033
4036
  chainIdAtBlockNumber,
4034
4037
  { accountBalance: this._accountBalanceViewer }
@@ -4036,7 +4039,7 @@ var SimpleBlockValidationViewer = class extends AbstractCreatableProvider {
4036
4039
  }))).flat();
4037
4040
  }
4038
4041
  async updateWindowedChainCache() {
4039
- this._uncleWindowedChainCache = await getWindowedChain(this.blockViewer, this.maxUncleWindowSize, this._uncleWindowedChainCache ?? []);
4042
+ this._uncleWindowedChainCache = await getWindowedChain(this.context, this.blockViewer, this.maxUncleWindowSize, this._uncleWindowedChainCache ?? []);
4040
4043
  return [...this._uncleWindowedChainCache];
4041
4044
  }
4042
4045
  };
@@ -4391,7 +4394,7 @@ var SimpleFinalizationViewer = class extends AbstractCreatableProvider {
4391
4394
  console.log(`Could not find current block with hash ${currentHead._hash}`);
4392
4395
  }
4393
4396
  return assertEx33(block, () => "Could not find current block");
4394
- }, { timeBudgetLimit: 200 });
4397
+ }, this.context);
4395
4398
  }
4396
4399
  async headBlock() {
4397
4400
  return (await this.head())[0];