@dignetwork/dig-sdk 0.0.1-alpha.164 → 0.0.1-alpha.166
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;IAYpC;;;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;CAsBpB"}
|
|
@@ -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,9 +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 ||
|
|
222
|
-
ip === FullNodePeer.getTrustedFullNode()) {
|
|
225
|
+
if (ip === LOCALHOST || ip === FullNodePeer.getTrustedFullNode()) {
|
|
223
226
|
FullNodePeer.peerWeights.set(ip, 5); // Higher weight for prioritized peers
|
|
224
227
|
}
|
|
225
228
|
else {
|
|
@@ -401,36 +404,12 @@ class FullNodePeer {
|
|
|
401
404
|
*/
|
|
402
405
|
static async waitForConfirmation(parentCoinInfo) {
|
|
403
406
|
const spinner = (0, nanospinner_1.createSpinner)("Waiting for confirmation...").start();
|
|
404
|
-
|
|
405
|
-
try {
|
|
406
|
-
peer = await FullNodePeer.connect();
|
|
407
|
-
}
|
|
408
|
-
catch (error) {
|
|
409
|
-
spinner.error({ text: "Failed to connect to a fullnode peer." });
|
|
410
|
-
console.error(`waitForConfirmation connection error: ${error.message}`);
|
|
411
|
-
throw error;
|
|
412
|
-
}
|
|
413
|
-
// Extract peer IP to access the corresponding limiter
|
|
414
|
-
const peerIP = FullNodePeer.extractPeerIP(peer);
|
|
415
|
-
if (!peerIP) {
|
|
416
|
-
spinner.error({ text: "Failed to extract fullnode peer IP." });
|
|
417
|
-
throw new Error("Failed to extract peer IP.");
|
|
418
|
-
}
|
|
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
|
-
}
|
|
407
|
+
const peer = await FullNodePeer.connect();
|
|
424
408
|
try {
|
|
425
409
|
while (true) {
|
|
426
410
|
// Schedule the isCoinSpent method call through the limiter
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
spinner.success({ text: "Coin confirmed!" });
|
|
430
|
-
return true;
|
|
431
|
-
}
|
|
432
|
-
// Wait for 5 seconds before the next check
|
|
433
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
411
|
+
await peer.waitForCoinToBeSpent(parentCoinInfo, config_1.MIN_HEIGHT, Buffer.from(config_1.MIN_HEIGHT_HEADER_HASH, "hex"));
|
|
412
|
+
spinner.success({ text: "Coin confirmed!" });
|
|
434
413
|
}
|
|
435
414
|
}
|
|
436
415
|
catch (error) {
|
|
@@ -444,7 +423,9 @@ exports.FullNodePeer = FullNodePeer;
|
|
|
444
423
|
// Singleton instance
|
|
445
424
|
FullNodePeer.instance = null;
|
|
446
425
|
// Cooldown cache to exclude faulty peers temporarily
|
|
447
|
-
FullNodePeer.cooldownCache = new node_cache_1.default({
|
|
426
|
+
FullNodePeer.cooldownCache = new node_cache_1.default({
|
|
427
|
+
stdTTL: COOLDOWN_DURATION / 1000,
|
|
428
|
+
});
|
|
448
429
|
// Failed DNS hosts cooldown cache
|
|
449
430
|
FullNodePeer.failedDNSCache = new node_cache_1.default({ stdTTL: 86400 });
|
|
450
431
|
// Peer reliability weights
|
|
@@ -455,6 +436,11 @@ FullNodePeer.prioritizedPeers = [];
|
|
|
455
436
|
FullNodePeer.peerInfos = new Map();
|
|
456
437
|
// Cache for fetched peer IPs
|
|
457
438
|
FullNodePeer.peerIPCache = new node_cache_1.default({ stdTTL: CACHE_DURATION / 1000 });
|
|
439
|
+
// Cache for DNS_HOST resolved IPs with a TTL of 3 days (259200 seconds)
|
|
440
|
+
FullNodePeer.dnsCache = new node_cache_1.default({
|
|
441
|
+
stdTTL: 259200,
|
|
442
|
+
checkperiod: 3600,
|
|
443
|
+
});
|
|
458
444
|
// Map to store rate limiters per peer IP
|
|
459
445
|
FullNodePeer.peerLimiters = new Map();
|
|
460
446
|
// Round-robin index
|
package/dist/utils/config.js
CHANGED
|
@@ -82,7 +82,7 @@ const promptUserForSelection = async (options) => {
|
|
|
82
82
|
return answer.selectedStore;
|
|
83
83
|
};
|
|
84
84
|
const getCoinState = (storeId) => {
|
|
85
|
-
const stateFile = path.join(exports.
|
|
85
|
+
const stateFile = path.join(exports.USER_DIR_PATH, `${storeId}.json`);
|
|
86
86
|
if (!fs.existsSync(stateFile)) {
|
|
87
87
|
return {
|
|
88
88
|
metadata: { rootHash: "", bytes: "", label: "", description: "" },
|