Add shamap::Family injection bundle

This commit is contained in:
Vinnie Falco
2015-02-06 14:54:44 -08:00
committed by Tom Ritchford
parent 617d84c0ef
commit 8bda9487c6
18 changed files with 333 additions and 211 deletions

View File

@@ -1537,11 +1537,6 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\misc\CanonicalTXSet.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\misc\DefaultMissingNodeHandler.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\misc\DefaultMissingNodeHandler.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\FeeVote.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\misc\FeeVoteImpl.cpp">
@@ -2888,6 +2883,8 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\server\Writer.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\shamap\Family.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\shamap\FullBelowCache.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\shamap\impl\SHAMap.cpp">
@@ -2925,6 +2922,8 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\shamap\SHAMapTreeNode.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\shamap\tests\common.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\shamap\tests\FetchPack.test.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>

View File

@@ -2376,12 +2376,6 @@
<ClInclude Include="..\..\src\ripple\app\misc\CanonicalTXSet.h">
<Filter>ripple\app\misc</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\misc\DefaultMissingNodeHandler.cpp">
<Filter>ripple\app\misc</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\misc\DefaultMissingNodeHandler.h">
<Filter>ripple\app\misc</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\FeeVote.h">
<Filter>ripple\app\misc</Filter>
</ClInclude>
@@ -3987,6 +3981,9 @@
<ClInclude Include="..\..\src\ripple\server\Writer.h">
<Filter>ripple\server</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\shamap\Family.h">
<Filter>ripple\shamap</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\shamap\FullBelowCache.h">
<Filter>ripple\shamap</Filter>
</ClInclude>
@@ -4032,6 +4029,9 @@
<ClInclude Include="..\..\src\ripple\shamap\SHAMapTreeNode.h">
<Filter>ripple\shamap</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\shamap\tests\common.h">
<Filter>ripple\shamap\tests</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\shamap\tests\FetchPack.test.cpp">
<Filter>ripple\shamap\tests</Filter>
</ClCompile>

View File

@@ -20,7 +20,6 @@
#include <BeastConfig.h>
#include <ripple/app/consensus/DisputedTx.h>
#include <ripple/app/consensus/LedgerConsensus.h>
#include <ripple/app/misc/DefaultMissingNodeHandler.h> // VFALCO bad dependency
#include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/ledger/LedgerTiming.h>
@@ -351,11 +350,9 @@ public:
{
if (hash.isZero ())
{
Application& app = getApp();
SHAMap::pointer empty = std::make_shared<SHAMap> (
smtTRANSACTION, app.getFullBelowCache(),
app.getTreeNodeCache(), getApp().getNodeStore(),
DefaultMissingNodeHandler(), deprecatedLogs().journal("SHAMap"));
smtTRANSACTION, getApp().family(),
deprecatedLogs().journal("SHAMap"));
mapCompleteInternal (hash, empty, false);
return empty;
}

View File

@@ -28,7 +28,6 @@
#include <ripple/app/data/DatabaseCon.h>
#include <ripple/app/data/SqliteDatabase.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/misc/DefaultMissingNodeHandler.h>
#include <ripple/app/misc/IHashRouter.h>
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/app/tx/TransactionMaster.h>
@@ -60,13 +59,9 @@ Ledger::Ledger (RippleAddress const& masterID, std::uint64_t startAmount)
, mAccepted (false)
, mImmutable (false)
, mTransactionMap (std::make_shared <SHAMap> (smtTRANSACTION,
getApp().getFullBelowCache(), getApp().getTreeNodeCache(),
getApp().getNodeStore(), DefaultMissingNodeHandler(),
deprecatedLogs().journal("SHAMap")))
getApp().family(), deprecatedLogs().journal("SHAMap")))
, mAccountStateMap (std::make_shared <SHAMap> (smtSTATE,
getApp().getFullBelowCache(), getApp().getTreeNodeCache(),
getApp().getNodeStore(), DefaultMissingNodeHandler(),
deprecatedLogs().journal("SHAMap")))
getApp().family(), deprecatedLogs().journal("SHAMap")))
{
// special case: put coins in root account
auto startAccount = std::make_shared<AccountState> (masterID);
@@ -109,13 +104,10 @@ Ledger::Ledger (uint256 const& parentHash,
, mAccepted (false)
, mImmutable (true)
, mTransactionMap (std::make_shared <SHAMap> (
smtTRANSACTION, transHash, getApp().getFullBelowCache(),
getApp().getTreeNodeCache(), getApp().getNodeStore(),
DefaultMissingNodeHandler(), deprecatedLogs().journal("SHAMap")))
, mAccountStateMap (std::make_shared <SHAMap> (smtSTATE, accountHash,
getApp().getFullBelowCache(), getApp().getTreeNodeCache(),
getApp().getNodeStore(), DefaultMissingNodeHandler(),
smtTRANSACTION, transHash, getApp().family(),
deprecatedLogs().journal("SHAMap")))
, mAccountStateMap (std::make_shared <SHAMap> (smtSTATE, accountHash,
getApp().family(), deprecatedLogs().journal("SHAMap")))
{
updateHash ();
loaded = true;
@@ -176,9 +168,7 @@ Ledger::Ledger (bool /* dummy */,
, mAccepted (false)
, mImmutable (false)
, mTransactionMap (std::make_shared <SHAMap> (smtTRANSACTION,
getApp().getFullBelowCache(), getApp().getTreeNodeCache(),
getApp().getNodeStore(), DefaultMissingNodeHandler(),
deprecatedLogs().journal("SHAMap")))
getApp().family(), deprecatedLogs().journal("SHAMap")))
, mAccountStateMap (prevLedger.mAccountStateMap->snapShot (true))
{
prevLedger.updateHash ();
@@ -246,13 +236,11 @@ Ledger::Ledger (std::uint32_t ledgerSeq, std::uint32_t closeTime)
mAccepted (false),
mImmutable (false),
mTransactionMap (std::make_shared <SHAMap> (
smtTRANSACTION, getApp().getFullBelowCache(),
getApp().getTreeNodeCache(), getApp().getNodeStore(),
DefaultMissingNodeHandler(), deprecatedLogs().journal("SHAMap"))),
smtTRANSACTION, getApp().family(),
deprecatedLogs().journal("SHAMap"))),
mAccountStateMap (std::make_shared <SHAMap> (
smtSTATE, getApp().getFullBelowCache(),
getApp().getTreeNodeCache(), getApp().getNodeStore(),
DefaultMissingNodeHandler(), deprecatedLogs().journal("SHAMap")))
smtSTATE, getApp().family(),
deprecatedLogs().journal("SHAMap")))
{
initializeFees ();
}
@@ -352,15 +340,10 @@ void Ledger::setRaw (Serializer& s, bool hasPrefix)
if (mValidHash)
{
Application& app = getApp();
mTransactionMap = std::make_shared<SHAMap> (smtTRANSACTION, mTransHash,
app.getFullBelowCache(), app.getTreeNodeCache(),
getApp().getNodeStore(), DefaultMissingNodeHandler(),
deprecatedLogs().journal("SHAMap"));
getApp().family(), deprecatedLogs().journal("SHAMap"));
mAccountStateMap = std::make_shared<SHAMap> (smtSTATE, mAccountHash,
app.getFullBelowCache(), app.getTreeNodeCache(),
getApp().getNodeStore(), DefaultMissingNodeHandler(),
deprecatedLogs().journal("SHAMap"));
getApp().family(), deprecatedLogs().journal("SHAMap"));
}
}

View File

@@ -59,6 +59,7 @@
#include <ripple/protocol/STParsedJSON.h>
#include <ripple/rpc/Manager.h>
#include <ripple/server/make_ServerHandler.h>
#include <ripple/shamap/Family.h>
#include <ripple/validators/make_Manager.h>
#include <ripple/unity/git_id.h>
#include <beast/asio/io_latency_probe.h>
@@ -100,6 +101,77 @@ Application* ApplicationImpBase::s_instance;
//------------------------------------------------------------------------------
namespace detail {
class AppFamily : public shamap::Family
{
private:
TreeNodeCache treecache_;
FullBelowCache fullbelow_;
NodeStore::Database& db_;
public:
AppFamily (AppFamily const&) = delete;
AppFamily& operator= (AppFamily const&) = delete;
AppFamily (NodeStore::Database& db,
CollectorManager& collectorManager)
: treecache_ ("TreeNodeCache", 65536, 60, get_seconds_clock(),
deprecatedLogs().journal("TaggedCache"))
, fullbelow_ ("full_below", get_seconds_clock(),
collectorManager.collector(),
fullBelowTargetSize, fullBelowExpirationSeconds)
, db_ (db)
{
}
FullBelowCache&
fullbelow() override
{
return fullbelow_;
}
FullBelowCache const&
fullbelow() const override
{
return fullbelow_;
}
TreeNodeCache&
treecache() override
{
return treecache_;
}
TreeNodeCache const&
treecache() const override
{
return treecache_;
}
NodeStore::Database&
db() override
{
return db_;
}
NodeStore::Database const&
db() const override
{
return db_;
}
void
missing_node (std::uint32_t refNum) override
{
getApp().getOPs().missingNodeInLedger (refNum);
}
};
} // detail
//------------------------------------------------------------------------------
// VFALCO TODO Move the function definitions into the class declaration
class ApplicationImp
: public ApplicationImpBase
@@ -185,11 +257,12 @@ public:
// These are not Stoppable-derived
NodeCache m_tempNodeCache;
std::unique_ptr <CollectorManager> m_collectorManager;
detail::AppFamily family_;
TreeNodeCache m_treeNodeCache;
SLECache m_sleCache;
LocalCredentials m_localCredentials;
std::unique_ptr <CollectorManager> m_collectorManager;
std::unique_ptr <Resource::Manager> m_resourceManager;
std::unique_ptr <FullBelowCache> m_fullBelowCache;
@@ -260,15 +333,17 @@ public:
, m_tempNodeCache ("NodeCache", 16384, 90, get_seconds_clock (),
m_logs.journal("TaggedCache"))
, m_collectorManager (CollectorManager::New (
getConfig().insightSettings, m_logs.journal("Collector")))
, family_ (*m_nodeStore, *m_collectorManager)
, m_treeNodeCache ("TreeNodeCache", 65536, 60, get_seconds_clock (),
deprecatedLogs().journal("TaggedCache"))
, m_sleCache ("LedgerEntryCache", 4096, 120, get_seconds_clock (),
m_logs.journal("TaggedCache"))
, m_collectorManager (CollectorManager::New (
getConfig().insightSettings, m_logs.journal("Collector")))
, m_resourceManager (Resource::make_Manager (
m_collectorManager->collector(), m_logs.journal("Resource")))
@@ -371,6 +446,12 @@ public:
return *m_collectorManager;
}
shamap::Family&
family()
{
return family_;
}
FullBelowCache& getFullBelowCache ()
{
return *m_fullBelowCache;

View File

@@ -39,6 +39,9 @@ namespace RPC { class Manager; }
// VFALCO TODO Fix forward declares required for header dependency loops
class AmendmentTable;
class CollectorManager;
namespace shamap {
class Family;
} // shamap
class IHashRouter;
class Logs;
class LoadFeeTrack;
@@ -94,6 +97,7 @@ public:
virtual boost::asio::io_service& getIOService () = 0;
virtual CollectorManager& getCollectorManager () = 0;
virtual shamap::Family& family() = 0;
virtual FullBelowCache& getFullBelowCache () = 0;
virtual JobQueue& getJobQueue () = 0;
virtual RPC::Manager& getRPCManager () = 0;

View File

@@ -1,33 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/app/misc/DefaultMissingNodeHandler.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/misc/NetworkOPs.h>
namespace ripple {
void
DefaultMissingNodeHandler::operator() (std::uint32_t refNUm)
{
getApp().getOPs ().missingNodeInLedger (refNUm);
}
} // ripple

View File

@@ -21,7 +21,6 @@
#include <ripple/app/ledger/ConsensusTransSetSF.h>
#include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/misc/DefaultMissingNodeHandler.h>
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/app/tx/TransactionAcquire.h>
#include <ripple/overlay/Overlay.h>
@@ -41,10 +40,8 @@ TransactionAcquire::TransactionAcquire (uint256 const& hash, clock_type& clock)
deprecatedLogs().journal("TransactionAcquire"))
, mHaveRoot (false)
{
Application& app = getApp();
mMap = std::make_shared<SHAMap> (smtTRANSACTION, hash,
app.getFullBelowCache (), app.getTreeNodeCache(), app.getNodeStore(),
DefaultMissingNodeHandler(), deprecatedLogs().journal("SHAMap"));
getApp().family(), deprecatedLogs().journal("SHAMap"));
mMap->setUnbacked ();
}

View File

@@ -143,7 +143,7 @@ public:
return false;
}
void waitReads ()
void waitReads() override
{
{
std::unique_lock <std::mutex> lock (m_readLock);

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Copyright (c) 2015 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -17,19 +17,52 @@
*/
//==============================================================================
#ifndef RIPPLE_APP_MISC_DEFAULTMISSINGNODEHANDLER_H_INCLUDED
#define RIPPLE_APP_MISC_DEFAULTMISSINGNODEHANDLER_H_INCLUDED
#ifndef RIPPLE_SHAMAP_FAMILY_H_INCLUDED
#define RIPPLE_SHAMAP_FAMILY_H_INCLUDED
#include <ripple/shamap/FullBelowCache.h>
#include <ripple/shamap/TreeNodeCache.h>
#include <ripple/nodestore/Database.h>
#include <cstdint>
namespace ripple {
namespace shamap {
/** Default handler which calls NetworkOPs. */
struct DefaultMissingNodeHandler
class Family
{
void operator()(std::uint32_t refNum);
public:
virtual ~Family() = default;
virtual
FullBelowCache&
fullbelow() = 0;
virtual
FullBelowCache const&
fullbelow() const = 0;
virtual
TreeNodeCache&
treecache() = 0;
virtual
TreeNodeCache const&
treecache() const = 0;
virtual
NodeStore::Database&
db() = 0;
virtual
NodeStore::Database const&
db() const = 0;
virtual
void
missing_node (std::uint32_t refNum) = 0;
};
}
} // shamap
} // ripple
#endif

View File

@@ -20,6 +20,7 @@
#ifndef RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
#define RIPPLE_SHAMAP_SHAMAP_H_INCLUDED
#include <ripple/shamap/Family.h>
#include <ripple/shamap/FullBelowCache.h>
#include <ripple/shamap/SHAMapAddNode.h>
#include <ripple/shamap/SHAMapItem.h>
@@ -100,6 +101,18 @@ using MissingNodeHandler = std::function <void (std::uint32_t refNum)>;
*/
class SHAMap
{
private:
using Family = shamap::Family;
Family& f_;
beast::Journal journal_;
std::uint32_t mSeq;
std::uint32_t mLedgerSeq; // sequence number of ledger this is part of
SHAMapTreeNode::pointer root;
SHAMapState mState;
SHAMapType mType;
bool mBacked = true; // Map is backed by the database
public:
enum
{
@@ -121,10 +134,7 @@ public:
// build new map
SHAMap (
SHAMapType t,
FullBelowCache& fullBelowCache,
TreeNodeCache& treeNodeCache,
NodeStore::Database& db,
MissingNodeHandler missing_node_handler,
Family& f,
beast::Journal journal,
std::uint32_t seq = 1
);
@@ -132,10 +142,7 @@ public:
SHAMap (
SHAMapType t,
uint256 const& hash,
FullBelowCache& fullBelowCache,
TreeNodeCache& treeNodeCache,
NodeStore::Database& db,
MissingNodeHandler missing_node_handler,
Family& f,
beast::Journal journal);
~SHAMap ();
@@ -321,19 +328,6 @@ private:
void visitLeavesInternal (std::function<void (SHAMapItem::ref item)>& function);
int walkSubTree (bool doWrite, NodeObjectType t, std::uint32_t seq);
private:
beast::Journal journal_;
NodeStore::Database& db_;
FullBelowCache& m_fullBelowCache;
std::uint32_t mSeq;
std::uint32_t mLedgerSeq; // sequence number of ledger this is part of
TreeNodeCache& mTreeNodeCache;
SHAMapTreeNode::pointer root;
SHAMapState mState;
SHAMapType mType;
bool mBacked = true; // Map is backed by the database
MissingNodeHandler m_missing_node_handler;
};
}

View File

@@ -26,21 +26,15 @@ namespace ripple {
SHAMap::SHAMap (
SHAMapType t,
FullBelowCache& fullBelowCache,
TreeNodeCache& treeNodeCache,
NodeStore::Database& db,
MissingNodeHandler missing_node_handler,
Family& f,
beast::Journal journal,
std::uint32_t seq)
: journal_(journal)
, db_(db)
, m_fullBelowCache (fullBelowCache)
: f_ (f)
, journal_(journal)
, mSeq (seq)
, mLedgerSeq (0)
, mTreeNodeCache (treeNodeCache)
, mState (smsModifying)
, mType (t)
, m_missing_node_handler (missing_node_handler)
{
assert (mSeq != 0);
@@ -51,20 +45,14 @@ SHAMap::SHAMap (
SHAMap::SHAMap (
SHAMapType t,
uint256 const& hash,
FullBelowCache& fullBelowCache,
TreeNodeCache& treeNodeCache,
NodeStore::Database& db,
MissingNodeHandler missing_node_handler,
Family& f,
beast::Journal journal)
: journal_(journal)
, db_(db)
, m_fullBelowCache (fullBelowCache)
: f_ (f)
, journal_(journal)
, mSeq (1)
, mLedgerSeq (0)
, mTreeNodeCache (treeNodeCache)
, mState (smsSynching)
, mType (t)
, m_missing_node_handler (missing_node_handler)
{
root = std::make_shared<SHAMapTreeNode> (mSeq);
root->makeInner ();
@@ -77,9 +65,8 @@ SHAMap::~SHAMap ()
SHAMap::pointer SHAMap::snapShot (bool isMutable)
{
SHAMap::pointer ret = std::make_shared<SHAMap> (mType,
m_fullBelowCache, mTreeNodeCache, db_, m_missing_node_handler,
journal_);
SHAMap::pointer ret = std::make_shared<SHAMap> (
mType, f_, journal_);
SHAMap& newMap = *ret;
if (!isMutable)
@@ -193,7 +180,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeFromDB (uint256 const& hash)
if (mBacked)
{
NodeObject::pointer obj = db_.fetch (hash);
NodeObject::pointer obj = f_.db().fetch (hash);
if (obj)
{
try
@@ -211,7 +198,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeFromDB (uint256 const& hash)
}
else if (mLedgerSeq != 0)
{
m_missing_node_handler (mLedgerSeq);
f_.missing_node(mLedgerSeq);
mLedgerSeq = 0;
}
}
@@ -394,7 +381,7 @@ SHAMapTreeNode* SHAMap::descendAsync (SHAMapTreeNode* parent, int branch,
if (!ptr && mBacked)
{
NodeObject::pointer obj;
if (! db_.asyncFetch (hash, obj))
if (! f_.db().asyncFetch (hash, obj))
{
pending = true;
return nullptr;
@@ -943,8 +930,8 @@ void SHAMap::writeNode (
Serializer s;
node->addRaw (s, snfPREFIX);
db_.store (t, std::move (s.modData()),
node->getNodeHash ());
f_.db().store (t,
std::move (s.modData ()), node->getNodeHash ());
}
// We can't modify an inner node someone else might have a
@@ -1157,7 +1144,7 @@ void SHAMap::dump (bool hash)
SHAMapTreeNode::pointer SHAMap::getCache (uint256 const& hash)
{
SHAMapTreeNode::pointer ret = mTreeNodeCache.fetch (hash);
SHAMapTreeNode::pointer ret = f_.treecache().fetch (hash);
assert (!ret || !ret->getSeq());
return ret;
}
@@ -1168,7 +1155,7 @@ void SHAMap::canonicalize (uint256 const& hash, SHAMapTreeNode::pointer& node)
assert (node->getSeq() == 0);
assert (node->getNodeHash() == hash);
mTreeNodeCache.canonicalize (hash, node);
f_.treecache().canonicalize (hash, node);
}

View File

@@ -118,7 +118,7 @@ void SHAMap::getMissingNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<ui
assert (root->isValid ());
assert (root->getNodeHash().isNonZero ());
std::uint32_t generation = m_fullBelowCache.getGeneration();
std::uint32_t generation = f_.fullbelow().getGeneration();
if (root->isFullBelow (generation))
{
clearSynching ();
@@ -132,7 +132,7 @@ void SHAMap::getMissingNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<ui
return;
}
int const maxDefer = db_.getDesiredAsyncReadCount ();
int const maxDefer = f_.db().getDesiredAsyncReadCount ();
// Track the missing hashes we have found so far
std::set <uint256> missingHashes;
@@ -169,7 +169,7 @@ void SHAMap::getMissingNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<ui
{
uint256 const& childHash = node->getChildHash (branch);
if (! mBacked || ! m_fullBelowCache.touch_if_exists (childHash))
if (! mBacked || ! f_.fullbelow().touch_if_exists (childHash))
{
SHAMapNodeID childID = nodeID.getChildNodeID (branch);
bool pending = false;
@@ -218,7 +218,7 @@ void SHAMap::getMissingNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<ui
{ // No partial node encountered below this node
node->setFullBelowGen (generation);
if (mBacked)
m_fullBelowCache.insert (node->getNodeHash ());
f_.fullbelow().insert (node->getNodeHash ());
}
if (stack.empty ())
@@ -238,7 +238,7 @@ void SHAMap::getMissingNodes (std::vector<SHAMapNodeID>& nodeIDs, std::vector<ui
if (deferredReads.empty ())
break;
db_.waitReads();
f_.db().waitReads();
// Process all deferred reads
for (auto const& node : deferredReads)
@@ -463,7 +463,7 @@ SHAMap::addKnownNode (const SHAMapNodeID& node, Blob const& rawNode,
return SHAMapAddNode::duplicate ();
}
std::uint32_t generation = m_fullBelowCache.getGeneration();
std::uint32_t generation = f_.fullbelow().getGeneration();
SHAMapNodeID iNodeID;
SHAMapTreeNode* iNode = root.get ();
@@ -481,7 +481,7 @@ SHAMap::addKnownNode (const SHAMapNodeID& node, Blob const& rawNode,
}
uint256 childHash = iNode->getChildHash (branch);
if (m_fullBelowCache.touch_if_exists (childHash))
if (f_.fullbelow().touch_if_exists (childHash))
return SHAMapAddNode::duplicate ();
SHAMapTreeNode* prevNode = iNode;

View File

@@ -19,18 +19,18 @@
#include <BeastConfig.h>
#include <ripple/shamap/SHAMap.h>
#include <ripple/shamap/tests/common.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/basics/UnorderedContainers.h>
#include <ripple/nodestore/DummyScheduler.h>
#include <ripple/nodestore/Manager.h>
#include <ripple/protocol/UInt160.h>
#include <beast/chrono/manual_clock.h>
#include <beast/module/core/maths/Random.h>
#include <beast/unit_test/suite.h>
#include <functional>
#include <stdexcept>
namespace ripple {
namespace shamap {
namespace tests {
class FetchPack_test : public beast::unit_test::suite
{
@@ -114,17 +114,10 @@ public:
void run ()
{
beast::manual_clock <std::chrono::steady_clock> clock; // manual advance clock
beast::Journal const j; // debug journal
FullBelowCache fullBelowCache ("test.full_below", clock);
TreeNodeCache treeNodeCache ("test.tree_node_cache", 65536, 60, clock, j);
NodeStore::DummyScheduler scheduler;
auto db = NodeStore::Manager::instance().make_Database (
"test", scheduler, j, 0, parseDelimitedKeyValueString("type=memory|path=FetchPack"));
TestFamily f(j);
std::shared_ptr <Table> t1 (std::make_shared <Table> (
smtFREE, fullBelowCache, treeNodeCache, *db, Handler(), beast::Journal()));
smtFREE, f, beast::Journal()));
pass ();
@@ -167,6 +160,9 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(FetchPack,ripple_app,ripple);
BEAST_DEFINE_TESTSUITE(FetchPack,shamap,ripple);
} // tests
} // shamap
} // ripple
}

View File

@@ -18,17 +18,16 @@
//==============================================================================
#include <BeastConfig.h>
#include <ripple/shamap/FullBelowCache.h>
#include <ripple/shamap/SHAMap.h>
#include <ripple/shamap/tests/common.h>
#include <ripple/basics/Blob.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/nodestore/DummyScheduler.h>
#include <ripple/nodestore/Manager.h>
#include <beast/unit_test/suite.h>
#include <beast/utility/Journal.h>
#include <beast/chrono/manual_clock.h>
namespace ripple {
namespace shamap {
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.getTag() != b.getTag(); }
@@ -38,14 +37,6 @@ inline bool operator!= (SHAMapItem const& a, uint256 const& b) { return a.getTag
class SHAMap_test : public beast::unit_test::suite
{
public:
struct Handler
{
void operator()(std::uint32_t refNum) const
{
throw std::runtime_error("missing node");
}
};
static Blob IntToVUC (int v)
{
Blob vuc;
@@ -60,14 +51,9 @@ public:
{
testcase ("add/traverse");
beast::manual_clock <std::chrono::steady_clock> clock; // manual advance clock
beast::Journal const j; // debug journal
FullBelowCache fullBelowCache ("test.full_below", clock);
TreeNodeCache treeNodeCache ("test.tree_node_cache", 65536, 60, clock, j);
NodeStore::DummyScheduler scheduler;
auto db = NodeStore::Manager::instance().make_Database (
"test", scheduler, j, 0, parseDelimitedKeyValueString("type=memory|Path=SHAMap_test"));
tests::TestFamily f(j);
// h3 and h4 differ only in the leaf, same terminal node (level 19)
uint256 h1, h2, h3, h4, h5;
@@ -77,8 +63,7 @@ public:
h4.SetHex ("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8");
h5.SetHex ("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
SHAMap sMap (smtFREE, fullBelowCache, treeNodeCache,
*db, Handler(), beast::Journal());
SHAMap sMap (smtFREE, f, beast::Journal());
SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5));
unexpected (!sMap.addItem (i2, true, false), "no add");
unexpected (!sMap.addItem (i1, true, false), "no add");
@@ -115,4 +100,6 @@ public:
BEAST_DEFINE_TESTSUITE(SHAMap,ripple_app,ripple);
} // tests
} // shamap
} // ripple

View File

@@ -20,32 +20,23 @@
#include <BeastConfig.h>
#include <ripple/shamap/SHAMap.h>
#include <ripple/shamap/SHAMapItem.h>
#include <ripple/shamap/tests/common.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/nodestore/Database.h>
#include <ripple/nodestore/DummyScheduler.h>
#include <ripple/nodestore/Manager.h>
#include <ripple/protocol/UInt160.h>
#include <beast/chrono/manual_clock.h>
#include <beast/unit_test/suite.h>
#include <openssl/rand.h> // DEPRECATED
namespace ripple {
namespace shamap {
namespace tests {
#ifdef BEAST_DEBUG
//#define SMS_DEBUG
#endif
class SHAMapSync_test : public beast::unit_test::suite
class sync_test : public beast::unit_test::suite
{
public:
struct Handler
{
void operator()(std::uint32_t refNum) const
{
throw std::runtime_error("missing node");
}
};
static SHAMapItem::pointer makeRandomAS ()
{
Serializer s;
@@ -107,19 +98,11 @@ public:
RAND_pseudo_bytes (reinterpret_cast<unsigned char*> (&seed), sizeof (seed));
srand (seed);
beast::manual_clock <std::chrono::steady_clock> clock; // manual advance clock
beast::Journal const j; // debug journal
FullBelowCache fullBelowCache ("test.full_below", clock);
TreeNodeCache treeNodeCache ("test.tree_node_cache", 65536, 60, clock, j);
NodeStore::DummyScheduler scheduler;
auto db = NodeStore::Manager::instance().make_Database (
"test", scheduler, j, 1, parseDelimitedKeyValueString("type=memory|path=SHAMapSync_test"));
SHAMap source (smtFREE, fullBelowCache, treeNodeCache,
*db, Handler(), beast::Journal());
SHAMap destination (smtFREE, fullBelowCache, treeNodeCache,
*db, Handler(), beast::Journal());
TestFamily f(j);
SHAMap source (smtFREE, f, j);
SHAMap destination (smtFREE, f, j);
int items = 10000;
for (int i = 0; i < items; ++i)
@@ -157,7 +140,7 @@ public:
do
{
++clock;
f.clock().advance(std::chrono::seconds(1));
++passes;
hashes.clear ();
@@ -238,6 +221,8 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(SHAMapSync,ripple_app,ripple);
BEAST_DEFINE_TESTSUITE(sync,shamap,ripple);
} // tests
} // shamap
} // ripple

View File

@@ -0,0 +1,113 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_SHAMAP_TESTS_COMMON_H_INCLUDED
#define RIPPLE_SHAMAP_TESTS_COMMON_H_INCLUDED
#include <BeastConfig.h>
#include <ripple/shamap/Family.h>
#include <ripple/shamap/FullBelowCache.h>
#include <ripple/shamap/TreeNodeCache.h>
#include <ripple/shamap/SHAMap.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/nodestore/DummyScheduler.h>
#include <ripple/nodestore/Manager.h>
#include <beast/utility/Journal.h>
#include <beast/chrono/manual_clock.h>
namespace ripple {
namespace shamap {
namespace tests {
class TestFamily : public shamap::Family
{
private:
beast::manual_clock <
std::chrono::steady_clock> clock_;
NodeStore::DummyScheduler scheduler_;
TreeNodeCache treecache_;
FullBelowCache fullbelow_;
std::unique_ptr<NodeStore::Database> db_;
public:
explicit
TestFamily (beast::Journal j)
: treecache_ ("TreeNodeCache", 65536, 60, clock_, j)
, fullbelow_ ("full_below", clock_)
, db_(NodeStore::Manager::instance().make_Database(
"test", scheduler_, j, 1,
parseDelimitedKeyValueString(
"type=memory|Path=SHAMap_test")))
{
}
beast::manual_clock <std::chrono::steady_clock>
clock()
{
return clock_;
}
FullBelowCache&
fullbelow() override
{
return fullbelow_;
}
FullBelowCache const&
fullbelow() const override
{
return fullbelow_;
}
TreeNodeCache&
treecache() override
{
return treecache_;
}
TreeNodeCache const&
treecache() const override
{
return treecache_;
}
NodeStore::Database&
db() override
{
return *db_;
}
NodeStore::Database const&
db() const override
{
return *db_;
}
void
missing_node (std::uint32_t refNum) override
{
throw std::runtime_error("missing node");
}
};
} // tests
} // shamap
} // ripple
#endif

View File

@@ -23,5 +23,4 @@
#include <ripple/app/ledger/LedgerHistory.cpp>
#include <ripple/app/tx/TransactionAcquire.cpp>
#include <ripple/app/tx/LocalTxs.cpp>
#include <ripple/app/misc/DefaultMissingNodeHandler.cpp>
#include <ripple/app/misc/NetworkOPs.cpp>