diff --git a/Ledger.cpp b/Ledger.cpp index 4293100fb7..588ec2e176 100644 --- a/Ledger.cpp +++ b/Ledger.cpp @@ -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(); +} diff --git a/Ledger.h b/Ledger.h index 0994b6af4e..dbab0d009d 100644 --- a/Ledger.h +++ b/Ledger.h @@ -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); diff --git a/LedgerAcquire.cpp b/LedgerAcquire.cpp index 57d16f85bb..945c0ed6cf 100644 --- a/LedgerAcquire.cpp +++ b/LedgerAcquire.cpp @@ -90,23 +90,19 @@ bool LedgerAcquire::takeBase(const std::vector& data) return false; } mLedger=Ledger::pointer(ledger); + mLedger->setAcquiring(); mHaveBase=true; return true; } -bool LedgerAcquire::takeTxNode(const std::list& hashes, const std::list >& data) +bool LedgerAcquire::takeTxNode(const std::list& nodeIDs, const std::list >& data) { + if(!mHaveBase) return false; // WRITEME return true; } -bool LedgerAcquire::takeAsNode(const std::list& hashes, const std::list >& data) -{ - // WRITEME - return true; -} - -bool LedgerAcquire::takeTx(const std::list& hashes, const std::list >& data) +bool LedgerAcquire::takeAsNode(const std::list& hashes, const std::list >& data) { // WRITEME return true; diff --git a/LedgerAcquire.h b/LedgerAcquire.h index f40a301f74..1d85bfaeda 100644 --- a/LedgerAcquire.h +++ b/LedgerAcquire.h @@ -45,9 +45,8 @@ public: void peerHas(Peer::pointer); void badPeer(Peer::pointer); bool takeBase(const std::vector& data); - bool takeTxNode(const std::list& hashes, const std::list >& data); - bool takeAsNode(const std::list& hashes, const std::list >& data); - bool takeTx(const std::list& hashes, const std::list >& data); + bool takeTxNode(const std::list& IDs, const std::list >& data); + bool takeAsNode(const std::list& IDs, const std::list >& data); }; class LedgerAcquireMaster diff --git a/SHAMap.h b/SHAMap.h index 5703f2cb26..ad4c665edf 100644 --- a/SHAMap.h +++ b/SHAMap.h @@ -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; } diff --git a/SHAMapSync.cpp b/SHAMapSync.cpp index acd1e08888..b3ca77bd63 100644 --- a/SHAMapSync.cpp +++ b/SHAMapSync.cpp @@ -18,6 +18,7 @@ void SHAMap::getMissingNodes(std::vector& nodeIDs, std::vector& 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& 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::vectorsetFullBelow(); } 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(s.getRIPEMD160(), s.peekData()); } @@ -314,8 +324,6 @@ static bool confuseMap(SHAMap &map, int count) std::list items; - map.dump(true); - for(int i=0; i(&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; isize(); 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))