Skip to content

Commit

Permalink
chore: suggested pr changes
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio authored and aasseman committed Sep 4, 2024
1 parent 8d120c2 commit 33eaa81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 3 additions & 5 deletions packages/indexer-common/src/allocations/__tests__/tap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 8 additions & 7 deletions packages/indexer-common/src/allocations/query-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -594,13 +594,13 @@ export class AllocationReceiptCollector implements ReceiptCollector {
}

private async filterAndUpdateRavs(
ravLastNotFinal: ReceiptAggregateVoucher[],
ravsLastNotFinal: ReceiptAggregateVoucher[],
): Promise<ReceiptAggregateVoucher[]> {
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),
Expand All @@ -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) =>
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 33eaa81

Please sign in to comment.