Skip to content

Commit

Permalink
Merge pull request #88 from Chia-Network/develop
Browse files Browse the repository at this point in the history
Release 1.7.7
  • Loading branch information
TheLastCicada authored Mar 8, 2024
2 parents 326495d + 8abead8 commit fe2826b
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 151 deletions.
4 changes: 4 additions & 0 deletions .repo-content-updater.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pr_target_grant: develop
assign_users:
- TheLastCicada
commit_prefix: "chore: "
219 changes: 110 additions & 109 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core-registry-cadt",
"version": "1.7.6",
"version": "1.7.7",
"_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2",
"private": true,
"bin": "build/server.js",
Expand Down Expand Up @@ -74,7 +74,7 @@
"chai-http": "^4.4.0",
"eslint": "^8.56.0",
"eslint-plugin-es": "^4.1.0",
"eslint-plugin-mocha": "^10.2.0",
"eslint-plugin-mocha": "^10.3.0",
"husky": "^9.0.11",
"mocha": "^10.3.0",
"semver": "^7.6.0",
Expand Down
22 changes: 14 additions & 8 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import fs from 'fs';
import path from 'path';
import superagent from 'superagent';
import { CONFIG } from '../user-config';
import fullNode from './fullNode';
import { publicIpv4 } from '../utils/ip-tools';
import wallet from './wallet';
import { Organization } from '../models';
import { logger } from '../logger.js';
import { getChiaRoot } from 'chia-root-resolver';
import { getMirrorUrl } from '../utils/datalayer-utils';

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

Expand Down Expand Up @@ -91,6 +90,16 @@ const getValue = async (storeId, storeKey) => {
const addMirror = async (storeId, url, forceAddMirror = false) => {
await wallet.waitForAllTransactionsToConfirm();
const homeOrg = await Organization.getHomeOrg();
logger.info(
`Checking mirrors for storeID is ${storeId} with mirror URL ${url}`,
);

if (!url) {
logger.info(
`No DATALAYER_FILE_SERVER_URL specified so skipping mirror for ${storeId}`,
);
return false;
}

if (!homeOrg && !forceAddMirror) {
logger.info(`No home org detected so skipping mirror for ${storeId}`);
Expand All @@ -105,7 +114,7 @@ const addMirror = async (storeId, url, forceAddMirror = false) => {
);

if (mirror) {
logger.info(`Mirror already available for ${storeId}`);
logger.info(`Mirror already available for ${storeId} at ${url}`);
return true;
}

Expand Down Expand Up @@ -564,12 +573,9 @@ const subscribeToStoreOnDataLayer = async (storeId) => {
if (Object.keys(data).includes('success') && data.success) {
logger.info(`Successfully Subscribed: ${storeId}`);

const chiaConfig = fullNode.getChiaConfig();
const mirrorUrl = await getMirrorUrl();

await addMirror(
storeId,
`http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`,
);
await addMirror(storeId, mirrorUrl, true);

return data;
}
Expand Down
7 changes: 5 additions & 2 deletions src/datalayer/writeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const createDataLayerStore = async () => {
if (shouldMirror) {
const mirrorUrl = await getMirrorUrl();
if (mirrorUrl) {
logger.info(
`Now attempting to create new mirror for ${storeId} at ${mirrorUrl}`,
);
await dataLayer.addMirror(storeId, mirrorUrl, true);
} else {
logger.error('Mirror URL not available, skipping mirror announcement.');
Expand All @@ -43,8 +46,8 @@ const createDataLayerStore = async () => {
return storeId;
};

const addMirror = async (storeId, url) => {
return dataLayer.addMirror(storeId, url);
const addMirror = async (storeId, url, force = false) => {
return dataLayer.addMirror(storeId, url, force);
};

const waitForStoreToBeConfirmed = async (storeId, retry = 0) => {
Expand Down
4 changes: 2 additions & 2 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ class Organization extends Model {
return registryVersionId;
}

static async addMirror(storeId, url) {
await datalayer.addMirror(storeId, url);
static async addMirror(storeId, url, force = false) {
await datalayer.addMirror(storeId, url, force);
}

static async importHomeOrg(orgUid) {
Expand Down
31 changes: 13 additions & 18 deletions src/tasks/mirror-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,19 @@ const job = new SimpleIntervalJob(
);

const runMirrorCheck = async () => {
const homeOrg = Organization.getHomeOrg();

if (homeOrg) {
const organizations = Organization.getOrgsMap();
const orgs = Object.keys(organizations);
for (const org of orgs) {
const orgData = organizations[org];
const mirrorUrl = await getMirrorUrl();

if (mirrorUrl) {
// There is logic within the addMirror function to check if the mirror already exists
await Organization.addMirror(orgData.orgUid, mirrorUrl);
await Organization.addMirror(orgData.registryId, mirrorUrl);
} else {
logger.error(
'Mirror URL is not available, skipping mirror announcement',
);
}
const organizations = await Organization.getOrgsMap();
const orgs = Object.keys(organizations);
for (const org of orgs) {
const orgData = organizations[org];
const mirrorUrl = await getMirrorUrl();
if (mirrorUrl) {
// There is logic within the addMirror function to check if the mirror already exists
await Organization.addMirror(orgData.orgUid, mirrorUrl, true);
await Organization.addMirror(orgData.registryId, mirrorUrl, true);
} else {
logger.error(
'DATALAYER_FILE_SERVER_URL not set, skipping mirror announcement',
);
}
}
};
Expand Down
16 changes: 6 additions & 10 deletions src/utils/datalayer-utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CONFIG } from '../user-config';
import fullNode from '../datalayer/fullNode';
import { publicIpv4 } from './ip-tools';
import { logger } from '../logger.js';

export const encodeHex = (str) => {
return Buffer.from(str).toString('hex');
Expand Down Expand Up @@ -114,14 +113,11 @@ export const optimizeAndSortKvDiff = (kvDiff) => {

export const getMirrorUrl = async () => {
try {
const { DATALAYER_FILE_SERVER_URL } = CONFIG().CHIA;
console.log(DATALAYER_FILE_SERVER_URL);
const chiaConfig = fullNode.getChiaConfig();
return (
DATALAYER_FILE_SERVER_URL ||
`http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`
);
} catch {
const finalUrl = CONFIG().CHIA.DATALAYER_FILE_SERVER_URL;
logger.debug(`Resolved Mirror Url: ${finalUrl}`);
return finalUrl;
} catch (error) {
logger.error('Error getting mirror url: ${error}');
return null;
}
};

0 comments on commit fe2826b

Please sign in to comment.