Change SHAMapSyncFilter to use SHAMapHash:

*  This also involves changing TaggedCache to use SHAMapHash
This commit is contained in:
Howard Hinnant
2015-12-01 13:10:25 -05:00
committed by Nik Bougalis
parent 0dbacedb58
commit 48ed44d117
14 changed files with 47 additions and 38 deletions

View File

@@ -35,7 +35,7 @@ AccountStateSF::AccountStateSF(Application& app)
void AccountStateSF::gotNode (bool fromFilter,
SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData,
SHAMapTreeNode::TNType)
{
@@ -43,14 +43,14 @@ void AccountStateSF::gotNode (bool fromFilter,
// SHAMap should provide an accessor to get the injected Database,
// and this should use that Database instad of getNodeStore
app_.getNodeStore ().store (
hotACCOUNT_NODE, std::move (nodeData), nodeHash);
hotACCOUNT_NODE, std::move (nodeData), nodeHash.as_uint256());
}
bool AccountStateSF::haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData)
{
return app_.getLedgerMaster ().getFetchPack (nodeHash, nodeData);
return app_.getLedgerMaster ().getFetchPack (nodeHash.as_uint256(), nodeData);
}
} // ripple

View File

@@ -40,12 +40,12 @@ public:
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData,
SHAMapTreeNode::TNType) override;
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData) override;
};

View File

@@ -39,7 +39,7 @@ ConsensusTransSetSF::ConsensusTransSetSF (Application& app, NodeCache& nodeCache
}
void ConsensusTransSetSF::gotNode (
bool fromFilter, const SHAMapNodeID& id, uint256 const& nodeHash,
bool fromFilter, const SHAMapNodeID& id, SHAMapHash const& nodeHash,
Blob& nodeData, SHAMapTreeNode::TNType type)
{
if (fromFilter)
@@ -59,7 +59,7 @@ void ConsensusTransSetSF::gotNode (
Serializer s (nodeData.data() + 4, nodeData.size() - 4);
SerialIter sit (s.slice());
auto stx = std::make_shared<STTx const> (std::ref (sit));
assert (stx->getTransactionID () == nodeHash);
assert (stx->getTransactionID () == nodeHash.as_uint256());
auto const pap = &app_;
app_.getJobQueue ().addJob (
jtTRANSACTION, "TXS->TXN",
@@ -76,12 +76,12 @@ void ConsensusTransSetSF::gotNode (
}
bool ConsensusTransSetSF::haveNode (
const SHAMapNodeID& id, uint256 const& nodeHash, Blob& nodeData)
const SHAMapNodeID& id, SHAMapHash const& nodeHash, Blob& nodeData)
{
if (m_nodeCache.retrieve (nodeHash, nodeData))
return true;
auto txn = app_.getMasterTransaction().fetch(nodeHash, false);
auto txn = app_.getMasterTransaction().fetch(nodeHash.as_uint256(), false);
if (txn)
{
@@ -91,7 +91,7 @@ bool ConsensusTransSetSF::haveNode (
Serializer s;
s.add32 (HashPrefix::transactionID);
txn->getSTransaction ()->add (s);
assert(sha512Half(s.slice()) == nodeHash);
assert(sha512Half(s.slice()) == nodeHash.as_uint256());
nodeData = s.peekData ();
return true;
}

View File

@@ -34,19 +34,19 @@ namespace ripple {
class ConsensusTransSetSF : public SHAMapSyncFilter
{
public:
using NodeCache = TaggedCache <uint256, Blob>;
using NodeCache = TaggedCache <SHAMapHash, Blob>;
ConsensusTransSetSF (Application& app, NodeCache& nodeCache);
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData,
SHAMapTreeNode::TNType) override;
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData) override;
private:

View File

@@ -36,7 +36,7 @@ TransactionStateSF::TransactionStateSF(Application& app)
// VFALCO This might be better as Blob&&
void TransactionStateSF::gotNode (bool fromFilter,
SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData,
SHAMapTreeNode::TNType type)
{
@@ -47,14 +47,14 @@ void TransactionStateSF::gotNode (bool fromFilter,
SHAMapTreeNode::tnTRANSACTION_NM);
app_.getNodeStore().store(
hotTRANSACTION_NODE,
std::move (nodeData), nodeHash);
std::move (nodeData), nodeHash.as_uint256());
}
bool TransactionStateSF::haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData)
{
return app_.getLedgerMaster ().getFetchPack (nodeHash, nodeData);
return app_.getLedgerMaster ().getFetchPack (nodeHash.as_uint256(), nodeData);
}
} // ripple

View File

@@ -41,13 +41,13 @@ public:
// Note that the nodeData is overwritten by this call
void gotNode (bool fromFilter,
SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData,
SHAMapTreeNode::TNType);
SHAMapTreeNode::TNType) override;
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
Blob& nodeData);
SHAMapHash const& nodeHash,
Blob& nodeData) override;
};
} // ripple

View File

@@ -69,7 +69,7 @@ class Cluster;
class DatabaseCon;
class SHAMapStore;
using NodeCache = TaggedCache <uint256, Blob>;
using NodeCache = TaggedCache <SHAMapHash, Blob>;
class Application : public beast::PropertyStream::Source
{

View File

@@ -190,7 +190,7 @@ private:
{
std::uint64_t check = 0;
for (uint256 const& key: cache.getKeys())
for (auto const& key: cache.getKeys())
{
database_->fetchNode (key);
if (! (++check % checkHealthInterval_) && health())

View File

@@ -37,12 +37,12 @@ public:
// Note that the nodeData is overwritten by this call
virtual void gotNode (bool fromFilter,
SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData,
SHAMapTreeNode::TNType type) = 0;
virtual bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash,
SHAMapHash const& nodeHash,
Blob& nodeData) = 0;
};

View File

@@ -73,6 +73,14 @@ public:
}
friend std::string to_string(SHAMapHash const& x) {return to_string(x.hash_);}
template <class H>
friend
void
hash_append(H& h, SHAMapHash const& x)
{
hash_append(h, x.hash_);
}
};
inline

View File

@@ -20,7 +20,8 @@
#ifndef RIPPLE_SHAMAP_TREENODECACHE_H_INCLUDED
#define RIPPLE_SHAMAP_TREENODECACHE_H_INCLUDED
#include <ripple/basics/TaggedCache.h>
#include <ripple/shamap/TreeNodeCache.h>
#include <ripple/shamap/SHAMapTreeNode.h>
namespace ripple {

View File

@@ -205,13 +205,13 @@ SHAMap::checkFilter(SHAMapHash const& hash, SHAMapNodeID const& id,
{
std::shared_ptr<SHAMapAbstractNode> node;
Blob nodeData;
if (filter->haveNode (id, hash.as_uint256(), nodeData))
if (filter->haveNode (id, hash, nodeData))
{
node = SHAMapAbstractNode::make(
nodeData, 0, snfPREFIX, hash, true, f_.journal ());
if (node)
{
filter->gotNode (true, id, hash.as_uint256(), nodeData, node->getType ());
filter->gotNode (true, id, hash, nodeData, node->getType ());
if (backed_)
canonicalize (hash, node);
}

View File

@@ -439,7 +439,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode,
{
Serializer s;
root_->addRaw (s, snfPREFIX);
filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash ().as_uint256(),
filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash (),
s.modData (), root_->getType ());
}
@@ -476,7 +476,7 @@ SHAMapAddNode SHAMap::addRootNode (SHAMapHash const& hash, Blob const& rootNode,
{
Serializer s;
root_->addRaw (s, snfPREFIX);
filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash ().as_uint256(),
filter->gotNode (false, SHAMapNodeID{}, root_->getNodeHash (),
s.modData (), root_->getType ());
}
@@ -563,7 +563,7 @@ SHAMap::addKnownNode (const SHAMapNodeID& node, Blob const& rawNode,
{
Serializer s;
newNode->addRaw (s, snfPREFIX);
filter->gotNode (false, node, childHash.as_uint256(),
filter->gotNode (false, node, childHash,
s.modData (), newNode->getType ());
}

View File

@@ -42,7 +42,7 @@ public:
tableItemsExtra = 20
};
using Map = hash_map <uint256, Blob>;
using Map = hash_map <SHAMapHash, Blob>;
using Table = SHAMap;
using Item = SHAMapItem;
@@ -61,13 +61,13 @@ public:
}
void gotNode (bool fromFilter,
SHAMapNodeID const& id, uint256 const& nodeHash,
Blob& nodeData, SHAMapTreeNode::TNType type)
SHAMapNodeID const& id, SHAMapHash const& nodeHash,
Blob& nodeData, SHAMapTreeNode::TNType type) override
{
}
bool haveNode (SHAMapNodeID const& id,
uint256 const& nodeHash, Blob& nodeData)
SHAMapHash const& nodeHash, Blob& nodeData) override
{
Map::iterator it = mMap.find (nodeHash);
if (it == mMap.end ())
@@ -106,9 +106,9 @@ public:
}
}
void on_fetch (Map& map, uint256 const& hash, Blob const& blob)
void on_fetch (Map& map, SHAMapHash const& hash, Blob const& blob)
{
expect (sha512Half(makeSlice(blob)) == hash,
expect (sha512Half(makeSlice(blob)) == hash.as_uint256(),
"Hash mismatch");
map.emplace (hash, blob);
}