@leofcoin/chain 1.7.123 → 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
  }
@@ -4933,6 +4940,11 @@ class State extends Contract {
4933
4940
  try {
4934
4941
  await this.jobber.add(() => this.#resolveBlock(hash));
4935
4942
  this.#resolving = false;
4943
+ const lastBlockHash = await globalThis.stateStore.get('lastBlock');
4944
+ if (lastBlockHash === hash) {
4945
+ this.#resolveErrored = false;
4946
+ return;
4947
+ }
4936
4948
  if (!this.#blockHashMap.has(this.#lastResolved.previousHash) && this.#lastResolved.previousHash !== '0x0')
4937
4949
  return this.resolveBlock(this.#lastResolved.previousHash);
4938
4950
  }
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
  }
@@ -1060,6 +1067,11 @@ class State extends Contract {
1060
1067
  try {
1061
1068
  await this.jobber.add(() => this.#resolveBlock(hash));
1062
1069
  this.#resolving = false;
1070
+ const lastBlockHash = await globalThis.stateStore.get('lastBlock');
1071
+ if (lastBlockHash === hash) {
1072
+ this.#resolveErrored = false;
1073
+ return;
1074
+ }
1063
1075
  if (!this.#blockHashMap.has(this.#lastResolved.previousHash) && this.#lastResolved.previousHash !== '0x0')
1064
1076
  return this.resolveBlock(this.#lastResolved.previousHash);
1065
1077
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.123",
3
+ "version": "1.7.125",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {