diff --git a/src/mempoollimit.cpp b/src/mempoollimit.cpp index 4c42d6044..594154d31 100644 --- a/src/mempoollimit.cpp +++ b/src/mempoollimit.cpp @@ -59,7 +59,7 @@ void WeightedTxTree::backPropagate(size_t fromIndex, const TxWeight& weightDelta } } -size_t WeightedTxTree::findByWeight(size_t fromIndex, uint64_t weightToFind) const +size_t WeightedTxTree::findByWeight(size_t fromIndex, int64_t weightToFind) const { int leftWeight = getWeightAt(fromIndex * 2 + 1).lowFeePenaltyWeight; int rightWeight = getWeightAt(fromIndex).lowFeePenaltyWeight - getWeightAt(fromIndex * 2 + 2).lowFeePenaltyWeight; @@ -124,7 +124,7 @@ void WeightedTxTree::remove(const uint256& txId) boost::optional WeightedTxTree::maybeDropRandom() { - uint64_t totalPenaltyWeight = getTotalWeight().lowFeePenaltyWeight; + int64_t totalPenaltyWeight = getTotalWeight().lowFeePenaltyWeight; if (totalPenaltyWeight <= capacity) { return boost::none; } @@ -155,8 +155,8 @@ WeightedTxInfo WeightedTxInfo::from(const CTransaction& tx, const CAmount& fee) memUsage += tx.vJoinSplit.size() * JOINSPLIT_SIZE; memUsage += tx.vShieldedOutput.size() * OUTPUTDESCRIPTION_SIZE; memUsage += tx.vShieldedSpend.size() * SPENDDESCRIPTION_SIZE; - uint64_t cost = std::max(memUsage, MIN_TX_WEIGHT); - uint64_t lowFeePenaltyCost = cost; + int64_t cost = std::max(memUsage, MIN_TX_WEIGHT); + int64_t lowFeePenaltyCost = cost; if (fee < DEFAULT_FEE) { lowFeePenaltyCost += LOW_FEE_PENALTY; } diff --git a/src/mempoollimit.h b/src/mempoollimit.h index af7b93f1f..985d1db55 100644 --- a/src/mempoollimit.h +++ b/src/mempoollimit.h @@ -46,10 +46,10 @@ public: struct TxWeight { - uint64_t weight; - uint64_t lowFeePenaltyWeight; + int64_t weight; + int64_t lowFeePenaltyWeight; - TxWeight(uint64_t weight_, uint64_t lowFeePenaltyWeight_) + TxWeight(int64_t weight_, int64_t lowFeePenaltyWeight_) : weight(weight_), lowFeePenaltyWeight(lowFeePenaltyWeight_) {} TxWeight add(const TxWeight& other) const; @@ -69,7 +69,7 @@ struct WeightedTxInfo { class WeightedTxTree { - const uint64_t capacity; + const int64_t capacity; size_t size = 0; std::vector txIdAndWeights; @@ -78,10 +78,12 @@ class WeightedTxTree TxWeight getWeightAt(size_t index) const; void backPropagate(size_t fromIndex, const TxWeight& weightDelta); - size_t findByWeight(size_t fromIndex, uint64_t weightToFind) const; + size_t findByWeight(size_t fromIndex, int64_t weightToFind) const; public: - WeightedTxTree(uint64_t capacity_) : capacity(capacity_) {} + WeightedTxTree(int64_t capacity_) : capacity(capacity_) { + assert(capacity >= 0); + } TxWeight getTotalWeight() const;