Skip to content

Commit

Permalink
fix: change block timestamp db type (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
amateima authored Dec 20, 2024
1 parent 7dbf691 commit 0c88a91
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ export class V3FundsDeposited {
createdAt: Date;

@Column({ nullable: true })
blockTimestamp?: number;
blockTimestamp?: Date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class V3FundsDeposited1733407862579 implements MigrationInterface {
name = "V3FundsDeposited1733407862579";

public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
await queryRunner.query(
`ALTER TABLE "evm"."v3_funds_deposited" DROP COLUMN "blockTimestamp"`,
);
}
}
8 changes: 4 additions & 4 deletions packages/indexer/src/database/SpokePoolRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
Expand Down

0 comments on commit 0c88a91

Please sign in to comment.