@xyo-network/xl1-protocol-sdk 1.26.2 → 1.26.4
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.
- package/dist/neutral/block/primitives/blockFromBlockNumber.d.ts.map +1 -1
- package/dist/neutral/index.mjs +65 -60
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/primitives/state/hydratedBlockByNumber.d.ts.map +1 -1
- package/dist/neutral/simple/mempool/SimpleMempoolRunner.d.ts.map +1 -1
- package/dist/neutral/test/index.mjs +64 -59
- package/dist/neutral/test/index.mjs.map +1 -1
- package/package.json +10 -10
- package/src/block/primitives/blockFromBlockNumber.ts +45 -42
- package/src/primitives/state/hydratedBlockByNumber.ts +14 -12
- package/src/simple/block/SimpleBlockViewer.ts +4 -4
- package/src/simple/mempool/SimpleMempoolRunner.ts +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydratedBlockByNumber.d.ts","sourceRoot":"","sources":["../../../../src/primitives/state/hydratedBlockByNumber.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EAAE,cAAc,EAC1C,MAAM,+BAA+B,CAAA;AAKtC,6CAA6C;AAC7C,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"hydratedBlockByNumber.d.ts","sourceRoot":"","sources":["../../../../src/primitives/state/hydratedBlockByNumber.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EAAE,cAAc,EAC1C,MAAM,+BAA+B,CAAA;AAKtC,6CAA6C;AAC7C,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAc7I"}
|
|
@@ -1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EAAE,QAAe,EAAE,QAAe,GACjD,GAAE,mBAAwB,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAyDjD,YAAY,CAAC,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAW5D,kBAAkB,CAAC,YAAY,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;cAsB3D,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;cAU7B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;YAQvC,0BAA0B;YA0B1B,gCAAgC;YAsChC,cAAc;YASd,gBAAgB;YAchB,oBAAoB;CAQnC"}
|
|
@@ -749,7 +749,8 @@ var hydrateBlock = async (context, hash, maxDepth = 1, minDepth = maxDepth) => {
|
|
|
749
749
|
// src/block/primitives/blockFromBlockNumber.ts
|
|
750
750
|
import {
|
|
751
751
|
asHash,
|
|
752
|
-
isDefined as isDefined4
|
|
752
|
+
isDefined as isDefined4,
|
|
753
|
+
spanAsync
|
|
753
754
|
} from "@xylabs/sdk-js";
|
|
754
755
|
import { toSafeJsonString } from "@xylabs/sdk-js";
|
|
755
756
|
import {
|
|
@@ -872,52 +873,54 @@ async function withContextCacheResponse(context, name, key, func, { max = 1e4 }
|
|
|
872
873
|
|
|
873
874
|
// src/block/primitives/blockFromBlockNumber.ts
|
|
874
875
|
async function blockFromBlockNumber(context, blockNumber) {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
883
|
-
result,
|
|
884
|
-
() => `Found Payload is not a Signed<BlockBoundWitness>: ${JSON.stringify(result, null, 2)}`
|
|
885
|
-
);
|
|
886
|
-
if (currentBlock.block < blockNumber) {
|
|
887
|
-
throw new Error(`Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
|
|
888
|
-
}
|
|
889
|
-
while (currentBlock.block > blockNumber) {
|
|
890
|
-
let jumpHash = currentBlock.previous;
|
|
891
|
-
let jumpBlockNumber = currentBlock.block - 1;
|
|
892
|
-
for (const [step, stepSize] of StepSizes.entries()) {
|
|
893
|
-
const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize - 1;
|
|
894
|
-
if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
|
|
895
|
-
jumpBlockNumber = possibleJumpBlockNumber;
|
|
896
|
-
jumpHash = asHash(currentBlock.step_hashes?.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
|
|
897
|
-
}
|
|
876
|
+
return await spanAsync("blockFromBlockNumber", async () => {
|
|
877
|
+
const cacheKey = `${blockNumber}`;
|
|
878
|
+
const { chainMap, head } = context;
|
|
879
|
+
return await withContextCacheResponse(context, "blockFromBlockNumber", cacheKey, async () => {
|
|
880
|
+
const [result] = await chainMap.get([head._hash]);
|
|
881
|
+
if (!isDefined4(result)) {
|
|
882
|
+
throw new Error(`Head block not found for hash: ${head._hash}`);
|
|
898
883
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if (!isDefined4(newBlock)) {
|
|
903
|
-
throw new Error(`Block not found for jump hash: ${jumpHash}`);
|
|
904
|
-
}
|
|
905
|
-
currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
906
|
-
newBlock,
|
|
907
|
-
() => {
|
|
908
|
-
const result2 = SignedBlockBoundWitnessWithHashMetaZod.safeParse(newBlock);
|
|
909
|
-
return `Found Payload [jump hash] is not a Signed<BlockBoundWitness>: ${result2.error}`;
|
|
910
|
-
}
|
|
884
|
+
let currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
885
|
+
result,
|
|
886
|
+
() => `Found Payload is not a Signed<BlockBoundWitness>: ${JSON.stringify(result, null, 2)}`
|
|
911
887
|
);
|
|
912
|
-
if (currentBlock.block === blockNumber) {
|
|
913
|
-
break;
|
|
914
|
-
}
|
|
915
888
|
if (currentBlock.block < blockNumber) {
|
|
916
|
-
throw new Error(`Block number ${blockNumber} is
|
|
889
|
+
throw new Error(`Block number ${blockNumber} is greater than head ${currentBlock.block}.`);
|
|
917
890
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
891
|
+
while (currentBlock.block > blockNumber) {
|
|
892
|
+
let jumpHash = currentBlock.previous;
|
|
893
|
+
let jumpBlockNumber = currentBlock.block - 1;
|
|
894
|
+
for (const [step, stepSize] of StepSizes.entries()) {
|
|
895
|
+
const possibleJumpBlockNumber = currentBlock.block - currentBlock.block % stepSize - 1;
|
|
896
|
+
if (possibleJumpBlockNumber >= blockNumber && possibleJumpBlockNumber <= jumpBlockNumber) {
|
|
897
|
+
jumpBlockNumber = possibleJumpBlockNumber;
|
|
898
|
+
jumpHash = asHash(currentBlock.step_hashes?.at(step), () => `Step hash not found for step ${step} in block ${currentBlock.block}`);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
const [newBlock] = await chainMap.get([
|
|
902
|
+
asHash(jumpHash, () => `Jump hash not found for block number [${blockNumber}]: ${jumpBlockNumber} ${toSafeJsonString(currentBlock, 10)}`)
|
|
903
|
+
]);
|
|
904
|
+
if (!isDefined4(newBlock)) {
|
|
905
|
+
throw new Error(`Block not found for jump hash: ${jumpHash}`);
|
|
906
|
+
}
|
|
907
|
+
currentBlock = asSignedBlockBoundWitnessWithStorageMeta(
|
|
908
|
+
newBlock,
|
|
909
|
+
() => {
|
|
910
|
+
const result2 = SignedBlockBoundWitnessWithHashMetaZod.safeParse(newBlock);
|
|
911
|
+
return `Found Payload [jump hash] is not a Signed<BlockBoundWitness>: ${result2.error}`;
|
|
912
|
+
}
|
|
913
|
+
);
|
|
914
|
+
if (currentBlock.block === blockNumber) {
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
if (currentBlock.block < blockNumber) {
|
|
918
|
+
throw new Error(`Block number ${blockNumber} is not a valid step block number for block ${head._hash}.`);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return currentBlock;
|
|
922
|
+
});
|
|
923
|
+
}, { ...context, timeBudgetLimit: 500 });
|
|
921
924
|
}
|
|
922
925
|
|
|
923
926
|
// src/block/primitives/validateTransactionOpcodes.ts
|
|
@@ -1226,19 +1229,21 @@ var findMostRecentBlock = async (chainArchivist, nextOptions = DEFAULT_NEXT_OPTI
|
|
|
1226
1229
|
};
|
|
1227
1230
|
|
|
1228
1231
|
// src/primitives/state/hydratedBlockByNumber.ts
|
|
1229
|
-
import { assertEx as assertEx9 } from "@xylabs/sdk-js";
|
|
1232
|
+
import { assertEx as assertEx9, spanAsync as spanAsync2 } from "@xylabs/sdk-js";
|
|
1230
1233
|
async function hydratedBlockByNumber(context, blockNumber) {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1234
|
+
return await spanAsync2("hydratedBlockByNumber", async () => {
|
|
1235
|
+
if (blockNumber < 0) throw new Error(`Block number ${blockNumber} is less than 0`);
|
|
1236
|
+
if (blockNumber > Number.MAX_SAFE_INTEGER) throw new Error(`Block number ${blockNumber} is greater than the maximum safe integer`);
|
|
1237
|
+
if (blockNumber % 1 !== 0) throw new Error(`Block number ${blockNumber} is not an integer`);
|
|
1238
|
+
const cacheKey = `${blockNumber}`;
|
|
1239
|
+
return await withContextCacheResponse(context, "hydratedBlockByNumber", cacheKey, async () => {
|
|
1240
|
+
const block = assertEx9(
|
|
1241
|
+
await blockFromBlockNumber(context, blockNumber),
|
|
1242
|
+
() => `Could not find block for block number ${blockNumber}`
|
|
1243
|
+
);
|
|
1244
|
+
return await hydrateBlock(context, block._hash);
|
|
1245
|
+
}, { max: 2e4 });
|
|
1246
|
+
}, { ...context, timeBudgetLimit: 500 });
|
|
1242
1247
|
}
|
|
1243
1248
|
|
|
1244
1249
|
// src/utils/HydratedCache.ts
|
|
@@ -1282,7 +1287,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
1282
1287
|
this._signedHydratedBlockCache = new HydratedCache(context, async (context2, hash, maxDepth, minDepth) => {
|
|
1283
1288
|
const result = await hydrateBlock(context2, hash, maxDepth, minDepth);
|
|
1284
1289
|
return asSignedHydratedBlockWithStorageMeta(result, true);
|
|
1285
|
-
},
|
|
1290
|
+
}, 2e4);
|
|
1286
1291
|
return this._signedHydratedBlockCache;
|
|
1287
1292
|
}
|
|
1288
1293
|
get store() {
|
|
@@ -1307,7 +1312,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
1307
1312
|
this.signedHydratedBlockWithDataLakePayloadsCache.set(hash, result);
|
|
1308
1313
|
}
|
|
1309
1314
|
return result;
|
|
1310
|
-
}, this.context);
|
|
1315
|
+
}, { ...this.context, timeBudgetLimit: 100 });
|
|
1311
1316
|
}
|
|
1312
1317
|
async blockByNumber(blockNumber) {
|
|
1313
1318
|
return await this.spanAsync("blockByNumber", async () => {
|
|
@@ -1318,7 +1323,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
1318
1323
|
const block = asSignedHydratedBlockWithHashMeta(await hydratedBlockByNumber(await this.getChainContextRead(), blockNumber)) ?? null;
|
|
1319
1324
|
const [result] = block ? await addDataLakePayloads(block, this.dataLakeViewer) : [null, []];
|
|
1320
1325
|
return result;
|
|
1321
|
-
}, this.context);
|
|
1326
|
+
}, { ...this.context, timeBudgetLimit: 100 });
|
|
1322
1327
|
}
|
|
1323
1328
|
async blocksByHash(hash, limit = 50) {
|
|
1324
1329
|
return await this.spanAsync("blocksByHash", async () => {
|
|
@@ -1333,7 +1338,7 @@ var SimpleBlockViewer = class extends AbstractCreatableProvider {
|
|
|
1333
1338
|
current = await this.blockByHash(previousHash);
|
|
1334
1339
|
}
|
|
1335
1340
|
return blocks.map((b) => asSignedHydratedBlockWithHashMeta(b, true));
|
|
1336
|
-
}, this.context);
|
|
1341
|
+
}, { ...this.context, timeBudgetLimit: 300 });
|
|
1337
1342
|
}
|
|
1338
1343
|
async blocksByNumber(blockNumber, limit = 50) {
|
|
1339
1344
|
return await this.spanAsync("blocksByNumber", async () => {
|