Skip to content

Commit

Permalink
Merge pull request #91 from DIG-Network/release/v0.0.1-alpha.97
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.97
  • Loading branch information
MichaelTaylor3D authored Oct 4, 2024
2 parents ef0afd1 + 8fe935a commit 2b47daf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.97](https://github.com/DIG-Network/dig-propagation-server/compare/v0.0.1-alpha.96...v0.0.1-alpha.97) (2024-10-04)


### Features

* continue to resync if not synced ([cd9f8a5](https://github.com/DIG-Network/dig-propagation-server/commit/cd9f8a58cd5e9e075cd9b0ac0a87d465d39df86a))

### [0.0.1-alpha.96](https://github.com/DIG-Network/dig-propagation-server/compare/v0.0.1-alpha.95...v0.0.1-alpha.96) (2024-10-04)


Expand Down
19 changes: 13 additions & 6 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dig-propagation-server",
"version": "0.0.1-alpha.96",
"version": "0.0.1-alpha.97",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand All @@ -26,7 +26,7 @@
],
"dependencies": {
"@dignetwork/datalayer-driver": "^0.1.28",
"@dignetwork/dig-sdk": "^0.0.1-alpha.130",
"@dignetwork/dig-sdk": "^0.0.1-alpha.131",
"async-mutex": "^0.5.0",
"busboy": "^1.6.0",
"express": "^4.19.2",
Expand All @@ -42,6 +42,7 @@
"@types/busboy": "^1.5.4",
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.10",
"@types/mocha": "^10.0.7",
"@types/node": "^22.1.0",
"@types/request-ip": "^0.0.41",
Expand Down
32 changes: 31 additions & 1 deletion src/tasks/sync_stores.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from "lodash";
import { SimpleIntervalJob, Task } from "toad-scheduler";
import {
getStoresList,
Expand All @@ -8,11 +9,14 @@ import {
StoreMonitorRegistry,
} from "@dignetwork/dig-sdk";
import { Mutex } from "async-mutex";
import { RootHistoryItem } from "@dignetwork/dig-sdk/dist/types";
const mutex = new Mutex();

const PUBLIC_IP_KEY = "publicIp";
const nconfManager = new NconfManager("config.json");

const missingSyncPool = new Set<string>();

// -------------------------
// Helper Functions
// -------------------------
Expand All @@ -31,6 +35,21 @@ const syncStoreFromNetwork = async (storeId: string): Promise<void> => {
const dataStore = await DataStore.from(storeId);
await dataStore.fetchCoinInfo();

const rootHistory = await dataStore.getRootHistory();

const lastRoot = _.last(rootHistory);
if (!lastRoot) {
console.error(`No root history found for store ${storeId}.`);
return;
}

// If not synced put in the pool to keep trying
if ((lastRoot as RootHistoryItem).synced) {
missingSyncPool.delete(storeId);
} else {
missingSyncPool.add(storeId);
}

console.log(`Store ${storeId} synchronized successfully.`);
} catch (error: any) {
console.warn(
Expand All @@ -43,7 +62,6 @@ const syncStoreFromNetwork = async (storeId: string): Promise<void> => {
}
};


/**
* Ensures that the server coin exists and is valid for a specific store.
* @param storeId - The ID of the store.
Expand All @@ -64,6 +82,16 @@ const ensureServerCoin = async (
}
};

const processMissingSyncPool = async (): Promise<void> => {
for (const storeId of missingSyncPool) {
try {
await syncStoreFromNetwork(storeId);
} catch (error: any) {
console.error(`Failed to sync store ${storeId}: ${error.message}`);
}
}
};

// -------------------------
// Initialization Function
// -------------------------
Expand Down Expand Up @@ -143,6 +171,8 @@ const syncStoresTask = new Task("sync-stores", async () => {
return; // Exit the task if we can't retrieve the public IP
}

await processMissingSyncPool();

for (const storeId of storeList) {
try {
if (publicIp) {
Expand Down

0 comments on commit 2b47daf

Please sign in to comment.