Skip to content

Commit e8c43c3

Browse files
check for duplicate digest in txs pool add (#597)
* check for duplicate digest in txs pool add
1 parent 4299093 commit e8c43c3

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

src/platform/debugging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "assert.h"
44
#include "concurrency.h"
5+
#include "console_logging.h"
56
#include "file_io.h"
67

78

src/platform/file_io.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include <lib/platform_common/processor.h>
99
#include <lib/platform_common/compiler_optimization.h>
1010
#include <lib/platform_efi/uefi.h>
11+
1112
#include "console_logging.h"
1213
#include "concurrency.h"
1314
#include "memory.h"
14-
#include "debugging.h"
1515

1616
// If you get an error reading and writing files, set the chunk sizes below to
1717
// the cluster size set for formatting you disk. If you have no idea about the
@@ -33,7 +33,9 @@ static constexpr int ASYNC_FILE_IO_MAX_QUEUE_ITEMS = (1ULL << ASYNC_FILE_IO_MAX_
3333
static EFI_FILE_PROTOCOL* root = NULL;
3434
class AsyncFileIO;
3535
static AsyncFileIO* gAsyncFileIO = NULL;
36+
3637
static void addDebugMessage(const CHAR16* msg);
38+
3739
static long long getFileSize(CHAR16* fileName, CHAR16* directory = NULL)
3840
{
3941
#ifdef NO_UEFI

src/platform/virtual_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "platform/time.h"
66
#include "platform/memory_util.h"
77
#include "platform/debugging.h"
8+
#include "platform/file_io.h"
89

910
#include "four_q.h"
1011
#include "kangaroo_twelve.h"

src/ticking/pending_txs_pool.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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

Comments
 (0)