Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from paritytech/timescasledb-history
Browse files Browse the repository at this point in the history
moved config.json out of src
  • Loading branch information
gilles437 authored Aug 19, 2022
2 parents fcc304b + 1cb0c5b commit 6c43f00
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
7 changes: 4 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PORT=8080
WS_PROVIDER=ws://localhost:9999
TSDB_CONN=''
PORT=8000
TSDB_CONN='postgres://<postgres user>:<postgres password>@localhost:5432/tsdb'
CONFIG_FULL_PATH='<the full path of config.json>'

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ https://grafana.com/docs/grafana/latest/setup-grafana/installation/debian/
```sh
PORT=8000
TSDB_CONN='postgres://<postgres user>:<postgres password>@localhost:5432/tsdb'
CONFIG_FULL_PATH='<the full path of config.json>'
```
PORT is the prometheus connection port corresponding to your installation.

TSDB_CONN is the timescaledb connection string
TSDB_CONN is the timescaledb connection string .

CONFIG_FULL_PATH is the full path of the config.json file.

If you are not using TimescaleDB, leave it empty.

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global:
scrape_interval: 1s
scrape_interval: 6s

scrape_configs:
- job_name: runtime
Expand Down
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import { SystemExporter, BalancesExporter, XCMTransfersExporter, StakingMinerAcc
import { getParachainLoadHistoryParams } from './utils';
import { logger } from "./logger";
//import parachains from "./parachains.json";
import parachainsList from "./config.json";
//import parachainsList from "../config.json";
import { DEFAULT_TIMEOUT, getTimeOfBlock, isPalletRequiredByHistoryConfig, getDistanceBetweenBlocks } from './utils'


config();
const configFullPath = process.env.CONFIG_FULL_PATH
const fs = require('fs');
let parachainsListRaw = fs.readFileSync(configFullPath);
const parachainsList = JSON.parse(parachainsListRaw);

const parachains = parachainsList.rpcs;

Expand Down Expand Up @@ -58,11 +63,11 @@ async function main() {
const api = await ApiPromise.create({ provider });
const chainName = await (await api.rpc.system.chain()).toString();

let [distanceBetweenBlocks, startingBlock, endingBlock, pallets] = getParachainLoadHistoryParams(chain.toString())
let [distanceBetweenBlocks, startingBlock, endingBlock, pallets] = getParachainLoadHistoryParams(chain)
distanceBetweenBlocks = distanceBetweenBlocks.valueOf();

startingBlock = startingBlock.valueOf();
endingBlock = endingBlock.valueOf();
//gilles removed valueof
startingBlock = startingBlock;
endingBlock = endingBlock;
const palletsArr = pallets.split(',');

const startingBlockHash = await api.rpc.chain.getBlockHash(startingBlock);
Expand Down
29 changes: 21 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import BN from "bn.js";
import { ApiDecoration } from "@polkadot/api/types";
import parachainsHistory from './config.json'
//import parachainsHistory from './config.json'
import parachainsids from "./parachains-ids.json";
import { logger } from "./logger";
import { ApiPromise } from "@polkadot/api";
import { config } from "dotenv";


config();
const configFullPath = process.env.CONFIG_FULL_PATH
const fs = require('fs');
let parachainsHistoryRaw = fs.readFileSync(configFullPath);
let parachainsHistory = JSON.parse(parachainsHistoryRaw);

const parachainsLoadHistory = parachainsHistory.history;

Expand Down Expand Up @@ -71,21 +79,26 @@ export function getParachainLoadHistoryParams(chain: string) {

let i = 0;

for (const [key, value] of Object.entries(parachainsLoadHistory)) {
if (chain == value.chain) {
const startingBlock = (value.startingBlock);
const endingBlock = value.endingBlock;
const pallets = value.pallets;
const distanceBetweenBlocks = value.distanceBetweenBlocks;
for (let record of parachainsLoadHistory) {

console.log(record.startingBlock, record.distanceBetweenBlocks)

if (chain == record.chain) {
const startingBlock = (record.startingBlock);
const endingBlock = record.endingBlock;
const pallets = record.pallets;
const distanceBetweenBlocks = record.distanceBetweenBlocks;
if ((startingBlock - endingBlock) % 100 != 0) {
logger.debug(`ERROR!, exit, (starting block - ending block) must be multiple of 100 in config.json`);
return [{}, 0, 0, ""] as const;
}
logger.debug(`found record for loading historical data for chain ${value.chain}, ${pallets}, starting at #${startingBlock}, ending at #${endingBlock}`);
logger.debug(`found record for loading historical data for chain ${record.chain}, ${pallets}, starting at #${startingBlock}, ending at #${endingBlock}`);
return [distanceBetweenBlocks, startingBlock, endingBlock, pallets] as const;
}
i++;

}

logger.debug(`no parachain settings for chain ${chain} config.json`);
return [{}, 0, 0, ""] as const;

Expand Down

0 comments on commit 6c43f00

Please sign in to comment.