Dispatch on consensus.

This commit is contained in:
JoelKatz
2012-05-30 17:08:50 -07:00
parent bb1c226fc0
commit 70767a3b1a
2 changed files with 35 additions and 9 deletions

View File

@@ -1,5 +1,8 @@
#include "LedgerConsensus.h"
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "Application.h"
#include "NetworkOPs.h"
#include "LedgerTiming.h"
@@ -521,16 +524,34 @@ bool LedgerConsensus::peerGaveNodes(Peer::pointer peer, const uint256& setHash,
}
void LedgerConsensus::beginAccept()
{
SHAMap::pointer consensusSet = mComplete[mOurPosition->getCurrentHash()];
if (!consensusSet)
{
std::cerr << "We don't have our own set" << std::endl;
assert(false);
abort();
return;
}
boost::thread thread(boost::bind(&LedgerConsensus::Saccept, shared_from_this(), consensusSet));
thread.detach();
}
void LedgerConsensus::Saccept(boost::shared_ptr<LedgerConsensus> This, SHAMap::pointer txSet)
{
This->accept(txSet);
}
void LedgerConsensus::accept(SHAMap::pointer set)
{
// WRITEME
// 1) Extract the consensus transaction set
// 2) Snapshot the last closed ledger
// 3) Dispatch a thread to:
// A) apply the consensus transaction set in canonical order
// B) Apply the consensus transaction set and replace the last closed ledger
// C) Rebuild the current ledger, applying as many transactions as possible
// D) Send a network state change
// E) Change the consensus state to lcsACCEPTED
// A) Snapshot the LCL
// B) apply the consensus transaction set in canonical order
// C) Apply the consensus transaction set and replace the last closed ledger
// D) Rebuild the current ledger, applying as many transactions as possible
// E) Send a network state change
// F) Change the consensus state to lcsACCEPTED
}
void LedgerConsensus::endConsensus()

View File

@@ -4,6 +4,7 @@
#include <list>
#include <boost/weak_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/unordered/unordered_map.hpp>
#include "key.h"
@@ -74,7 +75,7 @@ enum LCState
lcsABORTED // Abandoned
};
class LedgerConsensus
class LedgerConsensus : public boost::enable_shared_from_this<LedgerConsensus>
{
protected:
LCState mState;
@@ -95,6 +96,10 @@ protected:
// Disputed transactions
boost::unordered_map<uint256, LCTransaction::pointer, hash_SMN> mDisputes;
// final accept logic
static void Saccept(boost::shared_ptr<LedgerConsensus> This, SHAMap::pointer txSet);
void accept(SHAMap::pointer txSet);
void weHave(const uint256& id, Peer::pointer avoidPeer);
void startAcquiring(TransactionAcquire::pointer);
SHAMap::pointer find(const uint256& hash);