Represent tx costs as signed integers

This commit is contained in:
Eirik Ogilvie-Wigley 2019-10-09 13:14:35 -06:00
parent b680185f48
commit bf044cc0c3
2 changed files with 12 additions and 10 deletions

View File

@ -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<uint256> 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;
}

View File

@ -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<WeightedTxInfo> 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;