mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Ledger synch work.
This commit is contained in:
22
Ledger.cpp
22
Ledger.cpp
@@ -544,3 +544,25 @@ Ledger::pointer Ledger::switchPreviousLedger(Ledger::pointer oldPrevious, Ledger
|
|||||||
|
|
||||||
return Ledger::pointer(newLedger);
|
return Ledger::pointer(newLedger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ledger::setAcquiring(void)
|
||||||
|
{
|
||||||
|
if(!mTransactionMap || !mAccountStateMap) throw SHAMapException(InvalidMap);
|
||||||
|
mTransactionMap->setSynching();
|
||||||
|
mAccountStateMap->setSynching();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ledger::isAcquiring(void)
|
||||||
|
{
|
||||||
|
return isAcquiringTx() || isAcquiringAS();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ledger::isAcquiringTx(void)
|
||||||
|
{
|
||||||
|
return mTransactionMap->isSynching();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Ledger::isAcquiringAS(void)
|
||||||
|
{
|
||||||
|
return mAccountStateMap->isSynching();
|
||||||
|
}
|
||||||
|
|||||||
6
Ledger.h
6
Ledger.h
@@ -88,6 +88,12 @@ public:
|
|||||||
SHAMap::pointer peekTransactionMap() { return mTransactionMap; }
|
SHAMap::pointer peekTransactionMap() { return mTransactionMap; }
|
||||||
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
|
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
|
||||||
|
|
||||||
|
// ledger sync functions
|
||||||
|
void setAcquiring(void);
|
||||||
|
bool isAcquiring(void);
|
||||||
|
bool isAcquiringTx(void);
|
||||||
|
bool isAcquiringAS(void);
|
||||||
|
|
||||||
// mid level functions
|
// mid level functions
|
||||||
bool hasTransaction(const uint256& TransID) const;
|
bool hasTransaction(const uint256& TransID) const;
|
||||||
AccountState::pointer getAccountState(const uint160& acctID);
|
AccountState::pointer getAccountState(const uint160& acctID);
|
||||||
|
|||||||
@@ -90,23 +90,19 @@ bool LedgerAcquire::takeBase(const std::vector<unsigned char>& data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mLedger=Ledger::pointer(ledger);
|
mLedger=Ledger::pointer(ledger);
|
||||||
|
mLedger->setAcquiring();
|
||||||
mHaveBase=true;
|
mHaveBase=true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LedgerAcquire::takeTxNode(const std::list<uint256>& hashes, const std::list<std::vector<unsigned char> >& data)
|
bool LedgerAcquire::takeTxNode(const std::list<SHAMapNode>& nodeIDs, const std::list<std::vector<unsigned char> >& data)
|
||||||
{
|
{
|
||||||
|
if(!mHaveBase) return false;
|
||||||
// WRITEME
|
// WRITEME
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LedgerAcquire::takeAsNode(const std::list<uint160>& hashes, const std::list<std::vector<unsigned char> >& data)
|
bool LedgerAcquire::takeAsNode(const std::list<SHAMapNode>& hashes, const std::list<std::vector<unsigned char> >& data)
|
||||||
{
|
|
||||||
// WRITEME
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LedgerAcquire::takeTx(const std::list<uint256>& hashes, const std::list<std::vector<unsigned char> >& data)
|
|
||||||
{
|
{
|
||||||
// WRITEME
|
// WRITEME
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -45,9 +45,8 @@ public:
|
|||||||
void peerHas(Peer::pointer);
|
void peerHas(Peer::pointer);
|
||||||
void badPeer(Peer::pointer);
|
void badPeer(Peer::pointer);
|
||||||
bool takeBase(const std::vector<unsigned char>& data);
|
bool takeBase(const std::vector<unsigned char>& data);
|
||||||
bool takeTxNode(const std::list<uint256>& hashes, const std::list<std::vector<unsigned char> >& data);
|
bool takeTxNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data);
|
||||||
bool takeAsNode(const std::list<uint160>& hashes, const std::list<std::vector<unsigned char> >& data);
|
bool takeAsNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data);
|
||||||
bool takeTx(const std::list<uint256>& hashes, const std::list<std::vector<unsigned char> >& data);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LedgerAcquireMaster
|
class LedgerAcquireMaster
|
||||||
|
|||||||
4
SHAMap.h
4
SHAMap.h
@@ -204,7 +204,8 @@ public:
|
|||||||
enum SHAMapException
|
enum SHAMapException
|
||||||
{
|
{
|
||||||
MissingNode=1,
|
MissingNode=1,
|
||||||
InvalidNode=2
|
InvalidNode=2,
|
||||||
|
InvalidMap=3,
|
||||||
};
|
};
|
||||||
|
|
||||||
class SHAMap
|
class SHAMap
|
||||||
@@ -289,6 +290,7 @@ public:
|
|||||||
// status functions
|
// status functions
|
||||||
void setImmutable(void) { mImmutable=true; }
|
void setImmutable(void) { mImmutable=true; }
|
||||||
void clearImmutable(void) { mImmutable=false; }
|
void clearImmutable(void) { mImmutable=false; }
|
||||||
|
bool isSynching(void) const { return mSynching; }
|
||||||
void setSynching(void) { mSynching=true; }
|
void setSynching(void) { mSynching=true; }
|
||||||
void clearSynching(void) { mSynching=false; }
|
void clearSynching(void) { mSynching=false; }
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
|
|||||||
#ifdef GMN_DEBUG
|
#ifdef GMN_DEBUG
|
||||||
std::cerr << "getMissingNodes: root is full below" << std::endl;
|
std::cerr << "getMissingNodes: root is full below" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
clearSynching();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +124,11 @@ bool SHAMap::addRootNode(const std::vector<unsigned char>& rootNode)
|
|||||||
|
|
||||||
root=node;
|
root=node;
|
||||||
mTNByID[*root]=root;
|
mTNByID[*root]=root;
|
||||||
if(!root->getNodeHash()) root->setFullBelow();
|
if(!root->getNodeHash())
|
||||||
|
{
|
||||||
|
root->setFullBelow();
|
||||||
|
clearSynching();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -149,7 +154,11 @@ bool SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned char>&
|
|||||||
returnNode(root, true);
|
returnNode(root, true);
|
||||||
root=node;
|
root=node;
|
||||||
mTNByID[*root]=root;
|
mTNByID[*root]=root;
|
||||||
if(!root->getNodeHash()) root->setFullBelow();
|
if(!root->getNodeHash())
|
||||||
|
{
|
||||||
|
root->setFullBelow();
|
||||||
|
clearSynching();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -223,6 +232,7 @@ bool SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigned cha
|
|||||||
}
|
}
|
||||||
iNode->setFullBelow();
|
iNode->setFullBelow();
|
||||||
} while(!stack.empty());
|
} while(!stack.empty());
|
||||||
|
if(root->isFullBelow()) clearSynching();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +311,7 @@ bool SHAMap::deepCompare(SHAMap& other)
|
|||||||
static SHAMapItem::pointer makeRandomAS()
|
static SHAMapItem::pointer makeRandomAS()
|
||||||
{
|
{
|
||||||
Serializer s;
|
Serializer s;
|
||||||
for(int d=0; d<8; d++)
|
for(int d=0; d<3; d++)
|
||||||
s.add32(rand());
|
s.add32(rand());
|
||||||
return boost::make_shared<SHAMapItem>(s.getRIPEMD160(), s.peekData());
|
return boost::make_shared<SHAMapItem>(s.getRIPEMD160(), s.peekData());
|
||||||
}
|
}
|
||||||
@@ -314,8 +324,6 @@ static bool confuseMap(SHAMap &map, int count)
|
|||||||
|
|
||||||
std::list<uint256> items;
|
std::list<uint256> items;
|
||||||
|
|
||||||
map.dump(true);
|
|
||||||
|
|
||||||
for(int i=0; i<count; i++)
|
for(int i=0; i<count; i++)
|
||||||
{
|
{
|
||||||
SHAMapItem::pointer item=makeRandomAS();
|
SHAMapItem::pointer item=makeRandomAS();
|
||||||
@@ -339,7 +347,6 @@ static bool confuseMap(SHAMap &map, int count)
|
|||||||
if(beforeHash!=map.getHash())
|
if(beforeHash!=map.getHash())
|
||||||
{
|
{
|
||||||
std::cerr << "Hashes do not match" << std::endl;
|
std::cerr << "Hashes do not match" << std::endl;
|
||||||
map.dump(true);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,23 +355,25 @@ static bool confuseMap(SHAMap &map, int count)
|
|||||||
|
|
||||||
bool SHAMap::syncTest()
|
bool SHAMap::syncTest()
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
unsigned int seed;
|
unsigned int seed;
|
||||||
RAND_pseudo_bytes(reinterpret_cast<unsigned char *>(&seed), sizeof(seed));
|
RAND_pseudo_bytes(reinterpret_cast<unsigned char *>(&seed), sizeof(seed));
|
||||||
srand(seed);
|
srand(seed);
|
||||||
#endif
|
|
||||||
srand(2);
|
|
||||||
|
|
||||||
SHAMap source, destination;
|
SHAMap source, destination;
|
||||||
|
|
||||||
|
|
||||||
// add random data to the source map
|
// add random data to the source map
|
||||||
int items=8;
|
int items=1000000;
|
||||||
for(int i=0; i<items; i++)
|
for(int i=0; i<items; i++)
|
||||||
source.addItem(*makeRandomAS(), false);
|
source.addItem(*makeRandomAS(), false);
|
||||||
|
|
||||||
if(!confuseMap(source, 3))
|
#ifdef DO_CONFUSE
|
||||||
|
#ifdef DEBUG
|
||||||
|
std::cerr << "Adding items, then removing them" << std::endl;
|
||||||
|
#endif
|
||||||
|
if(!confuseMap(source, 12000))
|
||||||
return false;
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
source.setImmutable();
|
source.setImmutable();
|
||||||
|
|
||||||
@@ -408,6 +417,7 @@ bool SHAMap::syncTest()
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cerr << "ROOT COMPLETE, INNER SYNCHING" << std::endl;
|
std::cerr << "ROOT COMPLETE, INNER SYNCHING" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
int bytes=0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -448,6 +458,7 @@ bool SHAMap::syncTest()
|
|||||||
nodeIDIterator!=gotNodeIDs.end(); ++nodeIDIterator, ++rawNodeIterator)
|
nodeIDIterator!=gotNodeIDs.end(); ++nodeIDIterator, ++rawNodeIterator)
|
||||||
{
|
{
|
||||||
nodes++;
|
nodes++;
|
||||||
|
bytes+=rawNodeIterator->size();
|
||||||
if(!destination.addKnownNode(*nodeIDIterator, *rawNodeIterator))
|
if(!destination.addKnownNode(*nodeIDIterator, *rawNodeIterator))
|
||||||
{
|
{
|
||||||
std::cerr << "AddKnownNode fails" << std::endl;
|
std::cerr << "AddKnownNode fails" << std::endl;
|
||||||
@@ -463,7 +474,8 @@ bool SHAMap::syncTest()
|
|||||||
destination.clearSynching();
|
destination.clearSynching();
|
||||||
|
|
||||||
#ifdef SMS_DEBUG
|
#ifdef SMS_DEBUG
|
||||||
std::cerr << "SYNCHING COMPLETE " << items << " items, " << nodes << " nodes" << std::endl;
|
std::cerr << "SYNCHING COMPLETE " << items << " items, " << nodes << " nodes, " <<
|
||||||
|
bytes/1024 << " KB" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!source.deepCompare(destination))
|
if(!source.deepCompare(destination))
|
||||||
|
|||||||
Reference in New Issue
Block a user