Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.0.1 alpha.150 #135

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
25 changes: 19 additions & 6 deletions src/DigNetwork/DigNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DigPeer | null>} - A valid peer or null if none found.
*/
public static async findPeerWithStoreKey(
storeId: string,
rootHash: string,
key?: string,
initialBlackList: string[] = []
): Promise<DigPeer | null> {
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) {
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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.`
);
}
}

Expand Down
Loading