Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecot committed Jun 17, 2024
2 parents 4ee2293 + ce66fbd commit 939aac8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 90 deletions.
10 changes: 6 additions & 4 deletions src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,12 @@ const establishRpcConnection = async (): Promise<RpcConnection> => {
}

const migrateAndFetchDb = async (): Promise<PostgresJsDatabase> => {
// migrations die on timeout at 0015_tan_lockjaw.sql on testnet
// logger.info('Migrating DB...');
// await MigrateDb();
// logger.info('DB migrated.');
if (consts.JSINFO_INDEXER_RUN_MIGRATIONS) {
// migrations die on timeout at 0015_tan_lockjaw.sql on testnet
logger.info('Migrating DB...');
await MigrateDb();
logger.info('DB migrated.');
}
const db = GetJsinfoDb();
logger.info('DB fetched.');
return db;
Expand Down
1 change: 1 addition & 0 deletions src/indexer/indexerConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const JSINFO_INDEXER_EVENT_ATTRIBUTE_VALUE_MAX_LENGTH: number = parseInt(
// lava_provider_bonus_rewards was 600 keys
export const JSINFO_INDEXER_EVENT_ATTRIBUTE_KEY_COUNT_MAX: number = parseInt(GetEnvVar('JSINFO_INDEXER_EVENT_ATTRIBUTE_KEY_COUNT_MAX', "5000"));

export const JSINFO_INDEXER_RUN_MIGRATIONS: boolean = GetEnvVar('JSINFO_INDEXER_RUN_MIGRATIONS', "false").toLowerCase() == "true";
// Checks

// Create the directory if it doesn't exist
Expand Down
86 changes: 0 additions & 86 deletions src/query/handlers/indexHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ export const IndexHandlerOpts: RouteShorthandOptions = {
allSpecs: {
type: 'array',
},
qosData: {
type: 'array'
},
data: {
type: 'array'
}
}
}
}
Expand Down Expand Up @@ -79,24 +73,6 @@ export async function IndexHandler(request: FastifyRequest, reply: FastifyReply)
stakeSum = stakeSumQueryRes[0].stakeSum
}

//
// Get "top" providers
let res4 = await QueryGetJsinfoReadDbInstance().select({
address: JsinfoSchema.aggHourlyrelayPayments.provider,
rewardSum: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.rewardSum})`,
}).from(JsinfoSchema.aggHourlyrelayPayments).
groupBy(JsinfoSchema.aggHourlyrelayPayments.provider).
orderBy(desc(sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.rewardSum})`))
let providersAddrs: string[] = []
res4.map((provider) => {
providersAddrs.push(provider.address!)
})

if (providersAddrs.length == 0) {
reply.code(400).send({ error: 'Providers does not exist' });
return;
}

//
// Get top chains
let topSpecs = await QueryGetJsinfoReadDbInstance().select({
Expand All @@ -117,42 +93,6 @@ export async function IndexHandler(request: FastifyRequest, reply: FastifyReply)
console.log('IndexHandler empty data for topSpecs:: getChains:', getChains, 'topSpecs:', topSpecs);
}

//
// Get graph with 1 day resolution
let mainChartData = {}
if (getChains.length != 0) {
mainChartData = await QueryGetJsinfoReadDbInstance().select({
date: sql<string>`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour}) as mydate`,
chainId: JsinfoSchema.aggHourlyrelayPayments.specId,
cuSum: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.cuSum})`,
relaySum: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`,
rewardSum: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.rewardSum})`,
}).from(JsinfoSchema.aggHourlyrelayPayments).
where(
and(
gt(sql<string>`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour})`, sql<Date>`now() - interval '90 day'`),
inArray(JsinfoSchema.aggHourlyrelayPayments.specId, getChains)
)
).
groupBy(sql`${JsinfoSchema.aggHourlyrelayPayments.specId}`, sql`mydate`).
orderBy(sql`mydate DESC`)
}

//
// QoS graph
let qosDataRaw = await QueryGetJsinfoReadDbInstance().select({
date: sql`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour}) as mydate`,
qosSyncAvg: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.qosSyncAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`,
qosAvailabilityAvg: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.qosAvailabilityAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`,
qosLatencyAvg: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.qosLatencyAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`,
qosSyncExcAvg: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.qosSyncExcAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`,
qosAvailabilityExcAvg: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.qosAvailabilityAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`,
qosLatencyExcAv: sql<number>`sum(${JsinfoSchema.aggHourlyrelayPayments.qosLatencyExcAvg}*${JsinfoSchema.aggHourlyrelayPayments.relaySum})/sum(${JsinfoSchema.aggHourlyrelayPayments.relaySum})`,
}).from(JsinfoSchema.aggHourlyrelayPayments).
where(gt(sql<string>`DATE_TRUNC('day', ${JsinfoSchema.aggHourlyrelayPayments.datehour})`, sql<Date>`now() - interval '90 day'`)).
groupBy(sql`mydate`).
orderBy(sql`mydate DESC`)

return {
height: latestHeight,
datetime: latestDatetime,
Expand All @@ -161,31 +101,5 @@ export async function IndexHandler(request: FastifyRequest, reply: FastifyReply)
rewardSum: rewardSum,
stakeSum: stakeSum,
allSpecs: topSpecs,
qosData: FormatDates(qosDataRaw),
data: addAllChains(adjustRelayLossForMarchWeekendDowntime(FormatDates(mainChartData))),
}
}

function addAllChains(mainChartData) {
const dateSums = {};
mainChartData.forEach(data => {
if (!dateSums[data.date]) {
dateSums[data.date] = { date: data.date, chainId: "All Chains", cuSum: 0, relaySum: 0, rewardSum: null };
}
dateSums[data.date].cuSum += Number(data.cuSum);
dateSums[data.date].relaySum += Number(data.relaySum);
});
const newChartData = Object.values(dateSums);
return mainChartData.concat(newChartData);
}

function adjustRelayLossForMarchWeekendDowntime(mainChartData) {
mainChartData.forEach(data => {
if (data.date === "Mar 2") {
data.relaySum = Number(data.relaySum) * 1.7;
} else if (data.date === "Mar 3") {
data.relaySum = Number(data.relaySum) * 1.6;
}
});
return mainChartData
}

0 comments on commit 939aac8

Please sign in to comment.