@leofcoin/chain 1.7.145 → 1.7.147
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 +21 -9
- package/exports/chain.js +21 -9
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4876,11 +4876,15 @@ 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) {
|
|
4883
|
+
globalThis.stateStore.put('lastBlock', new TextEncoder().encode('0x0'));
|
|
4882
4884
|
debug$1('no local state found');
|
|
4883
4885
|
}
|
|
4886
|
+
debug$1(`resolving block: ${hash} @${index !== undefined ? index : 'unknown'}`);
|
|
4887
|
+
debug$1(`local state hash: ${localHash}`);
|
|
4884
4888
|
if (this.#blocks[index]) {
|
|
4885
4889
|
// Block already exists, check if we need to resolve previous blocks
|
|
4886
4890
|
const previousHash = this.#blocks[index].previousHash;
|
|
@@ -4934,10 +4938,15 @@ class State extends Contract {
|
|
|
4934
4938
|
try {
|
|
4935
4939
|
await this.jobber.add(() => this.#resolveBlock(hash));
|
|
4936
4940
|
this.#resolving = false;
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
+
try {
|
|
4942
|
+
const lastBlockHash = await globalThis.stateStore.get('lastBlock');
|
|
4943
|
+
if (lastBlockHash === hash) {
|
|
4944
|
+
this.#resolveErrored = false;
|
|
4945
|
+
return;
|
|
4946
|
+
}
|
|
4947
|
+
}
|
|
4948
|
+
catch (error) {
|
|
4949
|
+
debug$1('no local state found');
|
|
4941
4950
|
}
|
|
4942
4951
|
if (!this.#blockHashMap.has(this.#lastResolved.previousHash) && this.#lastResolved.previousHash !== '0x0')
|
|
4943
4952
|
return this.resolveBlock(this.#lastResolved.previousHash);
|
|
@@ -5133,7 +5142,9 @@ class State extends Contract {
|
|
|
5133
5142
|
debug$1(`Latest block from peers: ${latest.hash} @${latest.index}`);
|
|
5134
5143
|
if (latest.hash && latest.hash !== '0x0') {
|
|
5135
5144
|
let message = await globalThis.peernet.get(latest.hash, 'block');
|
|
5145
|
+
debug$1({ message });
|
|
5136
5146
|
message = await new BlockMessage(message);
|
|
5147
|
+
debug$1({ message });
|
|
5137
5148
|
const hash = await message.hash();
|
|
5138
5149
|
if (hash !== latest.hash)
|
|
5139
5150
|
throw new Error('invalid block @getLatestBlock');
|
|
@@ -5893,12 +5904,10 @@ class Chain extends VersionControl {
|
|
|
5893
5904
|
if (lastBlock.hash === '0x0')
|
|
5894
5905
|
return;
|
|
5895
5906
|
const higherThenCurrentLocal = !localBlock?.index ? true : lastBlock.index > localBlock.index;
|
|
5896
|
-
if (
|
|
5907
|
+
if (lastBlock) {
|
|
5897
5908
|
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
5898
5909
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
5899
|
-
|
|
5900
|
-
await this.syncChain(lastBlock);
|
|
5901
|
-
// this.machine.states.info = stateInfo
|
|
5910
|
+
this.wantList.push(...this.knownBlocks);
|
|
5902
5911
|
}
|
|
5903
5912
|
}
|
|
5904
5913
|
if (this.wantList.length > 0) {
|
|
@@ -5917,6 +5926,9 @@ class Chain extends VersionControl {
|
|
|
5917
5926
|
if (this.#participating && peerTransactionPool.length > 0)
|
|
5918
5927
|
return this.#runEpoch();
|
|
5919
5928
|
}, 3000);
|
|
5929
|
+
const stateInfo = await this.#makeRequest(peer, 'stateInfo');
|
|
5930
|
+
await this.syncChain(lastBlock);
|
|
5931
|
+
this.machine.states.info = stateInfo;
|
|
5920
5932
|
}
|
|
5921
5933
|
#epochTimeout;
|
|
5922
5934
|
async #transactionPoolHandler() {
|
package/exports/chain.js
CHANGED
|
@@ -1016,11 +1016,15 @@ 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) {
|
|
1023
|
+
globalThis.stateStore.put('lastBlock', new TextEncoder().encode('0x0'));
|
|
1022
1024
|
debug$1('no local state found');
|
|
1023
1025
|
}
|
|
1026
|
+
debug$1(`resolving block: ${hash} @${index !== undefined ? index : 'unknown'}`);
|
|
1027
|
+
debug$1(`local state hash: ${localHash}`);
|
|
1024
1028
|
if (this.#blocks[index]) {
|
|
1025
1029
|
// Block already exists, check if we need to resolve previous blocks
|
|
1026
1030
|
const previousHash = this.#blocks[index].previousHash;
|
|
@@ -1074,10 +1078,15 @@ class State extends Contract {
|
|
|
1074
1078
|
try {
|
|
1075
1079
|
await this.jobber.add(() => this.#resolveBlock(hash));
|
|
1076
1080
|
this.#resolving = false;
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
+
try {
|
|
1082
|
+
const lastBlockHash = await globalThis.stateStore.get('lastBlock');
|
|
1083
|
+
if (lastBlockHash === hash) {
|
|
1084
|
+
this.#resolveErrored = false;
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
catch (error) {
|
|
1089
|
+
debug$1('no local state found');
|
|
1081
1090
|
}
|
|
1082
1091
|
if (!this.#blockHashMap.has(this.#lastResolved.previousHash) && this.#lastResolved.previousHash !== '0x0')
|
|
1083
1092
|
return this.resolveBlock(this.#lastResolved.previousHash);
|
|
@@ -1273,7 +1282,9 @@ class State extends Contract {
|
|
|
1273
1282
|
debug$1(`Latest block from peers: ${latest.hash} @${latest.index}`);
|
|
1274
1283
|
if (latest.hash && latest.hash !== '0x0') {
|
|
1275
1284
|
let message = await globalThis.peernet.get(latest.hash, 'block');
|
|
1285
|
+
debug$1({ message });
|
|
1276
1286
|
message = await new BlockMessage(message);
|
|
1287
|
+
debug$1({ message });
|
|
1277
1288
|
const hash = await message.hash();
|
|
1278
1289
|
if (hash !== latest.hash)
|
|
1279
1290
|
throw new Error('invalid block @getLatestBlock');
|
|
@@ -2033,12 +2044,10 @@ class Chain extends VersionControl {
|
|
|
2033
2044
|
if (lastBlock.hash === '0x0')
|
|
2034
2045
|
return;
|
|
2035
2046
|
const higherThenCurrentLocal = !localBlock?.index ? true : lastBlock.index > localBlock.index;
|
|
2036
|
-
if (
|
|
2047
|
+
if (lastBlock) {
|
|
2037
2048
|
if (!this.lastBlock || higherThenCurrentLocal) {
|
|
2038
2049
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
2039
|
-
|
|
2040
|
-
await this.syncChain(lastBlock);
|
|
2041
|
-
// this.machine.states.info = stateInfo
|
|
2050
|
+
this.wantList.push(...this.knownBlocks);
|
|
2042
2051
|
}
|
|
2043
2052
|
}
|
|
2044
2053
|
if (this.wantList.length > 0) {
|
|
@@ -2057,6 +2066,9 @@ class Chain extends VersionControl {
|
|
|
2057
2066
|
if (this.#participating && peerTransactionPool.length > 0)
|
|
2058
2067
|
return this.#runEpoch();
|
|
2059
2068
|
}, 3000);
|
|
2069
|
+
const stateInfo = await this.#makeRequest(peer, 'stateInfo');
|
|
2070
|
+
await this.syncChain(lastBlock);
|
|
2071
|
+
this.machine.states.info = stateInfo;
|
|
2060
2072
|
}
|
|
2061
2073
|
#epochTimeout;
|
|
2062
2074
|
async #transactionPoolHandler() {
|