Skip to content

Commit

Permalink
Merge pull request #156 from DIG-Network/release/v0.0.1-alpha.171
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.171
  • Loading branch information
MichaelTaylor3D authored Oct 26, 2024
2 parents c280221 + 992bf9b commit 0daf62b
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 53 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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


### Features

* add interval promise ([380f5da](https://github.com/DIG-Network/dig-chia-sdk/commit/380f5dae168256e54cc9f0618e6aaa753546b2e5))
* optionally use redis cache instead of node cache if the right env is set up ([9c48999](https://github.com/DIG-Network/dig-chia-sdk/commit/9c4899987512a9ed4984dd6d31f327c0ed162237))

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


Expand Down
90 changes: 86 additions & 4 deletions package-lock.json

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

3 changes: 2 additions & 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.170",
"version": "0.0.1-alpha.171",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down Expand Up @@ -50,6 +50,7 @@
"node-stun": "^0.1.2",
"progress-stream": "^2.0.0",
"proper-lockfile": "^4.1.2",
"redis": "^4.7.0",
"superagent": "^10.0.0",
"unzipper": "^0.12.3"
},
Expand Down
10 changes: 4 additions & 6 deletions src/DigNetwork/ContentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import fs from "fs";
import http from "http";
import { URL } from "url";
import { Readable } from "stream";
import { getOrCreateSSLCerts } from "../utils/ssl";
import { formatHost } from "../utils/network";
import NodeCache from "node-cache";
import { formatHost, DigCache, getOrCreateSSLCerts } from "../utils";

const hasRootHashCache = new NodeCache({ stdTTL: 86400 });
const wellKnownCache = new NodeCache({ stdTTL: 86400 });
const hasRootHashCache = new DigCache({ stdTTL: 86400 });
const wellKnownCache = new DigCache({ stdTTL: 86400 });

export class ContentServer {
private ipAddress: string;
Expand Down Expand Up @@ -197,7 +195,7 @@ export class ContentServer {
const cacheKey = `${this.storeId}-${rootHash}`;

// Check if the result is already cached
const cachedResult = hasRootHashCache.get<boolean>(cacheKey);
const cachedResult = await hasRootHashCache.get<boolean>(cacheKey);
if (cachedResult !== undefined) {
return cachedResult;
}
Expand Down
21 changes: 12 additions & 9 deletions src/DigNetwork/PropagationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ import * as zlib from "zlib";
import { asyncPool } from "../utils/promiseUtils";
import { createSpinner } from "nanospinner";
import { getFilePathFromSha256 } from "../utils/hashUtils";
import { getOrCreateSSLCerts } from "../utils/ssl";
import { green, red, blue, yellow, cyan } from "colorette";
import { merkleIntegrityCheck } from "../utils/merkle";
import { PassThrough } from "stream";
import { promptCredentials } from "../utils/credentialsUtils";
import { STORE_PATH } from "../utils/config";
import { Wallet, DataStore } from "../blockchain";
import { formatHost } from "../utils/network";
import NodeCache from "node-cache";
import { formatHost, DigCache, getOrCreateSSLCerts } from "../utils";

// Initialize cache with a TTL of 1 week (604800 seconds)
const storeExistsCache = new NodeCache({ stdTTL: 86400 });
const pingUpdatecache = new NodeCache({ stdTTL: 86400 });
const storeExistsCache = new DigCache({ stdTTL: 86400 });
const pingUpdatecache = new DigCache({ stdTTL: 86400 });

// Helper function to trim long filenames with ellipsis and ensure consistent padding
function formatFilename(filename: string | undefined, maxLength = 30): string {
Expand Down Expand Up @@ -125,7 +123,7 @@ export class PropagationServer {
const cacheKey = `${this.ipAddress}-${this.storeId}-${rootHash}`;

// Check if response for this combination is already cached
if (pingUpdatecache.get(cacheKey) === "successfully synced") {
if ((await pingUpdatecache.get(cacheKey)) === "successfully synced") {
return;
}

Expand All @@ -151,7 +149,9 @@ export class PropagationServer {
try {
const response = await axios.post(url, data, config);
console.log(
green(`✔ Successfully pinged peer: ${this.ipAddress}`),
green(
`✔ Successfully pinged peer: ${this.ipAddress} ${this.storeId}`
),
response.data
);

Expand All @@ -162,7 +162,10 @@ export class PropagationServer {

return response.data;
} catch (error: any) {
console.error(red(`✖ Failed to ping peer: ${this.ipAddress}`), error.message);
console.error(
red(`✖ Failed to ping peer: ${this.ipAddress}`),
error.message
);
console.error(red(error.message));
throw error;
}
Expand Down Expand Up @@ -215,7 +218,7 @@ export class PropagationServer {
: `${this.storeId}-nohash`;

// Check if the result is already cached
const cachedResult = storeExistsCache.get<{
const cachedResult = await storeExistsCache.get<{
storeExists: boolean;
rootHashExists: boolean;
}>(cacheKey);
Expand Down
11 changes: 6 additions & 5 deletions src/blockchain/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ import { CreateStoreUserInputs } from "../types";
import { askForStoreDetails } from "../prompts";
import { FileCache } from "../utils/FileCache";
import { DataStoreSerializer } from "./DataStoreSerializer";
import NodeCache from "node-cache";
import { MAIN_NET_GENISES_CHALLENGE } from "../utils/config";
import { StoreMonitorRegistry } from "./StoreMonitorRegistry";
import { DigCache } from "../utils";

// Initialize the cache with a TTL of 180 seconds (3 minutes)
const rootHistoryCache = new NodeCache({ stdTTL: 180 });
const allStoresCache = new NodeCache({ stdTTL: 15 });
const rootHistoryCache = new DigCache({ stdTTL: 180 });

const stat = promisify(fs.stat);
const readdir = promisify(fs.readdir);
Expand Down Expand Up @@ -337,7 +336,7 @@ export class DataStore {
const deserializedStore = DataStoreSerializer.deserialize({
latestStore: cachedInfo.latestStore,
latestHeight: cachedInfo.latestHeight.toString(),
latestHash: cachedInfo.latestHash
latestHash: cachedInfo.latestHash,
});

return {
Expand Down Expand Up @@ -419,7 +418,9 @@ export class DataStore {
}

// Check if the root history is cached for this storeId
const cachedHistory = rootHistoryCache.get<RootHistoryItem[]>(this.storeId);
const cachedHistory = await rootHistoryCache.get<RootHistoryItem[]>(
this.storeId
);
if (cachedHistory) {
return cachedHistory;
}
Expand Down
Loading

0 comments on commit 0daf62b

Please sign in to comment.