From 33eaa81c48ca5848beedde1ea39611c3d8a31827 Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Fri, 30 Aug 2024 18:38:45 +0200 Subject: [PATCH] chore: suggested pr changes Signed-off-by: Gustavo Inacio --- .../src/allocations/__tests__/tap.test.ts | 8 +++----- .../indexer-common/src/allocations/query-fees.ts | 15 ++++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/indexer-common/src/allocations/__tests__/tap.test.ts b/packages/indexer-common/src/allocations/__tests__/tap.test.ts index e75f2f793..b644ba528 100644 --- a/packages/indexer-common/src/allocations/__tests__/tap.test.ts +++ b/packages/indexer-common/src/allocations/__tests__/tap.test.ts @@ -151,7 +151,7 @@ describe('TAP', () => { timeout, ) - test('should revert the rav request', async () => { + test('`revertRavsRedeemed` should revert RAV redeem status in DB only if older than subgraph last block', async () => { // we have a redeemed non-final rav in our database const nowSecs = Math.floor(Date.now() / 1000) // redeemed rav but non-final @@ -234,10 +234,8 @@ describe('TAP', () => { expect(lastRedeemedRavs).toEqual([]) }) - test('should not revert the rav request, allocation_id not in the list ', async () => { - // we have a redeemed non-final rav in our database + test('revertRavsRedeemed` should not revert the RAV redeem status in DB if (allocation, sender) not in the revert list', async () => { const nowSecs = Math.floor(Date.now() / 1000) - // redeemed rav but non-final const ravList = [ createLastNonFinalRav( ALLOCATION_ID_3, @@ -453,7 +451,7 @@ describe('TAP', () => { ) test( - 'test mark final rav via filterAndUpdateRavs', + 'test mark final rav via `filterAndUpdateRavs`', async () => { const date = new Date() const redeemDate = date.setHours(date.getHours() - 2) diff --git a/packages/indexer-common/src/allocations/query-fees.ts b/packages/indexer-common/src/allocations/query-fees.ts index bf38ed778..b002cf3d4 100644 --- a/packages/indexer-common/src/allocations/query-fees.ts +++ b/packages/indexer-common/src/allocations/query-fees.ts @@ -198,7 +198,7 @@ export class AllocationReceiptCollector implements ReceiptCollector { collector.startRAVProcessing() } else { collector.logger.info(`RAV process not initiated. - Tap Contracts: ${!!collector.tapSubgraph}. + Tap Contracts: ${!!collector.tapContracts}. Tap Subgraph: ${!!collector.tapSubgraph}.`) } await collector.queuePendingReceiptsFromDatabase() @@ -594,13 +594,13 @@ export class AllocationReceiptCollector implements ReceiptCollector { } private async filterAndUpdateRavs( - ravLastNotFinal: ReceiptAggregateVoucher[], + ravsLastNotFinal: ReceiptAggregateVoucher[], ): Promise { - const tapSubgraphResponse = await this.findTransactionsForRavs(ravLastNotFinal) + const tapSubgraphResponse = await this.findTransactionsForRavs(ravsLastNotFinal) const redeemedRavsNotOnOurDatabase = tapSubgraphResponse.transactions.filter( (tx) => - !ravLastNotFinal.find( + !ravsLastNotFinal.find( (rav) => toAddress(rav.senderAddress) === toAddress(tx.sender.id) && toAddress(rav.allocationId) === toAddress(tx.allocationID), @@ -620,7 +620,7 @@ export class AllocationReceiptCollector implements ReceiptCollector { } // Filter unfinalized RAVS fetched from DB, keeping RAVs that have not yet been redeemed on-chain - const nonRedeemedRavs = ravLastNotFinal + const nonRedeemedRavs = ravsLastNotFinal .filter((rav) => !!rav.redeemedAt) .filter( (rav) => @@ -638,8 +638,6 @@ export class AllocationReceiptCollector implements ReceiptCollector { // Mark RAVs as unredeemed in DB if the TAP subgraph couldn't find the redeem Tx. // To handle a chain reorg that "unredeemed" the RAVs. - // WE use sql directly due to a bug in sequelize update: - // https://github.com/sequelize/sequelize/issues/7664 (bug been open for 7 years no fix yet or ever) if (nonRedeemedRavs.length > 0) { await this.revertRavsRedeemed(nonRedeemedRavs, blockTimestampSecs) } @@ -706,6 +704,9 @@ export class AllocationReceiptCollector implements ReceiptCollector { if (ravsNotRedeemed.length == 0) { return } + + // WE use sql directly due to a bug in sequelize update: + // https://github.com/sequelize/sequelize/issues/7664 (bug been open for 7 years no fix yet or ever) const query = ` UPDATE scalar_tap_ravs SET redeemed_at = NULL