mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 21:15:58 +00:00
Change the way we track the state of a SHAMap so it makes more sense.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include "BitcoinUtil.h"
|
#include "BitcoinUtil.h"
|
||||||
#include "SHAMap.h"
|
#include "SHAMap.h"
|
||||||
|
|
||||||
SHAMap::SHAMap(uint32 seq) : mSeq(seq), mImmutable(false), mSynching(false)
|
SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(Modifying)
|
||||||
{
|
{
|
||||||
root=boost::make_shared<SHAMapTreeNode>(SHAMapNode(0, uint256()), mSeq);
|
root=boost::make_shared<SHAMapTreeNode>(SHAMapNode(0, uint256()), mSeq);
|
||||||
root->makeInner();
|
root->makeInner();
|
||||||
@@ -36,7 +36,7 @@ std::stack<SHAMapTreeNode::pointer> SHAMap::getStack(const uint256& id, bool inc
|
|||||||
node=getNode(node->getChildNodeID(branch), hash, false);
|
node=getNode(node->getChildNodeID(branch), hash, false);
|
||||||
if(!node)
|
if(!node)
|
||||||
{
|
{
|
||||||
if(mSynching) return stack;
|
if(isSynching()) return stack;
|
||||||
throw SHAMapException(MissingNode);
|
throw SHAMapException(MissingNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ void SHAMap::dirtyUp(std::stack<SHAMapTreeNode::pointer>& stack, const uint256&
|
|||||||
{ // walk the tree up from through the inner nodes to the root
|
{ // walk the tree up from through the inner nodes to the root
|
||||||
// update linking hashes and add nodes to dirty list
|
// update linking hashes and add nodes to dirty list
|
||||||
|
|
||||||
assert(!mImmutable && !mSynching);
|
assert(mState!=Synching && mState!=Immutable);
|
||||||
|
|
||||||
while(!stack.empty())
|
while(!stack.empty())
|
||||||
{
|
{
|
||||||
|
|||||||
23
SHAMap.h
23
SHAMap.h
@@ -208,6 +208,15 @@ enum SHAMapException
|
|||||||
InvalidMap=3,
|
InvalidMap=3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum SHAMapState
|
||||||
|
{
|
||||||
|
Modifying=0, // Objects can be added and removed (like an open ledger)
|
||||||
|
Immutable=1, // Map cannot be changed (like a closed ledger)
|
||||||
|
Synching=2, // Map's hash is locked in, valid nodes can be added (like a peer's closing ledger)
|
||||||
|
Floating=3, // Map is free to change hash (like a synching open ledger)
|
||||||
|
Invalid=4, // Map is known not to be valid (usually synching a corrupt ledger)
|
||||||
|
};
|
||||||
|
|
||||||
class SHAMap
|
class SHAMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -223,7 +232,7 @@ private:
|
|||||||
|
|
||||||
SHAMapTreeNode::pointer root;
|
SHAMapTreeNode::pointer root;
|
||||||
|
|
||||||
bool mImmutable, mSynching;
|
SHAMapState mState;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -288,11 +297,13 @@ public:
|
|||||||
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode);
|
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode);
|
||||||
|
|
||||||
// status functions
|
// status functions
|
||||||
void setImmutable(void) { mImmutable=true; }
|
void setImmutable(void) { assert(mState!=Invalid); mState=Immutable; }
|
||||||
void clearImmutable(void) { mImmutable=false; }
|
void clearImmutable(void) { mState=Modifying; }
|
||||||
bool isSynching(void) const { return mSynching; }
|
bool isSynching(void) const { return mState==Floating || mState==Synching; }
|
||||||
void setSynching(void) { mSynching=true; }
|
void setSynching(void) { mState=Synching; }
|
||||||
void clearSynching(void) { mSynching=false; }
|
void setFloating(void) { mState=Floating; }
|
||||||
|
void clearSynching(void) { mState=Modifying; }
|
||||||
|
bool isValid(void) { return mState!=Invalid; }
|
||||||
|
|
||||||
// caution: otherMap must be accessed only by this function
|
// caution: otherMap must be accessed only by this function
|
||||||
// return value: true=successfully completed, false=too different
|
// return value: true=successfully completed, false=too different
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ bool SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned char>&
|
|||||||
bool SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigned char>& rawNode)
|
bool SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigned char>& rawNode)
|
||||||
{ // return value: true=okay, false=error
|
{ // return value: true=okay, false=error
|
||||||
assert(!node.isRoot());
|
assert(!node.isRoot());
|
||||||
assert(mSynching);
|
if(!isSynching()) return false;
|
||||||
|
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
|
|
||||||
@@ -363,17 +363,15 @@ bool SHAMap::syncTest()
|
|||||||
|
|
||||||
|
|
||||||
// add random data to the source map
|
// add random data to the source map
|
||||||
int items=1000000;
|
int items=10000;
|
||||||
for(int i=0; i<items; i++)
|
for(int i=0; i<items; i++)
|
||||||
source.addItem(*makeRandomAS(), false);
|
source.addItem(*makeRandomAS(), false);
|
||||||
|
|
||||||
#ifdef DO_CONFUSE
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cerr << "Adding items, then removing them" << std::endl;
|
std::cerr << "Adding items, then removing them" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if(!confuseMap(source, 12000))
|
if(!confuseMap(source, 500))
|
||||||
return false;
|
return false;
|
||||||
#endif
|
|
||||||
|
|
||||||
source.setImmutable();
|
source.setImmutable();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user