From 73ae929193a4722acf87e85afdcd33461d5885d2 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 5 Oct 2024 13:13:44 -0400 Subject: [PATCH 1/4] feat: only run network sync one at a time --- src/DigNetwork/DigNetwork.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/DigNetwork/DigNetwork.ts b/src/DigNetwork/DigNetwork.ts index d940eba..6db4756 100644 --- a/src/DigNetwork/DigNetwork.ts +++ b/src/DigNetwork/DigNetwork.ts @@ -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>; // Map of file keys to blacklists + private networkSyncActive: boolean = false; constructor(storeId: string) { this.dataStore = DataStore.from(storeId); @@ -142,6 +139,7 @@ export class DigNetwork { maxRootsToProcess?: number ): Promise { console.log("Starting file download process..."); + this.networkSyncActive = true; let peerBlackList: string[] = []; try { @@ -231,17 +229,14 @@ 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 { + this.networkSyncActive = false; } } From fa1679c5298012192bb719a7b0237a13d78b317e Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 5 Oct 2024 13:14:40 -0400 Subject: [PATCH 2/4] chore(release): 0.0.1-alpha.132 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc7e36c..7157045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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.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) diff --git a/package-lock.json b/package-lock.json index cf55e49..d21b2d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.131", + "version": "0.0.1-alpha.132", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.131", + "version": "0.0.1-alpha.132", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index eaba0d0..ded9d07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.131", + "version": "0.0.1-alpha.132", "description": "", "type": "commonjs", "main": "./dist/index.js", From 12ed93c1c30f19411b222822698fa97c3b51fd3c Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 5 Oct 2024 13:21:13 -0400 Subject: [PATCH 3/4] fix: better sync coordination --- src/DigNetwork/DigNetwork.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/DigNetwork/DigNetwork.ts b/src/DigNetwork/DigNetwork.ts index 6db4756..4a0527e 100644 --- a/src/DigNetwork/DigNetwork.ts +++ b/src/DigNetwork/DigNetwork.ts @@ -10,7 +10,7 @@ export class DigNetwork { private serverCoin: ServerCoin; private storeDir: string; private peerBlacklist: Map>; // Map of file keys to blacklists - private networkSyncActive: boolean = false; + private static networkSyncMap: Map = new Map(); constructor(storeId: string) { this.dataStore = DataStore.from(storeId); @@ -138,8 +138,12 @@ export class DigNetwork { prioritizedPeer?: DigPeer, maxRootsToProcess?: number ): Promise { - console.log("Starting file download process..."); - this.networkSyncActive = true; + // 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 { @@ -236,7 +240,9 @@ export class DigNetwork { console.error("Error during syncing store from peers:", error); throw error; } finally { - this.networkSyncActive = false; + // 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.`); } } From d0d89d35a86fee84c9283a4a973a95897f341f44 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Sat, 5 Oct 2024 13:21:48 -0400 Subject: [PATCH 4/4] chore(release): 0.0.1-alpha.133 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7157045..99f2897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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) diff --git a/package-lock.json b/package-lock.json index d21b2d0..3463c7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.132", + "version": "0.0.1-alpha.133", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.132", + "version": "0.0.1-alpha.133", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index ded9d07..4f9f334 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.132", + "version": "0.0.1-alpha.133", "description": "", "type": "commonjs", "main": "./dist/index.js",