From 0c88a91ffd0a52452e5f5150cc85a8aee2b7c691 Mon Sep 17 00:00:00 2001 From: amateima <89395931+amateima@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:52:11 +0200 Subject: [PATCH] fix: change block timestamp db type (#139) --- .../src/entities/evm/V3FundsDeposited.ts | 2 +- .../1733407862579-V3FundsDeposited.ts | 20 +++++++++++++++++++ .../src/database/SpokePoolRepository.ts | 8 ++++---- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 packages/indexer-database/src/migrations/1733407862579-V3FundsDeposited.ts diff --git a/packages/indexer-database/src/entities/evm/V3FundsDeposited.ts b/packages/indexer-database/src/entities/evm/V3FundsDeposited.ts index 080f2a2..0718b9c 100644 --- a/packages/indexer-database/src/entities/evm/V3FundsDeposited.ts +++ b/packages/indexer-database/src/entities/evm/V3FundsDeposited.ts @@ -91,5 +91,5 @@ export class V3FundsDeposited { createdAt: Date; @Column({ nullable: true }) - blockTimestamp?: number; + blockTimestamp?: Date; } diff --git a/packages/indexer-database/src/migrations/1733407862579-V3FundsDeposited.ts b/packages/indexer-database/src/migrations/1733407862579-V3FundsDeposited.ts new file mode 100644 index 0000000..24cf8c8 --- /dev/null +++ b/packages/indexer-database/src/migrations/1733407862579-V3FundsDeposited.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class V3FundsDeposited1733407862579 implements MigrationInterface { + name = "V3FundsDeposited1733407862579"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "evm"."v3_funds_deposited" DROP COLUMN "blockTimestamp"`, + ); + await queryRunner.query( + `ALTER TABLE "evm"."v3_funds_deposited" ADD "blockTimestamp" TIMESTAMP`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "evm"."v3_funds_deposited" DROP COLUMN "blockTimestamp"`, + ); + } +} diff --git a/packages/indexer/src/database/SpokePoolRepository.ts b/packages/indexer/src/database/SpokePoolRepository.ts index e9a592c..83fa9dd 100644 --- a/packages/indexer/src/database/SpokePoolRepository.ts +++ b/packages/indexer/src/database/SpokePoolRepository.ts @@ -46,14 +46,14 @@ export class SpokePoolRepository extends dbUtils.BlockchainEventRepository { delete event.updatedRecipient; delete event.updatedOutputAmount; delete event.updatedMessage; - + const blockTimestamp = new Date(blockTimes[event.blockNumber]! * 1000); return { ...event, relayHash: across.utils.getRelayHashFromEvent(event), ...this.formatRelayData(event), quoteTimestamp: new Date(event.quoteTimestamp * 1000), finalised: event.blockNumber <= lastFinalisedBlock, - blockTimestamp: blockTimes[event.blockNumber], + blockTimestamp, }; }); const chunkedEvents = across.utils.chunk(formattedEvents, this.chunkSize); @@ -70,10 +70,10 @@ export class SpokePoolRepository extends dbUtils.BlockchainEventRepository { const result = savedEvents.flat(); // Log the time difference for each deposit event for profiling in datadog - const now = Date.now(); + const now = new Date(); formattedEvents.forEach((event) => { if (event.blockTimestamp === undefined) return; - const timeDifference = now - event.blockTimestamp * 1000; + const timeDifference = now.getTime() - event.blockTimestamp.getTime(); this.logger.debug({ at: "SpokePoolRepository#formatAndSaveV3FundsDepositedEvents", message: "V3FundsDepositedEvent profile",