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