Make transaction queue order deterministic:

* Sort by fee level (which is the current behavior) then by transaction
  ID (hash).
* Edge case when the account at the end of the queue submits a higher
  paying transaction to walk backwards and compare against the cheapest
  transaction from a different account.
* Use std::if_any to simplify the JobQueue::isOverloaded loop.
This commit is contained in:
Edward Hennis
2021-12-08 16:59:01 -05:00
committed by Nik Bougalis
parent ae9930b87d
commit b1c9b134dc
5 changed files with 185 additions and 136 deletions

View File

@@ -1538,21 +1538,37 @@ class LedgerRPC_test : public beast::unit_test::suite
env.close();
jrr = env.rpc("json", "ledger", to_string(jv))[jss::result];
std::string txid1;
std::string txid2;
if (BEAST_EXPECT(jrr[jss::queue_data].size() == 2))
{
auto const& txj = jrr[jss::queue_data][0u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
BEAST_EXPECT(txj["retries_remaining"] == 10);
BEAST_EXPECT(txj.isMember(jss::tx));
auto const& tx = txj[jss::tx];
BEAST_EXPECT(tx[jss::Account] == alice.human());
BEAST_EXPECT(tx[jss::TransactionType] == jss::OfferCreate);
txid1 = tx[jss::hash].asString();
}
const std::string txid1 = [&]() {
if (BEAST_EXPECT(jrr[jss::queue_data].size() == 2))
{
const std::string txid0 = [&]() {
auto const& txj = jrr[jss::queue_data][0u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
BEAST_EXPECT(txj["retries_remaining"] == 10);
BEAST_EXPECT(txj.isMember(jss::tx));
auto const& tx = txj[jss::tx];
BEAST_EXPECT(tx[jss::Account] == alice.human());
BEAST_EXPECT(tx[jss::TransactionType] == jss::AccountSet);
return tx[jss::hash].asString();
}();
auto const& txj = jrr[jss::queue_data][1u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
BEAST_EXPECT(txj["retries_remaining"] == 10);
BEAST_EXPECT(txj.isMember(jss::tx));
auto const& tx = txj[jss::tx];
BEAST_EXPECT(tx[jss::Account] == alice.human());
BEAST_EXPECT(tx[jss::TransactionType] == jss::OfferCreate);
const auto txid1 = tx[jss::hash].asString();
BEAST_EXPECT(txid0 < txid1);
return txid1;
}
return std::string{};
}();
env.close();
@@ -1561,7 +1577,15 @@ class LedgerRPC_test : public beast::unit_test::suite
jrr = env.rpc("json", "ledger", to_string(jv))[jss::result];
if (BEAST_EXPECT(jrr[jss::queue_data].size() == 2))
{
auto const& txj = jrr[jss::queue_data][0u];
auto const txid0 = [&]() {
auto const& txj = jrr[jss::queue_data][0u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
BEAST_EXPECT(txj.isMember(jss::tx));
return txj[jss::tx].asString();
}();
auto const& txj = jrr[jss::queue_data][1u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
@@ -1569,6 +1593,7 @@ class LedgerRPC_test : public beast::unit_test::suite
BEAST_EXPECT(txj["last_result"] == "terPRE_SEQ");
BEAST_EXPECT(txj.isMember(jss::tx));
BEAST_EXPECT(txj[jss::tx] == txid1);
BEAST_EXPECT(txid0 < txid1);
}
env.close();
@@ -1579,7 +1604,7 @@ class LedgerRPC_test : public beast::unit_test::suite
jrr = env.rpc("json", "ledger", to_string(jv))[jss::result];
if (BEAST_EXPECT(jrr[jss::queue_data].size() == 2))
{
auto const& txj = jrr[jss::queue_data][0u];
auto const& txj = jrr[jss::queue_data][1u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
@@ -1588,7 +1613,7 @@ class LedgerRPC_test : public beast::unit_test::suite
BEAST_EXPECT(txj.isMember(jss::tx));
BEAST_EXPECT(txj[jss::tx].isMember(jss::tx_blob));
auto const& txj2 = jrr[jss::queue_data][1u];
auto const& txj2 = jrr[jss::queue_data][0u];
BEAST_EXPECT(txj2[jss::account] == alice.human());
BEAST_EXPECT(txj2[jss::fee_level] == "256");
BEAST_EXPECT(txj2["preflight_result"] == "tesSUCCESS");
@@ -1607,18 +1632,21 @@ class LedgerRPC_test : public beast::unit_test::suite
jv[jss::binary] = false;
jrr = env.rpc("json", "ledger", to_string(jv))[jss::result];
if (BEAST_EXPECT(jrr[jss::queue_data].size() == 1))
{
auto const& txj = jrr[jss::queue_data][0u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
BEAST_EXPECT(txj["retries_remaining"] == 1);
BEAST_EXPECT(txj["last_result"] == "terPRE_SEQ");
BEAST_EXPECT(txj.isMember(jss::tx));
BEAST_EXPECT(txj[jss::tx] != txid1);
txid2 = txj[jss::tx].asString();
}
const std::string txid2 = [&]() {
if (BEAST_EXPECT(jrr[jss::queue_data].size() == 1))
{
auto const& txj = jrr[jss::queue_data][0u];
BEAST_EXPECT(txj[jss::account] == alice.human());
BEAST_EXPECT(txj[jss::fee_level] == "256");
BEAST_EXPECT(txj["preflight_result"] == "tesSUCCESS");
BEAST_EXPECT(txj["retries_remaining"] == 1);
BEAST_EXPECT(txj["last_result"] == "terPRE_SEQ");
BEAST_EXPECT(txj.isMember(jss::tx));
BEAST_EXPECT(txj[jss::tx] != txid1);
return txj[jss::tx].asString();
}
return std::string{};
}();
jv[jss::full] = true;