diff --git a/src/beast/beast/hash/hash_append.h b/src/beast/beast/hash/hash_append.h index 2d8ddbe24..e7d274535 100644 --- a/src/beast/beast/hash/hash_append.h +++ b/src/beast/beast/hash/hash_append.h @@ -62,7 +62,7 @@ template /*constexpr*/ inline void -maybe_reverse_bytes(T& t, std::true_type) +maybe_reverse_bytes(T& t, std::false_type) { } @@ -70,7 +70,7 @@ template /*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{}); + Hasher::endian != endian::native>{}); } } // detail @@ -140,7 +140,7 @@ struct is_uniquely_represented> template struct is_uniquely_represented - : public std::integral_constant::value> + : public is_uniquely_represented { }; @@ -176,7 +176,7 @@ struct is_contiguously_hashable template struct is_contiguously_hashable - : public std::integral_constant::value && + : public std::integral_constant::value && (sizeof(T) == 1 || HashAlgorithm::endian == endian::native)> {}; diff --git a/src/beast/beast/hash/siphash.h b/src/beast/beast/hash/siphash.h index a76466231..eeabfdcae 100644 --- a/src/beast/beast/hash/siphash.h +++ b/src/beast/beast/hash/siphash.h @@ -42,6 +42,8 @@ private: public: using result_type = std::size_t; + static beast::endian const endian = beast::endian::native; + siphash() = default; explicit diff --git a/src/beast/beast/hash/xxhasher.h b/src/beast/beast/hash/xxhasher.h index 7150db73c..c17d5ef5c 100644 --- a/src/beast/beast/hash/xxhasher.h +++ b/src/beast/beast/hash/xxhasher.h @@ -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); diff --git a/src/ripple/app/ledger/AcceptedLedger.cpp b/src/ripple/app/ledger/AcceptedLedger.cpp index 429c576f5..df289988b 100644 --- a/src/ripple/app/ledger/AcceptedLedger.cpp +++ b/src/ripple/app/ledger/AcceptedLedger.cpp @@ -38,7 +38,7 @@ AcceptedLedger::AcceptedLedger (Ledger::ref ledger) : mLedger (ledger) for (std::shared_ptr item = txSet.peekFirstItem (); item; item = txSet.peekNextItem (item->getTag ())) { - SerialIter sit (item->peekSerializer ()); + SerialIter sit (item->slice()); insert (std::make_shared (ledger, std::ref (sit))); } } diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.cpp b/src/ripple/app/ledger/AcceptedLedgerTx.cpp index 2b5418538..5e0e7b6f8 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.cpp +++ b/src/ripple/app/ledger/AcceptedLedgerTx.cpp @@ -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 (std::ref (txnIt)); mRawMeta = sit.getVL (); diff --git a/src/ripple/app/ledger/ConsensusTransSetSF.cpp b/src/ripple/app/ledger/ConsensusTransSetSF.cpp index 2341c6ef1..1684babb6 100644 --- a/src/ripple/app/ledger/ConsensusTransSetSF.cpp +++ b/src/ripple/app/ledger/ConsensusTransSetSF.cpp @@ -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 (std::ref (sit)); assert (stx->getTransactionID () == nodeHash); getApp().getJobQueue ().addJob ( diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index fd4bf1c26..74568a8a0 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -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 const& item, SHAMapTreeNode::TNType type) { - SerialIter sit (item->peekSerializer ()); + SerialIter sit (item->slice()); if (type == SHAMapTreeNode::tnTRANSACTION_NM) return std::make_shared (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 (tSit); } @@ -450,7 +451,7 @@ STTx::pointer Ledger::getSMTransaction ( std::shared_ptr 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 ( 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 (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 (entry->getIndex ()); - entry->add (item->peekSerializer ()); + entry->add (item->peekSerializer()); if (create) { @@ -1211,7 +1213,7 @@ bool Ledger::visitAccountItems ( static void visitHelper ( std::function& function, std::shared_ptr const& item) { - function (std::make_shared (item->peekSerializer (), item->getTag ())); + function (std::make_shared (item->peekSerializer(), item->getTag ())); } void Ledger::visitStateItems (std::function function) const diff --git a/src/ripple/app/ledger/LedgerToJson.h b/src/ripple/app/ledger/LedgerToJson.h index c38255128..518461155 100644 --- a/src/ripple/app/ledger/LedgerToJson.h +++ b/src/ripple/app/ledger/LedgerToJson.h @@ -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 ( diff --git a/src/ripple/app/ledger/TransactionStateSF.cpp b/src/ripple/app/ledger/TransactionStateSF.cpp index 2060de4ff..9214462c5 100644 --- a/src/ripple/app/ledger/TransactionStateSF.cpp +++ b/src/ripple/app/ledger/TransactionStateSF.cpp @@ -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, diff --git a/src/ripple/app/ledger/impl/DisputedTx.h b/src/ripple/app/ledger/impl/DisputedTx.h index 2b09c0282..161d3f056 100644 --- a/src/ripple/app/ledger/impl/DisputedTx.h +++ b/src/ripple/app/ledger/impl/DisputedTx.h @@ -40,12 +40,15 @@ class DisputedTx public: using pointer = std::shared_ptr ; + // 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 mVotes; diff --git a/src/ripple/app/ledger/impl/InboundLedger.cpp b/src/ripple/app/ledger/impl/InboundLedger.cpp index 38c2e2439..b2b50122a 100644 --- a/src/ripple/app/ledger/impl/InboundLedger.cpp +++ b/src/ripple/app/ledger/impl/InboundLedger.cpp @@ -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 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); diff --git a/src/ripple/app/ledger/impl/LedgerConsensus.cpp b/src/ripple/app/ledger/impl/LedgerConsensus.cpp index a3f17dab7..105e07782 100644 --- a/src/ripple/app/ledger/impl/LedgerConsensus.cpp +++ b/src/ripple/app/ledger/impl/LedgerConsensus.cpp @@ -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(sit); @@ -1868,7 +1868,7 @@ void applyTransactions (std::shared_ptr const& set, "Processing candidate transaction: " << item->getTag (); try { - SerialIter sit (item->peekSerializer ()); + SerialIter sit (item->slice()); STTx::pointer txn = std::make_shared(sit); if (applyTransaction (engine, txn, diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index e186e0d01..daf444686 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -36,13 +36,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -51,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -886,7 +885,7 @@ void NetworkOPsImp::submitTransaction ( Serializer s; iTrans->add (s); - SerialIter sit (s); + SerialIter sit (s.slice()); auto trans = std::make_shared (std::ref (sit)); uint256 suppress = trans->getTransactionID (); diff --git a/src/ripple/app/misc/impl/AccountTxPaging.cpp b/src/ripple/app/misc/impl/AccountTxPaging.cpp index 15612eff1..eaf2ae9b8 100644 --- a/src/ripple/app/misc/impl/AccountTxPaging.cpp +++ b/src/ripple/app/misc/impl/AccountTxPaging.cpp @@ -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 (it); std::string reason; diff --git a/src/ripple/app/tx/impl/Transaction.cpp b/src/ripple/app/tx/impl/Transaction.cpp index 0de032755..9e159263f 100644 --- a/src/ripple/app/tx/impl/Transaction.cpp +++ b/src/ripple/app/tx/impl/Transaction.cpp @@ -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 (std::make_shared (sit), @@ -134,7 +133,7 @@ Transaction::pointer Transaction::transactionFromSQL ( std::uint32_t const inLedger = rangeCheckedCast(ledgerSeq.value_or (0)); - SerialIter it (rawTxn); + SerialIter it (make_Slice(rawTxn)); auto txn = std::make_shared (it); std::string reason; auto tr = std::make_shared (txn, validate, reason); diff --git a/src/ripple/app/tx/impl/TransactionEngine.cpp b/src/ripple/app/tx/impl/TransactionEngine.cpp index 377d87a4d..a170e65e6 100644 --- a/src/ripple/app/tx/impl/TransactionEngine.cpp +++ b/src/ripple/app/tx/impl/TransactionEngine.cpp @@ -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)) diff --git a/src/ripple/app/tx/impl/TransactionMaster.cpp b/src/ripple/app/tx/impl/TransactionMaster.cpp index 004fe6d62..8e2723831 100644 --- a/src/ripple/app/tx/impl/TransactionMaster.cpp +++ b/src/ripple/app/tx/impl/TransactionMaster.cpp @@ -71,15 +71,15 @@ STTx::pointer TransactionMaster::fetch (std::shared_ptr const& item, if (type == SHAMapTreeNode::tnTRANSACTION_NM) { - SerialIter sit (item->peekSerializer ()); + SerialIter sit (item->slice()); txn = std::make_shared (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 (std::ref (sit)); } diff --git a/src/ripple/app/tx/impl/TransactionMeta.cpp b/src/ripple/app/tx/impl/TransactionMeta.cpp index a70a654b5..e8a38219b 100644 --- a/src/ripple/app/tx/impl/TransactionMeta.cpp +++ b/src/ripple/app/tx/impl/TransactionMeta.cpp @@ -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); diff --git a/src/ripple/nodestore/Backend.h b/src/ripple/nodestore/Backend.h index f5b3936a5..463f84d84 100644 --- a/src/ripple/nodestore/Backend.h +++ b/src/ripple/nodestore/Backend.h @@ -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* 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 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 f) = 0; + virtual void for_each (std::function )> f) = 0; /** Estimate the number of write operations pending. */ virtual int getWriteLoad () = 0; diff --git a/src/ripple/nodestore/Database.h b/src/ripple/nodestore/Database.h index 255672352..7ab775906 100644 --- a/src/ripple/nodestore/Database.h +++ b/src/ripple/nodestore/Database.h @@ -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 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& 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 f) = 0; + virtual void for_each(std::function )> f) = 0; /** Import objects from another database. */ virtual void import (Database& source) = 0; diff --git a/src/ripple/nodestore/DatabaseRotating.h b/src/ripple/nodestore/DatabaseRotating.h index 68be4e743..75173ed6b 100644 --- a/src/ripple/nodestore/DatabaseRotating.h +++ b/src/ripple/nodestore/DatabaseRotating.h @@ -47,7 +47,7 @@ public: std::shared_ptr const& newBackend) = 0; /** Ensure that node is in writableBackend */ - virtual NodeObject::Ptr fetchNode (uint256 const& hash) = 0; + virtual std::shared_ptr fetchNode (uint256 const& hash) = 0; }; } diff --git a/src/ripple/nodestore/NodeObject.h b/src/ripple/nodestore/NodeObject.h index fdcf915f0..e68636e55 100644 --- a/src/ripple/nodestore/NodeObject.h +++ b/src/ripple/nodestore/NodeObject.h @@ -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 ; - - // These are DEPRECATED, type names are capitalized. - using pointer = std::shared_ptr ; - 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 + 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; diff --git a/src/ripple/nodestore/Types.h b/src/ripple/nodestore/Types.h index e38d6f88f..cb1fb1663 100644 --- a/src/ripple/nodestore/Types.h +++ b/src/ripple/nodestore/Types.h @@ -47,7 +47,7 @@ enum Status }; /** A batch of NodeObjects to write at once. */ -using Batch = std::vector ; +using Batch = std::vector >; } } diff --git a/src/ripple/nodestore/backend/MemoryFactory.cpp b/src/ripple/nodestore/backend/MemoryFactory.cpp index 0223e51db..ec27fbf8e 100644 --- a/src/ripple/nodestore/backend/MemoryFactory.cpp +++ b/src/ripple/nodestore/backend/MemoryFactory.cpp @@ -32,7 +32,7 @@ struct MemoryDB { std::mutex mutex; bool open = false; - std::map table; + std::map > table; }; class MemoryFactory : public Factory @@ -75,7 +75,7 @@ static MemoryFactory memoryFactory; class MemoryBackend : public Backend { private: - using Map = std::map ; + using Map = std::map >; 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* pObject) { uint256 const hash (uint256::fromVoid (key)); @@ -142,7 +142,7 @@ public: } void - store (NodeObject::ref object) + store (std::shared_ptr const& object) { std::lock_guard _(db_->mutex); db_->table.emplace (object->getHash(), object); @@ -156,7 +156,7 @@ public: } void - for_each (std::function f) + for_each (std::function )> f) { for (auto const& e : db_->table) f (e.second); diff --git a/src/ripple/nodestore/backend/NuDBFactory.cpp b/src/ripple/nodestore/backend/NuDBFactory.cpp index e725a6071..91c86d55b 100644 --- a/src/ripple/nodestore/backend/NuDBFactory.cpp +++ b/src/ripple/nodestore/backend/NuDBFactory.cpp @@ -126,7 +126,7 @@ public: } Status - fetch (void const* key, NodeObject::Ptr* pno) + fetch (void const* key, std::shared_ptr* pno) { Status status; pno->reset(); @@ -201,7 +201,7 @@ public: } void - for_each (std::function f) + for_each (std::function )> f) { auto const dp = db_.dat_path(); auto const kp = db_.key_path(); diff --git a/src/ripple/nodestore/backend/NullFactory.cpp b/src/ripple/nodestore/backend/NullFactory.cpp index 8de240b98..52d9a2b24 100644 --- a/src/ripple/nodestore/backend/NullFactory.cpp +++ b/src/ripple/nodestore/backend/NullFactory.cpp @@ -48,7 +48,7 @@ public: } Status - fetch (void const*, NodeObject::Ptr*) + fetch (void const*, std::shared_ptr*) { return notFound; } @@ -67,7 +67,7 @@ public: } void - store (NodeObject::ref object) + store (std::shared_ptr const& object) { } @@ -77,7 +77,7 @@ public: } void - for_each (std::function f) + for_each (std::function )> f) { } diff --git a/src/ripple/nodestore/backend/RocksDBFactory.cpp b/src/ripple/nodestore/backend/RocksDBFactory.cpp index 09ef4e626..77f022be4 100644 --- a/src/ripple/nodestore/backend/RocksDBFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBFactory.cpp @@ -217,7 +217,7 @@ public: //-------------------------------------------------------------------------- Status - fetch (void const* key, NodeObject::Ptr* pObject) + fetch (void const* key, std::shared_ptr* pObject) { pObject->reset (); @@ -280,7 +280,7 @@ public: } void - store (NodeObject::ref object) + store (std::shared_ptr const& object) { m_batch.store (object); } @@ -312,7 +312,7 @@ public: } void - for_each (std::function f) + for_each (std::function )> f) { rocksdb::ReadOptions const options; diff --git a/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp b/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp index 8215df99b..2f6f15953 100644 --- a/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp @@ -201,7 +201,7 @@ public: //-------------------------------------------------------------------------- Status - fetch (void const* key, NodeObject::Ptr* pObject) + fetch (void const* key, std::shared_ptr* pObject) { pObject->reset (); @@ -257,7 +257,7 @@ public: } void - store (NodeObject::ref object) + store (std::shared_ptr const& object) { storeBatch(Batch{object}); } @@ -299,7 +299,7 @@ public: } void - for_each (std::function f) + for_each (std::function )> f) { rocksdb::ReadOptions const options; diff --git a/src/ripple/nodestore/impl/BatchWriter.cpp b/src/ripple/nodestore/impl/BatchWriter.cpp index 24a27c3e5..1dd40a33f 100644 --- a/src/ripple/nodestore/impl/BatchWriter.cpp +++ b/src/ripple/nodestore/impl/BatchWriter.cpp @@ -38,7 +38,7 @@ BatchWriter::~BatchWriter () } void -BatchWriter::store (NodeObject::ref object) +BatchWriter::store (std::shared_ptr const& object) { std::lock_guard sl (mWriteMutex); diff --git a/src/ripple/nodestore/impl/BatchWriter.h b/src/ripple/nodestore/impl/BatchWriter.h index 621cb762d..1b7e2c1d6 100644 --- a/src/ripple/nodestore/impl/BatchWriter.h +++ b/src/ripple/nodestore/impl/BatchWriter.h @@ -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 const& object); /** Get an estimate of the amount of writing I/O pending. */ int getWriteLoad (); diff --git a/src/ripple/nodestore/impl/DatabaseImp.h b/src/ripple/nodestore/impl/DatabaseImp.h index 40d4af171..6e214cbff 100644 --- a/src/ripple/nodestore/impl/DatabaseImp.h +++ b/src/ripple/nodestore/impl/DatabaseImp.h @@ -119,7 +119,7 @@ public: //------------------------------------------------------------------------------ - bool asyncFetch (uint256 const& hash, NodeObject::pointer& object) + bool asyncFetch (uint256 const& hash, std::shared_ptr& 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 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 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 ret = doFetch (hash, report); report.elapsed = std::chrono::duration_cast (std::chrono::steady_clock::now() - before); @@ -183,11 +183,11 @@ public: return ret; } - NodeObject::Ptr doFetch (uint256 const& hash, FetchReport &report) + std::shared_ptr 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 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 fetchFrom (uint256 const& hash) { return fetchInternal (*m_backend, hash); } - NodeObject::Ptr fetchInternal (Backend& backend, + std::shared_ptr fetchInternal (Backend& backend, uint256 const& hash) { - NodeObject::Ptr object; + std::shared_ptr 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 object = NodeObject::createObject( type, std::move(data), hash); #if RIPPLE_VERIFY_NODEOBJECT_KEYS @@ -376,7 +376,7 @@ public: //------------------------------------------------------------------------------ - void for_each (std::function f) override + void for_each (std::function )> 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 object) { if (b.size() >= batchWritePreallocationSize) { diff --git a/src/ripple/nodestore/impl/DatabaseRotatingImp.cpp b/src/ripple/nodestore/impl/DatabaseRotatingImp.cpp index 106c814bf..11649fdf5 100644 --- a/src/ripple/nodestore/impl/DatabaseRotatingImp.cpp +++ b/src/ripple/nodestore/impl/DatabaseRotatingImp.cpp @@ -34,10 +34,10 @@ std::shared_ptr DatabaseRotatingImp::rotateBackends ( return oldBackend; } -NodeObject::Ptr DatabaseRotatingImp::fetchFrom (uint256 const& hash) +std::shared_ptr DatabaseRotatingImp::fetchFrom (uint256 const& hash) { Backends b = getBackends(); - NodeObject::Ptr object = fetchInternal (*b.writableBackend, hash); + std::shared_ptr object = fetchInternal (*b.writableBackend, hash); if (!object) { object = fetchInternal (*b.archiveBackend, hash); diff --git a/src/ripple/nodestore/impl/DatabaseRotatingImp.h b/src/ripple/nodestore/impl/DatabaseRotatingImp.h index 7c02490e9..ad0165db8 100644 --- a/src/ripple/nodestore/impl/DatabaseRotatingImp.h +++ b/src/ripple/nodestore/impl/DatabaseRotatingImp.h @@ -95,7 +95,7 @@ public: return getWritableBackend()->getWriteLoad(); } - void for_each (std::function f) override + void for_each (std::function )> 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 fetchNode (uint256 const& hash) override { return fetchFrom (hash); } - NodeObject::Ptr fetchFrom (uint256 const& hash) override; + std::shared_ptr fetchFrom (uint256 const& hash) override; TaggedCache & getPositiveCache() override { return m_cache; diff --git a/src/ripple/nodestore/impl/DecodedBlob.cpp b/src/ripple/nodestore/impl/DecodedBlob.cpp index 8fbb914c8..793124c46 100644 --- a/src/ripple/nodestore/impl/DecodedBlob.cpp +++ b/src/ripple/nodestore/impl/DecodedBlob.cpp @@ -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 DecodedBlob::createObject () { bassert (m_success); - NodeObject::Ptr object; + std::shared_ptr object; if (m_success) { diff --git a/src/ripple/nodestore/impl/DecodedBlob.h b/src/ripple/nodestore/impl/DecodedBlob.h index 2f692c442..1e50a4504 100644 --- a/src/ripple/nodestore/impl/DecodedBlob.h +++ b/src/ripple/nodestore/impl/DecodedBlob.h @@ -45,7 +45,7 @@ public: bool wasOk () const noexcept { return m_success; } /** Create a NodeObject from this data. */ - NodeObject::Ptr createObject (); + std::shared_ptr createObject (); private: bool m_success; diff --git a/src/ripple/nodestore/impl/EncodedBlob.cpp b/src/ripple/nodestore/impl/EncodedBlob.cpp index 67cf26f1e..3a5722bf8 100644 --- a/src/ripple/nodestore/impl/EncodedBlob.cpp +++ b/src/ripple/nodestore/impl/EncodedBlob.cpp @@ -25,7 +25,7 @@ namespace ripple { namespace NodeStore { void -EncodedBlob::prepare (NodeObject::Ptr const& object) +EncodedBlob::prepare (std::shared_ptr const& object) { m_key = object->getHash().begin (); diff --git a/src/ripple/nodestore/impl/EncodedBlob.h b/src/ripple/nodestore/impl/EncodedBlob.h index 2a46fea3f..ec5ad5692 100644 --- a/src/ripple/nodestore/impl/EncodedBlob.h +++ b/src/ripple/nodestore/impl/EncodedBlob.h @@ -35,7 +35,7 @@ namespace NodeStore { struct EncodedBlob { public: - void prepare (NodeObject::Ptr const& object); + void prepare (std::shared_ptr 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 (); } diff --git a/src/ripple/nodestore/impl/NodeObject.cpp b/src/ripple/nodestore/impl/NodeObject.cpp index 97a1efa48..4df044b45 100644 --- a/src/ripple/nodestore/impl/NodeObject.cpp +++ b/src/ripple/nodestore/impl/NodeObject.cpp @@ -36,7 +36,7 @@ NodeObject::NodeObject ( mData = std::move (data); } -NodeObject::Ptr +std::shared_ptr 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; -} - -//------------------------------------------------------------------------------ - } diff --git a/src/ripple/nodestore/tests/Backend.test.cpp b/src/ripple/nodestore/tests/Backend.test.cpp index 1f8552b33..c97e356ca 100644 --- a/src/ripple/nodestore/tests/Backend.test.cpp +++ b/src/ripple/nodestore/tests/Backend.test.cpp @@ -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"); } } diff --git a/src/ripple/nodestore/tests/Base.test.h b/src/ripple/nodestore/tests/Base.test.h index fa322cab3..a4db232c1 100644 --- a/src/ripple/nodestore/tests/Base.test.h +++ b/src/ripple/nodestore/tests/Base.test.h @@ -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 const& lhs, + std::shared_ptr const& rhs) const noexcept + { + return lhs->getHash () < rhs->getHash (); + } +}; + +/** Returns `true` if objects are identical. */ +inline +bool isSame (std::shared_ptr const& lhs, + std::shared_ptr 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 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 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 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 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 object = db.fetch (batch [i]->getHash ()); if (object != nullptr) pCopy->push_back (object); diff --git a/src/ripple/nodestore/tests/Basics.test.cpp b/src/ripple/nodestore/tests/Basics.test.cpp index cbefd8f4f..0d9f6079c 100644 --- a/src/ripple/nodestore/tests/Basics.test.cpp +++ b/src/ripple/nodestore/tests/Basics.test.cpp @@ -70,9 +70,9 @@ public: if (decoded.wasOk ()) { - NodeObject::Ptr const object (decoded.createObject ()); + std::shared_ptr const object (decoded.createObject ()); - expect (batch [i]->isCloneOf (object), "Should be clones"); + expect (isSame(batch[i], object), "Should be clones"); } } } diff --git a/src/ripple/nodestore/tests/Database.test.cpp b/src/ripple/nodestore/tests/Database.test.cpp index dccf75781..2b163cb9a 100644 --- a/src/ripple/nodestore/tests/Database.test.cpp +++ b/src/ripple/nodestore/tests/Database.test.cpp @@ -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"); } } diff --git a/src/ripple/nodestore/tests/Timing.test.cpp b/src/ripple/nodestore/tests/Timing.test.cpp index 505575c65..c8cc0c29f 100644 --- a/src/ripple/nodestore/tests/Timing.test.cpp +++ b/src/ripple/nodestore/tests/Timing.test.cpp @@ -107,7 +107,7 @@ public: } // Returns the n-th complete NodeObject - NodeObject::Ptr + std::shared_ptr obj (std::size_t n) { gen_.seed(n+1); @@ -356,11 +356,11 @@ public: { try { - NodeObject::Ptr obj; - NodeObject::Ptr result; + std::shared_ptr obj; + std::shared_ptr 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 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 result; backend_.fetch(key.data(), &result); suite_.expect (! result); } else { - NodeObject::Ptr obj; - NodeObject::Ptr result; + std::shared_ptr obj; + std::shared_ptr 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 obj; + std::shared_ptr result; auto const j = older_(gen_); obj = seq1_.obj(j); - NodeObject::Ptr result1; + std::shared_ptr 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 obj; + std::shared_ptr 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; } diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index c32087c27..10d97b884 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -979,7 +979,7 @@ PeerImp::onMessage (std::shared_ptr const& m) return; } - SerialIter sit (m->rawtransaction ()); + SerialIter sit (make_Slice(m->rawtransaction())); try { @@ -1485,7 +1485,7 @@ PeerImp::onMessage (std::shared_ptr 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 hObj = getApp().getNodeStore ().fetch (hash); if (hObj) diff --git a/src/ripple/protocol/STLedgerEntry.h b/src/ripple/protocol/STLedgerEntry.h index 5a05e9196..799728301 100644 --- a/src/ripple/protocol/STLedgerEntry.h +++ b/src/ripple/protocol/STLedgerEntry.h @@ -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 getOwners (); // nodes notified if this node is deleted private: /** Make STObject comply with the template for this SLE type diff --git a/src/ripple/protocol/Serializer.h b/src/ripple/protocol/Serializer.h index 9135e0c7c..b64f62dfe 100644 --- a/src/ripple/protocol/Serializer.h +++ b/src/ripple/protocol/Serializer.h @@ -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 @@ -150,8 +137,6 @@ public: return success; } - uint256 get256 (int offset) const; - // TODO(tom): merge with get128 and get256. template 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 ::value && - sizeof(T) == 1>* = nullptr> - explicit - SerialIter (std::vector const& v) noexcept - : SerialIter (v.data(), v.size()) - { - } - - // DEPRECATED - SerialIter (Serializer const& s) noexcept - : SerialIter(s.peekData()) - { - } - std::size_t empty() const noexcept { diff --git a/src/ripple/protocol/impl/STLedgerEntry.cpp b/src/ripple/protocol/impl/STLedgerEntry.cpp index 8eb8db106..6738bd856 100644 --- a/src/ripple/protocol/impl/STLedgerEntry.cpp +++ b/src/ripple/protocol/impl/STLedgerEntry.cpp @@ -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 (s)); + SerialIter sit (s.slice()); set (sit); setSLEType (); } @@ -184,38 +183,4 @@ RippleAddress STLedgerEntry::getSecondOwner () return RippleAddress::createAccountID (getFieldAmount (sfHighLimit).getIssuer ()); } -std::vector STLedgerEntry::getOwners () -{ - std::vector 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 (peekAtPIndex (i)); - - if ((entry != nullptr) && entry->getValueH160 (account)) - owners.push_back (getAccountRootIndex (account)); - } - - if ((fc == sfLowLimit) || (fc == sfHighLimit)) - { - auto entry = dynamic_cast (peekAtPIndex (i)); - - if ((entry != nullptr)) - { - auto issuer = entry->getIssuer (); - - if (issuer.isNonZero ()) - owners.push_back (getAccountRootIndex (issuer)); - } - } - } - - return owners; -} - } // ripple diff --git a/src/ripple/protocol/impl/Serializer.cpp b/src/ripple/protocol/impl/Serializer.cpp index 24725af95..63d39472a 100644 --- a/src/ripple/protocol/impl/Serializer.cpp +++ b/src/ripple/protocol/impl/Serializer.cpp @@ -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 (); diff --git a/src/ripple/protocol/tests/STAmount.test.cpp b/src/ripple/protocol/tests/STAmount.test.cpp index 359057b07..23d6f5721 100644 --- a/src/ripple/protocol/tests/STAmount.test.cpp +++ b/src/ripple/protocol/tests/STAmount.test.cpp @@ -33,7 +33,7 @@ public: Serializer ser; s.add (ser); - SerialIter sit (ser); + SerialIter sit (ser.slice()); return STAmount(sit, sfGeneric); } diff --git a/src/ripple/protocol/tests/STObject.test.cpp b/src/ripple/protocol/tests/STObject.test.cpp index 0432384c0..5110a09ed 100644 --- a/src/ripple/protocol/tests/STObject.test.cpp +++ b/src/ripple/protocol/tests/STObject.test.cpp @@ -183,7 +183,7 @@ public: Serializer s; object1.add (s); - SerialIter it (s); + SerialIter it (s.slice()); STObject object3 (elements, it, sfTestObject); diff --git a/src/ripple/protocol/tests/STTx.test.cpp b/src/ripple/protocol/tests/STTx.test.cpp index fdf3f4aaf..de9e756af 100644 --- a/src/ripple/protocol/tests/STTx.test.cpp +++ b/src/ripple/protocol/tests/STTx.test.cpp @@ -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 { diff --git a/src/ripple/rpc/handlers/Submit.cpp b/src/ripple/rpc/handlers/Submit.cpp index 494ae7daa..bd5a3e953 100644 --- a/src/ripple/rpc/handlers/Submit.cpp +++ b/src/ripple/rpc/handlers/Submit.cpp @@ -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; diff --git a/src/ripple/shamap/SHAMapItem.h b/src/ripple/shamap/SHAMapItem.h index 10a94b4f9..9a5e92352 100644 --- a/src/ripple/shamap/SHAMapItem.h +++ b/src/ripple/shamap/SHAMapItem.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -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 diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index e043e5662..88755b0d4 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -174,7 +174,7 @@ SHAMap::fetchNodeFromDB (uint256 const& hash) const if (backed_) { - NodeObject::pointer obj = f_.db().fetch (hash); + std::shared_ptr 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 obj; if (! f_.db().asyncFetch (hash, obj)) { pending = true; diff --git a/src/ripple/shamap/impl/SHAMapItem.cpp b/src/ripple/shamap/impl/SHAMapItem.cpp index 7bc265e6e..7af336133 100644 --- a/src/ripple/shamap/impl/SHAMapItem.cpp +++ b/src/ripple/shamap/impl/SHAMapItem.cpp @@ -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()) { } diff --git a/src/ripple/shamap/impl/SHAMapTreeNode.cpp b/src/ripple/shamap/impl/SHAMapTreeNode.cpp index 80e9631ac..64d6d34e3 100644 --- a/src/ripple/shamap/impl/SHAMapTreeNode.cpp +++ b/src/ripple/shamap/impl/SHAMapTreeNode.cpp @@ -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( 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());