From 2866cec281239f71877cd26f1a19e4d2af374680 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 26 May 2012 14:21:13 -0700 Subject: [PATCH] Finish addDisputedTransaction and peerPosition. --- src/LedgerConsensus.cpp | 50 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index ae6798d383..77a23e9c8c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -138,10 +138,10 @@ void LedgerConsensus::closeTime(Ledger::pointer& current) void LedgerConsensus::mapComplete(SHAMap::pointer map) { boost::unordered_map::iterator it = mComplete.find(map->getHash()); - if (it != mComplete.end()) return; + if (it != mComplete.end()) return; // we already have this map if (mOurPosition && (map->getHash() != mOurPosition->getCurrentHash())) - { // this creates disputed transactions + { // this could create disputed transactions boost::unordered_map::iterator it2 = mComplete.find(mOurPosition->getCurrentHash()); if (it2 != mComplete.end()) { @@ -235,19 +235,6 @@ void LedgerConsensus::startAcquiring(TransactionAcquire::pointer acquire) } } -void LedgerConsensus::removePosition(LedgerProposal& position, bool ours) -{ -// int threshold = getThreshold(); -// uint256 txSet = position.getCurrentHash(); - - // WRITEME -} - -void LedgerConsensus::addPosition(LedgerProposal& position, bool ours) -{ - // WRITEME -} - void LedgerConsensus::addDisputedTransaction(const uint256& txID) { boost::unordered_map::iterator it = mDisputes.find(txID); @@ -259,25 +246,46 @@ void LedgerConsensus::addDisputedTransaction(const uint256& txID) boost::unordered_map::iterator mit = mComplete.find(mOurPosition->getCurrentHash()); if (mit != mComplete.end()) ourPosition = mit->second->hasItem(txID); + else assert(false); // We don't have our own position? } - mDisputes[txID] = boost::make_shared(txID, ourPosition); + LCTransaction::pointer txn = boost::make_shared(txID, ourPosition); + mDisputes[txID] = txn; + + for (boost::unordered_map::iterator pit = mPeerPositions.begin(), + pend = mPeerPositions.end(); pit != pend; ++pit) + { + boost::unordered_map::const_iterator cit = + mComplete.find(pit->second->getCurrentHash()); + if (cit != mComplete.end()) + txn->setVote(pit->first, cit->second->hasItem(txID)); + } } bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition) { LedgerProposal::pointer& currentPosition = mPeerPositions[newPosition->getPeerID()]; - if (!currentPosition) + if (currentPosition) { + assert(newPosition->getPeerID() == currentPosition->getPeerID()); if (newPosition->getProposeSeq() <= currentPosition->getProposeSeq()) return false; - - // change in position - removePosition(*currentPosition, false); + if (newPosition->getCurrentHash() == currentPosition->getCurrentHash()) + { // we missed an intermediary change + currentPosition = newPosition; + return true; + } } currentPosition = newPosition; - addPosition(*currentPosition, false); + SHAMap::pointer set = getTransactionTree(newPosition->getCurrentHash(), true); + if (set) + { + for (boost::unordered_map::iterator it = mDisputes.begin(), + end = mDisputes.end(); it != end; ++it) + it->second->setVote(newPosition->getPeerID(), set->hasItem(it->first)); + } + return true; }