Skip to content

Commit

Permalink
Merge pull request #121 from DIG-Network/release/v0.0.1-alpha.133
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.133
  • Loading branch information
MichaelTaylor3D authored Oct 5, 2024
2 parents 629123d + d0d89d3 commit 5afdedf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

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.133](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.132...v0.0.1-alpha.133) (2024-10-05)


### Bug Fixes

* better sync coordination ([12ed93c](https://github.com/DIG-Network/dig-chia-sdk/commit/12ed93c1c30f19411b222822698fa97c3b51fd3c))

### [0.0.1-alpha.132](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.131...v0.0.1-alpha.132) (2024-10-05)


### Features

* only run network sync one at a time ([73ae929](https://github.com/DIG-Network/dig-chia-sdk/commit/73ae929193a4722acf87e85afdcd33461d5885d2))

### [0.0.1-alpha.131](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.130...v0.0.1-alpha.131) (2024-10-04)


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.131",
"version": "0.0.1-alpha.133",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
21 changes: 11 additions & 10 deletions src/DigNetwork/DigNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import { DigPeer } from "./DigPeer";
import { DataStore, ServerCoin } from "../blockchain";
import { DIG_FOLDER_PATH } from "../utils/config";
import { withTimeout } from "../utils";
import { promisify } from "util";

const rename = promisify(fs.rename);
const unlink = promisify(fs.unlink);

export class DigNetwork {
private dataStore: DataStore;
private serverCoin: ServerCoin;
private storeDir: string;
private peerBlacklist: Map<string, Set<string>>; // Map of file keys to blacklists
private static networkSyncMap: Map<string, boolean> = new Map();

constructor(storeId: string) {
this.dataStore = DataStore.from(storeId);
Expand Down Expand Up @@ -141,7 +138,12 @@ export class DigNetwork {
prioritizedPeer?: DigPeer,
maxRootsToProcess?: number
): Promise<void> {
console.log("Starting file download process...");
// Check if synchronization is already active for this storeId
if (DigNetwork.networkSyncMap.get(this.dataStore.StoreId)) {
return;
}
console.log("Starting network sync for store:", this.dataStore.StoreId);
DigNetwork.networkSyncMap.set(this.dataStore.StoreId, true);
let peerBlackList: string[] = [];

try {
Expand Down Expand Up @@ -231,17 +233,16 @@ export class DigNetwork {
}
}
}

DigNetwork.pingNetworkOfUpdate(
this.dataStore.StoreId,
rootInfo.root_hash
);
}

console.log("Syncing store complete.");
} catch (error: any) {
console.error("Error during syncing store from peers:", error);
throw error;
} 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.`);
}
}

Expand Down

0 comments on commit 5afdedf

Please sign in to comment.