@typeberry/jam 0.4.1-0a3acb2 → 0.4.1-69ce381
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/bootstrap-importer.mjs +13 -14
- package/bootstrap-importer.mjs.map +1 -1
- package/index.js +13 -14
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -38186,7 +38186,7 @@ class BlockVerifier {
|
|
|
38186
38186
|
this.hasher = hasher;
|
|
38187
38187
|
this.blocks = blocks;
|
|
38188
38188
|
}
|
|
38189
|
-
async verifyBlock(block) {
|
|
38189
|
+
async verifyBlock(block, options = { skipParentAndStateRoot: false }) {
|
|
38190
38190
|
const headerView = block.header.view();
|
|
38191
38191
|
const headerHash = this.hasher.header(headerView);
|
|
38192
38192
|
// check if current block is already imported
|
|
@@ -38198,7 +38198,7 @@ class BlockVerifier {
|
|
|
38198
38198
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0c9d000c9d00?v=0.6.5
|
|
38199
38199
|
const parentHash = headerView.parentHeaderHash.materialize();
|
|
38200
38200
|
// importing genesis block
|
|
38201
|
-
if (!parentHash.isEqualTo(block_verifier_ZERO_HASH)) {
|
|
38201
|
+
if (!parentHash.isEqualTo(block_verifier_ZERO_HASH) && !options.skipParentAndStateRoot) {
|
|
38202
38202
|
const parentBlock = this.blocks.getHeader(parentHash);
|
|
38203
38203
|
if (parentBlock === null) {
|
|
38204
38204
|
return result_Result.error(BlockVerifierError.ParentNotFound, () => `Parent ${parentHash.toString()} not found`);
|
|
@@ -38218,21 +38218,20 @@ class BlockVerifier {
|
|
|
38218
38218
|
if (!extrinsicHash.isEqualTo(extrinsicMerkleCommitment.hash)) {
|
|
38219
38219
|
return result_Result.error(BlockVerifierError.InvalidExtrinsic, () => `Invalid extrinsic hash: ${extrinsicHash.toString()}, expected ${extrinsicMerkleCommitment.hash.toString()}`);
|
|
38220
38220
|
}
|
|
38221
|
-
|
|
38222
|
-
|
|
38223
|
-
|
|
38224
|
-
|
|
38225
|
-
|
|
38226
|
-
|
|
38227
|
-
|
|
38228
|
-
|
|
38229
|
-
|
|
38221
|
+
if (!options.skipParentAndStateRoot) {
|
|
38222
|
+
// Check if the state root is valid.
|
|
38223
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/0c73010c7301?v=0.7.2
|
|
38224
|
+
const stateRoot = headerView.priorStateRoot.materialize();
|
|
38225
|
+
const posteriorStateRoot = this.blocks.getPostStateRoot(parentHash);
|
|
38226
|
+
if (posteriorStateRoot === null) {
|
|
38227
|
+
return result_Result.error(BlockVerifierError.StateRootNotFound, () => `Posterior state root ${parentHash.toString()} not found`);
|
|
38228
|
+
}
|
|
38229
|
+
if (!stateRoot.isEqualTo(posteriorStateRoot)) {
|
|
38230
|
+
return result_Result.error(BlockVerifierError.InvalidStateRoot, () => `Invalid prior state root: ${stateRoot.toString()}, expected ${posteriorStateRoot.toString()} (ours)`);
|
|
38231
|
+
}
|
|
38230
38232
|
}
|
|
38231
38233
|
return result_Result.ok(headerHash.hash);
|
|
38232
38234
|
}
|
|
38233
|
-
hashHeader(block) {
|
|
38234
|
-
return this.hasher.header(block.header.view());
|
|
38235
|
-
}
|
|
38236
38235
|
}
|
|
38237
38236
|
|
|
38238
38237
|
;// CONCATENATED MODULE: ./packages/jam/transition/disputes/disputes-error-code.ts
|