@leofcoin/chain 1.7.144 → 1.7.146
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 +17 -7
- package/exports/chain.js +17 -7
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4876,11 +4876,14 @@ class State extends Contract {
|
|
|
4876
4876
|
let index = this.#blockHashMap.get(hash);
|
|
4877
4877
|
let localHash = '0x0';
|
|
4878
4878
|
try {
|
|
4879
|
-
|
|
4879
|
+
if (await globalThis.stateStore.has('lastBlock'))
|
|
4880
|
+
localHash = await globalThis.stateStore.get('lastBlock');
|
|
4880
4881
|
}
|
|
4881
4882
|
catch (error) {
|
|
4882
4883
|
debug$1('no local state found');
|
|
4883
4884
|
}
|
|
4885
|
+
debug$1(`resolving block: ${hash} @${index !== undefined ? index : 'unknown'}`);
|
|
4886
|
+
debug$1(`local state hash: ${localHash}`);
|
|
4884
4887
|
if (this.#blocks[index]) {
|
|
4885
4888
|
// Block already exists, check if we need to resolve previous blocks
|
|
4886
4889
|
const previousHash = this.#blocks[index].previousHash;
|
|
@@ -4934,10 +4937,15 @@ class State extends Contract {
|
|
|
4934
4937
|
try {
|
|
4935
4938
|
await this.jobber.add(() => this.#resolveBlock(hash));
|
|
4936
4939
|
this.#resolving = false;
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4940
|
+
try {
|
|
4941
|
+
const lastBlockHash = await globalThis.stateStore.get('lastBlock');
|
|
4942
|
+
if (lastBlockHash === hash) {
|
|
4943
|
+
this.#resolveErrored = false;
|
|
4944
|
+
return;
|
|
4945
|
+
}
|
|
4946
|
+
}
|
|
4947
|
+
catch (error) {
|
|
4948
|
+
debug$1('no local state found');
|
|
4941
4949
|
}
|
|
4942
4950
|
if (!this.#blockHashMap.has(this.#lastResolved.previousHash) && this.#lastResolved.previousHash !== '0x0')
|
|
4943
4951
|
return this.resolveBlock(this.#lastResolved.previousHash);
|
|
@@ -5133,7 +5141,9 @@ class State extends Contract {
|
|
|
5133
5141
|
debug$1(`Latest block from peers: ${latest.hash} @${latest.index}`);
|
|
5134
5142
|
if (latest.hash && latest.hash !== '0x0') {
|
|
5135
5143
|
let message = await globalThis.peernet.get(latest.hash, 'block');
|
|
5144
|
+
debug$1({ message });
|
|
5136
5145
|
message = await new BlockMessage(message);
|
|
5146
|
+
debug$1({ message });
|
|
5137
5147
|
const hash = await message.hash();
|
|
5138
5148
|
if (hash !== latest.hash)
|
|
5139
5149
|
throw new Error('invalid block @getLatestBlock');
|
|
@@ -5896,9 +5906,9 @@ class Chain extends VersionControl {
|
|
|
5896
5906
|
if (Object.keys(lastBlock).length > 0) {
|
|
5897
5907
|
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
5898
5908
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
5899
|
-
|
|
5909
|
+
await this.#makeRequest(peer, 'stateInfo');
|
|
5900
5910
|
await this.syncChain(lastBlock);
|
|
5901
|
-
this.machine.states.info = stateInfo
|
|
5911
|
+
// this.machine.states.info = stateInfo
|
|
5902
5912
|
}
|
|
5903
5913
|
}
|
|
5904
5914
|
if (this.wantList.length > 0) {
|
package/exports/chain.js
CHANGED
|
@@ -1016,11 +1016,14 @@ class State extends Contract {
|
|
|
1016
1016
|
let index = this.#blockHashMap.get(hash);
|
|
1017
1017
|
let localHash = '0x0';
|
|
1018
1018
|
try {
|
|
1019
|
-
|
|
1019
|
+
if (await globalThis.stateStore.has('lastBlock'))
|
|
1020
|
+
localHash = await globalThis.stateStore.get('lastBlock');
|
|
1020
1021
|
}
|
|
1021
1022
|
catch (error) {
|
|
1022
1023
|
debug$1('no local state found');
|
|
1023
1024
|
}
|
|
1025
|
+
debug$1(`resolving block: ${hash} @${index !== undefined ? index : 'unknown'}`);
|
|
1026
|
+
debug$1(`local state hash: ${localHash}`);
|
|
1024
1027
|
if (this.#blocks[index]) {
|
|
1025
1028
|
// Block already exists, check if we need to resolve previous blocks
|
|
1026
1029
|
const previousHash = this.#blocks[index].previousHash;
|
|
@@ -1074,10 +1077,15 @@ class State extends Contract {
|
|
|
1074
1077
|
try {
|
|
1075
1078
|
await this.jobber.add(() => this.#resolveBlock(hash));
|
|
1076
1079
|
this.#resolving = false;
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1080
|
+
try {
|
|
1081
|
+
const lastBlockHash = await globalThis.stateStore.get('lastBlock');
|
|
1082
|
+
if (lastBlockHash === hash) {
|
|
1083
|
+
this.#resolveErrored = false;
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
catch (error) {
|
|
1088
|
+
debug$1('no local state found');
|
|
1081
1089
|
}
|
|
1082
1090
|
if (!this.#blockHashMap.has(this.#lastResolved.previousHash) && this.#lastResolved.previousHash !== '0x0')
|
|
1083
1091
|
return this.resolveBlock(this.#lastResolved.previousHash);
|
|
@@ -1273,7 +1281,9 @@ class State extends Contract {
|
|
|
1273
1281
|
debug$1(`Latest block from peers: ${latest.hash} @${latest.index}`);
|
|
1274
1282
|
if (latest.hash && latest.hash !== '0x0') {
|
|
1275
1283
|
let message = await globalThis.peernet.get(latest.hash, 'block');
|
|
1284
|
+
debug$1({ message });
|
|
1276
1285
|
message = await new BlockMessage(message);
|
|
1286
|
+
debug$1({ message });
|
|
1277
1287
|
const hash = await message.hash();
|
|
1278
1288
|
if (hash !== latest.hash)
|
|
1279
1289
|
throw new Error('invalid block @getLatestBlock');
|
|
@@ -2036,9 +2046,9 @@ class Chain extends VersionControl {
|
|
|
2036
2046
|
if (Object.keys(lastBlock).length > 0) {
|
|
2037
2047
|
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
2038
2048
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
2039
|
-
|
|
2049
|
+
await this.#makeRequest(peer, 'stateInfo');
|
|
2040
2050
|
await this.syncChain(lastBlock);
|
|
2041
|
-
this.machine.states.info = stateInfo
|
|
2051
|
+
// this.machine.states.info = stateInfo
|
|
2042
2052
|
}
|
|
2043
2053
|
}
|
|
2044
2054
|
if (this.wantList.length > 0) {
|