Update parameter names to match ZIP

This commit is contained in:
Eirik Ogilvie-Wigley 2019-10-17 16:39:32 -06:00
parent e7aed48e7a
commit 64fc25ed6e
6 changed files with 23 additions and 23 deletions

View File

@ -12,13 +12,13 @@ in the situation where an attacker is trying to overwhelm the network with
transactions. This is achieved by keeping track of and limiting the total
`cost`, a function of a transaction's size in bytes and its fee, of the
mempool. The maximum total cost is configurable via the parameter
`mempooltotalcostlimit` which defaults to 80,000,000 (up to 20,000 txs). If a
`mempool.tx_cost_limit` which defaults to 80,000,000 (up to 20,000 txs). If a
node's total mempool `cost` exceeds this limit the node will evict a random
transaction, preferentially picking larger transactions and ones with below
the standard fee. To prevent a node from re-accepting evicted transactions, it
keeps track of ones that it has evicted recently. By default, a transaction
will be considered recently evicted for 60 minutes, but this can be configured
with the parameter `mempoolevictionmemoryminutes`.
with the parameter `mempool.eviction_memory_minutes`.
Fake chain detection during initial block download
--------------------------------------------------

View File

@ -26,11 +26,11 @@ class MempoolLimit(BitcoinTestFramework):
def setup_nodes(self):
extra_args = [
["-debug=mempool", '-mempooltotalcostlimit=8000'], # 2 transactions at min cost
["-debug=mempool", '-mempooltotalcostlimit=8000'], # 2 transactions at min cost
["-debug=mempool", '-mempooltotalcostlimit=8000'], # 2 transactions at min cost
["-debug=mempool", '-mempool.tx_cost_limit=8000'], # 2 transactions at min cost
["-debug=mempool", '-mempool.tx_cost_limit=8000'], # 2 transactions at min cost
["-debug=mempool", '-mempool.tx_cost_limit=8000'], # 2 transactions at min cost
# Let node 3 hold one more transaction
["-debug=mempool", '-mempooltotalcostlimit=12000'], # 3 transactions at min cost
["-debug=mempool", '-mempool.tx_cost_limit=12000'], # 3 transactions at min cost
]
return start_nodes(4, self.options.tmpdir, extra_args)

View File

@ -85,17 +85,17 @@ TEST(MempoolLimitTests, WeightedTxTreeCheckSizeAfterDropping)
// Run the test until we have tested dropping each of the elements
int trialNum = 0;
while (testedDropping.size() < 3) {
WeightedTxTree tree(MIN_TX_WEIGHT * 2);
WeightedTxTree tree(MIN_TX_COST * 2);
EXPECT_EQ(0, tree.getTotalWeight().cost);
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_COST, MIN_TX_COST)));
EXPECT_EQ(4000, tree.getTotalWeight().cost);
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_COST, MIN_TX_COST)));
EXPECT_EQ(8000, tree.getTotalWeight().cost);
EXPECT_EQ(8000, tree.getTotalWeight().evictionWeight);
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_COST, MIN_TX_COST + LOW_FEE_PENALTY)));
EXPECT_EQ(12000, tree.getTotalWeight().cost);
EXPECT_EQ(12000 + LOW_FEE_PENALTY, tree.getTotalWeight().evictionWeight);
boost::optional<uint256> drop = tree.maybeDropRandom();
@ -126,8 +126,8 @@ TEST(MempoolLimitTests, WeightedTxInfoFromTx)
builder.AddSaplingOutput(sk.full_viewing_key().ovk, sk.default_address(), 25000, {});
WeightedTxInfo info = WeightedTxInfo::from(builder.Build().GetTxOrThrow(), 10000);
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.cost);
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.evictionWeight);
EXPECT_EQ(MIN_TX_COST, info.txWeight.cost);
EXPECT_EQ(MIN_TX_COST, info.txWeight.evictionWeight);
}
// Lower than standard fee
@ -138,8 +138,8 @@ TEST(MempoolLimitTests, WeightedTxInfoFromTx)
builder.SetFee(9999);
WeightedTxInfo info = WeightedTxInfo::from(builder.Build().GetTxOrThrow(), 9999);
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.cost);
EXPECT_EQ(MIN_TX_WEIGHT + LOW_FEE_PENALTY, info.txWeight.evictionWeight);
EXPECT_EQ(MIN_TX_COST, info.txWeight.cost);
EXPECT_EQ(MIN_TX_COST + LOW_FEE_PENALTY, info.txWeight.evictionWeight);
}
// Larger Tx

View File

@ -384,8 +384,8 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-maxconnections=<n>", strprintf(_("Maintain at most <n> connections to peers (default: %u)"), DEFAULT_MAX_PEER_CONNECTIONS));
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("-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_COST_LIMIT));
strUsage += HelpMessageOpt("-mempool.eviction_memory_minutes=<n>", strprintf(_("The number of minutes before allowing rejected transactions to re-enter the mempool. (default: %u)"), DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES));
strUsage += HelpMessageOpt("-mempool.tx_cost_limit=<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("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1));
@ -978,8 +978,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
mempool.setSanityCheck(1.0 / ratio);
}
int64_t mempoolTotalCostLimit = GetArg("-mempooltotalcostlimit", DEFAULT_MEMPOOL_TOTAL_COST_LIMIT);
int64_t mempoolEvictionMemorySeconds = GetArg("-mempoolevictionmemoryminutes", DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES) * 60;
int64_t mempoolTotalCostLimit = GetArg("-mempool.tx_cost_limit", DEFAULT_MEMPOOL_TOTAL_COST_LIMIT);
int64_t mempoolEvictionMemorySeconds = GetArg("-mempool.eviction_memory_minutes", DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES) * 60;
mempool.SetMempoolCostLimit(mempoolTotalCostLimit, mempoolEvictionMemorySeconds);
fCheckBlockIndex = GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());

View File

@ -151,7 +151,7 @@ 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;
int64_t cost = std::max(memUsage, MIN_TX_WEIGHT);
int64_t cost = std::max(memUsage, MIN_TX_COST);
int64_t evictionWeight = cost;
if (fee < DEFAULT_FEE) {
evictionWeight += LOW_FEE_PENALTY;

View File

@ -16,8 +16,8 @@
const size_t DEFAULT_MEMPOOL_TOTAL_COST_LIMIT = 80000000;
const int64_t DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES = 60;
const size_t RECENTLY_EVICTED_SIZE = 40000;
const uint64_t MIN_TX_WEIGHT = 4000;
const size_t EVICTION_MEMORY_ENTRIES = 40000;
const uint64_t MIN_TX_COST = 4000;
const uint64_t LOW_FEE_PENALTY = 16000;
@ -39,9 +39,9 @@ class RecentlyEvictedList
public:
RecentlyEvictedList(size_t capacity_, int64_t timeToKeep_) : capacity(capacity_), timeToKeep(timeToKeep_)
{
assert(capacity <= RECENTLY_EVICTED_SIZE);
assert(capacity <= EVICTION_MEMORY_ENTRIES);
}
RecentlyEvictedList(int64_t timeToKeep_) : RecentlyEvictedList(RECENTLY_EVICTED_SIZE, timeToKeep_) {}
RecentlyEvictedList(int64_t timeToKeep_) : RecentlyEvictedList(EVICTION_MEMORY_ENTRIES, timeToKeep_) {}
void add(const uint256& txId);
bool contains(const uint256& txId);