@leofcoin/chain 1.7.77 → 1.7.79
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 +46 -3
- package/exports/browser/{client-Db0RyH-f-ZTHffSH0.js → client-MAPwcc7G-CjrC1JNQ.js} +1 -1
- package/exports/browser/{messages-CT983-_h-B6UgHloi.js → messages-BkkXT6WO-Cd5WEDxx.js} +1 -1
- package/exports/browser/{node-browser-g4r5zC--.js → node-browser-Ctauqi8V.js} +8 -3
- package/exports/browser/node-browser.js +1 -1
- package/exports/chain.js +46 -3
- package/exports/connection-monitor.d.ts +4 -3
- package/package.json +2 -2
package/exports/browser/chain.js
CHANGED
|
@@ -5019,7 +5019,7 @@ class State extends Contract {
|
|
|
5019
5019
|
const localBlock = await this.lastBlock;
|
|
5020
5020
|
if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
|
|
5021
5021
|
// TODO: check if valid
|
|
5022
|
-
const localIndex = localBlock ? localBlock.index : 0;
|
|
5022
|
+
const localIndex = localBlock ? Number(localBlock.index) : 0;
|
|
5023
5023
|
const index = lastBlock.index;
|
|
5024
5024
|
await this.resolveBlock(lastBlock.hash);
|
|
5025
5025
|
console.log('ok');
|
|
@@ -5300,6 +5300,7 @@ class ConnectionMonitor {
|
|
|
5300
5300
|
#isMonitoring = false;
|
|
5301
5301
|
#checkInterval = null;
|
|
5302
5302
|
#reconnectAttempts = 0;
|
|
5303
|
+
#peerReconnectAttempts = {};
|
|
5303
5304
|
#maxReconnectAttempts = 10;
|
|
5304
5305
|
#reconnectDelay = 5000;
|
|
5305
5306
|
#healthCheckInterval = 10000;
|
|
@@ -5313,11 +5314,12 @@ class ConnectionMonitor {
|
|
|
5313
5314
|
get compatiblePeers() {
|
|
5314
5315
|
return this.connectedPeers.filter((peer) => peer.version === this.#version);
|
|
5315
5316
|
}
|
|
5316
|
-
|
|
5317
|
-
|
|
5317
|
+
get disconnectedPeers() {
|
|
5318
|
+
return Object.values(globalThis.peernet?.connections || {}).filter((peer) => !peer.connected);
|
|
5318
5319
|
}
|
|
5319
5320
|
start(version) {
|
|
5320
5321
|
this.#version = version;
|
|
5322
|
+
console.log(`🔗 Connection Monitor initialized for version: ${this.#version}`);
|
|
5321
5323
|
if (this.#isMonitoring)
|
|
5322
5324
|
return;
|
|
5323
5325
|
this.#isMonitoring = true;
|
|
@@ -5348,12 +5350,24 @@ class ConnectionMonitor {
|
|
|
5348
5350
|
}
|
|
5349
5351
|
else if (compatiblePeers.length === 0) {
|
|
5350
5352
|
console.warn('⚠️ No compatible peers found');
|
|
5353
|
+
await this.#attemptReconnection();
|
|
5351
5354
|
// Could attempt to find compatible peers or trigger version negotiation
|
|
5352
5355
|
}
|
|
5353
5356
|
else {
|
|
5354
5357
|
// Reset reconnect attempts on successful connection
|
|
5355
5358
|
this.#reconnectAttempts = 0;
|
|
5356
5359
|
}
|
|
5360
|
+
// Log disconnected peers
|
|
5361
|
+
const disconnectedPeers = this.disconnectedPeers;
|
|
5362
|
+
if (disconnectedPeers.length > 0) {
|
|
5363
|
+
console.warn(`⚠️ Disconnected peers: ${disconnectedPeers.map((peer) => peer.peerId).join(', ')}`);
|
|
5364
|
+
// Attempt to reconnect each disconnected peer
|
|
5365
|
+
const promises = [];
|
|
5366
|
+
for (const peer of disconnectedPeers) {
|
|
5367
|
+
promises.push(this.#attemptPeerReconnection(peer));
|
|
5368
|
+
}
|
|
5369
|
+
await Promise.all(promises);
|
|
5370
|
+
}
|
|
5357
5371
|
// Publish connection status
|
|
5358
5372
|
globalThis.pubsub?.publish('connection-status', {
|
|
5359
5373
|
connected: connectedPeers.length,
|
|
@@ -5361,6 +5375,35 @@ class ConnectionMonitor {
|
|
|
5361
5375
|
healthy: compatiblePeers.length > 0
|
|
5362
5376
|
});
|
|
5363
5377
|
}
|
|
5378
|
+
async #attemptPeerReconnection(peer) {
|
|
5379
|
+
if (this.#peerReconnectAttempts[peer.peerId] >= this.#maxReconnectAttempts) {
|
|
5380
|
+
console.error('❌ Max reconnection attempts reached');
|
|
5381
|
+
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
5382
|
+
return;
|
|
5383
|
+
}
|
|
5384
|
+
if (!this.#peerReconnectAttempts[peer.peerId]) {
|
|
5385
|
+
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
5386
|
+
}
|
|
5387
|
+
this.#peerReconnectAttempts[peer.peerId]++;
|
|
5388
|
+
console.log(`🔄 Attempting reconnection ${this.#peerReconnectAttempts[peer.peerId]}/${this.#maxReconnectAttempts}`);
|
|
5389
|
+
try {
|
|
5390
|
+
const peerId = peer.peerId || peer.id;
|
|
5391
|
+
// Attempt to reconnect the specific peer
|
|
5392
|
+
await peernet.client.reconnect(peerId, globalThis.peernet?.stars[0]);
|
|
5393
|
+
}
|
|
5394
|
+
catch (error) {
|
|
5395
|
+
console.error('❌ Reconnection failed:', error.message);
|
|
5396
|
+
}
|
|
5397
|
+
// // Try to restart the network
|
|
5398
|
+
// if (globalThis.peernet?.start) {
|
|
5399
|
+
// await globalThis.peernet.start()
|
|
5400
|
+
// } else {
|
|
5401
|
+
// console.warn('⚠️ Peernet start method not available, skipping reconnection')
|
|
5402
|
+
// }
|
|
5403
|
+
// } catch (error) {
|
|
5404
|
+
// console.error('❌ Reconnection failed:', error.message)
|
|
5405
|
+
// }
|
|
5406
|
+
}
|
|
5364
5407
|
async #attemptReconnection() {
|
|
5365
5408
|
if (this.#reconnectAttempts >= this.#maxReconnectAttempts) {
|
|
5366
5409
|
console.error('❌ Max reconnection attempts reached');
|
|
@@ -8495,7 +8495,7 @@ class Peernet {
|
|
|
8495
8495
|
this.root = options.root;
|
|
8496
8496
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
8497
8497
|
// FolderMessageResponse
|
|
8498
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
8498
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-BkkXT6WO-Cd5WEDxx.js');
|
|
8499
8499
|
/**
|
|
8500
8500
|
* proto Object containing protos
|
|
8501
8501
|
* @type {Object}
|
|
@@ -8589,7 +8589,7 @@ class Peernet {
|
|
|
8589
8589
|
if (this.#starting || this.#started)
|
|
8590
8590
|
return;
|
|
8591
8591
|
this.#starting = true;
|
|
8592
|
-
const importee = await import('./client-
|
|
8592
|
+
const importee = await import('./client-MAPwcc7G-CjrC1JNQ.js');
|
|
8593
8593
|
/**
|
|
8594
8594
|
* @access public
|
|
8595
8595
|
* @type {PeernetClient}
|
|
@@ -8630,6 +8630,11 @@ class Peernet {
|
|
|
8630
8630
|
};
|
|
8631
8631
|
peer.once('error', onError);
|
|
8632
8632
|
peer.once('connect', async () => {
|
|
8633
|
+
if (!peer.connected) {
|
|
8634
|
+
peer.removeListener('error', onError);
|
|
8635
|
+
debug('Peer not connected');
|
|
8636
|
+
return;
|
|
8637
|
+
}
|
|
8633
8638
|
await peer.send(data, id);
|
|
8634
8639
|
this.bw.up += data.length;
|
|
8635
8640
|
peer.removeListener('error', onError);
|
|
@@ -8739,7 +8744,7 @@ class Peernet {
|
|
|
8739
8744
|
};
|
|
8740
8745
|
let walks = [];
|
|
8741
8746
|
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
8742
|
-
if (peerId !== this.id) {
|
|
8747
|
+
if (peerId !== this.id && peer.connected) {
|
|
8743
8748
|
walks.push(walk(peer, peerId));
|
|
8744
8749
|
}
|
|
8745
8750
|
}
|
package/exports/chain.js
CHANGED
|
@@ -1165,7 +1165,7 @@ class State extends Contract {
|
|
|
1165
1165
|
const localBlock = await this.lastBlock;
|
|
1166
1166
|
if (!localBlock || Number(localBlock.index) < Number(lastBlock.index)) {
|
|
1167
1167
|
// TODO: check if valid
|
|
1168
|
-
const localIndex = localBlock ? localBlock.index : 0;
|
|
1168
|
+
const localIndex = localBlock ? Number(localBlock.index) : 0;
|
|
1169
1169
|
const index = lastBlock.index;
|
|
1170
1170
|
await this.resolveBlock(lastBlock.hash);
|
|
1171
1171
|
console.log('ok');
|
|
@@ -1446,6 +1446,7 @@ class ConnectionMonitor {
|
|
|
1446
1446
|
#isMonitoring = false;
|
|
1447
1447
|
#checkInterval = null;
|
|
1448
1448
|
#reconnectAttempts = 0;
|
|
1449
|
+
#peerReconnectAttempts = {};
|
|
1449
1450
|
#maxReconnectAttempts = 10;
|
|
1450
1451
|
#reconnectDelay = 5000;
|
|
1451
1452
|
#healthCheckInterval = 10000;
|
|
@@ -1459,11 +1460,12 @@ class ConnectionMonitor {
|
|
|
1459
1460
|
get compatiblePeers() {
|
|
1460
1461
|
return this.connectedPeers.filter((peer) => peer.version === this.#version);
|
|
1461
1462
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1463
|
+
get disconnectedPeers() {
|
|
1464
|
+
return Object.values(globalThis.peernet?.connections || {}).filter((peer) => !peer.connected);
|
|
1464
1465
|
}
|
|
1465
1466
|
start(version) {
|
|
1466
1467
|
this.#version = version;
|
|
1468
|
+
console.log(`🔗 Connection Monitor initialized for version: ${this.#version}`);
|
|
1467
1469
|
if (this.#isMonitoring)
|
|
1468
1470
|
return;
|
|
1469
1471
|
this.#isMonitoring = true;
|
|
@@ -1494,12 +1496,24 @@ class ConnectionMonitor {
|
|
|
1494
1496
|
}
|
|
1495
1497
|
else if (compatiblePeers.length === 0) {
|
|
1496
1498
|
console.warn('⚠️ No compatible peers found');
|
|
1499
|
+
await this.#attemptReconnection();
|
|
1497
1500
|
// Could attempt to find compatible peers or trigger version negotiation
|
|
1498
1501
|
}
|
|
1499
1502
|
else {
|
|
1500
1503
|
// Reset reconnect attempts on successful connection
|
|
1501
1504
|
this.#reconnectAttempts = 0;
|
|
1502
1505
|
}
|
|
1506
|
+
// Log disconnected peers
|
|
1507
|
+
const disconnectedPeers = this.disconnectedPeers;
|
|
1508
|
+
if (disconnectedPeers.length > 0) {
|
|
1509
|
+
console.warn(`⚠️ Disconnected peers: ${disconnectedPeers.map((peer) => peer.peerId).join(', ')}`);
|
|
1510
|
+
// Attempt to reconnect each disconnected peer
|
|
1511
|
+
const promises = [];
|
|
1512
|
+
for (const peer of disconnectedPeers) {
|
|
1513
|
+
promises.push(this.#attemptPeerReconnection(peer));
|
|
1514
|
+
}
|
|
1515
|
+
await Promise.all(promises);
|
|
1516
|
+
}
|
|
1503
1517
|
// Publish connection status
|
|
1504
1518
|
globalThis.pubsub?.publish('connection-status', {
|
|
1505
1519
|
connected: connectedPeers.length,
|
|
@@ -1507,6 +1521,35 @@ class ConnectionMonitor {
|
|
|
1507
1521
|
healthy: compatiblePeers.length > 0
|
|
1508
1522
|
});
|
|
1509
1523
|
}
|
|
1524
|
+
async #attemptPeerReconnection(peer) {
|
|
1525
|
+
if (this.#peerReconnectAttempts[peer.peerId] >= this.#maxReconnectAttempts) {
|
|
1526
|
+
console.error('❌ Max reconnection attempts reached');
|
|
1527
|
+
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
if (!this.#peerReconnectAttempts[peer.peerId]) {
|
|
1531
|
+
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
1532
|
+
}
|
|
1533
|
+
this.#peerReconnectAttempts[peer.peerId]++;
|
|
1534
|
+
console.log(`🔄 Attempting reconnection ${this.#peerReconnectAttempts[peer.peerId]}/${this.#maxReconnectAttempts}`);
|
|
1535
|
+
try {
|
|
1536
|
+
const peerId = peer.peerId || peer.id;
|
|
1537
|
+
// Attempt to reconnect the specific peer
|
|
1538
|
+
await peernet.client.reconnect(peerId, globalThis.peernet?.stars[0]);
|
|
1539
|
+
}
|
|
1540
|
+
catch (error) {
|
|
1541
|
+
console.error('❌ Reconnection failed:', error.message);
|
|
1542
|
+
}
|
|
1543
|
+
// // Try to restart the network
|
|
1544
|
+
// if (globalThis.peernet?.start) {
|
|
1545
|
+
// await globalThis.peernet.start()
|
|
1546
|
+
// } else {
|
|
1547
|
+
// console.warn('⚠️ Peernet start method not available, skipping reconnection')
|
|
1548
|
+
// }
|
|
1549
|
+
// } catch (error) {
|
|
1550
|
+
// console.error('❌ Reconnection failed:', error.message)
|
|
1551
|
+
// }
|
|
1552
|
+
}
|
|
1510
1553
|
async #attemptReconnection() {
|
|
1511
1554
|
if (this.#reconnectAttempts >= this.#maxReconnectAttempts) {
|
|
1512
1555
|
console.error('❌ Max reconnection attempts reached');
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import Peer from '@netpeer/swarm/peer';
|
|
1
2
|
/**
|
|
2
3
|
* Connection Monitor - Monitors peer connections and handles reconnection logic
|
|
3
4
|
*/
|
|
4
5
|
export default class ConnectionMonitor {
|
|
5
6
|
#private;
|
|
6
7
|
get isMonitoring(): boolean;
|
|
7
|
-
get connectedPeers():
|
|
8
|
-
get compatiblePeers():
|
|
9
|
-
|
|
8
|
+
get connectedPeers(): Peer[];
|
|
9
|
+
get compatiblePeers(): Peer[];
|
|
10
|
+
get disconnectedPeers(): Peer[];
|
|
10
11
|
start(version: any): void;
|
|
11
12
|
stop(): void;
|
|
12
13
|
waitForPeers(timeoutMs?: number): Promise<boolean>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.79",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@leofcoin/messages": "^1.4.40",
|
|
70
70
|
"@leofcoin/multi-wallet": "^3.1.8",
|
|
71
71
|
"@leofcoin/networks": "^1.1.25",
|
|
72
|
-
"@leofcoin/peernet": "^1.1.
|
|
72
|
+
"@leofcoin/peernet": "^1.1.87",
|
|
73
73
|
"@leofcoin/storage": "^3.5.38",
|
|
74
74
|
"@leofcoin/utils": "^1.1.39",
|
|
75
75
|
"@leofcoin/workers": "^1.5.23",
|