Skip to content

Commit 0c79ead

Browse files
define num ticks for pending txs pool as 10 mins, add next power of 2 function to calc Collection capacity
1 parent 4026cbe commit 0c79ead

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/contracts/math_lib.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,21 @@ inline static unsigned char divUp(unsigned char a, unsigned char b)
4949
return b ? ((a + b - 1) / b) : 0;
5050
}
5151

52+
inline constexpr unsigned long long findNextPowerOf2(unsigned long long num)
53+
{
54+
if (num == 0)
55+
return 1;
56+
57+
num--;
58+
num |= num >> 1;
59+
num |= num >> 2;
60+
num |= num >> 4;
61+
num |= num >> 8;
62+
num |= num >> 16;
63+
num |= num >> 32;
64+
num++;
65+
66+
return num;
67+
}
68+
5269
}

src/public_settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define TRANSACTION_SPARSENESS 1
3333

3434
// Number of ticks that are stored in the pending txs pool. This also defines how many ticks in advance a tx can be registered.
35-
#define PENDING_TXS_POOL_NUM_TICKS 8192ULL // must be 2^N
35+
#define PENDING_TXS_POOL_NUM_TICKS (1000 * 60 * 10ULL / TICK_DURATION_FOR_ALLOCATION_MS) // 10 minutes
3636

3737
// Below are 2 variables that are used for auto-F5 feature:
3838
#define AUTO_FORCE_NEXT_TICK_THRESHOLD 0ULL // Multiplier of TARGET_TICK_DURATION for the system to detect "F5 case" | set to 0 to disable

src/ticking/pending_txs_pool.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mining/mining.h"
1212

1313
#include "contracts/qpi.h"
14+
#include "contracts/math_lib.h"
1415
#include "contract_core/qpi_collection_impl.h"
1516

1617
#include "public_settings.h"
@@ -29,6 +30,9 @@ class PendingTxsPool
2930
static constexpr unsigned long long tickTransactionOffsetsSize = maxNumTxs * sizeof(unsigned long long);
3031
static constexpr unsigned long long txsDigestsSize = maxNumTxs * sizeof(m256i);
3132

33+
// `maxNumTxs` priorities have to be saved at a time. Collection capacity has to be 2^N so find the next bigger power of 2.
34+
static constexpr unsigned long long txsPrioritiesCapacity = math_lib::findNextPowerOf2(maxNumTxs);
35+
3236
// The pool stores the tick range [firstStoredTick, firstStoredTick + PENDING_TXS_POOL_NUM_TICKS[
3337
inline static unsigned int firstStoredTick = 0;
3438

@@ -58,7 +62,7 @@ class PendingTxsPool
5862
inline static volatile char txsPrioritiesLock = 0;
5963

6064
// Priority queues for transactions in each saved tick.
61-
inline static Collection<unsigned int, NUMBER_OF_TRANSACTIONS_PER_TICK * PENDING_TXS_POOL_NUM_TICKS>* txsPriorities;
65+
inline static Collection<unsigned int, txsPrioritiesCapacity>* txsPriorities;
6266

6367
static void cleanupTxsPriorities(unsigned int tickIndex)
6468
{
@@ -138,7 +142,7 @@ class PendingTxsPool
138142
{
139143
if (!allocPoolWithErrorLog(L"PendingTxsPool::tickTransactionsPtr ", tickTransactionsSize, (void**)&tickTransactionsBuffer, __LINE__)
140144
|| !allocPoolWithErrorLog(L"PendingTxsPool::txsDigestsPtr ", txsDigestsSize, (void**)&txsDigestsBuffer, __LINE__)
141-
|| !allocPoolWithErrorLog(L"PendingTxsPool::txsPriorities", sizeof(Collection<unsigned int, NUMBER_OF_TRANSACTIONS_PER_TICK * PENDING_TXS_POOL_NUM_TICKS>), (void**)&txsPriorities, __LINE__))
145+
|| !allocPoolWithErrorLog(L"PendingTxsPool::txsPriorities", sizeof(Collection<unsigned int, txsPrioritiesCapacity>), (void**)&txsPriorities, __LINE__))
142146
{
143147
return false;
144148
}

0 commit comments

Comments
 (0)