diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h new file mode 100644 index 0000000000..980efb8a5b --- /dev/null +++ b/src/LedgerConsensus.h @@ -0,0 +1,88 @@ +#ifndef __LEDGER_CONSENSUS__ +#define __LEDGER_CONSENSUS__ + +#include + +#include "key.h" +#include "Transaction.h" +#include "LedgerAcquire.h" + +class LCPosition +{ // A position taken by one of our trusted peers +protected: + uint256 mPubKeyHash; + CKey::pointer mPubKey; + uint256 mCurrentPosition; + uint32 mSequence; + +public: + typedef boost::shared_ptr pointer; + + LCPosition(CKey::pointer pubKey, const uint256& currentPosition, uint32 seq) : + mPubKey(pubKey), mCurrentPosition(currentPosition), mSequence(seq) { ; } + + const uint256& getPubKeyHash() const { return mPubKeyHash; } + const uint256& getCurrentPosition() const { return mCurrentPosition; } + uint32 getSeq() const { return mSequence; } + + bool verifySignature(const uint256& hash, const std::vector& signature) const; + void setPosition(const uint256& position, uint32 sequence); +}; + + +class LCTransaction +{ // A transaction that may be disputed +protected: + uint256 mTransactionID; + int mYays, mNays; + bool mOurPosition; + boost::unordered_map mVotes; + Transaction::pointer mTransaction; + +public: + typedef boost::shared_ptr pointer; + + LCTransaction(const uint256 &txID, bool ourPosition) : mTransactionID(txID), mYays(0), mNays(0), + mOurPosition(ourPosition) { ; } + + 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); +}; + + +class LedgerConsensus +{ +protected: + Ledger::pointer mPreviousLedger, mCurrentLedger; + + // Convergence tracking, trusted peers indexed by hash of public key + boost::unordered_map mPeerPositions; + + // Transaction Sets, indexed by hash of transaction tree + boost::unordered_map mComplete; + boost::unordered_map mAcquiring; + + +public: + LedgerConsensus(Ledger::pointer previousLedger, Ledger::pointer currentLedger) : + mPreviousLedger(previousLedger), mCurrentLedger(currentLedger) { ; } + + Ledger::pointer peekPreviousLedger() { return mPreviousLedger; } + Ledger::pointer peekCurrentLedger() { return mCurrentLedger; } + + LCPosition::pointer getCreatePeerPosition(const uint256& pubKeyHash); + + SHAMap::pointer getTransactionTree(const uint256& hash); + TransactionAcquire::pointer getAcquiring(const uint256& hash); + void acquireComplete(const uint256& hash); +}; + + +#endif