diff --git a/src/datalayer/persistance.js b/src/datalayer/persistance.js index 17331f05..84ec71ba 100644 --- a/src/datalayer/persistance.js +++ b/src/datalayer/persistance.js @@ -6,6 +6,8 @@ import request from 'request-promise'; import os from 'os'; import { getConfig } from '../utils/config-loader'; import { decodeHex } from '../utils/datalayer-utils'; +import fullNode from './fullNode'; +import { publicIpv4 } from 'public-ip'; import { logger } from '../config/logger.cjs'; @@ -259,6 +261,13 @@ export const subscribeToStoreOnDataLayer = async (storeId) => { if (Object.keys(data).includes('success') && data.success) { logger.info(`Successfully Subscribed: ${storeId}`); + + const chiaConfig = fullNode.getChiaConfig(); + await addMirror( + storeId, + `http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`, + ); + return data; } @@ -321,7 +330,7 @@ export const getRootDiff = async (storeId, root1, root2) => { } }; -export const addMirror = async (storeId, url) => { +const _addMirror = async (storeId, url) => { const options = { url: `${rpcUrl}/add_mirror`, body: JSON.stringify({ @@ -349,3 +358,5 @@ export const addMirror = async (storeId, url) => { return false; } }; + +export const addMirror = _addMirror; diff --git a/src/datalayer/syncService.js b/src/datalayer/syncService.js index 5bb13f3a..b84d3724 100644 --- a/src/datalayer/syncService.js +++ b/src/datalayer/syncService.js @@ -196,6 +196,7 @@ const getSubscribedStoreData = async ( if (!alreadySubscribed) { const response = await subscribeToStoreOnDataLayer(storeId); + if (!response || !response.success) { if (!response) { logger.debug( diff --git a/src/datalayer/writeService.js b/src/datalayer/writeService.js index b58d068f..6d641b04 100644 --- a/src/datalayer/writeService.js +++ b/src/datalayer/writeService.js @@ -25,6 +25,7 @@ const createDataLayerStore = async () => { `Created storeId: ${storeId}, waiting for this to be confirmed on the blockchain.`, ); await waitForStoreToBeConfirmed(storeId); + const chiaConfig = fullNode.getChiaConfig(); await dataLayer.addMirror( storeId,