mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Clean up and modernize code:
This commit removes obsolete comments, dead or no longer useful code, and workarounds for several issues that were present in older compilers that we no longer support. Specifically: - It improves the transaction metadata handling class, simplifying its use and making it less error-prone. - It reduces the footprint of the Serializer class by consolidating code and leveraging templates. - It cleanups the ST* class hierarchy, removing dead code, improving and consolidating code to reduce complexity and code duplication. - It shores up the handling of currency codes and the conversation between 160-bit currency codes and their string representation. - It migrates beast::secure_erase to the ripple namespace and uses a call to OpenSSL_cleanse instead of the custom implementation.
This commit is contained in:
@@ -29,13 +29,8 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO Move to ripple/app/ledger/detail, rename to TxMeta
|
||||
class TxMeta
|
||||
{
|
||||
public:
|
||||
using pointer = std::shared_ptr<TxMeta>;
|
||||
using ref = const pointer&;
|
||||
|
||||
private:
|
||||
struct CtorHelper
|
||||
{
|
||||
@@ -49,32 +44,11 @@ private:
|
||||
CtorHelper);
|
||||
|
||||
public:
|
||||
TxMeta() : mLedger(0), mIndex(static_cast<std::uint32_t>(-1)), mResult(255)
|
||||
{
|
||||
}
|
||||
|
||||
TxMeta(uint256 const& txID, std::uint32_t ledger, std::uint32_t index)
|
||||
: mTransactionID(txID)
|
||||
, mLedger(ledger)
|
||||
, mIndex(static_cast<std::uint32_t>(-1))
|
||||
, mResult(255)
|
||||
{
|
||||
}
|
||||
|
||||
TxMeta(uint256 const& transactionID, std::uint32_t ledger);
|
||||
TxMeta(uint256 const& txID, std::uint32_t ledger, Blob const&);
|
||||
TxMeta(uint256 const& txID, std::uint32_t ledger, std::string const&);
|
||||
TxMeta(uint256 const& txID, std::uint32_t ledger, STObject const&);
|
||||
|
||||
void
|
||||
init(uint256 const& transactionID, std::uint32_t ledger);
|
||||
void
|
||||
clear()
|
||||
{
|
||||
mNodes.clear();
|
||||
}
|
||||
void
|
||||
swap(TxMeta&) noexcept;
|
||||
|
||||
uint256 const&
|
||||
getTxID()
|
||||
{
|
||||
@@ -101,16 +75,12 @@ public:
|
||||
return mIndex;
|
||||
}
|
||||
|
||||
bool
|
||||
isNodeAffected(uint256 const&) const;
|
||||
void
|
||||
setAffectedNode(uint256 const&, SField const& type, std::uint16_t nodeType);
|
||||
STObject&
|
||||
getAffectedNode(SLE::ref node, SField const& type); // create if needed
|
||||
STObject&
|
||||
getAffectedNode(uint256 const&);
|
||||
const STObject&
|
||||
peekAffectedNode(uint256 const&) const;
|
||||
|
||||
/** Return a list of accounts affected by this transaction */
|
||||
boost::container::flat_set<AccountID>
|
||||
@@ -151,9 +121,6 @@ public:
|
||||
return static_cast<bool>(mDelivered);
|
||||
}
|
||||
|
||||
static bool
|
||||
thread(STObject& node, uint256 const& prevTxID, std::uint32_t prevLgrID);
|
||||
|
||||
private:
|
||||
uint256 mTransactionID;
|
||||
std::uint32_t mLedger;
|
||||
|
||||
@@ -123,9 +123,7 @@ ApplyStateTable::apply(
|
||||
std::shared_ptr<Serializer> sMeta;
|
||||
if (!to.open())
|
||||
{
|
||||
TxMeta meta;
|
||||
// VFALCO Shouldn't TxMeta ctor do this?
|
||||
meta.init(tx.getTransactionID(), to.seq());
|
||||
TxMeta meta(tx.getTransactionID(), to.seq());
|
||||
if (deliver)
|
||||
meta.setDeliveredAmount(*deliver);
|
||||
Mods newMod;
|
||||
@@ -526,12 +524,24 @@ ApplyStateTable::threadItem(TxMeta& meta, std::shared_ptr<SLE> const& sle)
|
||||
{
|
||||
key_type prevTxID;
|
||||
LedgerIndex prevLgrID;
|
||||
|
||||
if (!sle->thread(meta.getTxID(), meta.getLgrSeq(), prevTxID, prevLgrID))
|
||||
return;
|
||||
if (prevTxID.isZero())
|
||||
return;
|
||||
TxMeta::thread(
|
||||
meta.getAffectedNode(sle, sfModifiedNode), prevTxID, prevLgrID);
|
||||
|
||||
if (!prevTxID.isZero())
|
||||
{
|
||||
auto& node = meta.getAffectedNode(sle, sfModifiedNode);
|
||||
|
||||
if (node.getFieldIndex(sfPreviousTxnID) == -1)
|
||||
{
|
||||
assert(node.getFieldIndex(sfPreviousTxnLgrSeq) == -1);
|
||||
node.setFieldH256(sfPreviousTxnID, prevTxID);
|
||||
node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
|
||||
}
|
||||
|
||||
assert(node.getFieldH256(sfPreviousTxnID) == prevTxID);
|
||||
assert(node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SLE>
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO TODO rename class to TransactionMeta
|
||||
|
||||
template <class T>
|
||||
TxMeta::TxMeta(
|
||||
uint256 const& txid,
|
||||
@@ -78,16 +76,14 @@ TxMeta::TxMeta(
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
TxMeta::isNodeAffected(uint256 const& node) const
|
||||
TxMeta::TxMeta(uint256 const& transactionID, std::uint32_t ledger)
|
||||
: mTransactionID(transactionID)
|
||||
, mLedger(ledger)
|
||||
, mIndex(static_cast<std::uint32_t>(-1))
|
||||
, mResult(255)
|
||||
, mNodes(sfAffectedNodes)
|
||||
{
|
||||
for (auto const& n : mNodes)
|
||||
{
|
||||
if (n.getFieldH256(sfLedgerIndex) == node)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
mNodes.reserve(32);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -205,57 +201,6 @@ TxMeta::getAffectedNode(uint256 const& node)
|
||||
return *(mNodes.begin()); // Silence compiler warning.
|
||||
}
|
||||
|
||||
const STObject&
|
||||
TxMeta::peekAffectedNode(uint256 const& node) const
|
||||
{
|
||||
for (auto const& n : mNodes)
|
||||
{
|
||||
if (n.getFieldH256(sfLedgerIndex) == node)
|
||||
return n;
|
||||
}
|
||||
|
||||
Throw<std::runtime_error>("Affected node not found");
|
||||
return *(mNodes.begin()); // Silence compiler warning.
|
||||
}
|
||||
|
||||
void
|
||||
TxMeta::init(uint256 const& id, std::uint32_t ledger)
|
||||
{
|
||||
mTransactionID = id;
|
||||
mLedger = ledger;
|
||||
mNodes = STArray(sfAffectedNodes, 32);
|
||||
mDelivered = boost::optional<STAmount>();
|
||||
}
|
||||
|
||||
void
|
||||
TxMeta::swap(TxMeta& s) noexcept
|
||||
{
|
||||
assert((mTransactionID == s.mTransactionID) && (mLedger == s.mLedger));
|
||||
mNodes.swap(s.mNodes);
|
||||
}
|
||||
|
||||
bool
|
||||
TxMeta::thread(STObject& node, uint256 const& prevTxID, std::uint32_t prevLgrID)
|
||||
{
|
||||
if (node.getFieldIndex(sfPreviousTxnID) == -1)
|
||||
{
|
||||
assert(node.getFieldIndex(sfPreviousTxnLgrSeq) == -1);
|
||||
node.setFieldH256(sfPreviousTxnID, prevTxID);
|
||||
node.setFieldU32(sfPreviousTxnLgrSeq, prevLgrID);
|
||||
return true;
|
||||
}
|
||||
|
||||
assert(node.getFieldH256(sfPreviousTxnID) == prevTxID);
|
||||
assert(node.getFieldU32(sfPreviousTxnLgrSeq) == prevLgrID);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
compare(const STObject& o1, const STObject& o2)
|
||||
{
|
||||
return o1.getFieldH256(sfLedgerIndex) < o2.getFieldH256(sfLedgerIndex);
|
||||
}
|
||||
|
||||
STObject
|
||||
TxMeta::getAsObject() const
|
||||
{
|
||||
@@ -276,7 +221,9 @@ TxMeta::addRaw(Serializer& s, TER result, std::uint32_t index)
|
||||
mIndex = index;
|
||||
assert((mResult == 0) || ((mResult > 100) && (mResult <= 255)));
|
||||
|
||||
mNodes.sort(compare);
|
||||
mNodes.sort([](STObject const& o1, STObject const& o2) {
|
||||
return o1.getFieldH256(sfLedgerIndex) < o2.getFieldH256(sfLedgerIndex);
|
||||
});
|
||||
|
||||
getAsObject().add(s);
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ addRaw(LedgerInfo const& info, Serializer& s)
|
||||
{
|
||||
s.add32(info.seq);
|
||||
s.add64(info.drops.drops());
|
||||
s.add256(info.parentHash);
|
||||
s.add256(info.txHash);
|
||||
s.add256(info.accountHash);
|
||||
s.addBitString(info.parentHash);
|
||||
s.addBitString(info.txHash);
|
||||
s.addBitString(info.accountHash);
|
||||
s.add32(info.parentCloseTime.time_since_epoch().count());
|
||||
s.add32(info.closeTime.time_since_epoch().count());
|
||||
s.add8(info.closeTimeResolution.count());
|
||||
|
||||
Reference in New Issue
Block a user