From 7515811efa096c653040f3aa6957a1b2237a88a5 Mon Sep 17 00:00:00 2001 From: Bart Date: Fri, 1 May 2026 05:50:00 -0400 Subject: [PATCH] refactor: Revert certain `Throw`s by `LogicError`s (#7036) Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com> --- include/xrpl/ledger/Ledger.h | 13 ------------- src/libxrpl/ledger/Ledger.cpp | 33 +++++---------------------------- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/include/xrpl/ledger/Ledger.h b/include/xrpl/ledger/Ledger.h index 69fb27975d..62303ba3d2 100644 --- a/include/xrpl/ledger/Ledger.h +++ b/include/xrpl/ledger/Ledger.h @@ -229,19 +229,6 @@ public: std::shared_ptr const& txn, std::shared_ptr const& metaData) override; - // Insert the transaction, and return the hash of the SHAMap leaf node - // holding the transaction. The hash can be used to fetch the transaction - // directly, instead of traversing the SHAMap - // @param key transaction ID - // @param txn transaction - // @param metaData transaction metadata - // @return hash of SHAMap leaf node that holds the transaction - uint256 - rawTxInsertWithHash( - uint256 const& key, - std::shared_ptr const& txn, - std::shared_ptr const& metaData); - //-------------------------------------------------------------------------- void diff --git a/src/libxrpl/ledger/Ledger.cpp b/src/libxrpl/ledger/Ledger.cpp index 729f1ebce9..6630d4f9bf 100644 --- a/src/libxrpl/ledger/Ledger.cpp +++ b/src/libxrpl/ledger/Ledger.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -31,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -43,7 +41,6 @@ #include #include #include -#include #include #include @@ -493,14 +490,14 @@ void Ledger::rawErase(std::shared_ptr const& sle) { if (!stateMap_.delItem(sle->key())) - Throw("Ledger::rawErase: key not found"); + LogicError("Ledger::rawErase: key not found"); } void Ledger::rawErase(uint256 const& key) { if (!stateMap_.delItem(key)) - Throw("Ledger::rawErase: key not found"); + LogicError("Ledger::rawErase: key not found"); } void @@ -510,7 +507,7 @@ Ledger::rawInsert(std::shared_ptr const& sle) sle->add(ss); if (!stateMap_.addGiveItem( SHAMapNodeType::tnACCOUNT_STATE, make_shamapitem(sle->key(), ss.slice()))) - Throw("Ledger::rawInsert: key already exists"); + LogicError("Ledger::rawInsert: key already exists"); } void @@ -520,7 +517,7 @@ Ledger::rawReplace(std::shared_ptr const& sle) sle->add(ss); if (!stateMap_.updateGiveItem( SHAMapNodeType::tnACCOUNT_STATE, make_shamapitem(sle->key(), ss.slice()))) - Throw("Ledger::rawReplace: key not found"); + LogicError("Ledger::rawReplace: key not found"); } void @@ -536,27 +533,7 @@ Ledger::rawTxInsert( s.addVL(txn->peekData()); s.addVL(metaData->peekData()); if (!txMap_.addGiveItem(SHAMapNodeType::tnTRANSACTION_MD, make_shamapitem(key, s.slice()))) - Throw("duplicate_tx: " + to_string(key)); -} - -uint256 -Ledger::rawTxInsertWithHash( - uint256 const& key, - std::shared_ptr const& txn, - std::shared_ptr const& metaData) -{ - XRPL_ASSERT(metaData, "xrpl::Ledger::rawTxInsertWithHash : non-null metadata input"); - - // low-level - just add to table - Serializer s(txn->getDataLength() + metaData->getDataLength() + 16); - s.addVL(txn->peekData()); - s.addVL(metaData->peekData()); - auto item = make_shamapitem(key, s.slice()); - auto hash = sha512Half(HashPrefix::txNode, item->slice(), item->key()); - if (!txMap_.addGiveItem(SHAMapNodeType::tnTRANSACTION_MD, std::move(item))) - Throw("duplicate_tx: " + to_string(key)); - - return hash; + LogicError("duplicate_tx: " + to_string(key)); } bool