Skip to content

Commit

Permalink
Merge pull request #566 from holographxyz/revert-565-revert-564-featu…
Browse files Browse the repository at this point in the history
…re/HOLO-1083-group-multiple-crosschain-logs

Revert "Revert "Feature/holo 1083 group multiple crosschain logs""
  • Loading branch information
sogoiii authored Aug 10, 2023
2 parents c964e42 + febce07 commit 0191450
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/commands/indexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,74 @@ export default class Indexer extends HealthCheck {
this.log('SQS service is reachable')
}

/**
* Preprocesses a list of transactions to remove duplicates based on a combination of transaction hash and the bloomId.
* Specifically, it filters out duplicate entries where the bloomId is 'CrossChainMessageSent'.
*
* How it works:
* 1. Iterates over each transaction.
* 2. Creates a unique identifier using the transaction hash and bloomId.
* 3. If the bloomId is 'CrossChainMessageSent' and the identifier is already seen, the transaction is skipped.
* 4. Otherwise, the transaction is processed: it's added to the groupedByTransactionHashAndBloomId dictionary and the updatedInterestingTransactions array.
* 5. The end result is a list of transactions with duplicates (based on the specific criteria) removed.
*
* @param interestingTransactions - The list of transactions to be preprocessed.
* @returns A new list of transactions with duplicates removed based on the described criteria.
*/
preprocessTransactions(interestingTransactions: InterestingTransaction[]): InterestingTransaction[] {
const groupedByTransactionHashAndBloomId: {[hash: string]: {[bloomId: string]: any}} = {}
const seenCombinations = new Set()
const updatedInterestingTransactions: InterestingTransaction[] = []

for (const item of interestingTransactions) {
const {hash} = item.transaction
const {bloomId} = item
const identifier = `${hash}-${bloomId}`

const isCrossChainMessageSent = bloomId === 'CrossChainMessageSent'

// If the current bloomId is "CrossChainMessageSent" and we've seen this combination before, skip the rest of this iteration.
if (isCrossChainMessageSent && seenCombinations.has(identifier)) {
continue
}

if (isCrossChainMessageSent) {
seenCombinations.add(identifier)
}

const {transaction, log, allLogs} = item

// Initialize or get existing entry
const transactionGroup =
groupedByTransactionHashAndBloomId[hash] || (groupedByTransactionHashAndBloomId[hash] = {})
const bloomGroup =
transactionGroup[bloomId] ||
(transactionGroup[bloomId] = {
transaction,
log,
allLogs: [],
})

if (allLogs) {
bloomGroup.allLogs.push(...allLogs)
}

updatedInterestingTransactions.push(item)
}

return updatedInterestingTransactions
}

async processTransactions2(job: BlockJob, interestingTransactions: InterestingTransaction[]): Promise<void> {
const startTime = performance.now()

if (interestingTransactions.length <= 0) {
return
}

// Filter out duplicate transaction / bloomId combinations (only CrossChainMessageSent is considered for now)
interestingTransactions = this.preprocessTransactions(interestingTransactions)

// Map over the transactions to create an array of Promises
const transactionPromises = interestingTransactions.map(interestingTransaction =>
this.processSingleTransaction(interestingTransaction, job),
Expand Down

0 comments on commit 0191450

Please sign in to comment.