@leofcoin/chain 1.7.129 → 1.7.131
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 +15 -3
- package/exports/chain.js +15 -3
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -4886,13 +4886,19 @@ class State extends Contract {
|
|
|
4886
4886
|
}
|
|
4887
4887
|
async #resolveBlock(hash) {
|
|
4888
4888
|
let index = this.#blockHashMap.get(hash);
|
|
4889
|
+
let localHash = '0x0';
|
|
4890
|
+
try {
|
|
4891
|
+
localHash = await globalThis.stateStore.get('lastBlock');
|
|
4892
|
+
}
|
|
4893
|
+
catch (error) {
|
|
4894
|
+
debug$1('no local state found');
|
|
4895
|
+
}
|
|
4889
4896
|
if (this.#blocks[index]) {
|
|
4890
4897
|
// Block already exists, check if we need to resolve previous blocks
|
|
4891
|
-
const localHash = await globalThis.stateStore.get('lastBlock');
|
|
4892
4898
|
const previousHash = this.#blocks[index].previousHash;
|
|
4893
4899
|
if (previousHash === localHash)
|
|
4894
4900
|
return;
|
|
4895
|
-
if (previousHash !== '0x0'
|
|
4901
|
+
if (previousHash !== '0x0') {
|
|
4896
4902
|
// Previous block not in memory, recursively resolve it
|
|
4897
4903
|
return this.resolveBlock(previousHash);
|
|
4898
4904
|
}
|
|
@@ -5478,6 +5484,11 @@ class ConnectionMonitor {
|
|
|
5478
5484
|
const connectedPeers = this.connectedPeers;
|
|
5479
5485
|
const compatiblePeers = this.compatiblePeers;
|
|
5480
5486
|
console.log(`🔍 Health check: ${connectedPeers.length} connected, ${compatiblePeers.length} compatible`);
|
|
5487
|
+
// If a reconnection is already ongoing, skip this cycle to avoid log spam/loops
|
|
5488
|
+
if (this.#reconnecting) {
|
|
5489
|
+
console.log('⏭️ Health check: reconnection already in progress, skipping reconnect attempt');
|
|
5490
|
+
return;
|
|
5491
|
+
}
|
|
5481
5492
|
// If we have no connections or none are compatible, try to reconnect
|
|
5482
5493
|
if (connectedPeers.length === 0) {
|
|
5483
5494
|
console.warn('⚠️ No peer connections detected — attempting reconnection');
|
|
@@ -5537,11 +5548,12 @@ class ConnectionMonitor {
|
|
|
5537
5548
|
console.log('🔁 Reconnection already in progress, skipping');
|
|
5538
5549
|
return;
|
|
5539
5550
|
}
|
|
5551
|
+
this.#reconnecting = true;
|
|
5540
5552
|
if (this.connectedPeers.length > 0) {
|
|
5541
5553
|
console.log('✅ Already connected to peers, skipping restoration');
|
|
5554
|
+
this.#reconnecting = false;
|
|
5542
5555
|
return;
|
|
5543
5556
|
}
|
|
5544
|
-
this.#reconnecting = true;
|
|
5545
5557
|
console.log('🔁 Restoring network');
|
|
5546
5558
|
try {
|
|
5547
5559
|
const online = await this.#isOnLine(1500);
|
package/exports/chain.js
CHANGED
|
@@ -1013,13 +1013,19 @@ class State extends Contract {
|
|
|
1013
1013
|
}
|
|
1014
1014
|
async #resolveBlock(hash) {
|
|
1015
1015
|
let index = this.#blockHashMap.get(hash);
|
|
1016
|
+
let localHash = '0x0';
|
|
1017
|
+
try {
|
|
1018
|
+
localHash = await globalThis.stateStore.get('lastBlock');
|
|
1019
|
+
}
|
|
1020
|
+
catch (error) {
|
|
1021
|
+
debug$1('no local state found');
|
|
1022
|
+
}
|
|
1016
1023
|
if (this.#blocks[index]) {
|
|
1017
1024
|
// Block already exists, check if we need to resolve previous blocks
|
|
1018
|
-
const localHash = await globalThis.stateStore.get('lastBlock');
|
|
1019
1025
|
const previousHash = this.#blocks[index].previousHash;
|
|
1020
1026
|
if (previousHash === localHash)
|
|
1021
1027
|
return;
|
|
1022
|
-
if (previousHash !== '0x0'
|
|
1028
|
+
if (previousHash !== '0x0') {
|
|
1023
1029
|
// Previous block not in memory, recursively resolve it
|
|
1024
1030
|
return this.resolveBlock(previousHash);
|
|
1025
1031
|
}
|
|
@@ -1605,6 +1611,11 @@ class ConnectionMonitor {
|
|
|
1605
1611
|
const connectedPeers = this.connectedPeers;
|
|
1606
1612
|
const compatiblePeers = this.compatiblePeers;
|
|
1607
1613
|
console.log(`🔍 Health check: ${connectedPeers.length} connected, ${compatiblePeers.length} compatible`);
|
|
1614
|
+
// If a reconnection is already ongoing, skip this cycle to avoid log spam/loops
|
|
1615
|
+
if (this.#reconnecting) {
|
|
1616
|
+
console.log('⏭️ Health check: reconnection already in progress, skipping reconnect attempt');
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1608
1619
|
// If we have no connections or none are compatible, try to reconnect
|
|
1609
1620
|
if (connectedPeers.length === 0) {
|
|
1610
1621
|
console.warn('⚠️ No peer connections detected — attempting reconnection');
|
|
@@ -1664,11 +1675,12 @@ class ConnectionMonitor {
|
|
|
1664
1675
|
console.log('🔁 Reconnection already in progress, skipping');
|
|
1665
1676
|
return;
|
|
1666
1677
|
}
|
|
1678
|
+
this.#reconnecting = true;
|
|
1667
1679
|
if (this.connectedPeers.length > 0) {
|
|
1668
1680
|
console.log('✅ Already connected to peers, skipping restoration');
|
|
1681
|
+
this.#reconnecting = false;
|
|
1669
1682
|
return;
|
|
1670
1683
|
}
|
|
1671
|
-
this.#reconnecting = true;
|
|
1672
1684
|
console.log('🔁 Restoring network');
|
|
1673
1685
|
try {
|
|
1674
1686
|
const online = await this.#isOnLine(1500);
|