55#include " platform/memory_util.h"
66#include " platform/concurrency.h"
77#include " platform/console_logging.h"
8+ #include " platform/debugging.h"
89
910#include " spectrum/spectrum.h"
1011
@@ -258,17 +259,32 @@ class PendingTxsPool
258259 unsigned int tickIndex = tickToIndex (tx->tick );
259260 const unsigned int transactionSize = tx->totalSize ();
260261
262+ // check if tx with same digest already exists
263+ m256i digest;
264+ KangarooTwelve (tx, transactionSize, &digest, sizeof (m256i));
265+ for (unsigned int txIndex = 0 ; txIndex < numSavedTxsPerTick[tickIndex]; ++txIndex)
266+ {
267+ if (*getDigestPtr (tickIndex, txIndex) == digest)
268+ {
269+ #if !defined(NDEBUG) && !defined(NO_UEFI)
270+ CHAR16 dbgMsgBuf[100 ];
271+ setText (dbgMsgBuf, L" tx with the same digest already exists for tick " );
272+ appendNumber (dbgMsgBuf, tx->tick , FALSE );
273+ addDebugMessage (dbgMsgBuf);
274+ #endif
275+ goto end_add_function;
276+ }
277+ }
278+
261279 sint64 priority = calculateTxPriority (tx);
262280 if (priority > 0 )
263281 {
264282 m256i povIndex{ tickIndex, 0 , 0 , 0 };
265283
266284 if (numSavedTxsPerTick[tickIndex] < maxNumTxsPerTick)
267285 {
268- KangarooTwelve (tx, transactionSize, getDigestPtr (tickIndex, numSavedTxsPerTick[tickIndex]), sizeof (m256i));
269-
286+ copyMem (getDigestPtr (tickIndex, numSavedTxsPerTick[tickIndex]), &digest, sizeof (m256i));
270287 copyMem (getTxPtr (tickIndex, numSavedTxsPerTick[tickIndex]), tx, transactionSize);
271-
272288 txsPriorities->add (povIndex, numSavedTxsPerTick[tickIndex], priority);
273289
274290 numSavedTxsPerTick[tickIndex]++;
@@ -286,8 +302,7 @@ class PendingTxsPool
286302 txsPriorities->remove (lowestElementIndex);
287303 txsPriorities->add (povIndex, replacedTxIndex, priority);
288304
289- KangarooTwelve (tx, transactionSize, getDigestPtr (tickIndex, replacedTxIndex), sizeof (m256i));
290-
305+ copyMem (getDigestPtr (tickIndex, replacedTxIndex), &digest, sizeof (m256i));
291306 copyMem (getTxPtr (tickIndex, replacedTxIndex), tx, transactionSize);
292307
293308 txAdded = true ;
@@ -326,13 +341,15 @@ class PendingTxsPool
326341#if !defined(NDEBUG) && !defined(NO_UEFI)
327342 else
328343 {
329- CHAR16 dbgMsgBuf[300 ];
344+ CHAR16 dbgMsgBuf[100 ];
330345 setText (dbgMsgBuf, L" tx with priority 0 was rejected for tick " );
331346 appendNumber (dbgMsgBuf, tx->tick , FALSE );
332347 addDebugMessage (dbgMsgBuf);
333348 }
334349#endif
335350 }
351+
352+ end_add_function:
336353 RELEASE (lock);
337354
338355#if !defined(NDEBUG) && !defined(NO_UEFI)
0 commit comments