diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 207406388b..b9c015a1a8 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -1,5 +1,8 @@ #include "LedgerConsensus.h" +#include +#include + #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 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() diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 48842d2b26..b90e7b3ee5 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -4,6 +4,7 @@ #include #include +#include #include #include "key.h" @@ -74,7 +75,7 @@ enum LCState lcsABORTED // Abandoned }; -class LedgerConsensus +class LedgerConsensus : public boost::enable_shared_from_this { protected: LCState mState; @@ -95,6 +96,10 @@ protected: // Disputed transactions boost::unordered_map mDisputes; + // final accept logic + static void Saccept(boost::shared_ptr 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);