More ledger consensus work.

This commit is contained in:
JoelKatz
2012-05-23 17:26:45 -07:00
parent 9b9177f15e
commit 07e353d8a2
2 changed files with 56 additions and 12 deletions

View File

@@ -105,12 +105,33 @@ void LedgerConsensus::closeTime(Ledger::pointer& current)
current->updateHash();
uint256 txSet = current->getTransHash();
mOurPosition = boost::make_shared<LedgerProposal>(nodePrivKey, current->getParentHash(), txSet);
mComplete[txSet] = current->peekTransactionMap()->snapShot();
mapComplete(current->peekTransactionMap()->snapShot());
// WRITME: Broadcast an IHAVE for this set
}
void LedgerConsensus::mapComplete(SHAMap::pointer map)
{
boost::unordered_map<uint256, SHAMap::pointer>::iterator it = mComplete.find(map->getHash());
if (it != mComplete.end()) return;
if (mOurPosition && (map->getHash() != mOurPosition->getCurrentHash()))
{ // this creates disputed transactions
boost::unordered_map<uint256, SHAMap::pointer>::iterator it2 = mComplete.find(mOurPosition->getCurrentHash());
if (it2 != mComplete.end())
{
SHAMap::SHAMapDiff differences;
it2->second->compare(it->second, differences, 16384);
for(SHAMap::SHAMapDiff::iterator pos = differences.begin(), end = differences.end(); pos != end; ++pos)
{ // create disputed transactions
addDisputedTransaction(pos->first);
}
}
}
mComplete[map->getHash()] = map;
}
void LedgerConsensus::abort()
{
mState = lcsABORTED;
}
int LedgerConsensus::startup()
@@ -165,14 +186,33 @@ void LedgerConsensus::startAcquiring(TransactionAcquire::pointer acquire)
}
}
void LedgerConsensus::removePosition(LedgerProposal& position)
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::addPosition(LedgerProposal& position)
void LedgerConsensus::addDisputedTransaction(const uint256& txID)
{
// WRITEME
boost::unordered_map<uint256, LCTransaction::pointer>::iterator it = mDisputes.find(txID);
if (it != mDisputes.end()) return;
bool ourPosition = false;
if (mOurPosition)
{
boost::unordered_map<uint256, SHAMap::pointer>::iterator mit = mComplete.find(mOurPosition->getCurrentHash());
if (mit != mComplete.end())
ourPosition = mit->second->hasItem(txID);
}
mDisputes[txID] = boost::make_shared<LCTransaction>(txID, ourPosition);
}
bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition)
@@ -184,11 +224,11 @@ bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition)
return false;
// change in position
removePosition(*currentPosition);
removePosition(*currentPosition, false);
}
currentPosition = newPosition;
addPosition(*currentPosition);
addPosition(*currentPosition, false);
return true;
}

View File

@@ -45,7 +45,6 @@ protected:
int mYays, mNays;
bool mOurPosition;
boost::unordered_map<uint256, bool> mVotes;
Transaction::pointer mTransaction;
public:
typedef boost::shared_ptr<LCTransaction> pointer;
@@ -56,9 +55,6 @@ public:
const uint256& getTransactionID() const { return mTransactionID; }
bool getOurPosition() const { return mOurPosition; }
bool haveTransaction() const { return !!mTransaction; }
Transaction::pointer getTransaction() { return mTransaction; }
void setVote(const uint256& peer, bool votesYes);
bool updatePosition(int timePassed);
@@ -71,6 +67,7 @@ enum LCState
lcsCUTOFF, // Past the cutoff for consensus
lcsFINSHED, // We have closed on a transaction set
lcsACCEPTED, // We have accepted/validated a new last closed ledger
lcsABORTED // Abandoned
};
class LedgerConsensus
@@ -90,12 +87,19 @@ protected:
// Peer sets
boost::unordered_map<uint256, std::vector< boost::weak_ptr<Peer> >, hash_SMN> mPeerData;
// Disputed transactions
boost::unordered_map<uint256, LCTransaction::pointer, hash_SMN> mDisputes;
void weHave(const uint256& id, Peer::pointer avoidPeer);
void startAcquiring(TransactionAcquire::pointer);
SHAMap::pointer find(const uint256& hash);
void addPosition(LedgerProposal&);
void removePosition(LedgerProposal&);
void mapComplete(SHAMap::pointer map);
void addDisputedTransaction(const uint256&);
void addPosition(LedgerProposal&, bool ours);
void removePosition(LedgerProposal&, bool ours);
int getThreshold();
public:
LedgerConsensus(Ledger::pointer previousLedger);