Ledger synch work.

This commit is contained in:
JoelKatz
2012-02-13 19:29:11 -08:00
parent 9524df694a
commit ccb7ed38e7
6 changed files with 61 additions and 24 deletions

View File

@@ -544,3 +544,25 @@ Ledger::pointer Ledger::switchPreviousLedger(Ledger::pointer oldPrevious, Ledger
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();
}

View File

@@ -88,6 +88,12 @@ public:
SHAMap::pointer peekTransactionMap() { return mTransactionMap; }
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
// ledger sync functions
void setAcquiring(void);
bool isAcquiring(void);
bool isAcquiringTx(void);
bool isAcquiringAS(void);
// mid level functions
bool hasTransaction(const uint256& TransID) const;
AccountState::pointer getAccountState(const uint160& acctID);

View File

@@ -90,23 +90,19 @@ bool LedgerAcquire::takeBase(const std::vector<unsigned char>& data)
return false;
}
mLedger=Ledger::pointer(ledger);
mLedger->setAcquiring();
mHaveBase=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
return true;
}
bool LedgerAcquire::takeAsNode(const std::list<uint160>& 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)
bool LedgerAcquire::takeAsNode(const std::list<SHAMapNode>& hashes, const std::list<std::vector<unsigned char> >& data)
{
// WRITEME
return true;

View File

@@ -45,9 +45,8 @@ public:
void peerHas(Peer::pointer);
void badPeer(Peer::pointer);
bool takeBase(const std::vector<unsigned char>& data);
bool takeTxNode(const std::list<uint256>& hashes, const std::list<std::vector<unsigned char> >& data);
bool takeAsNode(const std::list<uint160>& hashes, const std::list<std::vector<unsigned char> >& data);
bool takeTx(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<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data);
};
class LedgerAcquireMaster

View File

@@ -204,7 +204,8 @@ public:
enum SHAMapException
{
MissingNode=1,
InvalidNode=2
InvalidNode=2,
InvalidMap=3,
};
class SHAMap
@@ -289,6 +290,7 @@ public:
// 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; }

View File

@@ -18,6 +18,7 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
#ifdef GMN_DEBUG
std::cerr << "getMissingNodes: root is full below" << std::endl;
#endif
clearSynching();
return;
}
@@ -123,7 +124,11 @@ bool SHAMap::addRootNode(const std::vector<unsigned char>& rootNode)
root=node;
mTNByID[*root]=root;
if(!root->getNodeHash()) root->setFullBelow();
if(!root->getNodeHash())
{
root->setFullBelow();
clearSynching();
}
return true;
}
@@ -149,7 +154,11 @@ bool SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned char>&
returnNode(root, true);
root=node;
mTNByID[*root]=root;
if(!root->getNodeHash()) root->setFullBelow();
if(!root->getNodeHash())
{
root->setFullBelow();
clearSynching();
}
return true;
}
@@ -223,6 +232,7 @@ bool SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigned cha
}
iNode->setFullBelow();
} while(!stack.empty());
if(root->isFullBelow()) clearSynching();
return true;
}
@@ -301,7 +311,7 @@ bool SHAMap::deepCompare(SHAMap& other)
static SHAMapItem::pointer makeRandomAS()
{
Serializer s;
for(int d=0; d<8; d++)
for(int d=0; d<3; d++)
s.add32(rand());
return boost::make_shared<SHAMapItem>(s.getRIPEMD160(), s.peekData());
}
@@ -314,8 +324,6 @@ static bool confuseMap(SHAMap &map, int count)
std::list<uint256> items;
map.dump(true);
for(int i=0; i<count; i++)
{
SHAMapItem::pointer item=makeRandomAS();
@@ -339,7 +347,6 @@ static bool confuseMap(SHAMap &map, int count)
if(beforeHash!=map.getHash())
{
std::cerr << "Hashes do not match" << std::endl;
map.dump(true);
return false;
}
@@ -348,23 +355,25 @@ static bool confuseMap(SHAMap &map, int count)
bool SHAMap::syncTest()
{
#if 0
unsigned int seed;
RAND_pseudo_bytes(reinterpret_cast<unsigned char *>(&seed), sizeof(seed));
srand(seed);
#endif
srand(2);
SHAMap source, destination;
// add random data to the source map
int items=8;
int items=1000000;
for(int i=0; i<items; i++)
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;
#endif
source.setImmutable();
@@ -408,6 +417,7 @@ bool SHAMap::syncTest()
#ifdef DEBUG
std::cerr << "ROOT COMPLETE, INNER SYNCHING" << std::endl;
#endif
int bytes=0;
do
{
@@ -448,6 +458,7 @@ bool SHAMap::syncTest()
nodeIDIterator!=gotNodeIDs.end(); ++nodeIDIterator, ++rawNodeIterator)
{
nodes++;
bytes+=rawNodeIterator->size();
if(!destination.addKnownNode(*nodeIDIterator, *rawNodeIterator))
{
std::cerr << "AddKnownNode fails" << std::endl;
@@ -463,7 +474,8 @@ bool SHAMap::syncTest()
destination.clearSynching();
#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
if(!source.deepCompare(destination))