From d0310b451a8655b3f5ea0959d9b6c51af4a6e6f1 Mon Sep 17 00:00:00 2001 From: Timo Erdelt Date: Wed, 16 Oct 2024 15:18:08 +0200 Subject: [PATCH] fix(history-importer) move check for recent log error to correct place --- ...dity-info-history-importer.service.spec.ts | 4 +-- ...liquidity-info-history-importer.service.ts | 32 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts index b836b3a..6124848 100644 --- a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts +++ b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts @@ -142,7 +142,7 @@ describe('PairLiquidityInfoHistoryImporterService', () => { expect( mockPairLiquidityInfoHistoryErrorDb.getErrorWithinHours, - ).toHaveBeenCalledTimes(5); // Once for pair and 4 times for each inserted event + ).toHaveBeenCalledTimes(8); // Once for pair and 7 times for each (relevant) event log expect(mockPairLiquidityInfoHistoryDb.upsert).toHaveBeenCalledTimes(5); expect( @@ -235,7 +235,7 @@ describe('PairLiquidityInfoHistoryImporterService', () => { expect( mockPairLiquidityInfoHistoryErrorDb.getErrorWithinHours, - ).toHaveBeenCalledTimes(3); // Once for pair and 2 times for each event + ).toHaveBeenCalledTimes(5); // Once for pair and 4 times for each event log expect( mockPairLiquidityInfoHistoryDb.upsert.mock.calls, diff --git a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts index 1d4cbcd..2a38ca8 100644 --- a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts +++ b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts @@ -155,6 +155,22 @@ export class PairLiquidityInfoHistoryImporterService { let numUpserted = 0; for (const current of logsAndEvents) { try { + // If an error occurred for this log recently, skip block + const error = + await this.pairLiquidityInfoHistoryErrorDb.getErrorWithinHours( + pairWithTokens.id, + current.log.block_hash, + current.log.call_tx_hash, + parseInt(current.log.log_idx), + this.WITHIN_HOURS_TO_SKIP_IF_ERROR, + ); + if (error) { + this.logger.log( + `Skipped log with block hash ${current.log.block_hash} tx hash ${current.log.call_tx_hash} and log index ${current.log.log_idx} due to recent error.`, + ); + continue; + } + const succeeding = logsAndEvents[logsAndEvents.indexOf(current) + 1]; @@ -233,22 +249,6 @@ export class PairLiquidityInfoHistoryImporterService { continue; } - // If an error occurred for this log recently, skip block - const error = - await this.pairLiquidityInfoHistoryErrorDb.getErrorWithinHours( - pairWithTokens.id, - current.log.block_hash, - current.log.call_tx_hash, - parseInt(current.log.log_idx), - this.WITHIN_HOURS_TO_SKIP_IF_ERROR, - ); - if (error) { - this.logger.log( - `Skipped log with block hash ${current.log.block_hash} tx hash ${current.log.call_tx_hash} and log index ${current.log.log_idx} due to recent error.`, - ); - continue; - } - // Upsert liquidity await this.pairLiquidityInfoHistoryDb .upsert(liquidityInfo)