Skip to content

Commit

Permalink
fix(history-importer) move check for recent log error to correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrdlt committed Oct 16, 2024
1 parent 6492e40 commit d0310b4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d0310b4

Please sign in to comment.