Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: profile events storage relatively to insertion timestamp #144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the two async functions above this be called in parallel?

}

/**
* 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,
});
});
Comment on lines +130 to +144
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC would it make sense to spot-check a few of these values? Since this is an O(N) operation, it could add noticeable milliseconds to the process, and it seems worth optimizing to shave down execution time as much as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point we might reduce the number of logs, yes. I will introduce an ENV var to disable this while doing large backfills


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
Loading