Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Feature/holo 1083 group multiple crosschain logs"" #566

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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