@dignetwork/dig-sdk 0.0.1-alpha.164 → 0.0.1-alpha.165
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAO,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"FullNodePeer.d.ts","sourceRoot":"","sources":["../../src/blockchain/FullNodePeer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAO,MAAM,8BAA8B,CAAC;AAgCzD;;GAEG;AACH,qBAAa,YAAY;IAqCH,OAAO,CAAC,IAAI;IAnChC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IAGpD,OAAO,CAAC,MAAM,CAAC,aAAa,CAEzB;IAGH,OAAO,CAAC,MAAM,CAAC,cAAc,CAAoC;IAGjE,OAAO,CAAC,MAAM,CAAC,WAAW,CAAkC;IAG5D,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAgB;IAG/C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAoC;IAG5D,OAAO,CAAC,MAAM,CAAC,WAAW,CAAoD;IAG9E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAGpB;IAGH,OAAO,CAAC,MAAM,CAAC,YAAY,CAAsC;IAGjE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAa;IAG3C,OAAO;IAEP;;;OAGG;WACW,WAAW,IAAI,YAAY;IAOzC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxC;;;;OAIG;WACiB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5C;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAuB9B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IASjC;;;;OAIG;mBACkB,eAAe;IAkGpC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAS3B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAepC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAenC;;;OAGG;mBACkB,UAAU;IAK/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB;;;OAGG;YACW,WAAW;IAuEzB,OAAO,CAAC,eAAe;IAoDvB;;;OAGG;WACW,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAuB3D;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAS5B;;;;OAIG;WACiB,mBAAmB,CACrC,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC;CA2CpB"}
|
|
@@ -17,7 +17,6 @@ const node_cache_1 = __importDefault(require("node-cache"));
|
|
|
17
17
|
const bottleneck_1 = __importDefault(require("bottleneck"));
|
|
18
18
|
const FULLNODE_PORT = 8444;
|
|
19
19
|
const LOCALHOST = "127.0.0.1";
|
|
20
|
-
const CHIA_NODES_HOST = "chia-nodes";
|
|
21
20
|
const DNS_HOSTS = [
|
|
22
21
|
"dns-introducer.chia.net",
|
|
23
22
|
"chia.ctrlaltdel.ch",
|
|
@@ -128,7 +127,7 @@ class FullNodePeer {
|
|
|
128
127
|
const trustedNodeIp = FullNodePeer.getTrustedFullNode();
|
|
129
128
|
const priorityIps = [];
|
|
130
129
|
// Define prioritized peers
|
|
131
|
-
FullNodePeer.prioritizedPeers = [
|
|
130
|
+
FullNodePeer.prioritizedPeers = [LOCALHOST];
|
|
132
131
|
// Add trustedNodeIp if available
|
|
133
132
|
if (trustedNodeIp) {
|
|
134
133
|
FullNodePeer.prioritizedPeers.unshift(trustedNodeIp);
|
|
@@ -144,11 +143,6 @@ class FullNodePeer {
|
|
|
144
143
|
(await FullNodePeer.isPortReachable(LOCALHOST, FULLNODE_PORT))) {
|
|
145
144
|
priorityIps.push(LOCALHOST);
|
|
146
145
|
}
|
|
147
|
-
// Prioritize CHIA_NODES_HOST
|
|
148
|
-
if (!FullNodePeer.cooldownCache.has(CHIA_NODES_HOST) &&
|
|
149
|
-
(await FullNodePeer.isPortReachable(CHIA_NODES_HOST, FULLNODE_PORT))) {
|
|
150
|
-
priorityIps.push(CHIA_NODES_HOST);
|
|
151
|
-
}
|
|
152
146
|
if (priorityIps.length > 0) {
|
|
153
147
|
return priorityIps;
|
|
154
148
|
}
|
|
@@ -162,16 +156,27 @@ class FullNodePeer {
|
|
|
162
156
|
for (const DNS_HOST of DNS_HOSTS) {
|
|
163
157
|
// Check if DNS_HOST is in failedDNSCache
|
|
164
158
|
if (FullNodePeer.failedDNSCache.has(DNS_HOST)) {
|
|
165
|
-
console.warn(`Skipping DNS host ${DNS_HOST} due to recent failure.`);
|
|
166
159
|
continue;
|
|
167
160
|
}
|
|
168
161
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
162
|
+
let ips = [];
|
|
163
|
+
// Check if DNS_HOST's IPs are cached
|
|
164
|
+
if (FullNodePeer.dnsCache.has(DNS_HOST)) {
|
|
165
|
+
ips = FullNodePeer.dnsCache.get(DNS_HOST) || [];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// Resolve DNS_HOST and cache the results
|
|
169
|
+
ips = await (0, promises_1.resolve4)(DNS_HOST);
|
|
170
|
+
if (ips && ips.length > 0) {
|
|
171
|
+
FullNodePeer.dnsCache.set(DNS_HOST, ips);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (ips.length > 0) {
|
|
171
175
|
const shuffledIps = FullNodePeer.shuffleArray(ips);
|
|
172
176
|
const reachableIps = [];
|
|
173
177
|
for (const ip of shuffledIps) {
|
|
174
178
|
if (!FullNodePeer.cooldownCache.has(ip) &&
|
|
179
|
+
FullNodePeer.isValidIpAddress(ip) &&
|
|
175
180
|
(await FullNodePeer.isPortReachable(ip, FULLNODE_PORT))) {
|
|
176
181
|
reachableIps.push(ip);
|
|
177
182
|
}
|
|
@@ -189,7 +194,7 @@ class FullNodePeer {
|
|
|
189
194
|
FullNodePeer.failedDNSCache.set(DNS_HOST, true);
|
|
190
195
|
}
|
|
191
196
|
}
|
|
192
|
-
// Cache the fetched peer IPs
|
|
197
|
+
// Cache the fetched peer IPs if any
|
|
193
198
|
if (fetchedPeers.length > 0) {
|
|
194
199
|
FullNodePeer.peerIPCache.set("peerIPs", fetchedPeers);
|
|
195
200
|
return fetchedPeers;
|
|
@@ -217,8 +222,7 @@ class FullNodePeer {
|
|
|
217
222
|
static initializePeerWeights(peerIPs) {
|
|
218
223
|
for (const ip of peerIPs) {
|
|
219
224
|
if (!FullNodePeer.peerWeights.has(ip)) {
|
|
220
|
-
if (ip ===
|
|
221
|
-
ip === LOCALHOST ||
|
|
225
|
+
if (ip === LOCALHOST ||
|
|
222
226
|
ip === FullNodePeer.getTrustedFullNode()) {
|
|
223
227
|
FullNodePeer.peerWeights.set(ip, 5); // Higher weight for prioritized peers
|
|
224
228
|
}
|
|
@@ -416,15 +420,10 @@ class FullNodePeer {
|
|
|
416
420
|
spinner.error({ text: "Failed to extract fullnode peer IP." });
|
|
417
421
|
throw new Error("Failed to extract peer IP.");
|
|
418
422
|
}
|
|
419
|
-
const limiter = FullNodePeer.peerLimiters.get(peerIP);
|
|
420
|
-
if (!limiter) {
|
|
421
|
-
spinner.error({ text: "No rate limiter found for the fullnode peer." });
|
|
422
|
-
throw new Error("No rate limiter found for the peer.");
|
|
423
|
-
}
|
|
424
423
|
try {
|
|
425
424
|
while (true) {
|
|
426
425
|
// Schedule the isCoinSpent method call through the limiter
|
|
427
|
-
const confirmed = await
|
|
426
|
+
const confirmed = await peer.isCoinSpent(parentCoinInfo, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
|
|
428
427
|
if (confirmed) {
|
|
429
428
|
spinner.success({ text: "Coin confirmed!" });
|
|
430
429
|
return true;
|
|
@@ -444,7 +443,9 @@ exports.FullNodePeer = FullNodePeer;
|
|
|
444
443
|
// Singleton instance
|
|
445
444
|
FullNodePeer.instance = null;
|
|
446
445
|
// Cooldown cache to exclude faulty peers temporarily
|
|
447
|
-
FullNodePeer.cooldownCache = new node_cache_1.default({
|
|
446
|
+
FullNodePeer.cooldownCache = new node_cache_1.default({
|
|
447
|
+
stdTTL: COOLDOWN_DURATION / 1000,
|
|
448
|
+
});
|
|
448
449
|
// Failed DNS hosts cooldown cache
|
|
449
450
|
FullNodePeer.failedDNSCache = new node_cache_1.default({ stdTTL: 86400 });
|
|
450
451
|
// Peer reliability weights
|
|
@@ -455,6 +456,11 @@ FullNodePeer.prioritizedPeers = [];
|
|
|
455
456
|
FullNodePeer.peerInfos = new Map();
|
|
456
457
|
// Cache for fetched peer IPs
|
|
457
458
|
FullNodePeer.peerIPCache = new node_cache_1.default({ stdTTL: CACHE_DURATION / 1000 });
|
|
459
|
+
// Cache for DNS_HOST resolved IPs with a TTL of 3 days (259200 seconds)
|
|
460
|
+
FullNodePeer.dnsCache = new node_cache_1.default({
|
|
461
|
+
stdTTL: 259200,
|
|
462
|
+
checkperiod: 3600,
|
|
463
|
+
});
|
|
458
464
|
// Map to store rate limiters per peer IP
|
|
459
465
|
FullNodePeer.peerLimiters = new Map();
|
|
460
466
|
// Round-robin index
|