mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-22 23:00:55 +00:00
use asserts instead of checks
This commit is contained in:
@@ -130,8 +130,7 @@ class XRPNotCreated
|
||||
std::int64_t drops_ = 0;
|
||||
|
||||
public:
|
||||
static constexpr auto kRelevantLedgerEntryTypes =
|
||||
VisitLedgerEntryTypes<ltACCOUNT_ROOT, ltPAYCHAN, ltESCROW>{};
|
||||
static constexpr auto kRelevantLedgerEntryTypes = VisitAllLedgerEntryTypes{};
|
||||
|
||||
void
|
||||
visitEntry(bool, SLE::const_ref, SLE::const_ref);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
@@ -51,7 +52,11 @@ ValidBookDirectory::visitEntry(
|
||||
// Only validate newly-created directories and sfRootIndex changes;
|
||||
// LedgerStateFix handles legacy bad exchange-rate metadata. Skip deletions
|
||||
// because `after` is not guaranteed to be null.
|
||||
if (badBookDirectory_ || isDelete || !after || after->getType() != ltDIR_NODE)
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltDIR_NODE) && (!after || after->getType() == ltDIR_NODE),
|
||||
"xrpl::ValidBookDirectory::visitEntry : directory node input");
|
||||
|
||||
if (badBookDirectory_ || isDelete || !after)
|
||||
return;
|
||||
|
||||
auto const rootIndex = after->getFieldH256(sfRootIndex);
|
||||
|
||||
@@ -188,6 +188,11 @@ XRPNotCreated::finalize(
|
||||
void
|
||||
XRPBalanceChecks::visitEntry(bool, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltACCOUNT_ROOT) &&
|
||||
(!after || after->getType() == ltACCOUNT_ROOT),
|
||||
"xrpl::XRPBalanceChecks::visitEntry : account root input");
|
||||
|
||||
auto isBad = [](STAmount const& balance) {
|
||||
if (!balance.native())
|
||||
return true;
|
||||
@@ -206,10 +211,10 @@ XRPBalanceChecks::visitEntry(bool, SLE::const_ref before, SLE::const_ref after)
|
||||
return false;
|
||||
};
|
||||
|
||||
if (before && before->getType() == ltACCOUNT_ROOT)
|
||||
if (before)
|
||||
bad_ |= isBad((*before)[sfBalance]);
|
||||
|
||||
if (after && after->getType() == ltACCOUNT_ROOT)
|
||||
if (after)
|
||||
bad_ |= isBad((*after)[sfBalance]);
|
||||
}
|
||||
|
||||
@@ -235,6 +240,10 @@ XRPBalanceChecks::finalize(
|
||||
void
|
||||
NoBadOffers::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltOFFER) && (!after || after->getType() == ltOFFER),
|
||||
"xrpl::NoBadOffers::visitEntry : offer input");
|
||||
|
||||
auto isBad = [](STAmount const& pays, STAmount const& gets) {
|
||||
// An offer should never be negative
|
||||
if (pays < beast::kZero)
|
||||
@@ -247,10 +256,10 @@ NoBadOffers::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref aft
|
||||
return pays.native() && gets.native();
|
||||
};
|
||||
|
||||
if (before && before->getType() == ltOFFER)
|
||||
if (before)
|
||||
bad_ |= isBad((*before)[sfTakerPays], (*before)[sfTakerGets]);
|
||||
|
||||
if (after && after->getType() == ltOFFER)
|
||||
if (after)
|
||||
bad_ |= isBad((*after)[sfTakerPays], (*after)[sfTakerGets]);
|
||||
}
|
||||
|
||||
@@ -276,6 +285,14 @@ NoBadOffers::finalize(
|
||||
void
|
||||
NoZeroEscrow::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
auto const validType = [](SLE::const_ref sle) {
|
||||
return !sle || sle->getType() == ltESCROW || sle->getType() == ltMPTOKEN_ISSUANCE ||
|
||||
sle->getType() == ltMPTOKEN;
|
||||
};
|
||||
XRPL_ASSERT(
|
||||
validType(before) && validType(after),
|
||||
"xrpl::NoZeroEscrow::visitEntry : escrow or mpt input");
|
||||
|
||||
auto isBad = [](STAmount const& amount) {
|
||||
// XRP case
|
||||
if (amount.native())
|
||||
@@ -380,7 +397,11 @@ NoZeroEscrow::finalize(
|
||||
void
|
||||
AccountRootsNotDeleted::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref)
|
||||
{
|
||||
if (isDelete && before && before->getType() == ltACCOUNT_ROOT)
|
||||
XRPL_ASSERT(
|
||||
!before || before->getType() == ltACCOUNT_ROOT,
|
||||
"xrpl::AccountRootsNotDeleted::visitEntry : account root input");
|
||||
|
||||
if (isDelete && before)
|
||||
accountsDeleted_++;
|
||||
}
|
||||
|
||||
@@ -430,7 +451,12 @@ AccountRootsNotDeleted::finalize(
|
||||
void
|
||||
AccountRootsDeletedClean::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
if (isDelete && before && before->getType() == ltACCOUNT_ROOT)
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltACCOUNT_ROOT) &&
|
||||
(!after || after->getType() == ltACCOUNT_ROOT),
|
||||
"xrpl::AccountRootsDeletedClean::visitEntry : account root input");
|
||||
|
||||
if (isDelete && before)
|
||||
accountsDeleted_.emplace_back(before, after);
|
||||
}
|
||||
|
||||
@@ -601,9 +627,13 @@ LedgerEntryTypesMatch::finalize(
|
||||
void
|
||||
NoXRPTrustLines::visitEntry(bool, SLE::const_ref, SLE::const_ref after)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
!after || after->getType() == ltRIPPLE_STATE,
|
||||
"xrpl::NoXRPTrustLines::visitEntry : ripple state input");
|
||||
|
||||
bool const overwriteFixEnabled = isFeatureEnabled(fixCleanup3_1_3, true);
|
||||
|
||||
if (after && after->getType() == ltRIPPLE_STATE)
|
||||
if (after)
|
||||
{
|
||||
// checking the issue directly here instead of
|
||||
// relying on .native() just in case native somehow
|
||||
@@ -641,7 +671,11 @@ NoXRPTrustLines::finalize(
|
||||
void
|
||||
NoDeepFreezeTrustLinesWithoutFreeze::visitEntry(bool, SLE::const_ref, SLE::const_ref after)
|
||||
{
|
||||
if (after && after->getType() == ltRIPPLE_STATE)
|
||||
XRPL_ASSERT(
|
||||
!after || after->getType() == ltRIPPLE_STATE,
|
||||
"xrpl::NoDeepFreezeTrustLinesWithoutFreeze::visitEntry : ripple state input");
|
||||
|
||||
if (after)
|
||||
{
|
||||
bool const overwriteFixEnabled = isFeatureEnabled(fixCleanup3_1_3, true);
|
||||
|
||||
@@ -684,7 +718,12 @@ NoDeepFreezeTrustLinesWithoutFreeze::finalize(
|
||||
void
|
||||
ValidNewAccountRoot::visitEntry(bool, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
if (!before && after->getType() == ltACCOUNT_ROOT)
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltACCOUNT_ROOT) &&
|
||||
(!after || after->getType() == ltACCOUNT_ROOT),
|
||||
"xrpl::ValidNewAccountRoot::visitEntry : account root input");
|
||||
|
||||
if (!before && after)
|
||||
{
|
||||
accountsCreated_++;
|
||||
accountSeq_ = (*after)[sfSequence];
|
||||
@@ -758,6 +797,10 @@ ValidNewAccountRoot::finalize(
|
||||
void
|
||||
ValidClawback::visitEntry(bool, SLE::const_ref before, SLE::const_ref)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
!before || before->getType() == ltRIPPLE_STATE || before->getType() == ltMPTOKEN,
|
||||
"xrpl::ValidClawback::visitEntry : ripple state or mptoken input");
|
||||
|
||||
if (before && before->getType() == ltRIPPLE_STATE)
|
||||
trustlinesChanged_++;
|
||||
|
||||
@@ -843,13 +886,18 @@ ValidClawback::finalize(
|
||||
void
|
||||
ValidPseudoAccounts::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltACCOUNT_ROOT) &&
|
||||
(!after || after->getType() == ltACCOUNT_ROOT),
|
||||
"xrpl::ValidPseudoAccounts::visitEntry : account root input");
|
||||
|
||||
if (isDelete)
|
||||
{
|
||||
// Deletion is ignored
|
||||
return;
|
||||
}
|
||||
|
||||
if (after && after->getType() == ltACCOUNT_ROOT)
|
||||
if (after)
|
||||
{
|
||||
bool const isPseudo = [&]() {
|
||||
// isPseudoAccount checks that any of the pseudo-account fields are
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/Zero.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/LedgerFormats.h>
|
||||
#include <xrpl/protocol/SField.h>
|
||||
@@ -17,10 +18,12 @@ namespace xrpl {
|
||||
void
|
||||
ValidLoan::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
if (after && after->getType() == ltLOAN)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltLOAN) && (!after || after->getType() == ltLOAN),
|
||||
"xrpl::ValidLoan::visitEntry : loan input");
|
||||
|
||||
if (after)
|
||||
loans_.emplace_back(before, after);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/Zero.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/helpers/NFTokenHelpers.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
@@ -30,9 +31,10 @@ ValidNFTokenPage::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_re
|
||||
static constexpr uint256 const& kPageBits = nft::kPageMask;
|
||||
static constexpr uint256 kAccountBits = ~kPageBits;
|
||||
|
||||
if ((before && before->getType() != ltNFTOKEN_PAGE) ||
|
||||
(after && after->getType() != ltNFTOKEN_PAGE))
|
||||
return;
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltNFTOKEN_PAGE) &&
|
||||
(!after || after->getType() == ltNFTOKEN_PAGE),
|
||||
"xrpl::ValidNFTokenPage::visitEntry : nftoken page input");
|
||||
|
||||
auto check = [this, isDelete](SLE::const_ref sle) {
|
||||
uint256 const account = sle->key() & kAccountBits;
|
||||
@@ -185,13 +187,18 @@ ValidNFTokenPage::finalize(
|
||||
void
|
||||
NFTokenCountTracking::visitEntry(bool, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
if (before && before->getType() == ltACCOUNT_ROOT)
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltACCOUNT_ROOT) &&
|
||||
(!after || after->getType() == ltACCOUNT_ROOT),
|
||||
"xrpl::NFTokenCountTracking::visitEntry : account root input");
|
||||
|
||||
if (before)
|
||||
{
|
||||
beforeMintedTotal_ += (*before)[~sfMintedNFTokens].value_or(0);
|
||||
beforeBurnedTotal_ += (*before)[~sfBurnedNFTokens].value_or(0);
|
||||
}
|
||||
|
||||
if (after && after->getType() == ltACCOUNT_ROOT)
|
||||
if (after)
|
||||
{
|
||||
afterMintedTotal_ += (*after)[~sfMintedNFTokens].value_or(0);
|
||||
afterBurnedTotal_ += (*after)[~sfBurnedNFTokens].value_or(0);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/Indexes.h>
|
||||
@@ -19,6 +20,13 @@ namespace xrpl {
|
||||
void
|
||||
ValidPermissionedDEX::visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
auto const validType = [](SLE::const_ref sle) {
|
||||
return !sle || sle->getType() == ltDIR_NODE || sle->getType() == ltOFFER;
|
||||
};
|
||||
XRPL_ASSERT(
|
||||
validType(before) && validType(after),
|
||||
"xrpl::ValidPermissionedDEX::visitEntry : directory node or offer input");
|
||||
|
||||
if (after && after->getType() == ltDIR_NODE)
|
||||
{
|
||||
if (after->isFieldPresent(sfDomainID))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
#include <xrpl/beast/utility/Journal.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ReadView.h>
|
||||
#include <xrpl/ledger/helpers/CredentialHelpers.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
@@ -22,10 +23,10 @@ namespace xrpl {
|
||||
void
|
||||
ValidPermissionedDomain::visitEntry(bool isDel, SLE::const_ref before, SLE::const_ref after)
|
||||
{
|
||||
if (before && before->getType() != ltPERMISSIONED_DOMAIN)
|
||||
return;
|
||||
if (after && after->getType() != ltPERMISSIONED_DOMAIN)
|
||||
return;
|
||||
XRPL_ASSERT(
|
||||
(!before || before->getType() == ltPERMISSIONED_DOMAIN) &&
|
||||
(!after || after->getType() == ltPERMISSIONED_DOMAIN),
|
||||
"xrpl::ValidPermissionedDomain::visitEntry : permissioned domain input");
|
||||
|
||||
auto check = [isDel](std::vector<SleStatus>& sleStatus, SLE::const_ref sle) {
|
||||
auto const& credentials = sle->getFieldArray(sfAcceptedCredentials);
|
||||
|
||||
Reference in New Issue
Block a user