Skip to content

Commit 1454b93

Browse files
Merge pull request #135 from DIG-Network/release/v0.0.1-alpha.150
Release/v0.0.1 alpha.150
2 parents c88c591 + 93e6032 commit 1454b93

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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.150](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.149...v0.0.1-alpha.150) (2024-10-06)
6+
57
### [0.0.1-alpha.149](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.148...v0.0.1-alpha.149) (2024-10-06)
68

79
### [0.0.1-alpha.148](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.147...v0.0.1-alpha.148) (2024-10-06)

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.149",
3+
"version": "0.0.1-alpha.150",
44
"description": "",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/DigNetwork/DigNetwork.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,31 @@ export class DigNetwork {
3131
// TODO: Implement this method
3232
}
3333

34+
/**
35+
* Find a peer that has the store key and root hash.
36+
*
37+
* @param {string} storeId - The ID of the store.
38+
* @param {string} rootHash - The root hash of the store.
39+
* @param {string} [key] - Optional key to check for in the store.
40+
* @param {string[]} [initialBlackList] - Initial list of blacklisted peer IPs.
41+
* @returns {Promise<DigPeer | null>} - A valid peer or null if none found.
42+
*/
3443
public static async findPeerWithStoreKey(
3544
storeId: string,
3645
rootHash: string,
3746
key?: string,
3847
initialBlackList: string[] = []
3948
): Promise<DigPeer | null> {
40-
const peerBlackList: string[] = initialBlackList;
49+
const peerBlackList = new Set(initialBlackList);
4150
const serverCoin = new ServerCoin(storeId);
42-
const allPeers: string[] = await serverCoin.getActiveEpochPeers();
4351

4452
while (true) {
4553
try {
46-
// Sample 10 peers from the current epoch
47-
const digPeers = await serverCoin.sampleCurrentEpoch(10, peerBlackList);
54+
// Sample 10 peers from the current epoch excluding blacklisted peers
55+
const digPeers = await serverCoin.sampleCurrentEpoch(
56+
10,
57+
Array.from(peerBlackList)
58+
);
4859

4960
// If no peers are returned, break out of the loop
5061
if (digPeers.length === 0) {
@@ -98,7 +109,7 @@ export class DigNetwork {
98109
}
99110

100111
// If none of the peers were valid, add them to the blacklist
101-
digPeers.forEach((peerIp) => peerBlackList.push(peerIp));
112+
digPeers.forEach((peerIp) => peerBlackList.add(peerIp));
102113

103114
// Retry with the next set of peers
104115
console.log("No valid peers found, retrying with new peers...");
@@ -243,7 +254,9 @@ export class DigNetwork {
243254
} finally {
244255
// Mark synchronization as inactive for this storeId
245256
DigNetwork.networkSyncMap.set(this.dataStore.StoreId, false);
246-
console.log(`Network sync for storeId: ${this.dataStore.StoreId} has completed.`);
257+
console.log(
258+
`Network sync for storeId: ${this.dataStore.StoreId} has completed.`
259+
);
247260
}
248261
}
249262

0 commit comments

Comments
 (0)