Validate TxQ config and expected transactions range

This commit is contained in:
Edward Hennis
2019-02-27 11:56:02 -05:00
committed by seelabs
parent a3470c225b
commit 4c06b3f86f
2 changed files with 100 additions and 17 deletions

View File

@@ -111,10 +111,12 @@ TxQ::FeeMetrics::update(Application& app,
// Ledgers are taking to long to process,
// so clamp down on limits.
auto const cutPct = 100 - setup.slowConsensusDecreasePercent;
// upperLimit must be >= minimumTxnCount_ or boost::clamp can give
// unexpected results
auto const upperLimit = std::max<std::uint64_t>(
mulDiv(txnsExpected_, cutPct, 100).second, minimumTxnCount_);
txnsExpected_ = boost::algorithm::clamp(
mulDiv(size, cutPct, 100).second,
minimumTxnCount_,
mulDiv(txnsExpected_, cutPct, 100).second);
mulDiv(size, cutPct, 100).second, minimumTxnCount_, upperLimit);
recentTxnCounts_.clear();
}
else if (size > txnsExpected_ ||
@@ -1534,7 +1536,28 @@ setup_TxQ(Config const& config)
set(setup.targetTxnInLedger, "target_txn_in_ledger", section);
std::uint32_t max;
if (set(max, "maximum_txn_in_ledger", section))
{
if (max < setup.minimumTxnInLedger)
{
Throw<std::runtime_error>(
"The minimum number of low-fee transactions allowed "
"per ledger (minimum_txn_in_ledger) exceeds "
"the maximum number of low-fee transactions allowed per "
"ledger (maximum_txn_in_ledger)."
);
}
if (max < setup.minimumTxnInLedgerSA)
{
Throw<std::runtime_error>(
"The minimum number of low-fee transactions allowed "
"per ledger (minimum_txn_in_ledger_standalone) exceeds "
"the maximum number of low-fee transactions allowed per "
"ledger (maximum_txn_in_ledger)."
);
}
setup.maximumTxnInLedger.emplace(max);
}
/* The math works as expected for any value up to and including
MAXINT, but put a reasonable limit on this percentage so that

View File

@@ -1144,7 +1144,9 @@ public:
void testMaximum()
{
using namespace jtx;
using namespace std::string_literals;
{
Env env(*this, makeConfig(
{ {"minimum_txn_in_ledger_standalone", "2"},
{"target_txn_in_ledger", "4"},
@@ -1165,7 +1167,65 @@ public:
env.close();
// If not for the maximum, the per ledger would be 11.
checkMetrics(env, 0, 10, 0, 5, 256, 800025);
}
try
{
Env env(*this, makeConfig(
{ {"minimum_txn_in_ledger", "200"},
{"minimum_txn_in_ledger_standalone", "200"},
{"target_txn_in_ledger", "4"},
{"maximum_txn_in_ledger", "5"} }));
// should throw
fail();
}
catch (std::runtime_error const& e)
{
BEAST_EXPECT(e.what() ==
"The minimum number of low-fee transactions allowed "
"per ledger (minimum_txn_in_ledger) exceeds "
"the maximum number of low-fee transactions allowed per "
"ledger (maximum_txn_in_ledger)."s
);
}
try
{
Env env(*this, makeConfig(
{ {"minimum_txn_in_ledger", "200"},
{"minimum_txn_in_ledger_standalone", "2"},
{"target_txn_in_ledger", "4"},
{"maximum_txn_in_ledger", "5"} }));
// should throw
fail();
}
catch (std::runtime_error const& e)
{
BEAST_EXPECT(e.what() ==
"The minimum number of low-fee transactions allowed "
"per ledger (minimum_txn_in_ledger) exceeds "
"the maximum number of low-fee transactions allowed per "
"ledger (maximum_txn_in_ledger)."s
);
}
try
{
Env env(*this, makeConfig(
{ {"minimum_txn_in_ledger", "2"},
{"minimum_txn_in_ledger_standalone", "200"},
{"target_txn_in_ledger", "4"},
{"maximum_txn_in_ledger", "5"} }));
// should throw
fail();
}
catch (std::runtime_error const& e)
{
BEAST_EXPECT(e.what() ==
"The minimum number of low-fee transactions allowed "
"per ledger (minimum_txn_in_ledger_standalone) exceeds "
"the maximum number of low-fee transactions allowed per "
"ledger (maximum_txn_in_ledger)."s
);
}
}
void testUnexpectedBalanceChange()