Update parameter names to match ZIP
This commit is contained in:
parent
e7aed48e7a
commit
64fc25ed6e
|
@ -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
|
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
|
`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
|
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
|
node's total mempool `cost` exceeds this limit the node will evict a random
|
||||||
transaction, preferentially picking larger transactions and ones with below
|
transaction, preferentially picking larger transactions and ones with below
|
||||||
the standard fee. To prevent a node from re-accepting evicted transactions, it
|
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
|
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
|
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
|
Fake chain detection during initial block download
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
|
@ -26,11 +26,11 @@ class MempoolLimit(BitcoinTestFramework):
|
||||||
|
|
||||||
def setup_nodes(self):
|
def setup_nodes(self):
|
||||||
extra_args = [
|
extra_args = [
|
||||||
["-debug=mempool", '-mempooltotalcostlimit=8000'], # 2 transactions at min cost
|
["-debug=mempool", '-mempool.tx_cost_limit=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", '-mempooltotalcostlimit=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
|
# 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)
|
return start_nodes(4, self.options.tmpdir, extra_args)
|
||||||
|
|
||||||
|
|
|
@ -85,17 +85,17 @@ TEST(MempoolLimitTests, WeightedTxTreeCheckSizeAfterDropping)
|
||||||
// Run the test until we have tested dropping each of the elements
|
// Run the test until we have tested dropping each of the elements
|
||||||
int trialNum = 0;
|
int trialNum = 0;
|
||||||
while (testedDropping.size() < 3) {
|
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().cost);
|
||||||
EXPECT_EQ(0, tree.getTotalWeight().evictionWeight);
|
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().cost);
|
||||||
EXPECT_EQ(4000, tree.getTotalWeight().evictionWeight);
|
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().cost);
|
||||||
EXPECT_EQ(8000, tree.getTotalWeight().evictionWeight);
|
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_COST, MIN_TX_COST + LOW_FEE_PENALTY)));
|
||||||
EXPECT_EQ(12000, tree.getTotalWeight().cost);
|
EXPECT_EQ(12000, tree.getTotalWeight().cost);
|
||||||
EXPECT_EQ(12000 + LOW_FEE_PENALTY, tree.getTotalWeight().evictionWeight);
|
EXPECT_EQ(12000 + LOW_FEE_PENALTY, tree.getTotalWeight().evictionWeight);
|
||||||
boost::optional<uint256> drop = tree.maybeDropRandom();
|
boost::optional<uint256> drop = tree.maybeDropRandom();
|
||||||
|
@ -126,8 +126,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.cost);
|
EXPECT_EQ(MIN_TX_COST, info.txWeight.cost);
|
||||||
EXPECT_EQ(MIN_TX_WEIGHT, info.txWeight.evictionWeight);
|
EXPECT_EQ(MIN_TX_COST, info.txWeight.evictionWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lower than standard fee
|
// Lower than standard fee
|
||||||
|
@ -138,8 +138,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.cost);
|
EXPECT_EQ(MIN_TX_COST, info.txWeight.cost);
|
||||||
EXPECT_EQ(MIN_TX_WEIGHT + LOW_FEE_PENALTY, info.txWeight.evictionWeight);
|
EXPECT_EQ(MIN_TX_COST + LOW_FEE_PENALTY, info.txWeight.evictionWeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Larger Tx
|
// Larger Tx
|
||||||
|
|
|
@ -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("-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("-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("-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("-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.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("-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,8 +978,8 @@ 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_COST_LIMIT);
|
int64_t mempoolTotalCostLimit = GetArg("-mempool.tx_cost_limit", DEFAULT_MEMPOOL_TOTAL_COST_LIMIT);
|
||||||
int64_t mempoolEvictionMemorySeconds = GetArg("-mempoolevictionmemoryminutes", DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES) * 60;
|
int64_t mempoolEvictionMemorySeconds = GetArg("-mempool.eviction_memory_minutes", DEFAULT_MEMPOOL_EVICTION_MEMORY_MINUTES) * 60;
|
||||||
mempool.SetMempoolCostLimit(mempoolTotalCostLimit, mempoolEvictionMemorySeconds);
|
mempool.SetMempoolCostLimit(mempoolTotalCostLimit, mempoolEvictionMemorySeconds);
|
||||||
|
|
||||||
fCheckBlockIndex = GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
|
fCheckBlockIndex = GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
|
||||||
|
|
|
@ -151,7 +151,7 @@ WeightedTxInfo WeightedTxInfo::from(const CTransaction& tx, const CAmount& fee)
|
||||||
memUsage += tx.vJoinSplit.size() * JOINSPLIT_SIZE;
|
memUsage += tx.vJoinSplit.size() * JOINSPLIT_SIZE;
|
||||||
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_COST);
|
||||||
int64_t evictionWeight = cost;
|
int64_t evictionWeight = cost;
|
||||||
if (fee < DEFAULT_FEE) {
|
if (fee < DEFAULT_FEE) {
|
||||||
evictionWeight += LOW_FEE_PENALTY;
|
evictionWeight += LOW_FEE_PENALTY;
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
const size_t DEFAULT_MEMPOOL_TOTAL_COST_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 EVICTION_MEMORY_ENTRIES = 40000;
|
||||||
const uint64_t MIN_TX_WEIGHT = 4000;
|
const uint64_t MIN_TX_COST = 4000;
|
||||||
const uint64_t LOW_FEE_PENALTY = 16000;
|
const uint64_t LOW_FEE_PENALTY = 16000;
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ class RecentlyEvictedList
|
||||||
public:
|
public:
|
||||||
RecentlyEvictedList(size_t capacity_, int64_t timeToKeep_) : capacity(capacity_), timeToKeep(timeToKeep_)
|
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);
|
void add(const uint256& txId);
|
||||||
bool contains(const uint256& txId);
|
bool contains(const uint256& txId);
|
||||||
|
|
Loading…
Reference in New Issue