@leofcoin/chain 1.7.119 → 1.7.121
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 +12 -12
- package/exports/chain.js +12 -12
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4801,7 +4801,6 @@ class State extends Contract {
|
|
|
4801
4801
|
let localBlock;
|
|
4802
4802
|
try {
|
|
4803
4803
|
const rawBlock = await globalThis.chainStore.has('lastBlock');
|
|
4804
|
-
console.log({ rawBlock });
|
|
4805
4804
|
if (rawBlock) {
|
|
4806
4805
|
localBlockHash = new TextDecoder().decode(await globalThis.chainStore.get('lastBlock'));
|
|
4807
4806
|
blockMessage = await globalThis.peernet.get(localBlockHash, 'block');
|
|
@@ -5007,7 +5006,6 @@ class State extends Contract {
|
|
|
5007
5006
|
}
|
|
5008
5007
|
if (!lastBlock)
|
|
5009
5008
|
lastBlock = await this.#getLatestBlock();
|
|
5010
|
-
console.log('starting sync');
|
|
5011
5009
|
if (globalThis.peernet.peers.length === 0)
|
|
5012
5010
|
return 'connectionless';
|
|
5013
5011
|
try {
|
|
@@ -5033,15 +5031,17 @@ class State extends Contract {
|
|
|
5033
5031
|
}
|
|
5034
5032
|
async #syncChain(lastBlock) {
|
|
5035
5033
|
try {
|
|
5036
|
-
if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
}
|
|
5034
|
+
// if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
5035
|
+
// let promises = []
|
|
5036
|
+
// promises = await Promise.allSettled(
|
|
5037
|
+
// this.knownBlocks.map(async (address) => {
|
|
5038
|
+
// const has = await globalThis.peernet.has(address)
|
|
5039
|
+
// return { has, address }
|
|
5040
|
+
// })
|
|
5041
|
+
// )
|
|
5042
|
+
// promises = promises.filter(({ status, value }) => status === 'fulfilled' && !value.has)
|
|
5043
|
+
// await Promise.allSettled(promises.map(({ value }) => this.getAndPutBlock(value.address)))
|
|
5044
|
+
// }
|
|
5045
5045
|
const localBlock = await this.lastBlock;
|
|
5046
5046
|
if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
|
|
5047
5047
|
// TODO: check if valid
|
|
@@ -5052,7 +5052,7 @@ class State extends Contract {
|
|
|
5052
5052
|
let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index + 1 : index + -localIndex + 1) : index + 1;
|
|
5053
5053
|
debug$1(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
|
|
5054
5054
|
const blocks = this.#blocks;
|
|
5055
|
-
const start =
|
|
5055
|
+
const start = localIndex - blocksSynced;
|
|
5056
5056
|
if (this.#machine) {
|
|
5057
5057
|
await this.#loadBlocks(blocks.slice(start));
|
|
5058
5058
|
}
|
package/exports/chain.js
CHANGED
|
@@ -928,7 +928,6 @@ class State extends Contract {
|
|
|
928
928
|
let localBlock;
|
|
929
929
|
try {
|
|
930
930
|
const rawBlock = await globalThis.chainStore.has('lastBlock');
|
|
931
|
-
console.log({ rawBlock });
|
|
932
931
|
if (rawBlock) {
|
|
933
932
|
localBlockHash = new TextDecoder().decode(await globalThis.chainStore.get('lastBlock'));
|
|
934
933
|
blockMessage = await globalThis.peernet.get(localBlockHash, 'block');
|
|
@@ -1134,7 +1133,6 @@ class State extends Contract {
|
|
|
1134
1133
|
}
|
|
1135
1134
|
if (!lastBlock)
|
|
1136
1135
|
lastBlock = await this.#getLatestBlock();
|
|
1137
|
-
console.log('starting sync');
|
|
1138
1136
|
if (globalThis.peernet.peers.length === 0)
|
|
1139
1137
|
return 'connectionless';
|
|
1140
1138
|
try {
|
|
@@ -1160,15 +1158,17 @@ class State extends Contract {
|
|
|
1160
1158
|
}
|
|
1161
1159
|
async #syncChain(lastBlock) {
|
|
1162
1160
|
try {
|
|
1163
|
-
if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
}
|
|
1161
|
+
// if (this.knownBlocks?.length === Number(lastBlock.index) + 1) {
|
|
1162
|
+
// let promises = []
|
|
1163
|
+
// promises = await Promise.allSettled(
|
|
1164
|
+
// this.knownBlocks.map(async (address) => {
|
|
1165
|
+
// const has = await globalThis.peernet.has(address)
|
|
1166
|
+
// return { has, address }
|
|
1167
|
+
// })
|
|
1168
|
+
// )
|
|
1169
|
+
// promises = promises.filter(({ status, value }) => status === 'fulfilled' && !value.has)
|
|
1170
|
+
// await Promise.allSettled(promises.map(({ value }) => this.getAndPutBlock(value.address)))
|
|
1171
|
+
// }
|
|
1172
1172
|
const localBlock = await this.lastBlock;
|
|
1173
1173
|
if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
|
|
1174
1174
|
// TODO: check if valid
|
|
@@ -1179,7 +1179,7 @@ class State extends Contract {
|
|
|
1179
1179
|
let blocksSynced = localIndex > 0 ? (localIndex > index ? localIndex - index + 1 : index + -localIndex + 1) : index + 1;
|
|
1180
1180
|
debug$1(`synced ${blocksSynced} ${blocksSynced > 1 ? 'blocks' : 'block'}`);
|
|
1181
1181
|
const blocks = this.#blocks;
|
|
1182
|
-
const start =
|
|
1182
|
+
const start = localIndex - blocksSynced;
|
|
1183
1183
|
if (this.#machine) {
|
|
1184
1184
|
await this.#loadBlocks(blocks.slice(start));
|
|
1185
1185
|
}
|