Skip to content

Commit

Permalink
fix: profile events storage relatively to insertion timestamp (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
amateima authored Jan 7, 2025
1 parent 3f7c978 commit c31f0e5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
const block = await this.provider.getBlock(blockNumber);
if (!block) {
Expand Down
16 changes: 0 additions & 16 deletions packages/indexer/src/database/SpokePoolRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit c31f0e5

Please sign in to comment.