Structures for ledger closing logic.

This commit is contained in:
JoelKatz
2012-05-14 13:35:36 -07:00
parent a8c26d4d33
commit 80ed62481d

88
src/LedgerConsensus.h Normal file
View File

@@ -0,0 +1,88 @@
#ifndef __LEDGER_CONSENSUS__
#define __LEDGER_CONSENSUS__
#include <boost/unordered/unordered_map.hpp>
#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<LCPosition> 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<unsigned char>& 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<uint256, bool> mVotes;
Transaction::pointer mTransaction;
public:
typedef boost::shared_ptr<LCTransaction> 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<uint256, LCPosition::pointer> mPeerPositions;
// Transaction Sets, indexed by hash of transaction tree
boost::unordered_map<uint256, SHAMap::pointer> mComplete;
boost::unordered_map<uint256, TransactionAcquire::pointer> 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