Skip to content

Commit 27a1fa1

Browse files
author
tcsenpai
committed
fix: deduplicate transactions in petriBlockCompiler before ordering
A resolved TX from arbitration could still be in the mempool, causing duplicates in the block. Use a hash-keyed Map to deduplicate before ordering. Closes mycelium #144 (CR-4).
1 parent 567848d commit 27a1fa1

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/libs/consensus/petri/block/petriBlockCompiler.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ export async function compileBlock(
7070
)
7171
}
7272

73-
// Combine mempool txs with any resolved txs from arbitration
74-
const allTxs: Transaction[] = [
75-
...(filteredMempoolTxs as unknown as Transaction[]),
76-
...resolvedTxs,
77-
]
73+
// Combine mempool txs with any resolved txs from arbitration, deduplicating by hash
74+
const txByHash = new Map<string, Transaction>()
75+
for (const tx of filteredMempoolTxs as unknown as Transaction[]) {
76+
txByHash.set(tx.hash, tx)
77+
}
78+
for (const tx of resolvedTxs) {
79+
txByHash.set(tx.hash, tx)
80+
}
81+
const allTxs: Transaction[] = Array.from(txByHash.values())
7882

7983
const includedTxHashes = allTxs.map(tx => tx.hash)
8084

0 commit comments

Comments
 (0)