Skip to content

Commit

Permalink
get remote manifest if syncing from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
d10r committed Oct 13, 2023
1 parent d3af5b9 commit 0a38697
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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}`);
Expand Down
10 changes: 5 additions & 5 deletions src/config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"]);
Expand All @@ -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;
Expand Down

0 comments on commit 0a38697

Please sign in to comment.