Rename variables for consistency
This commit is contained in:
parent
1556ec6722
commit
2d9becbeb8
|
@ -59,26 +59,26 @@ TEST(MempoolLimitTests, WeightedTxTreeCheckSizeAfterDropping)
|
||||||
int trialNum = 0;
|
int trialNum = 0;
|
||||||
while (testedDropping.size() < 3) {
|
while (testedDropping.size() < 3) {
|
||||||
WeightedTxTree tree(MIN_TX_WEIGHT * 2);
|
WeightedTxTree tree(MIN_TX_WEIGHT * 2);
|
||||||
EXPECT_EQ(0, tree.getTotalWeight().weight);
|
EXPECT_EQ(0, tree.getTotalWeight().cost);
|
||||||
EXPECT_EQ(0, tree.getTotalWeight().lowFeePenaltyWeight);
|
EXPECT_EQ(0, tree.getTotalWeight().evictionWeight);
|
||||||
tree.add(WeightedTxInfo(TX_ID1, TxWeight(MIN_TX_WEIGHT, MIN_TX_WEIGHT)));
|
tree.add(WeightedTxInfo(TX_ID1, TxWeight(MIN_TX_WEIGHT, MIN_TX_WEIGHT)));
|
||||||
EXPECT_EQ(4000, tree.getTotalWeight().weight);
|
EXPECT_EQ(4000, tree.getTotalWeight().cost);
|
||||||
EXPECT_EQ(4000, tree.getTotalWeight().lowFeePenaltyWeight);
|
EXPECT_EQ(4000, tree.getTotalWeight().evictionWeight);
|
||||||
tree.add(WeightedTxInfo(TX_ID2, TxWeight(MIN_TX_WEIGHT, MIN_TX_WEIGHT)));
|
tree.add(WeightedTxInfo(TX_ID2, TxWeight(MIN_TX_WEIGHT, MIN_TX_WEIGHT)));
|
||||||
EXPECT_EQ(8000, tree.getTotalWeight().weight);
|
EXPECT_EQ(8000, tree.getTotalWeight().cost);
|
||||||
EXPECT_EQ(8000, tree.getTotalWeight().lowFeePenaltyWeight);
|
EXPECT_EQ(8000, tree.getTotalWeight().evictionWeight);
|
||||||
EXPECT_FALSE(tree.maybeDropRandom().is_initialized());
|
EXPECT_FALSE(tree.maybeDropRandom().is_initialized());
|
||||||
tree.add(WeightedTxInfo(TX_ID3, TxWeight(MIN_TX_WEIGHT, MIN_TX_WEIGHT + LOW_FEE_PENALTY)));
|
tree.add(WeightedTxInfo(TX_ID3, TxWeight(MIN_TX_WEIGHT, MIN_TX_WEIGHT + LOW_FEE_PENALTY)));
|
||||||
EXPECT_EQ(12000, tree.getTotalWeight().weight);
|
EXPECT_EQ(12000, tree.getTotalWeight().cost);
|
||||||
EXPECT_EQ(12000 + LOW_FEE_PENALTY, tree.getTotalWeight().lowFeePenaltyWeight);
|
EXPECT_EQ(12000 + LOW_FEE_PENALTY, tree.getTotalWeight().evictionWeight);
|
||||||
boost::optional<uint256> drop = tree.maybeDropRandom();
|
boost::optional<uint256> drop = tree.maybeDropRandom();
|
||||||
ASSERT_TRUE(drop.is_initialized());
|
ASSERT_TRUE(drop.is_initialized());
|
||||||
uint256 txid = drop.get();
|
uint256 txid = drop.get();
|
||||||
std::cerr << "Trial " << trialNum++ << ": dropped " << txid.ToString() << std::endl;
|
std::cerr << "Trial " << trialNum++ << ": dropped " << txid.ToString() << std::endl;
|
||||||
testedDropping.insert(txid);
|
testedDropping.insert(txid);
|
||||||
// Do not continue to test if a particular trial fails
|
// Do not continue to test if a particular trial fails
|
||||||
ASSERT_EQ(8000, tree.getTotalWeight().weight);
|
ASSERT_EQ(8000, tree.getTotalWeight().cost);
|
||||||
ASSERT_EQ(txid == TX_ID3 ? 8000 : 8000 + LOW_FEE_PENALTY, tree.getTotalWeight().lowFeePenaltyWeight);
|
ASSERT_EQ(txid == TX_ID3 ? 8000 : 8000 + LOW_FEE_PENALTY, tree.getTotalWeight().evictionWeight);
|
||||||
}
|
}
|
||||||
std::cerr << "All 3 scenarios tested in " << trialNum << " trials" << std::endl;
|
std::cerr << "All 3 scenarios tested in " << trialNum << " trials" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -99,8 +99,8 @@ TEST(MempoolLimitTests, WeightedTxInfoFromTx)
|
||||||
builder.AddSaplingOutput(sk.full_viewing_key().ovk, sk.default_address(), 25000, {});
|
builder.AddSaplingOutput(sk.full_viewing_key().ovk, sk.default_address(), 25000, {});
|
||||||
|
|
||||||
WeightedTxInfo info = WeightedTxInfo::from(builder.Build().GetTxOrThrow(), 10000);
|
WeightedTxInfo info = WeightedTxInfo::from(builder.Build().GetTxOrThrow(), 10000);
|
||||||
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.weight);
|
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.cost);
|
||||||
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.lowFeePenaltyWeight);
|
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.evictionWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lower than standard fee
|
// Lower than standard fee
|
||||||
|
@ -111,8 +111,8 @@ TEST(MempoolLimitTests, WeightedTxInfoFromTx)
|
||||||
builder.SetFee(9999);
|
builder.SetFee(9999);
|
||||||
|
|
||||||
WeightedTxInfo info = WeightedTxInfo::from(builder.Build().GetTxOrThrow(), 9999);
|
WeightedTxInfo info = WeightedTxInfo::from(builder.Build().GetTxOrThrow(), 9999);
|
||||||
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.weight);
|
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.cost);
|
||||||
EXPECT_EQ(MIN_TX_WEIGHT + LOW_FEE_PENALTY, info.txWeight.lowFeePenaltyWeight);
|
EXPECT_EQ(MIN_TX_WEIGHT + LOW_FEE_PENALTY, info.txWeight.evictionWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Larger Tx
|
// Larger Tx
|
||||||
|
@ -129,8 +129,8 @@ TEST(MempoolLimitTests, WeightedTxInfoFromTx)
|
||||||
std::cerr << result.GetError() << std::endl;
|
std::cerr << result.GetError() << std::endl;
|
||||||
}
|
}
|
||||||
WeightedTxInfo info = WeightedTxInfo::from(result.GetTxOrThrow(), 10000);
|
WeightedTxInfo info = WeightedTxInfo::from(result.GetTxOrThrow(), 10000);
|
||||||
EXPECT_EQ(5124, info.txWeight.weight);
|
EXPECT_EQ(5124, info.txWeight.cost);
|
||||||
EXPECT_EQ(5124, info.txWeight.lowFeePenaltyWeight);
|
EXPECT_EQ(5124, info.txWeight.evictionWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
RegtestDeactivateSapling();
|
RegtestDeactivateSapling();
|
||||||
|
|
|
@ -385,7 +385,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||||
strUsage += HelpMessageOpt("-maxreceivebuffer=<n>", strprintf(_("Maximum per-connection receive buffer, <n>*1000 bytes (default: %u)"), 5000));
|
strUsage += HelpMessageOpt("-maxreceivebuffer=<n>", strprintf(_("Maximum per-connection receive buffer, <n>*1000 bytes (default: %u)"), 5000));
|
||||||
strUsage += HelpMessageOpt("-maxsendbuffer=<n>", strprintf(_("Maximum per-connection send buffer, <n>*1000 bytes (default: %u)"), 1000));
|
strUsage += HelpMessageOpt("-maxsendbuffer=<n>", strprintf(_("Maximum per-connection send buffer, <n>*1000 bytes (default: %u)"), 1000));
|
||||||
strUsage += HelpMessageOpt("-mempoolevictionmemoryminutes=<n>", strprintf(_("The number of minutes before allowing rejected transactions to re-enter the mempool. (default: %u)"), DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES));
|
strUsage += HelpMessageOpt("-mempoolevictionmemoryminutes=<n>", strprintf(_("The number of minutes before allowing rejected transactions to re-enter the mempool. (default: %u)"), DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES));
|
||||||
strUsage += HelpMessageOpt("-mempooltotalcostlimit=<n>",strprintf(_("An upper bound on the maximum size in bytes of all transactions in the mempool. (default: %s)"), DEFAULT_MEMPOOL_TOTAL_WEIGHT_LIMIT));
|
strUsage += HelpMessageOpt("-mempooltotalcostlimit=<n>",strprintf(_("An upper bound on the maximum size in bytes of all transactions in the mempool. (default: %s)"), DEFAULT_MEMPOOL_TOTAL_COST_LIMIT));
|
||||||
strUsage += HelpMessageOpt("-onion=<ip:port>", strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: %s)"), "-proxy"));
|
strUsage += HelpMessageOpt("-onion=<ip:port>", strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: %s)"), "-proxy"));
|
||||||
strUsage += HelpMessageOpt("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
|
strUsage += HelpMessageOpt("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
|
||||||
strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1));
|
strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1));
|
||||||
|
@ -978,7 +978,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||||
mempool.setSanityCheck(1.0 / ratio);
|
mempool.setSanityCheck(1.0 / ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t mempoolTotalCostLimit = GetArg("-mempooltotalcostlimit", DEFAULT_MEMPOOL_TOTAL_WEIGHT_LIMIT);
|
int64_t mempoolTotalCostLimit = GetArg("-mempooltotalcostlimit", DEFAULT_MEMPOOL_TOTAL_COST_LIMIT);
|
||||||
int64_t mempoolEvictionMemorySeconds = GetArg("-mempoolevictionmemoryminutes", DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES) * 60;
|
int64_t mempoolEvictionMemorySeconds = GetArg("-mempoolevictionmemoryminutes", DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES) * 60;
|
||||||
mempool.SetMempoolCostLimit(mempoolTotalCostLimit, mempoolEvictionMemorySeconds);
|
mempool.SetMempoolCostLimit(mempoolTotalCostLimit, mempoolEvictionMemorySeconds);
|
||||||
|
|
||||||
|
|
|
@ -59,20 +59,20 @@ void WeightedTxTree::backPropagate(size_t fromIndex, const TxWeight& weightDelta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t WeightedTxTree::findByWeight(size_t fromIndex, int64_t weightToFind) const
|
size_t WeightedTxTree::findByEvictionWeight(size_t fromIndex, int64_t weightToFind) const
|
||||||
{
|
{
|
||||||
int leftWeight = getWeightAt(fromIndex * 2 + 1).lowFeePenaltyWeight;
|
int leftWeight = getWeightAt(fromIndex * 2 + 1).evictionWeight;
|
||||||
int rightWeight = getWeightAt(fromIndex).lowFeePenaltyWeight - getWeightAt(fromIndex * 2 + 2).lowFeePenaltyWeight;
|
int rightWeight = getWeightAt(fromIndex).evictionWeight - getWeightAt(fromIndex * 2 + 2).evictionWeight;
|
||||||
// On Left
|
// On Left
|
||||||
if (weightToFind < leftWeight) {
|
if (weightToFind < leftWeight) {
|
||||||
return findByWeight(fromIndex * 2 + 1, weightToFind);
|
return findByEvictionWeight(fromIndex * 2 + 1, weightToFind);
|
||||||
}
|
}
|
||||||
// Found
|
// Found
|
||||||
if (weightToFind < rightWeight) {
|
if (weightToFind < rightWeight) {
|
||||||
return fromIndex;
|
return fromIndex;
|
||||||
}
|
}
|
||||||
// On Right
|
// On Right
|
||||||
return findByWeight(fromIndex * 2 + 2, weightToFind - rightWeight);
|
return findByEvictionWeight(fromIndex * 2 + 2, weightToFind - rightWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
TxWeight WeightedTxTree::getTotalWeight() const
|
TxWeight WeightedTxTree::getTotalWeight() const
|
||||||
|
@ -124,15 +124,15 @@ void WeightedTxTree::remove(const uint256& txId)
|
||||||
|
|
||||||
boost::optional<uint256> WeightedTxTree::maybeDropRandom()
|
boost::optional<uint256> WeightedTxTree::maybeDropRandom()
|
||||||
{
|
{
|
||||||
int64_t totalPenaltyWeight = getTotalWeight().lowFeePenaltyWeight;
|
int64_t totalPenaltyWeight = getTotalWeight().evictionWeight;
|
||||||
if (totalPenaltyWeight <= capacity) {
|
if (totalPenaltyWeight <= capacity) {
|
||||||
return boost::none;
|
return boost::none;
|
||||||
}
|
}
|
||||||
LogPrint("mempool", "Mempool cost limit exceeded (cost=%d, limit=%d)\n", totalPenaltyWeight, capacity);
|
LogPrint("mempool", "Mempool cost limit exceeded (cost=%d, limit=%d)\n", totalPenaltyWeight, capacity);
|
||||||
int randomWeight = GetRand(totalPenaltyWeight);
|
int randomWeight = GetRand(totalPenaltyWeight);
|
||||||
WeightedTxInfo drop = txIdAndWeights[findByWeight(0, randomWeight)];
|
WeightedTxInfo drop = txIdAndWeights[findByEvictionWeight(0, randomWeight)];
|
||||||
LogPrint("mempool", "Evicting transaction (txid=%s, cost=%d, penaltyCost=%d)\n",
|
LogPrint("mempool", "Evicting transaction (txid=%s, cost=%d, evictionWeight=%d)\n",
|
||||||
drop.txId.ToString(), drop.txWeight.weight, drop.txWeight.lowFeePenaltyWeight);
|
drop.txId.ToString(), drop.txWeight.cost, drop.txWeight.evictionWeight);
|
||||||
remove(drop.txId);
|
remove(drop.txId);
|
||||||
return drop.txId;
|
return drop.txId;
|
||||||
}
|
}
|
||||||
|
@ -140,12 +140,12 @@ boost::optional<uint256> WeightedTxTree::maybeDropRandom()
|
||||||
|
|
||||||
TxWeight TxWeight::add(const TxWeight& other) const
|
TxWeight TxWeight::add(const TxWeight& other) const
|
||||||
{
|
{
|
||||||
return TxWeight(weight + other.weight, lowFeePenaltyWeight + other.lowFeePenaltyWeight);
|
return TxWeight(cost + other.cost, evictionWeight + other.evictionWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
TxWeight TxWeight::negate() const
|
TxWeight TxWeight::negate() const
|
||||||
{
|
{
|
||||||
return TxWeight(-weight, -lowFeePenaltyWeight);
|
return TxWeight(-cost, -evictionWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,9 +156,9 @@ WeightedTxInfo WeightedTxInfo::from(const CTransaction& tx, const CAmount& fee)
|
||||||
memUsage += tx.vShieldedOutput.size() * OUTPUTDESCRIPTION_SIZE;
|
memUsage += tx.vShieldedOutput.size() * OUTPUTDESCRIPTION_SIZE;
|
||||||
memUsage += tx.vShieldedSpend.size() * SPENDDESCRIPTION_SIZE;
|
memUsage += tx.vShieldedSpend.size() * SPENDDESCRIPTION_SIZE;
|
||||||
int64_t cost = std::max(memUsage, MIN_TX_WEIGHT);
|
int64_t cost = std::max(memUsage, MIN_TX_WEIGHT);
|
||||||
int64_t lowFeePenaltyCost = cost;
|
int64_t evictionWeight = cost;
|
||||||
if (fee < DEFAULT_FEE) {
|
if (fee < DEFAULT_FEE) {
|
||||||
lowFeePenaltyCost += LOW_FEE_PENALTY;
|
evictionWeight += LOW_FEE_PENALTY;
|
||||||
}
|
}
|
||||||
return WeightedTxInfo(tx.GetHash(), TxWeight(cost, lowFeePenaltyCost));
|
return WeightedTxInfo(tx.GetHash(), TxWeight(cost, evictionWeight));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "primitives/transaction.h"
|
#include "primitives/transaction.h"
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
|
|
||||||
const size_t DEFAULT_MEMPOOL_TOTAL_WEIGHT_LIMIT = 80000000;
|
const size_t DEFAULT_MEMPOOL_TOTAL_COST_LIMIT = 80000000;
|
||||||
const int64_t DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES = 60;
|
const int64_t DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES = 60;
|
||||||
|
|
||||||
const size_t RECENTLY_EVICTED_SIZE = 40000;
|
const size_t RECENTLY_EVICTED_SIZE = 40000;
|
||||||
|
@ -46,11 +46,11 @@ public:
|
||||||
|
|
||||||
|
|
||||||
struct TxWeight {
|
struct TxWeight {
|
||||||
int64_t weight;
|
int64_t cost;
|
||||||
int64_t lowFeePenaltyWeight;
|
int64_t evictionWeight;
|
||||||
|
|
||||||
TxWeight(int64_t weight_, int64_t lowFeePenaltyWeight_)
|
TxWeight(int64_t cost_, int64_t evictionWeight_)
|
||||||
: weight(weight_), lowFeePenaltyWeight(lowFeePenaltyWeight_) {}
|
: cost(cost_), evictionWeight(evictionWeight_) {}
|
||||||
|
|
||||||
TxWeight add(const TxWeight& other) const;
|
TxWeight add(const TxWeight& other) const;
|
||||||
TxWeight negate() const;
|
TxWeight negate() const;
|
||||||
|
@ -78,7 +78,7 @@ class WeightedTxTree
|
||||||
|
|
||||||
TxWeight getWeightAt(size_t index) const;
|
TxWeight getWeightAt(size_t index) const;
|
||||||
void backPropagate(size_t fromIndex, const TxWeight& weightDelta);
|
void backPropagate(size_t fromIndex, const TxWeight& weightDelta);
|
||||||
size_t findByWeight(size_t fromIndex, int64_t weightToFind) const;
|
size_t findByEvictionWeight(size_t fromIndex, int64_t weightToFind) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WeightedTxTree(int64_t capacity_) : capacity(capacity_) {
|
WeightedTxTree(int64_t capacity_) : capacity(capacity_) {
|
||||||
|
|
Loading…
Reference in New Issue