Skip to content

Commit a5a2b38

Browse files
committed
Review feedback from @dangell7: early return & coverage
- Exclude LogicError lines in ApplyView.cpp (specifically directory operations) from code coverage. - Replace the ability to set the next page on a new directory page with an assert, because nothing uses it right now. - Early return with success for batch inner transactions in preflight2.
1 parent 19c72b3 commit a5a2b38

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

src/libxrpl/ledger/ApplyView.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ findPreviousPage(ApplyView& view, Keylet const& directory, SLE::ref start)
4040
{
4141
node = view.peek(keylet::page(directory, page));
4242
if (!node)
43+
{ // LCOV_EXCL_START
4344
LogicError("Directory chain: root back-pointer broken.");
45+
// LCOV_EXCL_STOP
46+
}
4447
}
4548

4649
auto indexes = node->getFieldV256(sfIndexes);
@@ -59,7 +62,7 @@ insertKey(
5962
if (preserveOrder)
6063
{
6164
if (std::find(indexes.begin(), indexes.end(), key) != indexes.end())
62-
LogicError("dirInsert: double insertion");
65+
LogicError("dirInsert: double insertion"); // LCOV_EXCL_LINE
6366

6467
indexes.push_back(key);
6568
}
@@ -73,7 +76,7 @@ insertKey(
7376
auto pos = std::lower_bound(indexes.begin(), indexes.end(), key);
7477

7578
if (pos != indexes.end() && key == *pos)
76-
LogicError("dirInsert: double insertion");
79+
LogicError("dirInsert: double insertion"); // LCOV_EXCL_LINE
7780

7881
indexes.insert(pos, key);
7982
}
@@ -131,8 +134,15 @@ insertPage(
131134
// it's the default.
132135
if (page != 1)
133136
node->setFieldU64(sfIndexPrevious, page - 1);
137+
XRPL_ASSERT_PARTS(
138+
!nextPage,
139+
"ripple::directory::insertPage",
140+
"nextPage has default value");
141+
/* Reserved for future use when directory pages may be inserted in
142+
* between two other pages instead of only at the end of the chain.
134143
if (nextPage)
135144
node->setFieldU64(sfIndexNext, nextPage);
145+
*/
136146
describe(node);
137147
view.insert(node);
138148

@@ -197,10 +207,10 @@ ApplyView::emptyDirDelete(Keylet const& directory)
197207
auto nextPage = node->getFieldU64(sfIndexNext);
198208

199209
if (nextPage == rootPage && prevPage != rootPage)
200-
LogicError("Directory chain: fwd link broken");
210+
LogicError("Directory chain: fwd link broken"); // LCOV_EXCL_LINE
201211

202212
if (prevPage == rootPage && nextPage != rootPage)
203-
LogicError("Directory chain: rev link broken");
213+
LogicError("Directory chain: rev link broken"); // LCOV_EXCL_LINE
204214

205215
// Older versions of the code would, in some cases, allow the last
206216
// page to be empty. Remove such pages:
@@ -209,7 +219,10 @@ ApplyView::emptyDirDelete(Keylet const& directory)
209219
auto last = peek(keylet::page(directory, nextPage));
210220

211221
if (!last)
222+
{ // LCOV_EXCL_START
212223
LogicError("Directory chain: fwd link broken.");
224+
// LCOV_EXCL_STOP
225+
}
213226

214227
if (!last->getFieldV256(sfIndexes).empty())
215228
return false;
@@ -281,10 +294,16 @@ ApplyView::dirRemove(
281294
if (page == rootPage)
282295
{
283296
if (nextPage == page && prevPage != page)
297+
{ // LCOV_EXCL_START
284298
LogicError("Directory chain: fwd link broken");
299+
// LCOV_EXCL_STOP
300+
}
285301

286302
if (prevPage == page && nextPage != page)
303+
{ // LCOV_EXCL_START
287304
LogicError("Directory chain: rev link broken");
305+
// LCOV_EXCL_STOP
306+
}
288307

289308
// Older versions of the code would, in some cases,
290309
// allow the last page to be empty. Remove such
@@ -293,7 +312,10 @@ ApplyView::dirRemove(
293312
{
294313
auto last = peek(keylet::page(directory, nextPage));
295314
if (!last)
315+
{ // LCOV_EXCL_START
296316
LogicError("Directory chain: fwd link broken.");
317+
// LCOV_EXCL_STOP
318+
}
297319

298320
if (last->getFieldV256(sfIndexes).empty())
299321
{
@@ -325,25 +347,25 @@ ApplyView::dirRemove(
325347

326348
// This can never happen for nodes other than the root:
327349
if (nextPage == page)
328-
LogicError("Directory chain: fwd link broken");
350+
LogicError("Directory chain: fwd link broken"); // LCOV_EXCL_LINE
329351

330352
if (prevPage == page)
331-
LogicError("Directory chain: rev link broken");
353+
LogicError("Directory chain: rev link broken"); // LCOV_EXCL_LINE
332354

333355
// This node isn't the root, so it can either be in the
334356
// middle of the list, or at the end. Unlink it first
335357
// and then check if that leaves the list with only a
336358
// root:
337359
auto prev = peek(keylet::page(directory, prevPage));
338360
if (!prev)
339-
LogicError("Directory chain: fwd link broken.");
361+
LogicError("Directory chain: fwd link broken."); // LCOV_EXCL_LINE
340362
// Fix previous to point to its new next.
341363
prev->setFieldU64(sfIndexNext, nextPage);
342364
update(prev);
343365

344366
auto next = peek(keylet::page(directory, nextPage));
345367
if (!next)
346-
LogicError("Directory chain: rev link broken.");
368+
LogicError("Directory chain: rev link broken."); // LCOV_EXCL_LINE
347369
// Fix next to point to its new previous.
348370
next->setFieldU64(sfIndexPrevious, prevPage);
349371
update(next);
@@ -367,7 +389,10 @@ ApplyView::dirRemove(
367389
// And the root points to the last page:
368390
auto root = peek(keylet::page(directory, rootPage));
369391
if (!root)
392+
{ // LCOV_EXCL_START
370393
LogicError("Directory chain: root link broken.");
394+
// LCOV_EXCL_STOP
395+
}
371396
root->setFieldU64(sfIndexPrevious, prevPage);
372397
update(root);
373398

src/xrpld/app/tx/detail/Transactor.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,23 @@ Transactor::preflight2(PreflightContext const& ctx)
205205
return *ret;
206206

207207
// Skip signature check on batch inner transactions
208-
if (!ctx.tx.isFlag(tfInnerBatchTxn) || !ctx.rules.enabled(featureBatch))
209-
{
210-
auto const sigValid = checkValidity(
211-
ctx.app.getHashRouter(), ctx.tx, ctx.rules, ctx.app.config());
212-
if (sigValid.first == Validity::SigBad)
213-
{ // LCOV_EXCL_START
214-
JLOG(ctx.j.debug())
215-
<< "preflight2: bad signature. " << sigValid.second;
216-
return temINVALID;
217-
} // LCOV_EXCL_STOP
208+
if (ctx.tx.isFlag(tfInnerBatchTxn) && !ctx.rules.enabled(featureBatch))
209+
return tesSUCCESS;
210+
// Do not add any checks after this point that are relevant for
211+
// batch inner transactions. They will be skipped.
212+
213+
auto const sigValid = checkValidity(
214+
ctx.app.getHashRouter(), ctx.tx, ctx.rules, ctx.app.config());
215+
if (sigValid.first == Validity::SigBad)
216+
{ // LCOV_EXCL_START
217+
JLOG(ctx.j.debug()) << "preflight2: bad signature. " << sigValid.second;
218+
return temINVALID;
219+
// LCOV_EXCL_STOP
218220
}
221+
222+
// Do not add any checks after this point that are relevant for
223+
// batch inner transactions. They will be skipped.
224+
219225
return tesSUCCESS;
220226
}
221227

0 commit comments

Comments
 (0)