Skip to content

Commit

Permalink
fix: remove chain name
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Apr 8, 2024
1 parent 43db2a9 commit d420e2a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:
- You are about to drop the column `chain_name` on the `response_codes` table. All the data in the column will be lost.
*/
-- DropIndex
DROP INDEX "response_codes_chain_name_type_idx";

-- AlterTable
ALTER TABLE "response_codes" DROP COLUMN "chain_name";
18 changes: 8 additions & 10 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@ datasource db {
}

model ResponseCode {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
chainName String? @map("chain_name")
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime @updatedAt @db.Timestamptz(3)
type Types
httpResponseCode Int
url String
responseTime Int?
chainId String? @map("chain_id")
priority Int? @default(0)
endpointType EndpointType @default(latest_block)
chainId String? @map("chain_id")
priority Int? @default(0)
endpointType EndpointType @default(latest_block)
provider String?
errorMessage String?
chainPriority Int @default(1)
chainPriority Int @default(1)
@@index([chainName, type])
@@index([type])
@@index([createdAt])
@@index([chainId])
@@index([type])
@@index([httpResponseCode])
@@index([responseTime])
@@index([url])
Expand Down
27 changes: 8 additions & 19 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ async function startIndividualNodePinger(): Promise<void> {
logger.informational('Starting a new iteration of Individual Node Pinger.');
const pinger = Container.get(Pinger.token);

const handlePing = async (url: string, chainId: string, chainName: string | undefined) => {
return pinger.ping(url, chainName, Types.SINGULAR, chainId).catch((error) => {
const handlePing = async (url: string, chainId: string) => {
return pinger.ping(url, Types.SINGULAR, chainId).catch((error) => {
logger.error(`Error pinging ${url} for chainId ${chainId}: ${error.message}`);
return null; // Return a value to keep the array's structure consistent
});
Expand All @@ -72,11 +72,10 @@ async function startIndividualNodePinger(): Promise<void> {

for (const nodeData of jsonData) {
const chainId = nodeData.chainId;
const chainName = nodeData.chainName;
const nodes = nodeData.nodeList;

for (const url of nodes) {
promisesArr.push(handlePing(url, chainId, chainName));
promisesArr.push(handlePing(url, chainId));
}
}

Expand Down Expand Up @@ -126,21 +125,17 @@ async function startSingularPaidNodePinger(): Promise<void> {
return;
}

const chainIdToNameMap = new Map(
jsonData.map((node: { chainId: string; chainName: string }) => [node.chainId, node.chainName]),
);

while (true) {
try {
const startTime = Date.now();
logger.informational('Starting a new iteration of Singular Paid Node Pinger.');
const pinger = Container.get(Pinger.token); // Assuming Pinger is set up in Container

const handlePing = async (url: string, chainId: string, chainName: string, provider: string | null) => {
const handlePing = async (url: string, chainId: string, provider: string | null) => {
return pinger
.ping(
url,
chainName,
Types.SINGULAR_PAID,
chainId,
'/cosmos/base/tendermint/v1beta1/blocks/latest',
Expand All @@ -163,14 +158,13 @@ async function startSingularPaidNodePinger(): Promise<void> {
// Here's the critical check
if (!Array.isArray(nodes)) {
logger.error(
`Node list for provider "${provider}" in chain "${nodeData.chainName}" (${chainId}) is not an array.`,
`Node list for provider "${provider}" in chain (${chainId}) is not an array.`,
);
continue; // Skip this iteration
}

const chainName = chainIdToNameMap.get(chainId);
for (const url of nodes) {
promisesArr.push(handlePing(url, chainId, chainName!, provider));
promisesArr.push(handlePing(url, chainId, provider));
}
}
}
Expand Down Expand Up @@ -239,7 +233,7 @@ async function startEcostakePinger(): Promise<void> {
const details = chainDetails as any;
const url = `https://rest.cosmos.directory/${details.chainRegistryPath}`;
arr.push(
pinger.ping(url, details.chainName, Types.ECOSTAKE, details.chainId).catch((error) => {
pinger.ping(url, Types.ECOSTAKE, details.chainId).catch((error) => {
logger.error(`Error pinging ${url} for chainId ${details.chainId}: ${error.message}`);
return null;
}),
Expand Down Expand Up @@ -364,10 +358,6 @@ async function startNMSPinger(nmsRunType: Types): Promise<void> {
return;
}

const chainIdToNameMap = new Map(
jsonData.map((node: { chainId: string; chainName: string }) => [node.chainId, node.chainName]),
);

if (EnvVars.getNodeEnv() === 'test') return;
let promisesArr: Promise<Prisma.ResponseCodeCreateInput>[] = [];
while (true) {
Expand All @@ -381,11 +371,10 @@ async function startNMSPinger(nmsRunType: Types): Promise<void> {
for (let i = 0; i < chainIds.length; i++) {
const chainId = chainIds[i] || '';
const nodes = jsonData[chainId!];
const chainName = chainIdToNameMap.get(chainId);
const urls = await nmsGetNodeURL(nodes, nmsRunType);
urls.forEach(({ url, priority }) => {
promisesArr.push(
pinger.ping(url, chainName, nmsRunType, chainId, '/cosmos/base/tendermint/v1beta1/blocks/latest', priority),
pinger.ping(url, nmsRunType, chainId, '/cosmos/base/tendermint/v1beta1/blocks/latest', priority),
);
});

Expand Down
2 changes: 0 additions & 2 deletions src/pinger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export namespace Pinger {
export class DefaultApi {
async ping(
url: string,
chainName: string | null | undefined = null,
newType: Types = 'ECOSTAKE',
chainId: string,
endpoint = '/cosmos/base/tendermint/v1beta1/blocks/latest',
Expand Down Expand Up @@ -56,7 +55,6 @@ export namespace Pinger {
const endTime = Date.now();
const data: Prisma.ResponseCodeCreateInput = {
type: newType,
chainName: chainName,
httpResponseCode: responseCode,
url: chainUrl,
responseTime: endTime - startTime,
Expand Down

0 comments on commit d420e2a

Please sign in to comment.