mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-10 05:35:48 +00:00
Validate TxQ config and expected transactions range
This commit is contained in:
@@ -111,10 +111,12 @@ TxQ::FeeMetrics::update(Application& app,
|
|||||||
// Ledgers are taking to long to process,
|
// Ledgers are taking to long to process,
|
||||||
// so clamp down on limits.
|
// so clamp down on limits.
|
||||||
auto const cutPct = 100 - setup.slowConsensusDecreasePercent;
|
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(
|
txnsExpected_ = boost::algorithm::clamp(
|
||||||
mulDiv(size, cutPct, 100).second,
|
mulDiv(size, cutPct, 100).second, minimumTxnCount_, upperLimit);
|
||||||
minimumTxnCount_,
|
|
||||||
mulDiv(txnsExpected_, cutPct, 100).second);
|
|
||||||
recentTxnCounts_.clear();
|
recentTxnCounts_.clear();
|
||||||
}
|
}
|
||||||
else if (size > txnsExpected_ ||
|
else if (size > txnsExpected_ ||
|
||||||
@@ -1534,7 +1536,28 @@ setup_TxQ(Config const& config)
|
|||||||
set(setup.targetTxnInLedger, "target_txn_in_ledger", section);
|
set(setup.targetTxnInLedger, "target_txn_in_ledger", section);
|
||||||
std::uint32_t max;
|
std::uint32_t max;
|
||||||
if (set(max, "maximum_txn_in_ledger", section))
|
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);
|
setup.maximumTxnInLedger.emplace(max);
|
||||||
|
}
|
||||||
|
|
||||||
/* The math works as expected for any value up to and including
|
/* The math works as expected for any value up to and including
|
||||||
MAXINT, but put a reasonable limit on this percentage so that
|
MAXINT, but put a reasonable limit on this percentage so that
|
||||||
|
|||||||
@@ -1144,7 +1144,9 @@ public:
|
|||||||
void testMaximum()
|
void testMaximum()
|
||||||
{
|
{
|
||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
|
{
|
||||||
Env env(*this, makeConfig(
|
Env env(*this, makeConfig(
|
||||||
{ {"minimum_txn_in_ledger_standalone", "2"},
|
{ {"minimum_txn_in_ledger_standalone", "2"},
|
||||||
{"target_txn_in_ledger", "4"},
|
{"target_txn_in_ledger", "4"},
|
||||||
@@ -1165,7 +1167,65 @@ public:
|
|||||||
env.close();
|
env.close();
|
||||||
// If not for the maximum, the per ledger would be 11.
|
// If not for the maximum, the per ledger would be 11.
|
||||||
checkMetrics(env, 0, 10, 0, 5, 256, 800025);
|
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()
|
void testUnexpectedBalanceChange()
|
||||||
|
|||||||
Reference in New Issue
Block a user