Skip to content

Commit dcd2d06

Browse files
Merge pull request #90 from DIG-Network/release/v0.0.1-alpha.100
Release/v0.0.1 alpha.100
2 parents 579445f + 9ee42fe commit dcd2d06

File tree

4 files changed

+25
-62
lines changed

4 files changed

+25
-62
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [0.0.1-alpha.100](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.99...v0.0.1-alpha.100) (2024-09-26)
6+
7+
8+
### Bug Fixes
9+
10+
* revert fullnode peer changes ([a90cc54](https://github.com/DIG-Network/dig-chia-sdk/commit/a90cc5431803404994bc15114290ec39f11e28f9))
11+
512
### [0.0.1-alpha.99](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.98...v0.0.1-alpha.99) (2024-09-26)
613

714

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/dig-sdk",
3-
"version": "0.0.1-alpha.99",
3+
"version": "0.0.1-alpha.100",
44
"description": "",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/blockchain/FullNodePeer.ts

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,15 @@ export class FullNodePeer {
2929
private static deprioritizedIps: Set<string> = new Set(); // New set for deprioritized IPs
3030

3131
static {
32-
FullNodePeer.memoizedFetchNewPeerIPs = memoize(
33-
FullNodePeer.fetchNewPeerIPs
34-
);
32+
FullNodePeer.memoizedFetchNewPeerIPs = memoize(FullNodePeer.fetchNewPeerIPs);
3533
}
3634

3735
private constructor(peer: Peer) {
3836
this.peer = peer;
3937
}
4038

41-
/**
42-
* Connect to the best peer, optionally using custom certificate and key file paths.
43-
* @param {string} [certFilePath] - Optional custom certificate file path.
44-
* @param {string} [keyFilePath] - Optional custom key file path.
45-
* @returns {Promise<Peer>} The connected peer.
46-
*/
47-
public static async connect(
48-
certFilePath?: string,
49-
keyFilePath?: string
50-
): Promise<Peer> {
51-
const peer = await FullNodePeer.getBestPeer(certFilePath, keyFilePath);
39+
public static async connect(): Promise<Peer> {
40+
const peer = await FullNodePeer.getBestPeer();
5241
return new FullNodePeer(peer).peer;
5342
}
5443

@@ -143,9 +132,7 @@ export class FullNodePeer {
143132
}
144133
}
145134
} catch (error: any) {
146-
console.error(
147-
`Failed to resolve IPs from ${DNS_HOST}: ${error.message}`
148-
);
135+
console.error(`Failed to resolve IPs from ${DNS_HOST}: ${error.message}`);
149136
}
150137
}
151138
throw new Error("No reachable IPs found in any DNS records.");
@@ -191,9 +178,7 @@ export class FullNodePeer {
191178
const timeoutPromise = new Promise<null>((_, reject) => {
192179
timeoutId = setTimeout(() => {
193180
FullNodePeer.cachedPeer = null;
194-
reject(
195-
new Error("Operation timed out. Reconnecting to a new peer.")
196-
);
181+
reject(new Error("Operation timed out. Reconnecting to a new peer."));
197182
}, 60000); // 1 minute
198183
});
199184

@@ -212,17 +197,12 @@ export class FullNodePeer {
212197
return result;
213198
} catch (error: any) {
214199
// If the error is WebSocket-related or timeout, reset the peer
215-
if (
216-
error.message.includes("WebSocket") ||
217-
error.message.includes("Operation timed out")
218-
) {
200+
if (error.message.includes("WebSocket") || error.message.includes("Operation timed out")) {
219201
FullNodePeer.cachedPeer = null;
220202
// @ts-ignore
221203
FullNodePeer.memoizedFetchNewPeerIPs.cache.clear();
222204
FullNodePeer.deprioritizedIps.clear();
223-
console.info(
224-
`Fullnode Peer error, reconnecting to a new peer...`
225-
);
205+
console.info(`Fullnode Peer error, reconnecting to a new peer...`);
226206
const newPeer = await FullNodePeer.getBestPeer();
227207
return (newPeer as any)[prop](...args);
228208
}
@@ -235,10 +215,7 @@ export class FullNodePeer {
235215
});
236216
}
237217

238-
private static async getBestPeer(
239-
certFilePath?: string,
240-
keyFilePath?: string
241-
): Promise<Peer> {
218+
private static async getBestPeer(): Promise<Peer> {
242219
const now = Date.now();
243220

244221
if (
@@ -248,29 +225,12 @@ export class FullNodePeer {
248225
return FullNodePeer.cachedPeer.peer;
249226
}
250227

251-
let certFile: string;
252-
let keyFile: string;
253-
254-
// If certFilePath or keyFilePath is provided, ensure both are provided
255-
if (certFilePath && keyFilePath) {
256-
certFile = certFilePath;
257-
keyFile = keyFilePath;
228+
const sslFolder = path.resolve(os.homedir(), ".dig", "ssl");
229+
const certFile = path.join(sslFolder, "public_dig.crt");
230+
const keyFile = path.join(sslFolder, "public_dig.key");
258231

259-
if (!fs.existsSync(certFile)) {
260-
throw new Error(`Certificate file not found: ${certFile}`);
261-
}
262-
if (!fs.existsSync(keyFile)) {
263-
throw new Error(`Key file not found: ${keyFile}`);
264-
}
265-
} else {
266-
// Use default paths if no custom paths are provided
267-
const sslFolder = path.resolve(os.homedir(), ".dig", "ssl");
268-
certFile = path.join(sslFolder, "public_dig.crt");
269-
keyFile = path.join(sslFolder, "public_dig.key");
270-
271-
if (!fs.existsSync(sslFolder)) {
272-
throw new Error(`SSL folder not found: ${sslFolder}`);
273-
}
232+
if (!fs.existsSync(sslFolder)) {
233+
fs.mkdirSync(sslFolder, { recursive: true });
274234
}
275235

276236
new Tls(certFile, keyFile);
@@ -298,9 +258,7 @@ export class FullNodePeer {
298258
);
299259
return FullNodePeer.createPeerProxy(peer);
300260
} catch (error: any) {
301-
console.error(
302-
`Failed to create peer for IP ${ip}: ${error.message}`
303-
);
261+
console.error(`Failed to create peer for IP ${ip}: ${error.message}`);
304262
return null;
305263
}
306264
}
@@ -341,9 +299,7 @@ export class FullNodePeer {
341299
(height, index) =>
342300
height === highestPeak &&
343301
!FullNodePeer.deprioritizedIps.has(peerIPs[index]) && // Exclude deprioritized IPs
344-
(peerIPs[index] === LOCALHOST ||
345-
peerIPs[index] === trustedNodeIp ||
346-
peerIPs[index] === CHIA_NODES_HOST)
302+
(peerIPs[index] === LOCALHOST || peerIPs[index] === trustedNodeIp || peerIPs[index] === CHIA_NODES_HOST)
347303
);
348304

349305
// If LOCALHOST, TRUSTED_NODE_IP, or CHIA_NODES_HOST don't have the highest peak, select any peer with the highest peak

0 commit comments

Comments
 (0)