From 0a38697cdfa94335d4da03aad68444e76f1a7bb7 Mon Sep 17 00:00:00 2001 From: didi Date: Fri, 13 Oct 2023 14:33:20 +0200 Subject: [PATCH] get remote manifest if syncing from scratch --- src/app.js | 4 ++-- src/config/configuration.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app.js b/src/app.js index cef5fcc3..8855a9d3 100644 --- a/src/app.js +++ b/src/app.js @@ -179,9 +179,10 @@ class App { this.notifier.sendNotification(`Sentinel started at ${new Date()}`); // connect to provided rpc await this.client.connect(); + const dbFileExist = this.utils.fileExist(this.config.DB); // if we are running tests don't try to load network information if (!this.config.RUN_TEST_ENV) { - const error = await this.config.loadNetworkInfo(await this.client.getChainId()); + const error = await this.config.loadNetworkInfo(await this.client.getChainId(), dbFileExist); if(error !== undefined) { this.logger.warn(error); } @@ -191,7 +192,6 @@ class App { this.notifier.sendNotification(`RPC connected with chainId ${await this.client.getChainId()}, account ${this.client.agentAccounts?.address} has balance ${this.client.agentAccounts ? wad4human(await this.client.getAccountBalance()) : "N/A"}`); //check conditions to decide if getting snapshot data - const dbFileExist = this.utils.fileExist(this.config.DB); if ((!dbFileExist || this.config.COLD_BOOT) && this.config.FASTSYNC && this.config.CID) { this.logger.info(`getting snapshot from ${this.config.IPFS_GATEWAY + this.config.CID}`); diff --git a/src/config/configuration.js b/src/config/configuration.js index fc933364..63be7f84 100644 --- a/src/config/configuration.js +++ b/src/config/configuration.js @@ -109,7 +109,7 @@ class Config { this.POLLING_INTERVAL = process.env.POLLING_INTERVAL * 1000 || 30000; this.BLOCK_OFFSET = process.env.BLOCK_OFFSET || 12; this.MAX_TX_NUMBER = process.env.MAX_TX_NUMBER || 100; - this.NO_REMOTE_MANIFEST = this._parseToBool(process.env.NO_REMOTE_MANIFEST, true); + this.NO_REMOTE_MANIFEST = this._parseToBool(process.env.NO_REMOTE_MANIFEST, false); } _parseToBool(value, defaultValue = false) { @@ -130,13 +130,13 @@ class Config { return Array.from(new Set(array.map(x => x.toLowerCase()))).length !== array.length; } - async getManifestCIDAndNetworkType (chainId) { + async getManifestCIDAndNetworkType (chainId, dbFileExist) { let schemaVersion = Number(localManifest["schema-version"]); let cid = localManifest.networks[chainId]?.cid; let networkType = localManifest.networks[chainId]?.network_type; let returnError; const manifestUrl = "https://raw.githubusercontent.com/superfluid-finance/superfluid-sentinel/master/manifest.json"; - if (!this.NO_REMOTE_MANIFEST) { + if (!dbFileExist && !this.NO_REMOTE_MANIFEST) { try { const response = await axios.get(manifestUrl); const remoteManifestSchemaVersion = Number(response?.data["schema-version"]); @@ -156,14 +156,14 @@ class Config { return { cid, networkType, schemaVersion, returnError }; } - async loadNetworkInfo (chainId) { + async loadNetworkInfo (chainId, dbFileExist) { const network = metadata.filter(x => x.chainId === Number(chainId))[0]; if(network === undefined) { throw Error(`Config.loadNetworkInfo(): unknown chainId: ${chainId}`); } const contractsV1 = network.contractsV1 || {}; this.EPOCH_BLOCK = network.startBlockV1 || 0; - const { cid, networkType, schemaVersion, returnError } = await this.getManifestCIDAndNetworkType(chainId); + const { cid, networkType, schemaVersion, returnError } = await this.getManifestCIDAndNetworkType(chainId, dbFileExist); this.CID = cid; this.NETWORK_TYPE = networkType; this.SCHEMA_VERSION = schemaVersion;