Skip to content

Commit

Permalink
chore: Logs cleanup (#124)
Browse files Browse the repository at this point in the history
* logging upgrades

* remove comments

* chore: release 1.0.0

Release-As: 1.0.0

---------

Co-authored-by: MakMuftic <[email protected]>
  • Loading branch information
MakMuftic and MakMuftic authored Oct 24, 2023
1 parent 8237f64 commit 3567e51
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/controllers/TransfersController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const TransfersController = {

void reply.status(200).send(transfersResult)
} catch (e) {
logger.error("Error occured when fetching all transfers.", e)
logger.error("Error occurred when fetching all transfers.", e)
void reply.status(500)
}
},
Expand All @@ -52,7 +52,7 @@ export const TransfersController = {
if (e instanceof NotFound) {
void reply.status(404)
} else {
logger.error("Error occured when fetching transfer by ID.", e)
logger.error("Error occurred when fetching transfer by ID.", e)
void reply.status(500)
}
}
Expand All @@ -68,7 +68,7 @@ export const TransfersController = {
if (e instanceof NotFound) {
void reply.status(404)
} else {
logger.error("Error occured when fetching transfer by transaction hash.", e)
logger.error("Error occurred when fetching transfer by transaction hash.", e)
void reply.status(500)
}
}
Expand All @@ -90,7 +90,7 @@ export const TransfersController = {

void reply.status(200).send(transfers)
} catch (e) {
logger.error("Error occured when fetching transfers by sender address.", e)
logger.error("Error occurred when fetching transfers by sender address.", e)
void reply.status(500)
}
},
Expand Down
6 changes: 2 additions & 4 deletions src/indexer/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const getSharedConfig = async (url: string): Promise<SharedConfig> => {
const response = await fetch(url)
return (await response.json()) as SharedConfig
} catch (e) {
logger.error(`Failed to fecth config for ${process.env.STAGE || ""}`, e)
logger.error(`Failed to fetch config for ${process.env.STAGE || ""}`, e)
return Promise.reject(e)
}
}
Expand All @@ -95,10 +95,8 @@ export const getSsmDomainConfig = (): Map<number, string> => {
export const getDomainsToIndex = (domains: Domain[]): Domain[] => {
const parsedResponse = JSON.parse(process.env.RPC_URL_CONFIG!) as RpcUrlConfig

const domainsToUse = domains.filter(domain => {
return domains.filter(domain => {
const domainToIndex = parsedResponse.find(rpcData => rpcData.id === domain.id)
return domainToIndex !== undefined
})

return domainsToUse
}
18 changes: 8 additions & 10 deletions src/indexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ init()
initData.app
.close()
.then(() => {
logger.debug("Server closed.")
logger.warning("Server closed.")
})
.catch(err => {
logger.error("Error occurred during server closing: ", err)
Expand All @@ -48,7 +48,7 @@ init()
prisma
.$disconnect()
.then(() => {
logger.debug("Database connection closed.")
logger.warning("Database connection closed.")
})
.catch(err => logger.error("Error occurred during database closing: ", err))

Expand All @@ -58,12 +58,12 @@ init()

for (const domainIndexer of initData.domainIndexers) {
domainIndexer.listenToEvents().catch(reason => {
logger.error("Failed listening to events because of: ", reason)
logger.error("Error occurred while listening to events: ", reason)
})
}
})
.catch(reason => {
logger.error("Failed to initialize app because of: ", reason)
logger.error("Error occurred on app initialization: ", reason)
})

async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: FastifyInstance }> {
Expand Down Expand Up @@ -97,7 +97,7 @@ async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: Fast
for (const domain of domainsToIndex) {
const rpcURL = rpcUrlConfig.get(domain.id)
if (!rpcURL) {
logger.error(`local domain is not defined for the domain: ${domain.id}`)
logger.error(`Local domain is not defined for the domain: ${domain.id}`)
continue
}

Expand All @@ -118,8 +118,7 @@ async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: Fast
await substrateIndexer.init(rpcURL)
domainIndexers.push(substrateIndexer)
} catch (err) {
logger.error(`error on domain: ${domain.id}... skipping`)
continue
logger.error(`Error on domain: ${domain.id}... skipping`)
}
} else if (domain.type == DomainTypes.EVM) {
try {
Expand All @@ -139,11 +138,10 @@ async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: Fast
)
domainIndexers.push(evmIndexer)
} catch (err) {
logger.error(`error on domain: ${domain.id}... skipping`)
continue
logger.error(`Error on domain: ${domain.id}... skipping`)
}
} else {
logger.error(`unsuported type: ${JSON.stringify(domain)}`)
logger.error(`Unsupported type: ${JSON.stringify(domain)}`)
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/indexer/services/evmIndexer/evmIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ SPDX-License-Identifier: LGPL-3.0-only
import { Domain, EvmResource, SharedConfig } from "indexer/config"
import { ethers } from "ethers"

import winston from "winston"
import { sleep } from "../../utils/substrate"
import { saveDepositLogs, saveFailedHandlerExecutionLogs, saveFeeLogs, saveProposalExecutionLogs } from "../../utils/evm"
import DepositRepository from "../../repository/deposit"
import TransferRepository from "../../repository/transfer"
import ExecutionRepository from "../../repository/execution"
import DomainRepository from "../../repository/domain"
import FeeRepository from "../../repository/fee"
import { logger } from "../../../utils/logger"
import { logger as rootLogger } from "../../../utils/logger"
import AccountRepository from "../../repository/account"
import CoinMarketCapService from "../coinmarketcap/coinmarketcap.service"
import { OfacComplianceService } from "../ofac"
Expand All @@ -39,6 +40,7 @@ export class EvmIndexer {
private accountRepository: AccountRepository
private coinMarketCapService: CoinMarketCapService
private sharedConfig: SharedConfig
private logger: winston.Logger

constructor(
domain: Domain,
Expand Down Expand Up @@ -68,6 +70,10 @@ export class EvmIndexer {
this.accountRepository = accountRepository
this.coinMarketCapService = coinMarketCapServiceInstance
this.sharedConfig = sharedConfig
this.logger = rootLogger.child({
domain: domain.name,
domainID: domain.id,
})
}

public stop(): void {
Expand All @@ -81,7 +87,7 @@ export class EvmIndexer {
currentBlock = lastIndexedBlock + 1
}

logger.info(`Starting querying blocks for events on ${this.domain.name}, domainID: ${this.domain.id} from ${currentBlock}`)
this.logger.info(`Starting querying for events from block: ${currentBlock}`)

while (!this.stopped) {
try {
Expand All @@ -95,14 +101,13 @@ export class EvmIndexer {
if (currentBlock + this.pastEventsQueryInterval > latestBlock) {
queryInterval = this.eventsQueryInterval
}
this.logger.debug(`Indexing block ${currentBlock}`)
await this.saveEvents(currentBlock, currentBlock + queryInterval)

logger.info(`indexed block on ${this.domain.name}: ${currentBlock}, domainID: ${this.domain.id}`)
await this.domainRepository.updateBlock(currentBlock.toString(), this.domain.id)

currentBlock += queryInterval
} catch (error) {
logger.error(`Failed to process events for block ${currentBlock} for domain ${this.domain.id}:`, error)
this.logger.error(`Failed to process events for block ${currentBlock}:`, error)
await sleep(BLOCK_TIME)
}
}
Expand All @@ -114,7 +119,7 @@ export class EvmIndexer {
return
}

logger.info(`Found past events on ${this.domain.name} in block range [${startBlock}-${endBlock}]`)
this.logger.info(`Found past events in block range [${startBlock}-${endBlock}]`)
const decodedLogs = await decodeLogs(this.provider, this.domain, logs, this.resourceMap, this.domains)

const transferMap = new Map<string, string>()
Expand Down
15 changes: 10 additions & 5 deletions src/indexer/services/substrateIndexer/substrateIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ SPDX-License-Identifier: LGPL-3.0-only
*/
import { ApiPromise, WsProvider } from "@polkadot/api"
import FeeRepository from "indexer/repository/fee"
import winston from "winston"
import { Domain, SharedConfig, SubstrateResource } from "../../config"
import DomainRepository from "../../repository/domain"
import { logger } from "../../../utils/logger"
import { logger as rootLogger } from "../../../utils/logger"
import ExecutionRepository from "../../../indexer/repository/execution"
import DepositRepository from "../../../indexer/repository/deposit"
import TransferRepository from "../../../indexer/repository/transfer"
Expand All @@ -30,6 +31,7 @@ export class SubstrateIndexer {
private accountRepository: AccountRepository
private coinMarketCapService: CoinMarketCapService
private sharedConfig: SharedConfig
private logger: winston.Logger

constructor(
domainRepository: DomainRepository,
Expand All @@ -53,6 +55,10 @@ export class SubstrateIndexer {
this.accountRepository = accountRepository
this.coinMarketCapService = coinmarketcapService
this.sharedConfig = sharedConfig
this.logger = rootLogger.child({
domain: domain.name,
domainID: domain.id,
})
}

public async init(rpcUrl: string): Promise<void> {
Expand All @@ -73,7 +79,7 @@ export class SubstrateIndexer {
currentBlock = lastIndexedBlock + 1
}

logger.info(`Starting querying on ${this.domain.name} from ${currentBlock}`)
this.logger.info(`Starting querying for events from block: ${currentBlock}`)

while (!this.stopped) {
try {
Expand All @@ -83,6 +89,7 @@ export class SubstrateIndexer {
await sleep(BLOCK_TIME)
continue
}
this.logger.debug(`Indexing block ${currentBlock}`)

await saveEvents(
currentBlockHash,
Expand All @@ -98,13 +105,11 @@ export class SubstrateIndexer {
this.coinMarketCapService,
this.sharedConfig,
)

await this.domainRepository.updateBlock(currentBlock.toString(), this.domain.id)
logger.info(`indexed block on ${this.domain.name}: ${currentBlock}, domainID: ${this.domain.id}`)

currentBlock += this.eventsQueryInterval
} catch (error) {
logger.error(`Failed to process events for block ${currentBlock} for domain ${this.domain.id}:`, error)
this.logger.error(`Failed to process events for block ${currentBlock}:`, error)
await sleep(BLOCK_TIME)
}
}
Expand Down

0 comments on commit 3567e51

Please sign in to comment.