diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea2a1c..cb686f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ 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. +### [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) + ### [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) ### [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) diff --git a/package-lock.json b/package-lock.json index 8ec205c..aeafeb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.149", + "version": "0.0.1-alpha.150", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.149", + "version": "0.0.1-alpha.150", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index 69b66d1..e100775 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.149", + "version": "0.0.1-alpha.150", "description": "", "type": "commonjs", "main": "./dist/index.js", diff --git a/src/DigNetwork/DigNetwork.ts b/src/DigNetwork/DigNetwork.ts index 74deb88..90287da 100644 --- a/src/DigNetwork/DigNetwork.ts +++ b/src/DigNetwork/DigNetwork.ts @@ -31,20 +31,31 @@ export class DigNetwork { // TODO: Implement this method } + /** + * Find a peer that has the store key and root hash. + * + * @param {string} storeId - The ID of the store. + * @param {string} rootHash - The root hash of the store. + * @param {string} [key] - Optional key to check for in the store. + * @param {string[]} [initialBlackList] - Initial list of blacklisted peer IPs. + * @returns {Promise} - A valid peer or null if none found. + */ public static async findPeerWithStoreKey( storeId: string, rootHash: string, key?: string, initialBlackList: string[] = [] ): Promise { - const peerBlackList: string[] = initialBlackList; + const peerBlackList = new Set(initialBlackList); const serverCoin = new ServerCoin(storeId); - const allPeers: string[] = await serverCoin.getActiveEpochPeers(); while (true) { try { - // Sample 10 peers from the current epoch - const digPeers = await serverCoin.sampleCurrentEpoch(10, peerBlackList); + // Sample 10 peers from the current epoch excluding blacklisted peers + const digPeers = await serverCoin.sampleCurrentEpoch( + 10, + Array.from(peerBlackList) + ); // If no peers are returned, break out of the loop if (digPeers.length === 0) { @@ -98,7 +109,7 @@ export class DigNetwork { } // If none of the peers were valid, add them to the blacklist - digPeers.forEach((peerIp) => peerBlackList.push(peerIp)); + digPeers.forEach((peerIp) => peerBlackList.add(peerIp)); // Retry with the next set of peers console.log("No valid peers found, retrying with new peers..."); @@ -243,7 +254,9 @@ export class DigNetwork { } finally { // Mark synchronization as inactive for this storeId DigNetwork.networkSyncMap.set(this.dataStore.StoreId, false); - console.log(`Network sync for storeId: ${this.dataStore.StoreId} has completed.`); + console.log( + `Network sync for storeId: ${this.dataStore.StoreId} has completed.` + ); } }