mirror of
https://github.com/Xahau/xahaud.git
synced 2026-07-26 00:20:20 +00:00
Refactor Serializer, SerialIter, SHAMapItem, NodeObject:
* Make LessThan private * Make NodeObject::isSame private * Remove hotTRANSACTION * Remove some Serializer members * Remove unused SHAMapItem::getRaw * Remove unused STLedgerEntry::getOwners * Remove Serializer constructors * Remove unused Serializer members * Remove SerialIter ctor
This commit is contained in:
@@ -62,7 +62,7 @@ template <class T>
|
||||
/*constexpr*/
|
||||
inline
|
||||
void
|
||||
maybe_reverse_bytes(T& t, std::true_type)
|
||||
maybe_reverse_bytes(T& t, std::false_type)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ template <class T>
|
||||
/*constexpr*/
|
||||
inline
|
||||
void
|
||||
maybe_reverse_bytes(T& t, std::false_type)
|
||||
maybe_reverse_bytes(T& t, std::true_type)
|
||||
{
|
||||
reverse_bytes(t);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ void
|
||||
maybe_reverse_bytes(T& t, Hasher&)
|
||||
{
|
||||
maybe_reverse_bytes(t, std::integral_constant<bool,
|
||||
Hasher::endian == endian::native>{});
|
||||
Hasher::endian != endian::native>{});
|
||||
}
|
||||
|
||||
} // detail
|
||||
@@ -140,7 +140,7 @@ struct is_uniquely_represented<std::tuple<T...>>
|
||||
|
||||
template <class T, std::size_t N>
|
||||
struct is_uniquely_represented<T[N]>
|
||||
: public std::integral_constant<bool, is_uniquely_represented<T>::value>
|
||||
: public is_uniquely_represented<T>
|
||||
{
|
||||
};
|
||||
|
||||
@@ -176,7 +176,7 @@ struct is_contiguously_hashable
|
||||
|
||||
template <class T, std::size_t N, class HashAlgorithm>
|
||||
struct is_contiguously_hashable<T[N], HashAlgorithm>
|
||||
: public std::integral_constant<bool, is_uniquely_represented<T>::value &&
|
||||
: public std::integral_constant<bool, is_uniquely_represented<T[N]>::value &&
|
||||
(sizeof(T) == 1 ||
|
||||
HashAlgorithm::endian == endian::native)>
|
||||
{};
|
||||
|
||||
@@ -42,6 +42,8 @@ private:
|
||||
public:
|
||||
using result_type = std::size_t;
|
||||
|
||||
static beast::endian const endian = beast::endian::native;
|
||||
|
||||
siphash() = default;
|
||||
|
||||
explicit
|
||||
|
||||
@@ -43,10 +43,10 @@ private:
|
||||
detail::XXH64_state_t state_;
|
||||
|
||||
public:
|
||||
static beast::endian const endian = beast::endian::native;
|
||||
|
||||
using result_type = std::size_t;
|
||||
|
||||
static beast::endian const endian = beast::endian::native;
|
||||
|
||||
xxhasher() noexcept
|
||||
{
|
||||
detail::XXH64_reset (&state_, 1);
|
||||
|
||||
@@ -38,7 +38,7 @@ AcceptedLedger::AcceptedLedger (Ledger::ref ledger) : mLedger (ledger)
|
||||
for (std::shared_ptr<SHAMapItem> item = txSet.peekFirstItem (); item;
|
||||
item = txSet.peekNextItem (item->getTag ()))
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
SerialIter sit (item->slice());
|
||||
insert (std::make_shared<AcceptedLedgerTx> (ledger, std::ref (sit)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,9 @@ namespace ripple {
|
||||
AcceptedLedgerTx::AcceptedLedgerTx (Ledger::ref ledger, SerialIter& sit)
|
||||
: mLedger (ledger)
|
||||
{
|
||||
Serializer txnSer (sit.getVL ());
|
||||
SerialIter txnIt (txnSer);
|
||||
// VFALCO This is making a needless copy
|
||||
auto const vl = sit.getVL();
|
||||
SerialIter txnIt (make_Slice(vl));
|
||||
|
||||
mTxn = std::make_shared<STTx> (std::ref (txnIt));
|
||||
mRawMeta = sit.getVL ();
|
||||
|
||||
@@ -50,8 +50,9 @@ void ConsensusTransSetSF::gotNode (bool fromFilter, const SHAMapNodeID& id, uint
|
||||
|
||||
try
|
||||
{
|
||||
Serializer s (nodeData.begin () + 4, nodeData.end ()); // skip prefix
|
||||
SerialIter sit (s);
|
||||
// skip prefix
|
||||
Serializer s (nodeData.data() + 4, nodeData.size() - 4);
|
||||
SerialIter sit (s.slice());
|
||||
STTx::pointer stx = std::make_shared<STTx> (std::ref (sit));
|
||||
assert (stx->getTransactionID () == nodeHash);
|
||||
getApp().getJobQueue ().addJob (
|
||||
|
||||
@@ -410,7 +410,7 @@ Transaction::pointer Ledger::getTransaction (uint256 const& transID) const
|
||||
Blob txnData;
|
||||
int txnLength;
|
||||
|
||||
if (!item->peekSerializer ().getVL (txnData, 0, txnLength))
|
||||
if (!item->peekSerializer().getVL (txnData, 0, txnLength))
|
||||
return Transaction::pointer ();
|
||||
|
||||
txn = Transaction::sharedTransaction (txnData, Validate::NO);
|
||||
@@ -431,15 +431,16 @@ Transaction::pointer Ledger::getTransaction (uint256 const& transID) const
|
||||
STTx::pointer Ledger::getSTransaction (
|
||||
std::shared_ptr<SHAMapItem> const& item, SHAMapTreeNode::TNType type)
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
SerialIter sit (item->slice());
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
return std::make_shared<STTx> (sit);
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
Serializer sTxn (sit.getVL ());
|
||||
SerialIter tSit (sTxn);
|
||||
// VFALCO This is making a needless copy
|
||||
auto const vl = sit.getVL();
|
||||
SerialIter tSit (make_Slice(vl));
|
||||
return std::make_shared<STTx> (tSit);
|
||||
}
|
||||
|
||||
@@ -450,7 +451,7 @@ STTx::pointer Ledger::getSMTransaction (
|
||||
std::shared_ptr<SHAMapItem> const& item, SHAMapTreeNode::TNType type,
|
||||
TransactionMetaSet::pointer& txMeta) const
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
SerialIter sit (item->slice());
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
{
|
||||
@@ -459,8 +460,9 @@ STTx::pointer Ledger::getSMTransaction (
|
||||
}
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
Serializer sTxn (sit.getVL ());
|
||||
SerialIter tSit (sTxn);
|
||||
// VFALCO This is making a needless copy
|
||||
auto const vl = sit.getVL();
|
||||
SerialIter tSit (make_Slice(vl));
|
||||
|
||||
txMeta = std::make_shared<TransactionMetaSet> (
|
||||
item->getTag (), mLedgerSeq, sit.getVL ());
|
||||
@@ -496,7 +498,7 @@ bool Ledger::getTransaction (
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
// in tree with metadata
|
||||
SerialIter it (item->peekSerializer ());
|
||||
SerialIter it (item->slice());
|
||||
txn = getApp().getMasterTransaction ().fetch (txID, false);
|
||||
|
||||
if (!txn)
|
||||
@@ -529,7 +531,7 @@ bool Ledger::getTransactionMeta (
|
||||
if (type != SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
return false;
|
||||
|
||||
SerialIter it (item->peekSerializer ());
|
||||
SerialIter it (item->slice());
|
||||
it.getVL (); // skip transaction
|
||||
meta = std::make_shared<TransactionMetaSet> (txID, mLedgerSeq, it.getVL ());
|
||||
|
||||
@@ -547,7 +549,7 @@ bool Ledger::getMetaHex (uint256 const& transID, std::string& hex) const
|
||||
if (type != SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
return false;
|
||||
|
||||
SerialIter it (item->peekSerializer ());
|
||||
SerialIter it (item->slice());
|
||||
it.getVL (); // skip transaction
|
||||
hex = strHex (it.getVL ());
|
||||
return true;
|
||||
@@ -1041,7 +1043,7 @@ LedgerStateParms Ledger::writeBack (LedgerStateParms parms, SLE::ref entry)
|
||||
}
|
||||
|
||||
auto item = std::make_shared<SHAMapItem> (entry->getIndex ());
|
||||
entry->add (item->peekSerializer ());
|
||||
entry->add (item->peekSerializer());
|
||||
|
||||
if (create)
|
||||
{
|
||||
@@ -1211,7 +1213,7 @@ bool Ledger::visitAccountItems (
|
||||
static void visitHelper (
|
||||
std::function<void (SLE::ref)>& function, std::shared_ptr<SHAMapItem> const& item)
|
||||
{
|
||||
function (std::make_shared<SLE> (item->peekSerializer (), item->getTag ()));
|
||||
function (std::make_shared<SLE> (item->peekSerializer(), item->getTag ()));
|
||||
}
|
||||
|
||||
void Ledger::visitStateItems (std::function<void (SLE::ref)> function) const
|
||||
|
||||
@@ -136,14 +136,14 @@ void fillJson (Object& json, LedgerFill const& fill)
|
||||
{
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
{
|
||||
if (bBinary)
|
||||
if (bBinary)
|
||||
{
|
||||
auto&& obj = appendObject (txns);
|
||||
obj[jss::tx_blob] = strHex (item->peekData ());
|
||||
}
|
||||
else
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
SerialIter sit (item->slice ());
|
||||
STTx txn (sit);
|
||||
txns.append (txn.getJson (0));
|
||||
}
|
||||
@@ -152,7 +152,7 @@ void fillJson (Object& json, LedgerFill const& fill)
|
||||
{
|
||||
if (bBinary)
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
SerialIter sit (item->slice ());
|
||||
|
||||
auto&& obj = appendObject (txns);
|
||||
obj[jss::tx_blob] = strHex (sit.getVL ());
|
||||
@@ -160,10 +160,10 @@ void fillJson (Object& json, LedgerFill const& fill)
|
||||
}
|
||||
else
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
Serializer sTxn (sit.getVL ());
|
||||
|
||||
SerialIter tsit (sTxn);
|
||||
// VFALCO This is making a needless copy
|
||||
SerialIter sit (item->slice ());
|
||||
auto const vl = sit.getVL();
|
||||
SerialIter tsit (make_Slice(vl));
|
||||
STTx txn (tsit);
|
||||
|
||||
TransactionMetaSet meta (
|
||||
|
||||
@@ -31,6 +31,7 @@ TransactionStateSF::TransactionStateSF()
|
||||
{
|
||||
}
|
||||
|
||||
// VFALCO This might be better as Blob&&
|
||||
void TransactionStateSF::gotNode (bool fromFilter,
|
||||
SHAMapNodeID const& id,
|
||||
uint256 const& nodeHash,
|
||||
@@ -40,10 +41,11 @@ void TransactionStateSF::gotNode (bool fromFilter,
|
||||
// VFALCO SHAMapSync filters should be passed the SHAMap, the
|
||||
// SHAMap should provide an accessor to get the injected Database,
|
||||
// and this should use that Database instad of getNodeStore
|
||||
getApp().getNodeStore ().store (
|
||||
(type == SHAMapTreeNode::tnTRANSACTION_NM) ? hotTRANSACTION : hotTRANSACTION_NODE,
|
||||
std::move (nodeData),
|
||||
nodeHash);
|
||||
assert(type !=
|
||||
SHAMapTreeNode::tnTRANSACTION_NM);
|
||||
getApp().getNodeStore().store(
|
||||
hotTRANSACTION_NODE,
|
||||
std::move (nodeData), nodeHash);
|
||||
}
|
||||
|
||||
bool TransactionStateSF::haveNode (SHAMapNodeID const& id,
|
||||
|
||||
@@ -40,12 +40,15 @@ class DisputedTx
|
||||
public:
|
||||
using pointer = std::shared_ptr <DisputedTx>;
|
||||
|
||||
// VFALCO `Blob` is a poor choice of parameter
|
||||
DisputedTx (uint256 const& txID,
|
||||
Blob const& tx,
|
||||
bool ourVote) :
|
||||
mTransactionID (txID), mYays (0), mNays (0), mOurVote (ourVote), transaction (tx)
|
||||
Blob const& tx, bool ourVote)
|
||||
: mTransactionID (txID)
|
||||
, mYays (0)
|
||||
, mNays (0)
|
||||
, mOurVote (ourVote)
|
||||
, transaction (tx.data(), tx.size())
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
uint256 const& getTransactionID () const
|
||||
@@ -59,6 +62,7 @@ public:
|
||||
}
|
||||
|
||||
// VFALCO TODO make this const
|
||||
// VFALCO TODO Don't return a Serializer (doh)
|
||||
Serializer& peekTransaction ()
|
||||
{
|
||||
return transaction;
|
||||
@@ -82,6 +86,7 @@ private:
|
||||
int mYays;
|
||||
int mNays;
|
||||
bool mOurVote;
|
||||
// VFALCO Why is this being stored as a Serializer?
|
||||
Serializer transaction;
|
||||
|
||||
hash_map <NodeID, bool> mVotes;
|
||||
|
||||
@@ -150,7 +150,7 @@ bool InboundLedger::tryLocal ()
|
||||
if (!mHaveHeader)
|
||||
{
|
||||
// Nothing we can do without the ledger header
|
||||
NodeObject::pointer node = getApp().getNodeStore ().fetch (mHash);
|
||||
std::shared_ptr<NodeObject> node = getApp().getNodeStore ().fetch (mHash);
|
||||
|
||||
if (!node)
|
||||
{
|
||||
@@ -779,7 +779,7 @@ bool InboundLedger::takeHeader (std::string const& data)
|
||||
|
||||
Serializer s (data.size () + 4);
|
||||
s.add32 (HashPrefix::ledgerMaster);
|
||||
s.addRaw (data);
|
||||
s.addRaw (data.data(), data.size());
|
||||
getApp().getNodeStore ().store (
|
||||
hotLEDGER, std::move (s.modData ()), mHash);
|
||||
|
||||
|
||||
@@ -1030,7 +1030,7 @@ private:
|
||||
WriteLog (lsDEBUG, LedgerConsensus)
|
||||
<< "Test applying disputed transaction that did"
|
||||
<< " not get in";
|
||||
SerialIter sit (it.second->peekTransaction ());
|
||||
SerialIter sit (it.second->peekTransaction().slice());
|
||||
STTx::pointer txn
|
||||
= std::make_shared<STTx>(sit);
|
||||
|
||||
@@ -1868,7 +1868,7 @@ void applyTransactions (std::shared_ptr<SHAMap> const& set,
|
||||
"Processing candidate transaction: " << item->getTag ();
|
||||
try
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
SerialIter sit (item->slice());
|
||||
STTx::pointer txn
|
||||
= std::make_shared<STTx>(sit);
|
||||
if (applyTransaction (engine, txn,
|
||||
|
||||
@@ -36,13 +36,11 @@
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/app/misc/Validations.h>
|
||||
#include <ripple/app/misc/impl/AccountTxPaging.h>
|
||||
#include <ripple/overlay/ClusterNodeStatus.h>
|
||||
#include <ripple/app/misc/UniqueNodeList.h>
|
||||
#include <ripple/app/tx/TransactionMaster.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/Time.h>
|
||||
#include <ripple/basics/SHA512Half.h>
|
||||
#include <ripple/basics/SHA512Half.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/UptimeTimer.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
@@ -51,6 +49,7 @@
|
||||
#include <ripple/crypto/RandomNumbers.h>
|
||||
#include <ripple/crypto/RFC1751.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/overlay/ClusterNodeStatus.h>
|
||||
#include <ripple/overlay/Overlay.h>
|
||||
#include <ripple/overlay/predicates.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
@@ -886,7 +885,7 @@ void NetworkOPsImp::submitTransaction (
|
||||
Serializer s;
|
||||
iTrans->add (s);
|
||||
|
||||
SerialIter sit (s);
|
||||
SerialIter sit (s.slice());
|
||||
auto trans = std::make_shared<STTx> (std::ref (sit));
|
||||
|
||||
uint256 suppress = trans->getTransactionID ();
|
||||
|
||||
@@ -36,7 +36,7 @@ convertBlobsToTxResult (
|
||||
Blob const& rawTxn,
|
||||
Blob const& rawMeta)
|
||||
{
|
||||
SerialIter it (rawTxn);
|
||||
SerialIter it (make_Slice(rawTxn));
|
||||
STTx::pointer txn = std::make_shared<STTx> (it);
|
||||
std::string reason;
|
||||
|
||||
|
||||
@@ -64,8 +64,7 @@ Transaction::pointer Transaction::sharedTransaction (
|
||||
{
|
||||
try
|
||||
{
|
||||
Serializer s (vucTransaction);
|
||||
SerialIter sit (s);
|
||||
SerialIter sit (make_Slice(vucTransaction));
|
||||
std::string reason;
|
||||
|
||||
return std::make_shared<Transaction> (std::make_shared<STTx> (sit),
|
||||
@@ -134,7 +133,7 @@ Transaction::pointer Transaction::transactionFromSQL (
|
||||
std::uint32_t const inLedger =
|
||||
rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or (0));
|
||||
|
||||
SerialIter it (rawTxn);
|
||||
SerialIter it (make_Slice(rawTxn));
|
||||
auto txn = std::make_shared<STTx> (it);
|
||||
std::string reason;
|
||||
auto tr = std::make_shared<Transaction> (txn, validate, reason);
|
||||
|
||||
@@ -105,7 +105,7 @@ TransactionEngine::applyTransaction (
|
||||
{
|
||||
Serializer ser;
|
||||
txn.add (ser);
|
||||
SerialIter sit (ser);
|
||||
SerialIter sit(ser.slice());
|
||||
STTx s2 (sit);
|
||||
|
||||
if (!s2.isEquivalent (txn))
|
||||
|
||||
@@ -71,15 +71,15 @@ STTx::pointer TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item,
|
||||
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
{
|
||||
SerialIter sit (item->peekSerializer ());
|
||||
SerialIter sit (item->slice());
|
||||
txn = std::make_shared<STTx> (std::ref (sit));
|
||||
}
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
Serializer s;
|
||||
int length;
|
||||
item->peekSerializer ().getVL (s.modData (), 0, length);
|
||||
SerialIter sit (s);
|
||||
item->peekSerializer().getVL (s.modData (), 0, length);
|
||||
SerialIter sit (s.slice());
|
||||
|
||||
txn = std::make_shared<STTx> (std::ref (sit));
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ TransactionMetaSet::TransactionMetaSet (uint256 const& txid,
|
||||
, mLedger (ledger)
|
||||
, mNodes (sfAffectedNodes, 32)
|
||||
{
|
||||
Serializer s (data);
|
||||
SerialIter sit (s);
|
||||
SerialIter sit (make_Slice(data));
|
||||
|
||||
STObject obj(sit, sfMetadata);
|
||||
mResult = obj.getFieldU8 (sfTransactionResult);
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
@param pObject [out] The created object if successful.
|
||||
@return The result of the operation.
|
||||
*/
|
||||
virtual Status fetch (void const* key, NodeObject::Ptr* pObject) = 0;
|
||||
virtual Status fetch (void const* key, std::shared_ptr<NodeObject>* pObject) = 0;
|
||||
|
||||
/** Return `true` if batch fetches are optimized. */
|
||||
virtual
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
@note This will be called concurrently.
|
||||
@param object The object to store.
|
||||
*/
|
||||
virtual void store (NodeObject::Ptr const& object) = 0;
|
||||
virtual void store (std::shared_ptr<NodeObject> const& object) = 0;
|
||||
|
||||
/** Store a group of objects.
|
||||
@note This function will not be called concurrently with
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
or other methods.
|
||||
@see import
|
||||
*/
|
||||
virtual void for_each (std::function <void (NodeObject::Ptr)> f) = 0;
|
||||
virtual void for_each (std::function <void (std::shared_ptr<NodeObject>)> f) = 0;
|
||||
|
||||
/** Estimate the number of write operations pending. */
|
||||
virtual int getWriteLoad () = 0;
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
@param hash The key of the object to retrieve.
|
||||
@return The object, or nullptr if it couldn't be retrieved.
|
||||
*/
|
||||
virtual NodeObject::pointer fetch (uint256 const& hash) = 0;
|
||||
virtual std::shared_ptr<NodeObject> fetch (uint256 const& hash) = 0;
|
||||
|
||||
/** Fetch an object without waiting.
|
||||
If I/O is required to determine whether or not the object is present,
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
@param object The object retrieved
|
||||
@return Whether the operation completed
|
||||
*/
|
||||
virtual bool asyncFetch (uint256 const& hash, NodeObject::pointer& object) = 0;
|
||||
virtual bool asyncFetch (uint256 const& hash, std::shared_ptr<NodeObject>& object) = 0;
|
||||
|
||||
/** Wait for all currently pending async reads to complete.
|
||||
*/
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
or other methods.
|
||||
@see import
|
||||
*/
|
||||
virtual void for_each(std::function <void(NodeObject::Ptr)> f) = 0;
|
||||
virtual void for_each(std::function <void(std::shared_ptr<NodeObject>)> f) = 0;
|
||||
|
||||
/** Import objects from another database. */
|
||||
virtual void import (Database& source) = 0;
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
std::shared_ptr <Backend> const& newBackend) = 0;
|
||||
|
||||
/** Ensure that node is in writableBackend */
|
||||
virtual NodeObject::Ptr fetchNode (uint256 const& hash) = 0;
|
||||
virtual std::shared_ptr<NodeObject> fetchNode (uint256 const& hash) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ enum NodeObjectType
|
||||
{
|
||||
hotUNKNOWN = 0,
|
||||
hotLEDGER = 1,
|
||||
hotTRANSACTION = 2,
|
||||
//hotTRANSACTION = 2 // Not used
|
||||
hotACCOUNT_NODE = 3,
|
||||
hotTRANSACTION_NODE = 4
|
||||
};
|
||||
@@ -62,13 +62,6 @@ public:
|
||||
keyBytes = 32,
|
||||
};
|
||||
|
||||
// Please use this one. For a reference use Ptr const&
|
||||
using Ptr = std::shared_ptr <NodeObject>;
|
||||
|
||||
// These are DEPRECATED, type names are capitalized.
|
||||
using pointer = std::shared_ptr <NodeObject>;
|
||||
using ref = pointer const&;
|
||||
|
||||
private:
|
||||
// This hack is used to make the constructor effectively private
|
||||
// except for when we use it in the call to make_shared.
|
||||
@@ -92,41 +85,20 @@ public:
|
||||
is overwritten.
|
||||
@param hash The 256-bit hash of the payload data.
|
||||
*/
|
||||
static Ptr createObject (NodeObjectType type,
|
||||
Blob&& data,
|
||||
uint256 const& hash);
|
||||
static
|
||||
std::shared_ptr<NodeObject>
|
||||
createObject (NodeObjectType type,
|
||||
Blob&& data, uint256 const& hash);
|
||||
|
||||
/** Retrieve the type of this object.
|
||||
*/
|
||||
/** Returns the type of this object. */
|
||||
NodeObjectType getType () const;
|
||||
|
||||
/** Retrieve the hash metadata.
|
||||
*/
|
||||
/** Returns the hash of the data. */
|
||||
uint256 const& getHash () const;
|
||||
|
||||
/** Retrieve the binary data.
|
||||
*/
|
||||
/** Returns the underlying data. */
|
||||
Blob const& getData () const;
|
||||
|
||||
/** See if this object has the same data as another object.
|
||||
*/
|
||||
bool isCloneOf (NodeObject::Ptr const& other) const;
|
||||
|
||||
/** Binary function that satisfies the strict-weak-ordering requirement.
|
||||
|
||||
This compares the hashes of both objects and returns true if
|
||||
the first hash is considered to go before the second.
|
||||
|
||||
@see std::sort
|
||||
*/
|
||||
struct LessThan
|
||||
{
|
||||
inline bool operator() (NodeObject::Ptr const& lhs, NodeObject::Ptr const& rhs) const noexcept
|
||||
{
|
||||
return lhs->getHash () < rhs->getHash ();
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
NodeObjectType mType;
|
||||
uint256 mHash;
|
||||
|
||||
@@ -47,7 +47,7 @@ enum Status
|
||||
};
|
||||
|
||||
/** A batch of NodeObjects to write at once. */
|
||||
using Batch = std::vector <NodeObject::Ptr>;
|
||||
using Batch = std::vector <std::shared_ptr<NodeObject>>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ struct MemoryDB
|
||||
{
|
||||
std::mutex mutex;
|
||||
bool open = false;
|
||||
std::map <uint256 const, NodeObject::Ptr> table;
|
||||
std::map <uint256 const, std::shared_ptr<NodeObject>> table;
|
||||
};
|
||||
|
||||
class MemoryFactory : public Factory
|
||||
@@ -75,7 +75,7 @@ static MemoryFactory memoryFactory;
|
||||
class MemoryBackend : public Backend
|
||||
{
|
||||
private:
|
||||
using Map = std::map <uint256 const, NodeObject::Ptr>;
|
||||
using Map = std::map <uint256 const, std::shared_ptr<NodeObject>>;
|
||||
|
||||
std::string name_;
|
||||
beast::Journal journal_;
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Status
|
||||
fetch (void const* key, NodeObject::Ptr* pObject)
|
||||
fetch (void const* key, std::shared_ptr<NodeObject>* pObject)
|
||||
{
|
||||
uint256 const hash (uint256::fromVoid (key));
|
||||
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
store (NodeObject::ref object)
|
||||
store (std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
std::lock_guard<std::mutex> _(db_->mutex);
|
||||
db_->table.emplace (object->getHash(), object);
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
for_each (std::function <void(NodeObject::Ptr)> f)
|
||||
for_each (std::function <void(std::shared_ptr<NodeObject>)> f)
|
||||
{
|
||||
for (auto const& e : db_->table)
|
||||
f (e.second);
|
||||
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
}
|
||||
|
||||
Status
|
||||
fetch (void const* key, NodeObject::Ptr* pno)
|
||||
fetch (void const* key, std::shared_ptr<NodeObject>* pno)
|
||||
{
|
||||
Status status;
|
||||
pno->reset();
|
||||
@@ -201,7 +201,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
for_each (std::function <void(NodeObject::Ptr)> f)
|
||||
for_each (std::function <void(std::shared_ptr<NodeObject>)> f)
|
||||
{
|
||||
auto const dp = db_.dat_path();
|
||||
auto const kp = db_.key_path();
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
}
|
||||
|
||||
Status
|
||||
fetch (void const*, NodeObject::Ptr*)
|
||||
fetch (void const*, std::shared_ptr<NodeObject>*)
|
||||
{
|
||||
return notFound;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
store (NodeObject::ref object)
|
||||
store (std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
for_each (std::function <void(NodeObject::Ptr)> f)
|
||||
for_each (std::function <void(std::shared_ptr<NodeObject>)> f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Status
|
||||
fetch (void const* key, NodeObject::Ptr* pObject)
|
||||
fetch (void const* key, std::shared_ptr<NodeObject>* pObject)
|
||||
{
|
||||
pObject->reset ();
|
||||
|
||||
@@ -280,7 +280,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
store (NodeObject::ref object)
|
||||
store (std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
m_batch.store (object);
|
||||
}
|
||||
@@ -312,7 +312,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
for_each (std::function <void(NodeObject::Ptr)> f)
|
||||
for_each (std::function <void(std::shared_ptr<NodeObject>)> f)
|
||||
{
|
||||
rocksdb::ReadOptions const options;
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ public:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Status
|
||||
fetch (void const* key, NodeObject::Ptr* pObject)
|
||||
fetch (void const* key, std::shared_ptr<NodeObject>* pObject)
|
||||
{
|
||||
pObject->reset ();
|
||||
|
||||
@@ -257,7 +257,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
store (NodeObject::ref object)
|
||||
store (std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
storeBatch(Batch{object});
|
||||
}
|
||||
@@ -299,7 +299,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
for_each (std::function <void(NodeObject::Ptr)> f)
|
||||
for_each (std::function <void(std::shared_ptr<NodeObject>)> f)
|
||||
{
|
||||
rocksdb::ReadOptions const options;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ BatchWriter::~BatchWriter ()
|
||||
}
|
||||
|
||||
void
|
||||
BatchWriter::store (NodeObject::ref object)
|
||||
BatchWriter::store (std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
std::lock_guard<decltype(mWriteMutex)> sl (mWriteMutex);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
This will add to the batch and initiate a scheduled task to
|
||||
write the batch out.
|
||||
*/
|
||||
void store (NodeObject::Ptr const& object);
|
||||
void store (std::shared_ptr<NodeObject> const& object);
|
||||
|
||||
/** Get an estimate of the amount of writing I/O pending. */
|
||||
int getWriteLoad ();
|
||||
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool asyncFetch (uint256 const& hash, NodeObject::pointer& object)
|
||||
bool asyncFetch (uint256 const& hash, std::shared_ptr<NodeObject>& object)
|
||||
{
|
||||
// See if the object is in cache
|
||||
object = m_cache.fetch (hash);
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
return m_cache.getTargetSize() / asyncDivider;
|
||||
}
|
||||
|
||||
NodeObject::Ptr fetch (uint256 const& hash) override
|
||||
std::shared_ptr<NodeObject> fetch (uint256 const& hash) override
|
||||
{
|
||||
ScopedMetrics::incrementThreadFetches ();
|
||||
|
||||
@@ -166,14 +166,14 @@ public:
|
||||
}
|
||||
|
||||
/** Perform a fetch and report the time it took */
|
||||
NodeObject::Ptr doTimedFetch (uint256 const& hash, bool isAsync)
|
||||
std::shared_ptr<NodeObject> doTimedFetch (uint256 const& hash, bool isAsync)
|
||||
{
|
||||
FetchReport report;
|
||||
report.isAsync = isAsync;
|
||||
report.wentToDisk = false;
|
||||
|
||||
auto const before = std::chrono::steady_clock::now();
|
||||
NodeObject::Ptr ret = doFetch (hash, report);
|
||||
std::shared_ptr<NodeObject> ret = doFetch (hash, report);
|
||||
report.elapsed = std::chrono::duration_cast <std::chrono::milliseconds>
|
||||
(std::chrono::steady_clock::now() - before);
|
||||
|
||||
@@ -183,11 +183,11 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
NodeObject::Ptr doFetch (uint256 const& hash, FetchReport &report)
|
||||
std::shared_ptr<NodeObject> doFetch (uint256 const& hash, FetchReport &report)
|
||||
{
|
||||
// See if the object already exists in the cache
|
||||
//
|
||||
NodeObject::Ptr obj = m_cache.fetch (hash);
|
||||
std::shared_ptr<NodeObject> obj = m_cache.fetch (hash);
|
||||
|
||||
if (obj != nullptr)
|
||||
return obj;
|
||||
@@ -236,15 +236,15 @@ public:
|
||||
return obj;
|
||||
}
|
||||
|
||||
virtual NodeObject::Ptr fetchFrom (uint256 const& hash)
|
||||
virtual std::shared_ptr<NodeObject> fetchFrom (uint256 const& hash)
|
||||
{
|
||||
return fetchInternal (*m_backend, hash);
|
||||
}
|
||||
|
||||
NodeObject::Ptr fetchInternal (Backend& backend,
|
||||
std::shared_ptr<NodeObject> fetchInternal (Backend& backend,
|
||||
uint256 const& hash)
|
||||
{
|
||||
NodeObject::Ptr object;
|
||||
std::shared_ptr<NodeObject> object;
|
||||
|
||||
Status const status = backend.fetch (hash.begin (), &object);
|
||||
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
uint256 const& hash,
|
||||
Backend& backend)
|
||||
{
|
||||
NodeObject::Ptr object = NodeObject::createObject(
|
||||
std::shared_ptr<NodeObject> object = NodeObject::createObject(
|
||||
type, std::move(data), hash);
|
||||
|
||||
#if RIPPLE_VERIFY_NODEOBJECT_KEYS
|
||||
@@ -376,7 +376,7 @@ public:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void for_each (std::function <void(NodeObject::Ptr)> f) override
|
||||
void for_each (std::function <void(std::shared_ptr<NodeObject>)> f) override
|
||||
{
|
||||
m_backend->for_each (f);
|
||||
}
|
||||
@@ -391,7 +391,7 @@ public:
|
||||
Batch b;
|
||||
b.reserve (batchWritePreallocationSize);
|
||||
|
||||
source.for_each ([&](NodeObject::Ptr object)
|
||||
source.for_each ([&](std::shared_ptr<NodeObject> object)
|
||||
{
|
||||
if (b.size() >= batchWritePreallocationSize)
|
||||
{
|
||||
|
||||
@@ -34,10 +34,10 @@ std::shared_ptr <Backend> DatabaseRotatingImp::rotateBackends (
|
||||
return oldBackend;
|
||||
}
|
||||
|
||||
NodeObject::Ptr DatabaseRotatingImp::fetchFrom (uint256 const& hash)
|
||||
std::shared_ptr<NodeObject> DatabaseRotatingImp::fetchFrom (uint256 const& hash)
|
||||
{
|
||||
Backends b = getBackends();
|
||||
NodeObject::Ptr object = fetchInternal (*b.writableBackend, hash);
|
||||
std::shared_ptr<NodeObject> object = fetchInternal (*b.writableBackend, hash);
|
||||
if (!object)
|
||||
{
|
||||
object = fetchInternal (*b.archiveBackend, hash);
|
||||
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
return getWritableBackend()->getWriteLoad();
|
||||
}
|
||||
|
||||
void for_each (std::function <void(NodeObject::Ptr)> f) override
|
||||
void for_each (std::function <void(std::shared_ptr<NodeObject>)> f) override
|
||||
{
|
||||
Backends b = getBackends();
|
||||
b.archiveBackend->for_each (f);
|
||||
@@ -115,12 +115,12 @@ public:
|
||||
*getWritableBackend());
|
||||
}
|
||||
|
||||
NodeObject::Ptr fetchNode (uint256 const& hash) override
|
||||
std::shared_ptr<NodeObject> fetchNode (uint256 const& hash) override
|
||||
{
|
||||
return fetchFrom (hash);
|
||||
}
|
||||
|
||||
NodeObject::Ptr fetchFrom (uint256 const& hash) override;
|
||||
std::shared_ptr<NodeObject> fetchFrom (uint256 const& hash) override;
|
||||
TaggedCache <uint256, NodeObject>& getPositiveCache() override
|
||||
{
|
||||
return m_cache;
|
||||
|
||||
@@ -63,7 +63,6 @@ DecodedBlob::DecodedBlob (void const* key, void const* value, int valueBytes)
|
||||
|
||||
case hotUNKNOWN:
|
||||
case hotLEDGER:
|
||||
case hotTRANSACTION:
|
||||
case hotACCOUNT_NODE:
|
||||
case hotTRANSACTION_NODE:
|
||||
m_success = true;
|
||||
@@ -72,11 +71,11 @@ DecodedBlob::DecodedBlob (void const* key, void const* value, int valueBytes)
|
||||
}
|
||||
}
|
||||
|
||||
NodeObject::Ptr DecodedBlob::createObject ()
|
||||
std::shared_ptr<NodeObject> DecodedBlob::createObject ()
|
||||
{
|
||||
bassert (m_success);
|
||||
|
||||
NodeObject::Ptr object;
|
||||
std::shared_ptr<NodeObject> object;
|
||||
|
||||
if (m_success)
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
bool wasOk () const noexcept { return m_success; }
|
||||
|
||||
/** Create a NodeObject from this data. */
|
||||
NodeObject::Ptr createObject ();
|
||||
std::shared_ptr<NodeObject> createObject ();
|
||||
|
||||
private:
|
||||
bool m_success;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ripple {
|
||||
namespace NodeStore {
|
||||
|
||||
void
|
||||
EncodedBlob::prepare (NodeObject::Ptr const& object)
|
||||
EncodedBlob::prepare (std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
m_key = object->getHash().begin ();
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace NodeStore {
|
||||
struct EncodedBlob
|
||||
{
|
||||
public:
|
||||
void prepare (NodeObject::Ptr const& object);
|
||||
void prepare (std::shared_ptr<NodeObject> const& object);
|
||||
void const* getKey () const noexcept { return m_key; }
|
||||
std::size_t getSize () const noexcept { return m_size; }
|
||||
void const* getData () const noexcept { return m_data.getData (); }
|
||||
|
||||
@@ -36,7 +36,7 @@ NodeObject::NodeObject (
|
||||
mData = std::move (data);
|
||||
}
|
||||
|
||||
NodeObject::Ptr
|
||||
std::shared_ptr<NodeObject>
|
||||
NodeObject::createObject (
|
||||
NodeObjectType type,
|
||||
Blob&& data,
|
||||
@@ -64,21 +64,4 @@ NodeObject::getData () const
|
||||
return mData;
|
||||
}
|
||||
|
||||
bool
|
||||
NodeObject::isCloneOf (NodeObject::Ptr const& other) const
|
||||
{
|
||||
if (mType != other->mType)
|
||||
return false;
|
||||
|
||||
if (mHash != other->mHash)
|
||||
return false;
|
||||
|
||||
if (mData != other->mData)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ public:
|
||||
Batch copy;
|
||||
fetchCopyOfBatch (*backend, ©, batch);
|
||||
// Canonicalize the source and destination batches
|
||||
std::sort (batch.begin (), batch.end (), NodeObject::LessThan ());
|
||||
std::sort (copy.begin (), copy.end (), NodeObject::LessThan ());
|
||||
std::sort (batch.begin (), batch.end (), LessThan{});
|
||||
std::sort (copy.begin (), copy.end (), LessThan{});
|
||||
expect (areBatchesEqual (batch, copy), "Should be equal");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,35 @@
|
||||
namespace ripple {
|
||||
namespace NodeStore {
|
||||
|
||||
/** Binary function that satisfies the strict-weak-ordering requirement.
|
||||
|
||||
This compares the hashes of both objects and returns true if
|
||||
the first hash is considered to go before the second.
|
||||
|
||||
@see std::sort
|
||||
*/
|
||||
struct LessThan
|
||||
{
|
||||
bool
|
||||
operator()(
|
||||
std::shared_ptr<NodeObject> const& lhs,
|
||||
std::shared_ptr<NodeObject> const& rhs) const noexcept
|
||||
{
|
||||
return lhs->getHash () < rhs->getHash ();
|
||||
}
|
||||
};
|
||||
|
||||
/** Returns `true` if objects are identical. */
|
||||
inline
|
||||
bool isSame (std::shared_ptr<NodeObject> const& lhs,
|
||||
std::shared_ptr<NodeObject> const& rhs)
|
||||
{
|
||||
return
|
||||
(lhs->getType() == rhs->getType()) &&
|
||||
(lhs->getHash() == rhs->getHash()) &&
|
||||
(lhs->getData() == rhs->getData());
|
||||
}
|
||||
|
||||
// Some common code for the unit tests
|
||||
//
|
||||
class TestBase : public beast::unit_test::suite
|
||||
@@ -52,16 +81,16 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
NodeObject::Ptr createObject ()
|
||||
std::shared_ptr<NodeObject> createObject ()
|
||||
{
|
||||
NodeObjectType type;
|
||||
switch (r.nextInt (4))
|
||||
{
|
||||
case 0: type = hotLEDGER; break;
|
||||
case 1: type = hotTRANSACTION; break;
|
||||
case 2: type = hotACCOUNT_NODE; break;
|
||||
case 3: type = hotTRANSACTION_NODE; break;
|
||||
default:
|
||||
case 1: // was hotTRANSACTION
|
||||
type = hotUNKNOWN;
|
||||
break;
|
||||
};
|
||||
@@ -103,7 +132,7 @@ public:
|
||||
{
|
||||
for (int i = 0; i < lhs.size (); ++i)
|
||||
{
|
||||
if (! lhs [i]->isCloneOf (rhs [i]))
|
||||
if (! isSame(lhs[i], rhs[i]))
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
@@ -135,7 +164,7 @@ public:
|
||||
|
||||
for (int i = 0; i < batch.size (); ++i)
|
||||
{
|
||||
NodeObject::Ptr object;
|
||||
std::shared_ptr<NodeObject> object;
|
||||
|
||||
Status const status = backend.fetch (
|
||||
batch [i]->getHash ().cbegin (), &object);
|
||||
@@ -155,7 +184,7 @@ public:
|
||||
{
|
||||
for (int i = 0; i < batch.size (); ++i)
|
||||
{
|
||||
NodeObject::Ptr object;
|
||||
std::shared_ptr<NodeObject> object;
|
||||
|
||||
Status const status = backend.fetch (
|
||||
batch [i]->getHash ().cbegin (), &object);
|
||||
@@ -169,7 +198,7 @@ public:
|
||||
{
|
||||
for (int i = 0; i < batch.size (); ++i)
|
||||
{
|
||||
NodeObject::Ptr const object (batch [i]);
|
||||
std::shared_ptr<NodeObject> const object (batch [i]);
|
||||
|
||||
Blob data (object->getData ());
|
||||
|
||||
@@ -189,7 +218,7 @@ public:
|
||||
|
||||
for (int i = 0; i < batch.size (); ++i)
|
||||
{
|
||||
NodeObject::Ptr object = db.fetch (batch [i]->getHash ());
|
||||
std::shared_ptr<NodeObject> object = db.fetch (batch [i]->getHash ());
|
||||
|
||||
if (object != nullptr)
|
||||
pCopy->push_back (object);
|
||||
|
||||
@@ -70,9 +70,9 @@ public:
|
||||
|
||||
if (decoded.wasOk ())
|
||||
{
|
||||
NodeObject::Ptr const object (decoded.createObject ());
|
||||
std::shared_ptr<NodeObject> const object (decoded.createObject ());
|
||||
|
||||
expect (batch [i]->isCloneOf (object), "Should be clones");
|
||||
expect (isSame(batch[i], object), "Should be clones");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ public:
|
||||
}
|
||||
|
||||
// Canonicalize the source and destination batches
|
||||
std::sort (batch.begin (), batch.end (), NodeObject::LessThan ());
|
||||
std::sort (copy.begin (), copy.end (), NodeObject::LessThan ());
|
||||
std::sort (batch.begin (), batch.end (), LessThan{});
|
||||
std::sort (copy.begin (), copy.end (), LessThan{});
|
||||
expect (areBatchesEqual (batch, copy), "Should be equal");
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ public:
|
||||
fetchCopyOfBatch (*db, ©, batch);
|
||||
|
||||
// Canonicalize the source and destination batches
|
||||
std::sort (batch.begin (), batch.end (), NodeObject::LessThan ());
|
||||
std::sort (copy.begin (), copy.end (), NodeObject::LessThan ());
|
||||
std::sort (batch.begin (), batch.end (), LessThan{});
|
||||
std::sort (copy.begin (), copy.end (), LessThan{});
|
||||
expect (areBatchesEqual (batch, copy), "Should be equal");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
}
|
||||
|
||||
// Returns the n-th complete NodeObject
|
||||
NodeObject::Ptr
|
||||
std::shared_ptr<NodeObject>
|
||||
obj (std::size_t n)
|
||||
{
|
||||
gen_.seed(n+1);
|
||||
@@ -356,11 +356,11 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
NodeObject::Ptr obj;
|
||||
NodeObject::Ptr result;
|
||||
std::shared_ptr<NodeObject> obj;
|
||||
std::shared_ptr<NodeObject> result;
|
||||
obj = seq1_.obj(dist_(gen_));
|
||||
backend_.fetch(obj->getHash().data(), &result);
|
||||
suite_.expect (result && result->isCloneOf(obj));
|
||||
suite_.expect (result && isSame(result, obj));
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
@@ -420,7 +420,7 @@ public:
|
||||
try
|
||||
{
|
||||
auto const key = seq2_.key(i);
|
||||
NodeObject::Ptr result;
|
||||
std::shared_ptr<NodeObject> result;
|
||||
backend_.fetch(key.data(), &result);
|
||||
suite_.expect (! result);
|
||||
}
|
||||
@@ -489,17 +489,17 @@ public:
|
||||
if (rand_(gen_) < missingNodePercent)
|
||||
{
|
||||
auto const key = seq2_.key(dist_(gen_));
|
||||
NodeObject::Ptr result;
|
||||
std::shared_ptr<NodeObject> result;
|
||||
backend_.fetch(key.data(), &result);
|
||||
suite_.expect (! result);
|
||||
}
|
||||
else
|
||||
{
|
||||
NodeObject::Ptr obj;
|
||||
NodeObject::Ptr result;
|
||||
std::shared_ptr<NodeObject> obj;
|
||||
std::shared_ptr<NodeObject> result;
|
||||
obj = seq1_.obj(dist_(gen_));
|
||||
backend_.fetch(obj->getHash().data(), &result);
|
||||
suite_.expect (result && result->isCloneOf(obj));
|
||||
suite_.expect (result && isSame(result, obj));
|
||||
}
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
@@ -572,15 +572,15 @@ public:
|
||||
if (rand_(gen_) < 200)
|
||||
{
|
||||
// historical lookup
|
||||
NodeObject::Ptr obj;
|
||||
NodeObject::Ptr result;
|
||||
std::shared_ptr<NodeObject> obj;
|
||||
std::shared_ptr<NodeObject> result;
|
||||
auto const j = older_(gen_);
|
||||
obj = seq1_.obj(j);
|
||||
NodeObject::Ptr result1;
|
||||
std::shared_ptr<NodeObject> result1;
|
||||
backend_.fetch(obj->getHash().data(), &result);
|
||||
suite_.expect (result != nullptr,
|
||||
"object " + std::to_string(j) + " missing");
|
||||
suite_.expect (result->isCloneOf(obj),
|
||||
suite_.expect (isSame(result, obj),
|
||||
"object " + std::to_string(j) + " not a clone");
|
||||
}
|
||||
|
||||
@@ -594,12 +594,13 @@ public:
|
||||
case 0:
|
||||
{
|
||||
// fetch recent
|
||||
NodeObject::Ptr obj;
|
||||
NodeObject::Ptr result;
|
||||
std::shared_ptr<NodeObject> obj;
|
||||
std::shared_ptr<NodeObject> result;
|
||||
auto const j = recent_(gen_);
|
||||
obj = seq1_.obj(j);
|
||||
backend_.fetch(obj->getHash().data(), &result);
|
||||
suite_.expect(! result || result->isCloneOf(obj));
|
||||
suite_.expect(! result ||
|
||||
isSame(result, obj));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -979,7 +979,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMTransaction> const& m)
|
||||
return;
|
||||
}
|
||||
|
||||
SerialIter sit (m->rawtransaction ());
|
||||
SerialIter sit (make_Slice(m->rawtransaction()));
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1485,7 +1485,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMGetObjectByHash> const& m)
|
||||
memcpy (hash.begin (), obj.hash ().data (), 256 / 8);
|
||||
// VFALCO TODO Move this someplace more sensible so we dont
|
||||
// need to inject the NodeStore interfaces.
|
||||
NodeObject::pointer hObj =
|
||||
std::shared_ptr<NodeObject> hObj =
|
||||
getApp().getNodeStore ().fetch (hash);
|
||||
|
||||
if (hObj)
|
||||
|
||||
@@ -104,7 +104,6 @@ public:
|
||||
std::uint32_t getThreadedLedger ();
|
||||
bool thread (uint256 const& txID, std::uint32_t ledgerSeq, uint256 & prevTxID,
|
||||
std::uint32_t & prevLedgerID);
|
||||
std::vector<uint256> getOwners (); // nodes notified if this node is deleted
|
||||
|
||||
private:
|
||||
/** Make STObject comply with the template for this SLE type
|
||||
|
||||
@@ -47,23 +47,15 @@ public:
|
||||
{
|
||||
mData.reserve (n);
|
||||
}
|
||||
Serializer (Blob const& data) : mData (data)
|
||||
|
||||
Serializer (void const* data,
|
||||
std::size_t size)
|
||||
{
|
||||
;
|
||||
}
|
||||
Serializer (std::string const& data) : mData (data.data (), (data.data ()) + data.size ())
|
||||
{
|
||||
;
|
||||
}
|
||||
Serializer (Blob ::iterator begin, Blob ::iterator end) :
|
||||
mData (begin, end)
|
||||
{
|
||||
;
|
||||
}
|
||||
Serializer (Blob ::const_iterator begin, Blob ::const_iterator end) :
|
||||
mData (begin, end)
|
||||
{
|
||||
;
|
||||
mData.resize(size);
|
||||
std::memcpy(mData.data(),
|
||||
reinterpret_cast<
|
||||
unsigned char const*>(
|
||||
data), size);
|
||||
}
|
||||
|
||||
Slice slice() const noexcept
|
||||
@@ -118,11 +110,6 @@ public:
|
||||
|
||||
// disassemble functions
|
||||
bool get8 (int&, int offset) const;
|
||||
bool get8 (unsigned char&, int offset) const;
|
||||
bool get16 (std::uint16_t&, int offset) const;
|
||||
bool get32 (std::uint32_t&, int offset) const;
|
||||
bool get64 (std::uint64_t&, int offset) const;
|
||||
bool get128 (uint128&, int offset) const;
|
||||
bool get256 (uint256&, int offset) const;
|
||||
|
||||
template <typename Integer>
|
||||
@@ -150,8 +137,6 @@ public:
|
||||
return success;
|
||||
}
|
||||
|
||||
uint256 get256 (int offset) const;
|
||||
|
||||
// TODO(tom): merge with get128 and get256.
|
||||
template <class Tag>
|
||||
bool get160 (base_uint<160, Tag>& o, int offset) const
|
||||
@@ -188,10 +173,7 @@ public:
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
int getCapacity () const
|
||||
{
|
||||
return mData.capacity ();
|
||||
}
|
||||
|
||||
int getDataLength () const
|
||||
{
|
||||
return mData.size ();
|
||||
@@ -318,28 +300,6 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
// VFALCO TODO Remove this overload use Slice instead
|
||||
explicit
|
||||
SerialIter (std::string const& s) noexcept
|
||||
: SerialIter(s.data(), s.size())
|
||||
{
|
||||
}
|
||||
|
||||
template <class T,
|
||||
std::enable_if_t<std::is_integral<T>::value &&
|
||||
sizeof(T) == 1>* = nullptr>
|
||||
explicit
|
||||
SerialIter (std::vector<T> const& v) noexcept
|
||||
: SerialIter (v.data(), v.size())
|
||||
{
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
SerialIter (Serializer const& s) noexcept
|
||||
: SerialIter(s.peekData())
|
||||
{
|
||||
}
|
||||
|
||||
std::size_t
|
||||
empty() const noexcept
|
||||
{
|
||||
|
||||
@@ -40,8 +40,7 @@ STLedgerEntry::STLedgerEntry (
|
||||
const Serializer& s, uint256 const& index)
|
||||
: STObject (sfLedgerEntry), mIndex (index), mMutable (true)
|
||||
{
|
||||
// we know 's' isn't going away
|
||||
SerialIter sit (const_cast<Serializer&> (s));
|
||||
SerialIter sit (s.slice());
|
||||
set (sit);
|
||||
setSLEType ();
|
||||
}
|
||||
@@ -184,38 +183,4 @@ RippleAddress STLedgerEntry::getSecondOwner ()
|
||||
return RippleAddress::createAccountID (getFieldAmount (sfHighLimit).getIssuer ());
|
||||
}
|
||||
|
||||
std::vector<uint256> STLedgerEntry::getOwners ()
|
||||
{
|
||||
std::vector<uint256> owners;
|
||||
Account account;
|
||||
|
||||
for (int i = 0, fields = getCount (); i < fields; ++i)
|
||||
{
|
||||
auto const& fc = getFieldSType (i);
|
||||
|
||||
if ((fc == sfAccount) || (fc == sfOwner))
|
||||
{
|
||||
auto entry = dynamic_cast<const STAccount*> (peekAtPIndex (i));
|
||||
|
||||
if ((entry != nullptr) && entry->getValueH160 (account))
|
||||
owners.push_back (getAccountRootIndex (account));
|
||||
}
|
||||
|
||||
if ((fc == sfLowLimit) || (fc == sfHighLimit))
|
||||
{
|
||||
auto entry = dynamic_cast<const STAmount*> (peekAtPIndex (i));
|
||||
|
||||
if ((entry != nullptr))
|
||||
{
|
||||
auto issuer = entry->getIssuer ();
|
||||
|
||||
if (issuer.isNonZero ())
|
||||
owners.push_back (getAccountRootIndex (issuer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return owners;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -106,63 +106,6 @@ int Serializer::addRaw (const void* ptr, int len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Serializer::get16 (std::uint16_t& o, int offset) const
|
||||
{
|
||||
if ((offset + 2) > mData.size ()) return false;
|
||||
|
||||
const unsigned char* ptr = &mData[offset];
|
||||
o = *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Serializer::get32 (std::uint32_t& o, int offset) const
|
||||
{
|
||||
if ((offset + 4) > mData.size ()) return false;
|
||||
|
||||
const unsigned char* ptr = &mData[offset];
|
||||
o = *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Serializer::get64 (std::uint64_t& o, int offset) const
|
||||
{
|
||||
if ((offset + 8) > mData.size ()) return false;
|
||||
|
||||
const unsigned char* ptr = &mData[offset];
|
||||
o = *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr++;
|
||||
o <<= 8;
|
||||
o |= *ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Serializer::get128 (uint128& o, int offset) const
|
||||
{
|
||||
if ((offset + (128 / 8)) > mData.size ()) return false;
|
||||
|
||||
memcpy (o.begin (), & (mData.front ()) + offset, (128 / 8));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Serializer::get256 (uint256& o, int offset) const
|
||||
{
|
||||
if ((offset + (256 / 8)) > mData.size ()) return false;
|
||||
@@ -171,16 +114,6 @@ bool Serializer::get256 (uint256& o, int offset) const
|
||||
return true;
|
||||
}
|
||||
|
||||
uint256 Serializer::get256 (int offset) const
|
||||
{
|
||||
uint256 ret;
|
||||
|
||||
if ((offset + (256 / 8)) > mData.size ()) return ret;
|
||||
|
||||
memcpy (ret.begin (), & (mData.front ()) + offset, (256 / 8));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Serializer::addFieldID (int type, int name)
|
||||
{
|
||||
int ret = mData.size ();
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
Serializer ser;
|
||||
s.add (ser);
|
||||
|
||||
SerialIter sit (ser);
|
||||
SerialIter sit (ser.slice());
|
||||
return STAmount(sit, sfGeneric);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
|
||||
Serializer s;
|
||||
object1.add (s);
|
||||
SerialIter it (s);
|
||||
SerialIter it (s.slice());
|
||||
|
||||
STObject object3 (elements, it, sfTestObject);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
Serializer rawTxn;
|
||||
j.add (rawTxn);
|
||||
SerialIter sit (rawTxn);
|
||||
SerialIter sit (rawTxn.slice());
|
||||
STTx copy (sit);
|
||||
|
||||
if (copy != j)
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
|
||||
Serializer rawTxn;
|
||||
tempTxn.add (rawTxn);
|
||||
SerialIter sit (rawTxn);
|
||||
SerialIter sit (rawTxn.slice());
|
||||
bool serialized = false;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -53,8 +53,7 @@ Json::Value doSubmit (RPC::Context& context)
|
||||
if (!ret.second || !ret.first.size ())
|
||||
return rpcError (rpcINVALID_PARAMS);
|
||||
|
||||
Serializer sTrans (ret.first);
|
||||
SerialIter sitTrans (sTrans);
|
||||
SerialIter sitTrans (make_Slice(ret.first));
|
||||
|
||||
STTx::pointer stpTrans;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <ripple/protocol/Serializer.h>
|
||||
#include <ripple/basics/base_uint.h>
|
||||
#include <ripple/basics/Slice.h>
|
||||
#include <beast/utility/Journal.h>
|
||||
|
||||
#include <cstddef>
|
||||
@@ -40,6 +41,8 @@ public:
|
||||
SHAMapItem (uint256 const& tag, Blob const & data);
|
||||
SHAMapItem (uint256 const& tag, Serializer const& s);
|
||||
|
||||
Slice slice() const;
|
||||
|
||||
uint256 const& getTag() const;
|
||||
Blob const& peekData() const;
|
||||
Serializer& peekSerializer();
|
||||
@@ -51,16 +54,24 @@ private:
|
||||
explicit SHAMapItem (Blob const& data);
|
||||
|
||||
void const* data() const;
|
||||
void addRaw (Blob& s) const;
|
||||
void dump (beast::Journal journal);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
inline
|
||||
SHAMapItem::SHAMapItem (uint256 const& tag)
|
||||
: mTag (tag)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Slice
|
||||
SHAMapItem::slice() const
|
||||
{
|
||||
return mData.slice();
|
||||
}
|
||||
|
||||
inline
|
||||
std::size_t
|
||||
SHAMapItem::size() const
|
||||
@@ -96,13 +107,6 @@ SHAMapItem::peekSerializer()
|
||||
return mData;
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
SHAMapItem::addRaw (Blob& s) const
|
||||
{
|
||||
s.insert (s.end (), mData.begin (), mData.end ());
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
#endif
|
||||
|
||||
@@ -174,7 +174,7 @@ SHAMap::fetchNodeFromDB (uint256 const& hash) const
|
||||
|
||||
if (backed_)
|
||||
{
|
||||
NodeObject::pointer obj = f_.db().fetch (hash);
|
||||
std::shared_ptr<NodeObject> obj = f_.db().fetch (hash);
|
||||
if (obj)
|
||||
{
|
||||
try
|
||||
@@ -377,7 +377,7 @@ SHAMapTreeNode* SHAMap::descendAsync (SHAMapTreeNode* parent, int branch,
|
||||
|
||||
if (!ptr && backed_)
|
||||
{
|
||||
NodeObject::pointer obj;
|
||||
std::shared_ptr<NodeObject> obj;
|
||||
if (! f_.db().asyncFetch (hash, obj))
|
||||
{
|
||||
pending = true;
|
||||
|
||||
@@ -26,13 +26,13 @@ class SHAMap;
|
||||
|
||||
SHAMapItem::SHAMapItem (uint256 const& tag, Blob const& data)
|
||||
: mTag (tag)
|
||||
, mData (data)
|
||||
, mData (data.data(), data.size())
|
||||
{
|
||||
}
|
||||
|
||||
SHAMapItem::SHAMapItem (uint256 const& tag, const Serializer& data)
|
||||
: mTag (tag)
|
||||
, mData (data.peekData ())
|
||||
, mData (data.data(), data.size())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ SHAMapTreeNode::SHAMapTreeNode (Blob const& rawNode,
|
||||
throw std::runtime_error ("invalid node AW type");
|
||||
}
|
||||
|
||||
Serializer s (rawNode.begin (), rawNode.end () - 1);
|
||||
Serializer s (rawNode.data(), rawNode.size() - 1);
|
||||
int type = rawNode.back ();
|
||||
int len = s.getLength ();
|
||||
|
||||
@@ -112,7 +112,7 @@ SHAMapTreeNode::SHAMapTreeNode (Blob const& rawNode,
|
||||
// transaction
|
||||
mItem = std::make_shared<SHAMapItem>(
|
||||
sha512Half(HashPrefix::transactionID,
|
||||
Slice(s.data(), s.size() - 1)),
|
||||
Slice(s.data(), s.size())),
|
||||
s.peekData());
|
||||
mType = tnTRANSACTION_NM;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ SHAMapTreeNode::SHAMapTreeNode (Blob const& rawNode,
|
||||
prefix |= rawNode[2];
|
||||
prefix <<= 8;
|
||||
prefix |= rawNode[3];
|
||||
Serializer s (rawNode.begin () + 4, rawNode.end ());
|
||||
Serializer s (rawNode.data() + 4, rawNode.size() - 4);
|
||||
|
||||
if (prefix == HashPrefix::transactionID)
|
||||
{
|
||||
@@ -307,10 +307,6 @@ bool SHAMapTreeNode::updateHash ()
|
||||
}
|
||||
else if (mType == tnACCOUNT_STATE)
|
||||
{
|
||||
Serializer s (mItem->size() + (256 + 32) / 8);
|
||||
s.add32 (HashPrefix::leafNode);
|
||||
s.addRaw (mItem->peekData ());
|
||||
s.add256 (mItem->getTag ());
|
||||
nh = sha512Half(HashPrefix::leafNode,
|
||||
make_Slice(mItem->peekData()),
|
||||
mItem->getTag());
|
||||
|
||||
Reference in New Issue
Block a user