@leofcoin/chain 1.7.124 → 1.7.125

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.
@@ -4887,10 +4887,17 @@ class State extends Contract {
4887
4887
  async #resolveBlock(hash) {
4888
4888
  let index = this.#blockHashMap.get(hash);
4889
4889
  if (this.#blocks[index]) {
4890
- if (this.#blocks[index].previousHash !== '0x0') {
4891
- return this.resolveBlock(this.#blocks[index].previousHash);
4890
+ // Block already exists, check if we need to resolve previous blocks
4891
+ const localHash = await globalThis.stateStore.get('lastBlock');
4892
+ const previousHash = this.#blocks[index].previousHash;
4893
+ if (hash === localHash)
4894
+ return;
4895
+ if (previousHash !== '0x0' && !this.#blocks[this.#blockHashMap.get(previousHash)]) {
4896
+ // Previous block not in memory, recursively resolve it
4897
+ return this.resolveBlock(previousHash);
4892
4898
  }
4893
4899
  else {
4900
+ // Previous block already exists or is genesis, stop resolving
4894
4901
  return;
4895
4902
  }
4896
4903
  }
package/exports/chain.js CHANGED
@@ -1014,10 +1014,17 @@ class State extends Contract {
1014
1014
  async #resolveBlock(hash) {
1015
1015
  let index = this.#blockHashMap.get(hash);
1016
1016
  if (this.#blocks[index]) {
1017
- if (this.#blocks[index].previousHash !== '0x0') {
1018
- return this.resolveBlock(this.#blocks[index].previousHash);
1017
+ // Block already exists, check if we need to resolve previous blocks
1018
+ const localHash = await globalThis.stateStore.get('lastBlock');
1019
+ const previousHash = this.#blocks[index].previousHash;
1020
+ if (hash === localHash)
1021
+ return;
1022
+ if (previousHash !== '0x0' && !this.#blocks[this.#blockHashMap.get(previousHash)]) {
1023
+ // Previous block not in memory, recursively resolve it
1024
+ return this.resolveBlock(previousHash);
1019
1025
  }
1020
1026
  else {
1027
+ // Previous block already exists or is genesis, stop resolving
1021
1028
  return;
1022
1029
  }
1023
1030
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.124",
3
+ "version": "1.7.125",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {