Skip to content

Commit

Permalink
chore: add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
meomeocoj committed Aug 30, 2024
1 parent f898a6f commit 4adc486
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
38 changes: 29 additions & 9 deletions packages/cw-to-ton/src/PacketProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { SyncDataOptions } from "@oraichain/cosmos-rpc-sync";
import {
AckPacketWithBasicInfo,
TransferPacketWithBasicInfo,
} from "./@types/interfaces/cosmwasm";
import { Config } from "./config";
import {
createCosmosBridgeWatcher,
CosmosProofHandler,
} from "@src/services/cosmos.service";
import { DuckDb } from "./services/duckdb.service";
import { CosmosProofHandler } from "@src/services/cosmos.service";
import { CosmosBlockOffset } from "./models/block-offset";
import { sleep } from "./utils";
import { ACK } from "./dtos/packets/AckPacket";
Expand All @@ -31,7 +25,6 @@ export class PacketProcessor {
cosmosBlockOffset: CosmosBlockOffset;
cosmosProofHandler: CosmosProofHandler;
tonHandler: TonHandler;

pollingInterval: number;
// Memory packets
lock: boolean = false;
Expand Down Expand Up @@ -70,11 +63,25 @@ export class PacketProcessor {
}

async run() {
logger.info("PacketProcessor:Start running");
while (true) {
try {
this.lock = true;
logger.debug(
`PacketProcessor:Before pop all pending packets, ${JSON.stringify(this.getPendingRelayPackets())}`
);
logger.debug(
`PacketProcessor:Before pop all pending packets, ${JSON.stringify(this.getPendingAckSuccessPackets())}`
);
const pendingPackets = this._popAllPendingRelayPackets();
const pendingAckSuccessPacket = this._popAllPendingAckSuccessPackets();
logger.debug(
`PacketProcessor:After pop all pending packets, ${JSON.stringify(this.getPendingRelayPackets())}`
);
logger.debug(
`PacketProcessor:After pop all pending packets, ${JSON.stringify(this.getPendingAckSuccessPackets())}`
);

this.lock = false;
this.processingPackets = [
...pendingPackets,
Expand All @@ -99,6 +106,15 @@ export class PacketProcessor {
latestLightClientHeight,
neededUpdateHeight
);
logger.debug(
`PacketProcessor:heightForQueryProof ${heightForQueryProof}`
);
logger.debug(
`PacketProcessor:neededUpdateHeight ${neededUpdateHeight}`
);
logger.debug(
`PacketProcessor:latestLightClientHeight ${latestLightClientHeight}`
);

if (finalUpdateHeight === neededUpdateHeight) {
const clientData =
Expand Down Expand Up @@ -127,13 +143,14 @@ export class PacketProcessor {

if (packetProof.length !== this.processingPackets.length) {
throw new Error(
"Packet proof length not match with processing packets length"
"`PacketProcessor:Packet proof length not match with processing packets length"
);
}

// Get proof from minProvenHeight
while (this.processingPackets.length > 1) {
const packet = this.processingPackets.shift();
logger.debug(`PacketProcessor:packet.data ${packet.data}`);
const proof = packetProof.shift();
const data = packet.data;
// TODO: should change to highload_wallet contract
Expand All @@ -143,6 +160,9 @@ export class PacketProcessor {
);
}
await this.cosmosBlockOffset.updateBlockOffset(finalUpdateHeight);
logger.info(
`PacketProcessor:Update block offset to ${finalUpdateHeight}`
);
} catch (error) {
logger.error(`PacketProcessor:Error when run:${error}`);
throw new Error(`PacketProcessor:Error when run:${error}`);
Expand Down
2 changes: 2 additions & 0 deletions packages/cw-to-ton/src/services/ton.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class TonHandler {
};

async updateLightClient(clientData: LightClientData) {
logger.debug(`TonHandler:updateLightClient:${JSON.stringify(clientData)}`);
const header = deserializeHeader(clientData.header);
const height = BigInt(header.height);
await retry(
Expand Down Expand Up @@ -124,6 +125,7 @@ export class TonHandler {
packet: IntoCell,
proofs: ExistenceProof[]
) {
logger.debug(`TonHandler:sendPacket:${JSON.stringify(packet)}`);
try {
const seqno = await retry(async () => {
try {
Expand Down

0 comments on commit 4adc486

Please sign in to comment.