Skip to content

Commit

Permalink
testing prod
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Aug 17, 2024
1 parent 3946122 commit a9c80cc
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions server/api/vts/health.get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { max, count, } from 'drizzle-orm';
import { NimiqRPCClient } from 'nimiq-rpc-client-ts';
import { Range, getRange } from 'nimiq-vts';
import { getMissingEpochs } from '~~/server/database/utils';

export enum HealthFlag {
MissingEpochs = 'missing-epochs',
Expand Down Expand Up @@ -31,8 +29,8 @@ export default defineEventHandler(async (event) => {
if (!url)
throw new Error('Missing RPC URL in runtime config')
console.log('RPC URL:', url)
const rpcClient = new NimiqRPCClient(new URL(url))
console.log('RPC Client:', rpcClient)
// const rpcClient = new NimiqRPCClient(new URL(url))
// console.log('RPC Client:', rpcClient)

// Get the latest epoch number in the activity table
const latestActivityBlock = await useDrizzle()
Expand All @@ -42,10 +40,10 @@ export default defineEventHandler(async (event) => {
.then((row) => row?.epoch ?? -1);
console.log('Latest Activity Block:', latestActivityBlock)

const { data: latestFetchedEpoch, error: errorLatestFetchedEpoch } = await rpcClient.policy.getEpochAt(latestActivityBlock)
if (errorLatestFetchedEpoch)
throw errorLatestFetchedEpoch;
console.log('Latest Fetched Epoch:', latestFetchedEpoch)
// const { data: latestFetchedEpoch, error: errorLatestFetchedEpoch } = await rpcClient.policy.getEpochAt(latestActivityBlock)
// if (errorLatestFetchedEpoch)
// throw errorLatestFetchedEpoch;
// console.log('Latest Fetched Epoch:', latestFetchedEpoch)

// Get the total number of validators
const totalValidators = await useDrizzle()
Expand All @@ -64,40 +62,40 @@ export default defineEventHandler(async (event) => {
console.log('Fetched Epochs:', fetchedEpochs)


const { data: headBlockNumber, error: errorHeadBlockNumber } = await rpcClient.blockchain.getBlockNumber()
if (errorHeadBlockNumber)
throw errorHeadBlockNumber;
console.log('Head Block Number:', headBlockNumber)
const { data: currentEpoch, error: errorCurrentEpoch } = await rpcClient.blockchain.getEpochNumber()
if (errorCurrentEpoch)
throw errorCurrentEpoch;
console.log('Current Epoch:', currentEpoch)
// const { data: headBlockNumber, error: errorHeadBlockNumber } = await rpcClient.blockchain.getBlockNumber()
// if (errorHeadBlockNumber)
// throw errorHeadBlockNumber;
// console.log('Head Block Number:', headBlockNumber)
// const { data: currentEpoch, error: errorCurrentEpoch } = await rpcClient.blockchain.getEpochNumber()
// if (errorCurrentEpoch)
// throw errorCurrentEpoch;
// console.log('Current Epoch:', currentEpoch)

const range = await getRange(rpcClient);
console.log('Range:', range)
const missingEpochs = await getMissingEpochs(range);
console.log('Missing Epochs:', missingEpochs)
// const range = await getRange(rpcClient);
// console.log('Range:', range)
// const missingEpochs = await getMissingEpochs(range);
// console.log('Missing Epochs:', missingEpochs)

const isSynced = missingEpochs.length === 0;
console.log('Is Synced:', isSynced)
// const isSynced = missingEpochs.length === 0;
// console.log('Is Synced:', isSynced)
const flags: HealthFlag[] = []
if (!isSynced) flags.push(HealthFlag.MissingEpochs)
// if (!isSynced) flags.push(HealthFlag.MissingEpochs)

// Combine all the data into a HealthStatus object
const healthStatus: HealthStatus = {
latestFetchedEpoch,
totalValidators,
headBlockNumber,
currentEpoch,
range,
missingEpochs,
isSynced,
flags,
fetchedEpochs,
};
console.log('Health Status:', healthStatus)
// const healthStatus: HealthStatus = {
// latestFetchedEpoch,
// totalValidators,
// headBlockNumber,
// currentEpoch,
// range,
// missingEpochs,
// isSynced,
// flags,
// fetchedEpochs,
// };
// console.log('Health Status:', healthStatus)

// Return the health status
setResponseStatus(event, 200);
return healthStatus;
return { status: 'ok' } as const;
});

0 comments on commit a9c80cc

Please sign in to comment.