mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 18:45:52 +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 "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->makeInner();
|
||||
@@ -36,7 +36,7 @@ std::stack<SHAMapTreeNode::pointer> SHAMap::getStack(const uint256& id, bool inc
|
||||
node=getNode(node->getChildNodeID(branch), hash, false);
|
||||
if(!node)
|
||||
{
|
||||
if(mSynching) return stack;
|
||||
if(isSynching()) return stack;
|
||||
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
|
||||
// update linking hashes and add nodes to dirty list
|
||||
|
||||
assert(!mImmutable && !mSynching);
|
||||
assert(mState!=Synching && mState!=Immutable);
|
||||
|
||||
while(!stack.empty())
|
||||
{
|
||||
|
||||
23
SHAMap.h
23
SHAMap.h
@@ -208,6 +208,15 @@ enum SHAMapException
|
||||
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
|
||||
{
|
||||
public:
|
||||
@@ -223,7 +232,7 @@ private:
|
||||
|
||||
SHAMapTreeNode::pointer root;
|
||||
|
||||
bool mImmutable, mSynching;
|
||||
SHAMapState mState;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -288,11 +297,13 @@ public:
|
||||
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode);
|
||||
|
||||
// status functions
|
||||
void setImmutable(void) { mImmutable=true; }
|
||||
void clearImmutable(void) { mImmutable=false; }
|
||||
bool isSynching(void) const { return mSynching; }
|
||||
void setSynching(void) { mSynching=true; }
|
||||
void clearSynching(void) { mSynching=false; }
|
||||
void setImmutable(void) { assert(mState!=Invalid); mState=Immutable; }
|
||||
void clearImmutable(void) { mState=Modifying; }
|
||||
bool isSynching(void) const { return mState==Floating || mState==Synching; }
|
||||
void setSynching(void) { mState=Synching; }
|
||||
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
|
||||
// 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)
|
||||
{ // return value: true=okay, false=error
|
||||
assert(!node.isRoot());
|
||||
assert(mSynching);
|
||||
if(!isSynching()) return false;
|
||||
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -363,17 +363,15 @@ bool SHAMap::syncTest()
|
||||
|
||||
|
||||
// add random data to the source map
|
||||
int items=1000000;
|
||||
int items=10000;
|
||||
for(int i=0; i<items; i++)
|
||||
source.addItem(*makeRandomAS(), false);
|
||||
|
||||
#ifdef DO_CONFUSE
|
||||
#ifdef DEBUG
|
||||
std::cerr << "Adding items, then removing them" << std::endl;
|
||||
#endif
|
||||
if(!confuseMap(source, 12000))
|
||||
if(!confuseMap(source, 500))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
source.setImmutable();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user