diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index e31462d63a..25a7953571 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -87,6 +87,28 @@ bool TransactionAcquire::takeNodes(const std::list& nodeIDs, return true; } +LedgerConsensus::LedgerConsensus(Ledger::pointer previousLedger) + : mState(lcsPRE_CLOSE), mPreviousLedger(previousLedger) +{ +} + +void LedgerConsensus::closeTime(Ledger::pointer& current) +{ + if (mState != lcsPRE_CLOSE) + { + assert(false); + return; + } + CKey::pointer nodePrivKey = boost::make_shared(); + nodePrivKey->MakeNewKey(); // FIXME + + current->updateHash(); + uint256 txSet = current->getTransHash(); + mOurPosition = boost::make_shared(nodePrivKey, current->getParentHash(), txSet); + mComplete[txSet] = current->peekTransactionMap()->snapShot(); + // WRITME: Broadcast an IHAVE for this set +} + void LedgerConsensus::abort() { } diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 8b31f84bab..e1b58db0fc 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -64,13 +64,20 @@ public: bool updatePosition(int timePassed); }; +enum LCState +{ + lcsPRE_CLOSE, // We haven't closed our ledger yet, but others might have + lcsESTABLISH, // Establishing consensus + lcsCUTOFF, // Past the cutoff for consensus + lcsFINSHED, // We have closed on a transaction set + lcsACCEPTED, // We have accepted/validated a new last closed ledger +}; class LedgerConsensus { protected: - Ledger::pointer mPreviousLedger, mCurrentLedger; - LedgerProposal::pointer mCurrentProposal; - + LCState mState; + Ledger::pointer mPreviousLedger; LedgerProposal::pointer mOurPosition; // Convergence tracking, trusted peers indexed by hash of public key @@ -91,13 +98,12 @@ protected: void removePosition(LedgerProposal&); public: - LedgerConsensus(Ledger::pointer previousLedger, Ledger::pointer currentLedger) : - mPreviousLedger(previousLedger), mCurrentLedger(currentLedger) { ; } + LedgerConsensus(Ledger::pointer previousLedger); + void closeTime(Ledger::pointer& currentLedger); int startup(); Ledger::pointer peekPreviousLedger() { return mPreviousLedger; } - Ledger::pointer peekCurrentLedger() { return mCurrentLedger; } SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire); TransactionAcquire::pointer getAcquiring(const uint256& hash); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index cabe7de699..0dc660fff4 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -368,7 +368,8 @@ int NetworkOPs::beginConsensus(Ledger::pointer closingLedger) // Create a consensus object to get consensus on this ledger if (!!mConsensus) mConsensus->abort(); - mConsensus = boost::make_shared(prevLedger, closingLedger); + mConsensus = boost::make_shared(prevLedger); + mConsensus->closeTime(closingLedger); // FIXME: Create consensus a few seconds before close time #ifdef DEBUG std::cerr << "Broadcasting ledger close" << std::endl;