@typeberry/jam 0.4.1-0a3acb2 → 0.4.1-8408216
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/bootstrap-importer.mjs
CHANGED
|
@@ -11811,7 +11811,7 @@ class BlockVerifier {
|
|
|
11811
11811
|
this.hasher = hasher;
|
|
11812
11812
|
this.blocks = blocks;
|
|
11813
11813
|
}
|
|
11814
|
-
async verifyBlock(block) {
|
|
11814
|
+
async verifyBlock(block, options = { skipParentAndStateRoot: false }) {
|
|
11815
11815
|
const headerView = block.header.view();
|
|
11816
11816
|
const headerHash = this.hasher.header(headerView);
|
|
11817
11817
|
// check if current block is already imported
|
|
@@ -11823,7 +11823,7 @@ class BlockVerifier {
|
|
|
11823
11823
|
// https://graypaper.fluffylabs.dev/#/cc517d7/0c9d000c9d00?v=0.6.5
|
|
11824
11824
|
const parentHash = headerView.parentHeaderHash.materialize();
|
|
11825
11825
|
// importing genesis block
|
|
11826
|
-
if (!parentHash.isEqualTo(block_verifier_ZERO_HASH)) {
|
|
11826
|
+
if (!parentHash.isEqualTo(block_verifier_ZERO_HASH) && !options.skipParentAndStateRoot) {
|
|
11827
11827
|
const parentBlock = this.blocks.getHeader(parentHash);
|
|
11828
11828
|
if (parentBlock === null) {
|
|
11829
11829
|
return Result.error(BlockVerifierError.ParentNotFound, () => `Parent ${parentHash.toString()} not found`);
|
|
@@ -11843,21 +11843,20 @@ class BlockVerifier {
|
|
|
11843
11843
|
if (!extrinsicHash.isEqualTo(extrinsicMerkleCommitment.hash)) {
|
|
11844
11844
|
return Result.error(BlockVerifierError.InvalidExtrinsic, () => `Invalid extrinsic hash: ${extrinsicHash.toString()}, expected ${extrinsicMerkleCommitment.hash.toString()}`);
|
|
11845
11845
|
}
|
|
11846
|
-
|
|
11847
|
-
|
|
11848
|
-
|
|
11849
|
-
|
|
11850
|
-
|
|
11851
|
-
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
|
|
11846
|
+
if (!options.skipParentAndStateRoot) {
|
|
11847
|
+
// Check if the state root is valid.
|
|
11848
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/0c73010c7301?v=0.7.2
|
|
11849
|
+
const stateRoot = headerView.priorStateRoot.materialize();
|
|
11850
|
+
const posteriorStateRoot = this.blocks.getPostStateRoot(parentHash);
|
|
11851
|
+
if (posteriorStateRoot === null) {
|
|
11852
|
+
return Result.error(BlockVerifierError.StateRootNotFound, () => `Posterior state root ${parentHash.toString()} not found`);
|
|
11853
|
+
}
|
|
11854
|
+
if (!stateRoot.isEqualTo(posteriorStateRoot)) {
|
|
11855
|
+
return Result.error(BlockVerifierError.InvalidStateRoot, () => `Invalid prior state root: ${stateRoot.toString()}, expected ${posteriorStateRoot.toString()} (ours)`);
|
|
11856
|
+
}
|
|
11855
11857
|
}
|
|
11856
11858
|
return Result.ok(headerHash.hash);
|
|
11857
11859
|
}
|
|
11858
|
-
hashHeader(block) {
|
|
11859
|
-
return this.hasher.header(block.header.view());
|
|
11860
|
-
}
|
|
11861
11860
|
}
|
|
11862
11861
|
|
|
11863
11862
|
;// CONCATENATED MODULE: ./packages/jam/transition/disputes/disputes-error-code.ts
|