From c31f0e552f4da14e5561f5fe995dcb4a86e5aa93 Mon Sep 17 00:00:00 2001 From: amateima <89395931+amateima@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:20:50 +0200 Subject: [PATCH] fix: profile events storage relatively to insertion timestamp (#144) --- .../service/SpokePoolIndexerDataHandler.ts | 49 +++++++++++++++++++ .../src/database/SpokePoolRepository.ts | 16 ------ 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/packages/indexer/src/data-indexing/service/SpokePoolIndexerDataHandler.ts b/packages/indexer/src/data-indexing/service/SpokePoolIndexerDataHandler.ts index f40ffddb..d5681936 100644 --- a/packages/indexer/src/data-indexing/service/SpokePoolIndexerDataHandler.ts +++ b/packages/indexer/src/data-indexing/service/SpokePoolIndexerDataHandler.ts @@ -114,7 +114,56 @@ export class SpokePoolIndexerDataHandler implements IndexerDataHandler { ); await this.updateNewDepositsWithIntegratorId(newInsertedDeposits); await this.spokePoolProcessor.process(storedEvents); + this.profileStoreEvents(storedEvents); } + + /** + * Log the time that it took to store the events from the moment they were emitted onchain + * @param events + */ + private profileStoreEvents(events: StoreEventsResult) { + const insertedDeposits = indexerDatabaseUtils.filterSaveQueryResults( + events.deposits, + SaveQueryResultType.Inserted, + ); + + // Log the time difference for each deposit event for profiling in datadog + insertedDeposits.forEach((event) => { + if (event.blockTimestamp === undefined) return; + const timeDifference = + event.createdAt.getTime() - event.blockTimestamp.getTime(); + this.logger.debug({ + at: "SpokePoolIndexerDataHandler#profileStoreEvents", + message: "V3FundsDeposited event profile", + depositId: event.depositId, + originChainId: event.originChainId, + timeDifference, + createdAt: event.createdAt, + blockTimestamp: event.blockTimestamp, + }); + }); + + const insertedFills = indexerDatabaseUtils.filterSaveQueryResults( + events.fills, + SaveQueryResultType.Inserted, + ); + insertedFills.forEach((event) => { + if (event.blockTimestamp === undefined) return; + const timeDifference = + event.createdAt.getTime() - event.blockTimestamp.getTime(); + this.logger.debug({ + at: "SpokePoolIndexerDataHandler#profileStoreEvents", + message: "FilledV3Relay event profile", + depositId: event.depositId, + originChainId: event.originChainId, + destinationChainId: event.destinationChainId, + timeDifference, + createdAt: event.createdAt, + blockTimestamp: event.blockTimestamp, + }); + }); + } + private async getBlockTime(blockNumber: number): Promise { const block = await this.provider.getBlock(blockNumber); if (!block) { diff --git a/packages/indexer/src/database/SpokePoolRepository.ts b/packages/indexer/src/database/SpokePoolRepository.ts index dd123412..0158c71d 100644 --- a/packages/indexer/src/database/SpokePoolRepository.ts +++ b/packages/indexer/src/database/SpokePoolRepository.ts @@ -68,22 +68,6 @@ export class SpokePoolRepository extends dbUtils.BlockchainEventRepository { ), ); const result = savedEvents.flat(); - - // Log the time difference for each deposit event for profiling in datadog - const now = new Date(); - formattedEvents.forEach((event) => { - if (event.blockTimestamp === undefined) return; - const timeDifference = now.getTime() - event.blockTimestamp.getTime(); - this.logger.debug({ - at: "SpokePoolRepository#formatAndSaveV3FundsDepositedEvents", - message: "V3FundsDepositedEvent profile", - depositId: event.depositId, - chainId: event.originChainId, - timeDifference, - now, - blockTimestamp: event.blockTimestamp, - }); - }); return result; }