diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 77a23e9c8c..a616e6b286 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -1,6 +1,9 @@ #include "LedgerConsensus.h" +#include "Application.h" +#include "NetworkOPs.h" + TransactionAcquire::TransactionAcquire(const uint256& hash) : PeerSet(hash, 1), mHaveRoot(false) { mMap = boost::make_shared(); @@ -9,8 +12,10 @@ TransactionAcquire::TransactionAcquire(const uint256& hash) : PeerSet(hash, 1), void TransactionAcquire::done() { - // insert SHAMap in finished set (as valid or invalid), remove ourselves from current set - // WRITEME + if (mFailed) + theApp->getOPs().mapComplete(mHash, SHAMap::pointer()); + else + theApp->getOPs().mapComplete(mHash, mMap); } boost::weak_ptr TransactionAcquire::pmDowncast() @@ -131,12 +136,19 @@ void LedgerConsensus::closeTime(Ledger::pointer& current) current->updateHash(); uint256 txSet = current->getTransHash(); mOurPosition = boost::make_shared(nodePrivKey, current->getParentHash(), txSet); - mapComplete(current->peekTransactionMap()->snapShot()); - // WRITME: Broadcast an IHAVE for this set + mapComplete(txSet, current->peekTransactionMap()->snapShot()); } -void LedgerConsensus::mapComplete(SHAMap::pointer map) +void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map) { + if (!map) + { // this is an invalid/corrupt map + mComplete[hash] = map; + return; + } + + mAcquiring.erase(hash); + boost::unordered_map::iterator it = mComplete.find(map->getHash()); if (it != mComplete.end()) return; // we already have this map @@ -165,6 +177,8 @@ void LedgerConsensus::mapComplete(SHAMap::pointer map) } if (!peers.empty()) adjustCount(map, peers); + + // WRITEME: broadcast an IHAVE for this set } void LedgerConsensus::adjustCount(SHAMap::pointer map, const std::vector& peers) @@ -257,7 +271,7 @@ void LedgerConsensus::addDisputedTransaction(const uint256& txID) { boost::unordered_map::const_iterator cit = mComplete.find(pit->second->getCurrentHash()); - if (cit != mComplete.end()) + if (cit != mComplete.end() && cit->second) txn->setVote(pit->first, cit->second->hasItem(txID)); } } diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 75d1063a82..af46afe4f8 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -94,7 +94,6 @@ protected: void startAcquiring(TransactionAcquire::pointer); SHAMap::pointer find(const uint256& hash); - void mapComplete(SHAMap::pointer map); void addDisputedTransaction(const uint256&); void adjustCount(SHAMap::pointer map, const std::vector& peers); @@ -112,7 +111,7 @@ public: SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire); TransactionAcquire::pointer getAcquiring(const uint256& hash); - void acquireComplete(const uint256& hash); + void mapComplete(const uint256& hash, SHAMap::pointer map); void abort(); int timerEntry(void); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index f03465bf20..0de1d63b2a 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -434,3 +434,9 @@ bool NetworkOPs::hasTXSet(boost::shared_ptr peer, const std::vectorpeerHasSet(peer, sets); } + +void NetworkOPs::mapComplete(const uint256& hash, SHAMap::pointer map) +{ + if (mConsensus) + mConsensus->mapComplete(hash, map); +} \ No newline at end of file diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 0dc79da25d..ce791bf98b 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -77,6 +77,7 @@ public: const std::list& nodeIDs, const std::list< std::vector >& nodeData); SHAMap::pointer getTXMap(const uint256& hash); bool hasTXSet(boost::shared_ptr peer, const std::vector& sets); + void mapComplete(const uint256& hash, SHAMap::pointer map); // network state machine void checkState(const boost::system::error_code& result);