Skip to content

Commit

Permalink
Disable peptide query when juno has no data
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi committed Jul 30, 2024
1 parent 97e7727 commit 1c78851
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/handlers/packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { Block, Context, Log } from '../utils/types'
import { getDispatcherClientName, getDispatcherType, packetToSender } from "./helpers";
import { logger } from "../utils/logger";
import { In } from "typeorm";
import { TmClient } from "./tmclient";
import { IndexedTx } from "@cosmjs/stargate";
import { SearchTxQuery } from "@cosmjs/stargate/build/search";
import { getCosmosPolymerData, PolymerData } from "./cosmosIndexer";
import { CATCHUP_ERROR_LIMIT } from "../chains/constants";
import {Promise as Bluebird} from "bluebird";
import { Promise as Bluebird } from "bluebird";

export function handleSendPacket(block: Block, log: Log, portPrefix: string, uchEventSender: string): models.SendPacket {
let event = dispatcher.events.SendPacket.decode(log)
Expand Down Expand Up @@ -309,25 +307,7 @@ async function getPolymerData(query: SearchTxQuery, eventType: string): Promise<
return polymerData
}

const stargateClient = await TmClient.getStargate();

let txs: IndexedTx[] = []
try {
txs = await stargateClient.searchTx(query)
} catch (e) {
throw new Error(`Polymer tx search failed ${e}`)
}

if (txs.length > 1) {
throw new Error(`Multiple txs found during search`);
}

if (txs.length == 0) {
console.log(query)
throw new Error(`No polymer data found in peptide for ${eventType}`)
}

return txs[0]
throw new Error(`No polymer data found in juno for ${eventType} with query parameters: ${JSON.stringify(query, (key, value) => typeof value === 'bigint' ? value.toString() : value)}`)
}

async function updateSendToRecvPolymerGas(packet: Packet, ctx: Context) {
Expand Down Expand Up @@ -386,7 +366,12 @@ async function addCatchupErrorsToPackets(packets: Packet[], ctx: Context) {

for (const packet of packets) {
if (!packet.catchupError) {
packet.catchupError = new PacketCatchUpError({id: packet.id, packet: packet, sendToRecvPolymerGas: 0, sendToAckPolymerGas: 0})
packet.catchupError = new PacketCatchUpError({
id: packet.id,
packet: packet,
sendToRecvPolymerGas: 0,
sendToAckPolymerGas: 0
})
catchupErrors.push(packet.catchupError)
}
}
Expand Down Expand Up @@ -436,7 +421,7 @@ export async function packetMetrics(packetIds: string[], ctx: Context, concurren
await updateSendToRecvPolymerGas(packet, ctx);
sendPackets.push(packet.sendPacket)
} catch (e) {
ctx.log.error(`Error updating sendToRecvPolymerGas for ${packet.id} ${e}`)
ctx.log.error(`Error updating sendToRecvPolymerGas for ${packet.id}\n${e}`)
packet.catchupError!.sendToRecvPolymerGas += 1
catchUpErrors.add(packet.catchupError!);
}
Expand All @@ -447,7 +432,7 @@ export async function packetMetrics(packetIds: string[], ctx: Context, concurren
await updateSendToAckPolymerGas(packet, ctx);
writeAckPackets.push(packet.writeAckPacket)
} catch (e) {
ctx.log.error(`Error updating sendToAckPolymerGas for ${packet.id} ${e}`)
ctx.log.error(`Error updating sendToAckPolymerGas for ${packet.id}\n${e}`)
packet.catchupError!.sendToAckPolymerGas += 1
catchUpErrors.add(packet.catchupError!);
}
Expand Down

0 comments on commit 1c78851

Please sign in to comment.