Replace Serializer with Blob in SHAMapItem:

* This helps decouples SHAMap and Serializer.
* Restyle data member names.
* Rename getTag() to key().
This commit is contained in:
Howard Hinnant
2015-06-23 17:59:07 -04:00
committed by Vinnie Falco
parent 72659d431e
commit 26bfeb1319
17 changed files with 92 additions and 137 deletions

View File

@@ -375,13 +375,8 @@ getTransaction (Ledger const& ledger,
txn = Transaction::sharedTransaction (item->peekData (), Validate::YES); txn = Transaction::sharedTransaction (item->peekData (), Validate::YES);
else if (type == SHAMapTreeNode::tnTRANSACTION_MD) else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
{ {
Blob txnData; auto sit = SerialIter{item->data(), item->size()};
int txnLength; txn = Transaction::sharedTransaction(sit.getVL(), Validate::NO);
if (!item->peekSerializer().getVL (txnData, 0, txnLength))
return Transaction::pointer ();
txn = Transaction::sharedTransaction (txnData, Validate::NO);
} }
else else
{ {
@@ -917,7 +912,7 @@ Ledger::read (Keylet const& k) const
if (! value) if (! value)
return nullptr; return nullptr;
auto sle = std::make_shared<SLE>( auto sle = std::make_shared<SLE>(
value->peekSerializer(), value->key()); SerialIter{value->data(), value->size()}, value->key());
if (! k.check(*sle)) if (! k.check(*sle))
return nullptr; return nullptr;
// VFALCO TODO Eliminate "immutable" runtime property // VFALCO TODO Eliminate "immutable" runtime property
@@ -1037,7 +1032,7 @@ Ledger::peek (Keylet const& k) const
if (! value) if (! value)
return nullptr; return nullptr;
auto sle = std::make_shared<SLE>( auto sle = std::make_shared<SLE>(
value->peekSerializer(), value->key()); SerialIter{value->data(), value->size()}, value->key());
if (! k.check(*sle)) if (! k.check(*sle))
return nullptr; return nullptr;
// VFALCO TODO Eliminate "immutable" runtime property // VFALCO TODO Eliminate "immutable" runtime property
@@ -1050,20 +1045,21 @@ Ledger::peek (Keylet const& k) const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static void visitHelper ( static void visitHelper (
std::function<void (std::shared_ptr<SLE> const&)>& function, std::function<void (std::shared_ptr<SLE> const&)>& callback,
std::shared_ptr<SHAMapItem const> const& item) std::shared_ptr<SHAMapItem const> const& item)
{ {
function (std::make_shared<SLE> (item->peekSerializer(), item->key())); callback(std::make_shared<SLE>(SerialIter{item->data(), item->size()},
item->key()));
} }
void Ledger::visitStateItems (std::function<void (SLE::ref)> function) const void Ledger::visitStateItems (std::function<void (SLE::ref)> callback) const
{ {
try try
{ {
if (stateMap_) if (stateMap_)
{ {
stateMap_->visitLeaves( stateMap_->visitLeaves(
std::bind(&visitHelper, std::ref(function), std::bind(&visitHelper, std::ref(callback),
std::placeholders::_1)); std::placeholders::_1));
} }
} }

View File

@@ -312,13 +312,13 @@ void LedgerHistory::handleMismatch (LedgerHash const& built, LedgerHash const& v
builtLedger->txMap().visitLeaves( builtLedger->txMap().visitLeaves(
[&builtTx](std::shared_ptr<SHAMapItem const> const& item) [&builtTx](std::shared_ptr<SHAMapItem const> const& item)
{ {
builtTx.push_back({item->getTag(), item->peekData()}); builtTx.push_back({item->key(), item->peekData()});
}); });
// Get valid ledger hashes and metadata // Get valid ledger hashes and metadata
validLedger->txMap().visitLeaves( validLedger->txMap().visitLeaves(
[&validTx](std::shared_ptr<SHAMapItem const> const& item) [&validTx](std::shared_ptr<SHAMapItem const> const& item)
{ {
validTx.push_back({item->getTag(), item->peekData()}); validTx.push_back({item->key(), item->peekData()});
}); });
// Sort both by hash // Sort both by hash

View File

@@ -129,7 +129,7 @@ void fillJson (Object& json, LedgerFill const& fill)
CountedYield count ( CountedYield count (
fill.yieldStrategy.transactionYieldCount, fill.yield); fill.yieldStrategy.transactionYieldCount, fill.yield);
for (auto item = txMap.peekFirstItem (type); item; for (auto item = txMap.peekFirstItem (type); item;
item = txMap.peekNextItem (item->getTag (), type)) item = txMap.peekNextItem (item->key(), type))
{ {
count.yield(); count.yield();
if (bFull || bExpand) if (bFull || bExpand)
@@ -167,7 +167,7 @@ void fillJson (Object& json, LedgerFill const& fill)
STTx txn (tsit); STTx txn (tsit);
TxMeta meta ( TxMeta meta (
item->getTag (), ledger.getLedgerSeq(), sit.getVL ()); item->key(), ledger.getLedgerSeq(), sit.getVL ());
auto&& txJson = appendObject (txns); auto&& txJson = appendObject (txns);
copyFrom(txJson, txn.getJson (0)); copyFrom(txJson, txn.getJson (0));
@@ -177,12 +177,12 @@ void fillJson (Object& json, LedgerFill const& fill)
else else
{ {
auto&& error = appendObject (txns); auto&& error = appendObject (txns);
error[to_string (item->getTag ())] = (int) type; error[to_string (item->key())] = (int) type;
} }
} }
else else
{ {
txns.append (to_string (item->getTag ())); txns.append (to_string (item->key()));
} }
} }
} }
@@ -201,7 +201,7 @@ void fillJson (Object& json, LedgerFill const& fill)
[&array] (std::shared_ptr<SHAMapItem const> const& smi) [&array] (std::shared_ptr<SHAMapItem const> const& smi)
{ {
auto&& obj = appendObject (array); auto&& obj = appendObject (array);
obj[jss::hash] = to_string(smi->getTag ()); obj[jss::hash] = to_string(smi->key());
obj[jss::tx_blob] = strHex(smi->peekData ()); obj[jss::tx_blob] = strHex(smi->peekData ());
}); });
} }
@@ -221,7 +221,7 @@ void fillJson (Object& json, LedgerFill const& fill)
[&array, &count] (std::shared_ptr<SHAMapItem const> const& smi) [&array, &count] (std::shared_ptr<SHAMapItem const> const& smi)
{ {
count.yield(); count.yield();
array.append (to_string(smi->getTag ())); array.append (to_string(smi->key()));
}); });
} }
} }

View File

@@ -1825,7 +1825,7 @@ void applyTransactions (
// The transaction isn't in the check ledger, try to apply it // The transaction isn't in the check ledger, try to apply it
WriteLog (lsDEBUG, LedgerConsensus) << WriteLog (lsDEBUG, LedgerConsensus) <<
"Processing candidate transaction: " << item->getTag (); "Processing candidate transaction: " << item->key();
try try
{ {

View File

@@ -1331,16 +1331,16 @@ bool ApplicationImp::loadOldLedger (
for (auto const& item : txns) for (auto const& item : txns)
{ {
auto const txn = auto const txn =
getTransaction(*replayLedger, item->getTag(), getTransaction(*replayLedger, item->key(),
getApp().getMasterTransaction()); getApp().getMasterTransaction());
if (m_journal.info) m_journal.info << if (m_journal.info) m_journal.info <<
txn->getJson(0); txn->getJson(0);
Serializer s; Serializer s;
txn->getSTransaction()->add(s); txn->getSTransaction()->add(s);
cur->txInsert(item->getTag(), cur->txInsert(item->key(),
std::make_shared<Serializer const>( std::make_shared<Serializer const>(
std::move(s)), nullptr); std::move(s)), nullptr);
getApp().getHashRouter().setFlag (item->getTag(), SF_SIGGOOD); getApp().getHashRouter().setFlag (item->key(), SF_SIGGOOD);
} }
// Switch to the mutable snapshot // Switch to the mutable snapshot

View File

@@ -64,7 +64,7 @@ STTx::pointer TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item,
bool checkDisk, std::uint32_t uCommitLedger) bool checkDisk, std::uint32_t uCommitLedger)
{ {
STTx::pointer txn; STTx::pointer txn;
Transaction::pointer iTx = getApp().getMasterTransaction ().fetch (item->getTag (), false); auto iTx = getApp().getMasterTransaction ().fetch (item->key(), false);
if (!iTx) if (!iTx)
{ {
@@ -76,12 +76,8 @@ STTx::pointer TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item,
} }
else if (type == SHAMapTreeNode::tnTRANSACTION_MD) else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
{ {
Serializer s; auto blob = SerialIter{item->data(), item->size()}.getVL();
int length; txn = std::make_shared<STTx>(SerialIter{blob.data(), blob.size()});
item->peekSerializer().getVL (s.modData (), 0, length);
SerialIter sit (s.slice());
txn = std::make_shared<STTx> (std::ref (sit));
} }
} }
else else

View File

@@ -48,6 +48,8 @@ public:
STLedgerEntry (const Serializer & s, uint256 const& index); STLedgerEntry (const Serializer & s, uint256 const& index);
STLedgerEntry (SerialIter & sit, uint256 const& index); STLedgerEntry (SerialIter & sit, uint256 const& index);
STLedgerEntry(SerialIter&& sit, uint256 const& index)
: STLedgerEntry(sit, index) {}
STLedgerEntry (const STObject & object, uint256 const& index); STLedgerEntry (const STObject & object, uint256 const& index);

View File

@@ -54,6 +54,7 @@ public:
STTx (STTx const& other) = default; STTx (STTx const& other) = default;
explicit STTx (SerialIter& sit); explicit STTx (SerialIter& sit);
explicit STTx (SerialIter&& sit) : STTx(sit) {}
explicit STTx (TxType type); explicit STTx (TxType type);
explicit STTx (STObject&& object); explicit STTx (STObject&& object);

View File

@@ -82,7 +82,7 @@ Json::Value doLedgerData (RPC::Context& context)
auto item = map.peekNextItem (resumePoint); auto item = map.peekNextItem (resumePoint);
if (!item) if (!item)
break; break;
resumePoint = item->getTag(); resumePoint = item->key();
if (limit-- <= 0) if (limit-- <= 0)
{ {
@@ -96,13 +96,13 @@ Json::Value doLedgerData (RPC::Context& context)
Json::Value& entry = nodes.append (Json::objectValue); Json::Value& entry = nodes.append (Json::objectValue);
entry[jss::data] = strHex ( entry[jss::data] = strHex (
item->peekData().begin(), item->peekData().size()); item->peekData().begin(), item->peekData().size());
entry[jss::index] = to_string (item->getTag ()); entry[jss::index] = to_string (item->key());
} }
else else
{ {
SLE sle (item->peekSerializer(), item->getTag ()); SLE sle (SerialIter{item->data(), item->size()}, item->key());
Json::Value& entry = nodes.append (sle.getJson (0)); Json::Value& entry = nodes.append (sle.getJson (0));
entry[jss::index] = to_string (item->getTag ()); entry[jss::index] = to_string (item->key());
} }
} }

View File

@@ -20,9 +20,10 @@
#ifndef RIPPLE_SHAMAP_SHAMAPITEM_H_INCLUDED #ifndef RIPPLE_SHAMAP_SHAMAPITEM_H_INCLUDED
#define RIPPLE_SHAMAP_SHAMAPITEM_H_INCLUDED #define RIPPLE_SHAMAP_SHAMAPITEM_H_INCLUDED
#include <ripple/protocol/Serializer.h>
#include <ripple/basics/base_uint.h> #include <ripple/basics/base_uint.h>
#include <ripple/basics/Blob.h>
#include <ripple/basics/Slice.h> #include <ripple/basics/Slice.h>
#include <ripple/protocol/Serializer.h>
#include <beast/utility/Journal.h> #include <beast/utility/Journal.h>
#include <cstddef> #include <cstddef>
@@ -33,87 +34,58 @@ namespace ripple {
class SHAMapItem class SHAMapItem
{ {
private: private:
uint256 mTag; uint256 tag_;
Serializer mData; Blob data_;
public: public:
explicit SHAMapItem (uint256 const& tag);
SHAMapItem (uint256 const& tag, Blob const & data); SHAMapItem (uint256 const& tag, Blob const & data);
SHAMapItem (uint256 const& tag, Serializer const& s); SHAMapItem (uint256 const& tag, Serializer const& s);
SHAMapItem (uint256 const& key, Serializer&& s);
Slice slice() const; Slice slice() const;
uint256 const& uint256 const& key() const;
key() const
{
return mTag;
}
// DEPRECATED
uint256 const& getTag() const;
Blob const& peekData() const; Blob const& peekData() const;
Serializer const& peekSerializer() const;
public: // public only to SHAMapTreeNode
std::size_t size() const; std::size_t size() const;
private:
explicit SHAMapItem (Blob const& data);
void const* data() const; void const* data() const;
void dump (beast::Journal journal);
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
inline
SHAMapItem::SHAMapItem (uint256 const& tag)
: mTag (tag)
{
}
inline inline
Slice Slice
SHAMapItem::slice() const SHAMapItem::slice() const
{ {
return mData.slice(); return {data_.data(), data_.size()};
} }
inline inline
std::size_t std::size_t
SHAMapItem::size() const SHAMapItem::size() const
{ {
return mData.peekData().size(); return data_.size();
} }
inline inline
void const* void const*
SHAMapItem::data() const SHAMapItem::data() const
{ {
return mData.peekData().data(); return data_.data();
} }
inline inline
uint256 const& uint256 const&
SHAMapItem::getTag() const SHAMapItem::key() const
{ {
return mTag; return tag_;
} }
inline inline
Blob const& Blob const&
SHAMapItem::peekData() const SHAMapItem::peekData() const
{ {
return mData.peekData(); return data_;
}
inline
Serializer const&
SHAMapItem::peekSerializer() const
{
return mData;
} }
} // ripple } // ripple

View File

@@ -107,7 +107,7 @@ SHAMap::getStack (uint256 const& id, bool include_nonmatching_leaf) const
} }
if (include_nonmatching_leaf || if (include_nonmatching_leaf ||
(std::static_pointer_cast<SHAMapTreeNode>(node)->peekItem()->getTag() == id)) (std::static_pointer_cast<SHAMapTreeNode>(node)->peekItem()->key() == id))
stack.push ({node, nodeID}); stack.push ({node, nodeID});
return stack; return stack;
@@ -164,7 +164,7 @@ SHAMapTreeNode* SHAMap::walkToPointer (uint256 const& id) const
} }
auto ret = static_cast<SHAMapTreeNode*>(inNode); auto ret = static_cast<SHAMapTreeNode*>(inNode);
return ret->peekItem()->getTag() == id ? ret : nullptr; return ret->peekItem()->key() == id ? ret : nullptr;
} }
std::shared_ptr<SHAMapAbstractNode> std::shared_ptr<SHAMapAbstractNode>
@@ -577,7 +577,7 @@ SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNType& type) const
if (node->isLeaf ()) if (node->isLeaf ())
{ {
auto leaf = static_cast<SHAMapTreeNode*>(node); auto leaf = static_cast<SHAMapTreeNode*>(node);
if (leaf->peekItem ()->getTag () > id) if (leaf->peekItem ()->key() > id)
{ {
type = leaf->getType (); type = leaf->getType ();
return leaf->peekItem (); return leaf->peekItem ();
@@ -621,7 +621,7 @@ SHAMap::peekPrevItem (uint256 const& id) const
if (node->isLeaf ()) if (node->isLeaf ())
{ {
auto leaf = static_cast<SHAMapTreeNode*>(node); auto leaf = static_cast<SHAMapTreeNode*>(node);
if (leaf->peekItem ()->getTag () < id) if (leaf->peekItem ()->key() < id)
return leaf->peekItem (); return leaf->peekItem ();
} }
else else
@@ -699,7 +699,7 @@ bool SHAMap::delItem (uint256 const& id)
auto leaf = std::dynamic_pointer_cast<SHAMapTreeNode>(stack.top ().first); auto leaf = std::dynamic_pointer_cast<SHAMapTreeNode>(stack.top ().first);
stack.pop (); stack.pop ();
if (!leaf || (leaf->peekItem ()->getTag () != id)) if (!leaf || (leaf->peekItem ()->key() != id))
return false; return false;
SHAMapTreeNode::TNType type = leaf->getType (); SHAMapTreeNode::TNType type = leaf->getType ();
@@ -773,7 +773,7 @@ SHAMap::addGiveItem (std::shared_ptr<SHAMapItem const> const& item,
bool isTransaction, bool hasMeta) bool isTransaction, bool hasMeta)
{ {
// add the specified item, does not update // add the specified item, does not update
uint256 tag = item->getTag (); uint256 tag = item->key();
SHAMapTreeNode::TNType type = !isTransaction ? SHAMapTreeNode::tnACCOUNT_STATE : SHAMapTreeNode::TNType type = !isTransaction ? SHAMapTreeNode::tnACCOUNT_STATE :
(hasMeta ? SHAMapTreeNode::tnTRANSACTION_MD : SHAMapTreeNode::tnTRANSACTION_NM); (hasMeta ? SHAMapTreeNode::tnTRANSACTION_MD : SHAMapTreeNode::tnTRANSACTION_NM);
@@ -791,7 +791,7 @@ SHAMap::addGiveItem (std::shared_ptr<SHAMapItem const> const& item,
if (node->isLeaf()) if (node->isLeaf())
{ {
auto leaf = std::static_pointer_cast<SHAMapTreeNode>(node); auto leaf = std::static_pointer_cast<SHAMapTreeNode>(node);
if (leaf->peekItem()->getTag() == tag) if (leaf->peekItem()->key() == tag)
return false; return false;
} }
node = unshareNode(std::move(node), nodeID); node = unshareNode(std::move(node), nodeID);
@@ -809,14 +809,14 @@ SHAMap::addGiveItem (std::shared_ptr<SHAMapItem const> const& item,
// this is a leaf node that has to be made an inner node holding two items // this is a leaf node that has to be made an inner node holding two items
auto leaf = std::static_pointer_cast<SHAMapTreeNode>(node); auto leaf = std::static_pointer_cast<SHAMapTreeNode>(node);
std::shared_ptr<SHAMapItem const> otherItem = leaf->peekItem (); std::shared_ptr<SHAMapItem const> otherItem = leaf->peekItem ();
assert (otherItem && (tag != otherItem->getTag ())); assert (otherItem && (tag != otherItem->key()));
node = std::make_shared<SHAMapInnerNode>(node->getSeq()); node = std::make_shared<SHAMapInnerNode>(node->getSeq());
int b1, b2; int b1, b2;
while ((b1 = nodeID.selectBranch (tag)) == while ((b1 = nodeID.selectBranch (tag)) ==
(b2 = nodeID.selectBranch (otherItem->getTag ()))) (b2 = nodeID.selectBranch (otherItem->key())))
{ {
stack.push ({node, nodeID}); stack.push ({node, nodeID});
@@ -865,7 +865,7 @@ SHAMap::updateGiveItem (std::shared_ptr<SHAMapItem const> const& item,
bool isTransaction, bool hasMeta) bool isTransaction, bool hasMeta)
{ {
// can't change the tag but can change the hash // can't change the tag but can change the hash
uint256 tag = item->getTag (); uint256 tag = item->key();
assert (state_ != SHAMapState::Immutable); assert (state_ != SHAMapState::Immutable);
@@ -878,7 +878,7 @@ SHAMap::updateGiveItem (std::shared_ptr<SHAMapItem const> const& item,
auto nodeID = stack.top ().second; auto nodeID = stack.top ().second;
stack.pop (); stack.pop ();
if (!node || (node->peekItem ()->getTag () != tag)) if (!node || (node->peekItem ()->key() != tag))
{ {
assert (false); assert (false);
return false; return false;

View File

@@ -58,14 +58,14 @@ bool SHAMap::walkBranch (SHAMapAbstractNode* node,
// This is a leaf node, process its item // This is a leaf node, process its item
auto item = static_cast<SHAMapTreeNode*>(node)->peekItem(); auto item = static_cast<SHAMapTreeNode*>(node)->peekItem();
if (emptyBranch || (item->getTag () != otherMapItem->getTag ())) if (emptyBranch || (item->key() != otherMapItem->key()))
{ {
// unmatched // unmatched
if (isFirstMap) if (isFirstMap)
differences.insert (std::make_pair (item->getTag (), differences.insert (std::make_pair (item->key(),
DeltaRef (item, std::shared_ptr<SHAMapItem const> ()))); DeltaRef (item, std::shared_ptr<SHAMapItem const> ())));
else else
differences.insert (std::make_pair (item->getTag (), differences.insert (std::make_pair (item->key(),
DeltaRef (std::shared_ptr<SHAMapItem const> (), item))); DeltaRef (std::shared_ptr<SHAMapItem const> (), item)));
if (--maxCount <= 0) if (--maxCount <= 0)
@@ -75,10 +75,10 @@ bool SHAMap::walkBranch (SHAMapAbstractNode* node,
{ {
// non-matching items with same tag // non-matching items with same tag
if (isFirstMap) if (isFirstMap)
differences.insert (std::make_pair (item->getTag (), differences.insert (std::make_pair (item->key(),
DeltaRef (item, otherMapItem))); DeltaRef (item, otherMapItem)));
else else
differences.insert (std::make_pair (item->getTag (), differences.insert (std::make_pair (item->key(),
DeltaRef (otherMapItem, item))); DeltaRef (otherMapItem, item)));
if (--maxCount <= 0) if (--maxCount <= 0)
@@ -98,11 +98,11 @@ bool SHAMap::walkBranch (SHAMapAbstractNode* node,
{ {
// otherMapItem was unmatched, must add // otherMapItem was unmatched, must add
if (isFirstMap) // this is first map, so other item is from second if (isFirstMap) // this is first map, so other item is from second
differences.insert(std::make_pair(otherMapItem->getTag (), differences.insert(std::make_pair(otherMapItem->key(),
DeltaRef(std::shared_ptr<SHAMapItem const>(), DeltaRef(std::shared_ptr<SHAMapItem const>(),
otherMapItem))); otherMapItem)));
else else
differences.insert(std::make_pair(otherMapItem->getTag (), differences.insert(std::make_pair(otherMapItem->key(),
DeltaRef(otherMapItem, std::shared_ptr<SHAMapItem const>()))); DeltaRef(otherMapItem, std::shared_ptr<SHAMapItem const>())));
if (--maxCount <= 0) if (--maxCount <= 0)
@@ -147,11 +147,11 @@ SHAMap::compare (std::shared_ptr<SHAMap> const& otherMap,
// two leaves // two leaves
auto ours = static_cast<SHAMapTreeNode*>(ourNode); auto ours = static_cast<SHAMapTreeNode*>(ourNode);
auto other = static_cast<SHAMapTreeNode*>(otherNode); auto other = static_cast<SHAMapTreeNode*>(otherNode);
if (ours->peekItem()->getTag () == other->peekItem()->getTag ()) if (ours->peekItem()->key() == other->peekItem()->key())
{ {
if (ours->peekItem()->peekData () != other->peekItem()->peekData ()) if (ours->peekItem()->peekData () != other->peekItem()->peekData ())
{ {
differences.insert (std::make_pair (ours->peekItem()->getTag (), differences.insert (std::make_pair (ours->peekItem()->key(),
DeltaRef (ours->peekItem (), DeltaRef (ours->peekItem (),
other->peekItem ()))); other->peekItem ())));
if (--maxCount <= 0) if (--maxCount <= 0)
@@ -160,13 +160,13 @@ SHAMap::compare (std::shared_ptr<SHAMap> const& otherMap,
} }
else else
{ {
differences.insert (std::make_pair(ours->peekItem()->getTag (), differences.insert (std::make_pair(ours->peekItem()->key(),
DeltaRef(ours->peekItem(), DeltaRef(ours->peekItem(),
std::shared_ptr<SHAMapItem const>()))); std::shared_ptr<SHAMapItem const>())));
if (--maxCount <= 0) if (--maxCount <= 0)
return false; return false;
differences.insert(std::make_pair(other->peekItem()->getTag (), differences.insert(std::make_pair(other->peekItem()->key(),
DeltaRef(std::shared_ptr<SHAMapItem const>(), other->peekItem ()))); DeltaRef(std::shared_ptr<SHAMapItem const>(), other->peekItem ())));
if (--maxCount <= 0) if (--maxCount <= 0)
return false; return false;

View File

@@ -18,6 +18,7 @@
//============================================================================== //==============================================================================
#include <BeastConfig.h> #include <BeastConfig.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/shamap/SHAMapItem.h> #include <ripple/shamap/SHAMapItem.h>
namespace ripple { namespace ripple {
@@ -25,28 +26,15 @@ namespace ripple {
class SHAMap; class SHAMap;
SHAMapItem::SHAMapItem (uint256 const& tag, Blob const& data) SHAMapItem::SHAMapItem (uint256 const& tag, Blob const& data)
: mTag (tag) : tag_(tag)
, mData (data.data(), data.size()) , data_(data)
{ {
} }
SHAMapItem::SHAMapItem (uint256 const& tag, const Serializer& data) SHAMapItem::SHAMapItem (uint256 const& tag, const Serializer& data)
: mTag (tag) : tag_ (tag)
, mData (data.data(), data.size()) , data_(data.peekData())
{ {
} }
SHAMapItem::SHAMapItem (uint256 const& key, Serializer&& s)
: mTag(key)
, mData(std::move(s))
{
}
// VFALCO This function appears not to be called
void SHAMapItem::dump (beast::Journal journal)
{
if (journal.info) journal.info <<
"SHAMapItem(" << mTag << ") " << mData.size () << "bytes";
}
} // ripple } // ripple

View File

@@ -606,7 +606,7 @@ bool SHAMap::deepCompare (SHAMap& other) const
return false; return false;
auto& nodePeek = static_cast<SHAMapTreeNode*>(node)->peekItem(); auto& nodePeek = static_cast<SHAMapTreeNode*>(node)->peekItem();
auto& otherNodePeek = static_cast<SHAMapTreeNode*>(otherNode)->peekItem(); auto& otherNodePeek = static_cast<SHAMapTreeNode*>(otherNode)->peekItem();
if (nodePeek->getTag() != otherNodePeek->getTag()) if (nodePeek->key() != otherNodePeek->key())
return false; return false;
if (nodePeek->peekData() != otherNodePeek->peekData()) if (nodePeek->peekData() != otherNodePeek->peekData())
return false; return false;
@@ -742,7 +742,7 @@ SHAMap::visitDifferences(SHAMap* have,
if (root_->isLeaf ()) if (root_->isLeaf ())
{ {
auto leaf = std::static_pointer_cast<SHAMapTreeNode>(root_); auto leaf = std::static_pointer_cast<SHAMapTreeNode>(root_);
if (!have || !have->hasLeafNode(leaf->peekItem()->getTag(), leaf->getNodeHash())) if (!have || !have->hasLeafNode(leaf->peekItem()->key(), leaf->getNodeHash()))
func (*root_); func (*root_);
return; return;
@@ -779,7 +779,7 @@ SHAMap::visitDifferences(SHAMap* have,
stack.push ({static_cast<SHAMapInnerNode*>(next), childID}); stack.push ({static_cast<SHAMapInnerNode*>(next), childID});
} }
else if (!have || !have->hasLeafNode( else if (!have || !have->hasLeafNode(
static_cast<SHAMapTreeNode*>(next)->peekItem()->getTag(), static_cast<SHAMapTreeNode*>(next)->peekItem()->key(),
childHash)) childHash))
{ {
if (! func (*next)) if (! func (*next))

View File

@@ -328,13 +328,13 @@ SHAMapTreeNode::updateHash()
{ {
nh = sha512Half(HashPrefix::leafNode, nh = sha512Half(HashPrefix::leafNode,
make_Slice(mItem->peekData()), make_Slice(mItem->peekData()),
mItem->getTag()); mItem->key());
} }
else if (mType == tnTRANSACTION_MD) else if (mType == tnTRANSACTION_MD)
{ {
nh = sha512Half(HashPrefix::txNode, nh = sha512Half(HashPrefix::txNode,
make_Slice(mItem->peekData()), make_Slice(mItem->peekData()),
mItem->getTag()); mItem->key());
} }
else else
assert (false); assert (false);
@@ -414,12 +414,12 @@ SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) const
{ {
s.add32 (HashPrefix::leafNode); s.add32 (HashPrefix::leafNode);
s.addRaw (mItem->peekData ()); s.addRaw (mItem->peekData ());
s.add256 (mItem->getTag ()); s.add256 (mItem->key());
} }
else else
{ {
s.addRaw (mItem->peekData ()); s.addRaw (mItem->peekData ());
s.add256 (mItem->getTag ()); s.add256 (mItem->key());
s.add8 (1); s.add8 (1);
} }
} }
@@ -442,12 +442,12 @@ SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) const
{ {
s.add32 (HashPrefix::txNode); s.add32 (HashPrefix::txNode);
s.addRaw (mItem->peekData ()); s.addRaw (mItem->peekData ());
s.add256 (mItem->getTag ()); s.add256 (mItem->key());
} }
else else
{ {
s.addRaw (mItem->peekData ()); s.addRaw (mItem->peekData ());
s.add256 (mItem->getTag ()); s.add256 (mItem->key());
s.add8 (4); s.add8 (4);
} }
} }
@@ -534,7 +534,7 @@ SHAMapTreeNode::getString(const SHAMapNodeID & id) const
ret += ",leaf\n"; ret += ",leaf\n";
ret += " Tag="; ret += " Tag=";
ret += to_string (peekItem()->getTag ()); ret += to_string (peekItem()->key());
ret += "\n Hash="; ret += "\n Hash=";
ret += to_string (mHash); ret += to_string (mHash);
ret += "/"; ret += "/";

View File

@@ -29,10 +29,10 @@ namespace ripple {
namespace shamap { namespace shamap {
namespace tests { namespace tests {
inline bool operator== (SHAMapItem const& a, SHAMapItem const& b) { return a.getTag() == b.getTag(); } inline bool operator== (SHAMapItem const& a, SHAMapItem const& b) { return a.key() == b.key(); }
inline bool operator!= (SHAMapItem const& a, SHAMapItem const& b) { return a.getTag() != b.getTag(); } inline bool operator!= (SHAMapItem const& a, SHAMapItem const& b) { return a.key() != b.key(); }
inline bool operator== (SHAMapItem const& a, uint256 const& b) { return a.getTag() == b; } inline bool operator== (SHAMapItem const& a, uint256 const& b) { return a.key() == b; }
inline bool operator!= (SHAMapItem const& a, uint256 const& b) { return a.getTag() != b; } inline bool operator!= (SHAMapItem const& a, uint256 const& b) { return a.key() != b; }
class SHAMap_test : public beast::unit_test::suite class SHAMap_test : public beast::unit_test::suite
{ {
@@ -71,20 +71,20 @@ public:
std::shared_ptr<SHAMapItem const> i; std::shared_ptr<SHAMapItem const> i;
i = sMap.peekFirstItem (); i = sMap.peekFirstItem ();
unexpected (!i || (*i != i1), "bad traverse"); unexpected (!i || (*i != i1), "bad traverse");
i = sMap.peekNextItem (i->getTag ()); i = sMap.peekNextItem (i->key());
unexpected (!i || (*i != i2), "bad traverse"); unexpected (!i || (*i != i2), "bad traverse");
i = sMap.peekNextItem (i->getTag ()); i = sMap.peekNextItem (i->key());
unexpected (i, "bad traverse"); unexpected (i, "bad traverse");
sMap.addItem (i4, true, false); sMap.addItem (i4, true, false);
sMap.delItem (i2.getTag ()); sMap.delItem (i2.key());
sMap.addItem (i3, true, false); sMap.addItem (i3, true, false);
i = sMap.peekFirstItem (); i = sMap.peekFirstItem ();
unexpected (!i || (*i != i1), "bad traverse"); unexpected (!i || (*i != i1), "bad traverse");
i = sMap.peekNextItem (i->getTag ()); i = sMap.peekNextItem (i->key());
unexpected (!i || (*i != i3), "bad traverse"); unexpected (!i || (*i != i3), "bad traverse");
i = sMap.peekNextItem (i->getTag ()); i = sMap.peekNextItem (i->key());
unexpected (!i || (*i != i4), "bad traverse"); unexpected (!i || (*i != i4), "bad traverse");
i = sMap.peekNextItem (i->getTag ()); i = sMap.peekNextItem (i->key());
unexpected (i, "bad traverse"); unexpected (i, "bad traverse");
testcase ("snapshot"); testcase ("snapshot");
@@ -92,7 +92,7 @@ public:
std::shared_ptr<SHAMap> map2 = sMap.snapShot (false); std::shared_ptr<SHAMap> map2 = sMap.snapShot (false);
unexpected (sMap.getHash () != mapHash, "bad snapshot"); unexpected (sMap.getHash () != mapHash, "bad snapshot");
unexpected (map2->getHash () != mapHash, "bad snapshot"); unexpected (map2->getHash () != mapHash, "bad snapshot");
unexpected (!sMap.delItem (sMap.peekFirstItem ()->getTag ()), "bad mod"); unexpected (!sMap.delItem (sMap.peekFirstItem ()->key()), "bad mod");
unexpected (sMap.getHash () == mapHash, "bad snapshot"); unexpected (sMap.getHash () == mapHash, "bad snapshot");
unexpected (map2->getHash () != mapHash, "bad snapshot"); unexpected (map2->getHash () != mapHash, "bad snapshot");

View File

@@ -58,7 +58,7 @@ public:
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
std::shared_ptr<SHAMapItem> item = makeRandomAS (); std::shared_ptr<SHAMapItem> item = makeRandomAS ();
items.push_back (item->getTag ()); items.push_back (item->key());
if (!map.addItem (*item, false, false)) if (!map.addItem (*item, false, false))
{ {