@leofcoin/chain 1.7.125 → 1.7.127
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/exports/browser/chain.js +11 -5
- package/exports/chain.js +11 -5
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4876,11 +4876,17 @@ class State extends Contract {
|
|
|
4876
4876
|
let block = await globalThis.peernet.get(hash, 'block');
|
|
4877
4877
|
if (block !== undefined) {
|
|
4878
4878
|
block = await new BlockMessage(block);
|
|
4879
|
+
const computedHash = await block.hash();
|
|
4880
|
+
if (computedHash !== hash) {
|
|
4881
|
+
throw new ResolveError(`block hash mismatch for ${hash}`, {
|
|
4882
|
+
cause: new Error('hash does not match payload')
|
|
4883
|
+
});
|
|
4884
|
+
}
|
|
4879
4885
|
const { index } = block.decoded;
|
|
4880
|
-
if (this.#blocks[index] && this.#blocks[index].hash !==
|
|
4881
|
-
throw `invalid block ${
|
|
4882
|
-
if (!(await globalThis.peernet.has(
|
|
4883
|
-
await globalThis.peernet.put(
|
|
4886
|
+
if (this.#blocks[index] && this.#blocks[index].hash !== computedHash)
|
|
4887
|
+
throw new ResolveError(`invalid block ${computedHash} @${index}`);
|
|
4888
|
+
if (!(await globalThis.peernet.has(computedHash)))
|
|
4889
|
+
await globalThis.peernet.put(computedHash, block.encoded, 'block');
|
|
4884
4890
|
}
|
|
4885
4891
|
return block;
|
|
4886
4892
|
}
|
|
@@ -4890,7 +4896,7 @@ class State extends Contract {
|
|
|
4890
4896
|
// Block already exists, check if we need to resolve previous blocks
|
|
4891
4897
|
const localHash = await globalThis.stateStore.get('lastBlock');
|
|
4892
4898
|
const previousHash = this.#blocks[index].previousHash;
|
|
4893
|
-
if (
|
|
4899
|
+
if (previousHash === localHash)
|
|
4894
4900
|
return;
|
|
4895
4901
|
if (previousHash !== '0x0' && !this.#blocks[this.#blockHashMap.get(previousHash)]) {
|
|
4896
4902
|
// Previous block not in memory, recursively resolve it
|
package/exports/chain.js
CHANGED
|
@@ -1003,11 +1003,17 @@ class State extends Contract {
|
|
|
1003
1003
|
let block = await globalThis.peernet.get(hash, 'block');
|
|
1004
1004
|
if (block !== undefined) {
|
|
1005
1005
|
block = await new BlockMessage(block);
|
|
1006
|
+
const computedHash = await block.hash();
|
|
1007
|
+
if (computedHash !== hash) {
|
|
1008
|
+
throw new ResolveError(`block hash mismatch for ${hash}`, {
|
|
1009
|
+
cause: new Error('hash does not match payload')
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1006
1012
|
const { index } = block.decoded;
|
|
1007
|
-
if (this.#blocks[index] && this.#blocks[index].hash !==
|
|
1008
|
-
throw `invalid block ${
|
|
1009
|
-
if (!(await globalThis.peernet.has(
|
|
1010
|
-
await globalThis.peernet.put(
|
|
1013
|
+
if (this.#blocks[index] && this.#blocks[index].hash !== computedHash)
|
|
1014
|
+
throw new ResolveError(`invalid block ${computedHash} @${index}`);
|
|
1015
|
+
if (!(await globalThis.peernet.has(computedHash)))
|
|
1016
|
+
await globalThis.peernet.put(computedHash, block.encoded, 'block');
|
|
1011
1017
|
}
|
|
1012
1018
|
return block;
|
|
1013
1019
|
}
|
|
@@ -1017,7 +1023,7 @@ class State extends Contract {
|
|
|
1017
1023
|
// Block already exists, check if we need to resolve previous blocks
|
|
1018
1024
|
const localHash = await globalThis.stateStore.get('lastBlock');
|
|
1019
1025
|
const previousHash = this.#blocks[index].previousHash;
|
|
1020
|
-
if (
|
|
1026
|
+
if (previousHash === localHash)
|
|
1021
1027
|
return;
|
|
1022
1028
|
if (previousHash !== '0x0' && !this.#blocks[this.#blockHashMap.get(previousHash)]) {
|
|
1023
1029
|
// Previous block not in memory, recursively resolve it
|