Skip to content

Commit ebc2a9a

Browse files
a1q123456vvysokikh1
authored andcommitted
fix: Skip processing transaction batch if the batch is empty (#5670)
Avoids an assertion failure in NetworkOPsImp::apply in the unlikely event that all incoming transactions are invalid.
1 parent 70d5c62 commit ebc2a9a

File tree

3 files changed

+92
-6
lines changed

3 files changed

+92
-6
lines changed

src/test/app/NetworkOPs_test.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//------------------------------------------------------------------------------
2+
/*
3+
This file is part of rippled: https://github.com/ripple/rippled
4+
Copyright (c) 2020 Dev Null Productions
5+
6+
Permission to use, copy, modify, and/or distribute this software for any
7+
purpose with or without fee is hereby granted, provided that the above
8+
copyright notice and this permission notice appear in all copies.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
//==============================================================================
19+
20+
#include <test/jtx.h>
21+
#include <test/jtx/CaptureLogs.h>
22+
#include <test/jtx/Env.h>
23+
24+
#include <xrpld/app/misc/HashRouter.h>
25+
26+
namespace ripple {
27+
namespace test {
28+
29+
class NetworkOPs_test : public beast::unit_test::suite
30+
{
31+
public:
32+
void
33+
run() override
34+
{
35+
testAllBadHeldTransactions();
36+
}
37+
38+
void
39+
testAllBadHeldTransactions()
40+
{
41+
// All trasactions are already marked as SF_BAD, and we should be able
42+
// to handle the case properly without an assertion failure
43+
testcase("No valid transactions in batch");
44+
45+
std::string logs;
46+
47+
{
48+
using namespace jtx;
49+
auto const alice = Account{"alice"};
50+
Env env{
51+
*this,
52+
envconfig(),
53+
std::make_unique<CaptureLogs>(&logs),
54+
beast::severities::kAll};
55+
env.memoize(env.master);
56+
env.memoize(alice);
57+
58+
auto const jtx = env.jt(ticket::create(alice, 1), seq(1), fee(10));
59+
60+
auto transacionId = jtx.stx->getTransactionID();
61+
env.app().getHashRouter().setFlags(
62+
transacionId, HashRouterFlags::HELD);
63+
64+
env(jtx, json(jss::Sequence, 1), ter(terNO_ACCOUNT));
65+
66+
env.app().getHashRouter().setFlags(
67+
transacionId, HashRouterFlags::BAD);
68+
69+
env.close();
70+
}
71+
72+
BEAST_EXPECT(
73+
logs.find("No transaction to process!") != std::string::npos);
74+
}
75+
};
76+
77+
BEAST_DEFINE_TESTSUITE(NetworkOPs, app, ripple);
78+
79+
} // namespace test
80+
} // namespace ripple

src/xrpld/app/misc/NetworkOPs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,11 @@ NetworkOPsImp::processTransactionSet(CanonicalTXSet const& set)
14481448
for (auto& t : transactions)
14491449
mTransactions.push_back(std::move(t));
14501450
}
1451+
if (mTransactions.empty())
1452+
{
1453+
JLOG(m_journal.debug()) << "No transaction to process!";
1454+
return;
1455+
}
14511456

14521457
doTransactionSyncBatch(lock, [&](std::unique_lock<std::mutex> const&) {
14531458
XRPL_ASSERT(

src/xrpld/overlay/detail/PeerImp.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,7 @@ PeerImp::handleTransaction(
12861286

12871287
// Charge strongly for attempting to relay a txn with tfInnerBatchTxn
12881288
// LCOV_EXCL_START
1289-
if (stx->isFlag(tfInnerBatchTxn) &&
1290-
getCurrentTransactionRules()->enabled(featureBatch))
1289+
if (stx->isFlag(tfInnerBatchTxn))
12911290
{
12921291
JLOG(p_journal_.warn()) << "Ignoring Network relayed Tx containing "
12931292
"tfInnerBatchTxn (handleTransaction).";
@@ -2851,8 +2850,7 @@ PeerImp::checkTransaction(
28512850
{
28522851
// charge strongly for relaying batch txns
28532852
// LCOV_EXCL_START
2854-
if (stx->isFlag(tfInnerBatchTxn) &&
2855-
getCurrentTransactionRules()->enabled(featureBatch))
2853+
if (stx->isFlag(tfInnerBatchTxn))
28562854
{
28572855
JLOG(p_journal_.warn()) << "Ignoring Network relayed Tx containing "
28582856
"tfInnerBatchTxn (checkSignature).";
@@ -2866,6 +2864,9 @@ PeerImp::checkTransaction(
28662864
(stx->getFieldU32(sfLastLedgerSequence) <
28672865
app_.getLedgerMaster().getValidLedgerIndex()))
28682866
{
2867+
JLOG(p_journal_.info())
2868+
<< "Marking transaction " << stx->getTransactionID()
2869+
<< "as BAD because it's expired";
28692870
app_.getHashRouter().setFlags(
28702871
stx->getTransactionID(), HashRouterFlags::BAD);
28712872
charge(Resource::feeUselessData, "expired tx");
@@ -2922,7 +2923,7 @@ PeerImp::checkTransaction(
29222923
{
29232924
if (!validReason.empty())
29242925
{
2925-
JLOG(p_journal_.trace())
2926+
JLOG(p_journal_.debug())
29262927
<< "Exception checking transaction: " << validReason;
29272928
}
29282929

@@ -2949,7 +2950,7 @@ PeerImp::checkTransaction(
29492950
{
29502951
if (!reason.empty())
29512952
{
2952-
JLOG(p_journal_.trace())
2953+
JLOG(p_journal_.debug())
29532954
<< "Exception checking transaction: " << reason;
29542955
}
29552956
app_.getHashRouter().setFlags(

0 commit comments

Comments
 (0)