From c3603c403d98d13347d6d553873db7d5787ace14 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 31 Aug 2012 14:47:31 -0700 Subject: [PATCH] Code to determine how old a proposal is. Low-level code to remove a peer from the consensus process. --- src/LedgerConsensus.cpp | 19 +++++++++++++++++++ src/LedgerConsensus.h | 2 ++ src/LedgerProposal.cpp | 7 ++++--- src/LedgerProposal.h | 5 +++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 980e0be376..a0ae08095b 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -161,6 +161,18 @@ void LCTransaction::setVote(const uint160& peer, bool votesYes) } } +void LCTransaction::unVote(const uint160& peer) +{ + boost::unordered_map::iterator it = mVotes.find(peer); + if (it != mVotes.end()) + { + if (it->second) + --mYays; + else + --mNays; + } +} + bool LCTransaction::updatePosition(int percentTime, bool proposing) { // this many seconds after close, should our position change if (mOurPosition && (mNays == 0)) @@ -766,6 +778,13 @@ bool LedgerConsensus::peerPosition(const LedgerProposal::pointer& newPosition) return true; } +void LedgerConsensus::removePeer(const uint160& peerID) +{ + mPeerPositions.erase(peerID); + BOOST_FOREACH(u256_lct_pair& it, mDisputes) + it.second->unVote(peerID); +} + bool LedgerConsensus::peerHasSet(const Peer::pointer& peer, const uint256& hashSet, newcoin::TxSetStatus status) { if (status != newcoin::tsHAVE) // Indirect requests are for future support diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 31ffdf06c9..e4e71da0ab 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -64,6 +64,7 @@ public: Serializer& peekTransaction() { return transaction; } void setVote(const uint160& peer, bool votesYes); + void unVote(const uint160& peer); bool updatePosition(int percentTime, bool proposing); }; @@ -171,6 +172,7 @@ public: bool haveConsensus(); bool peerPosition(const LedgerProposal::pointer&); + void removePeer(const uint160& peerID); void deferProposal(const LedgerProposal::pointer& proposal, const NewcoinAddress& peerPublic); bool peerHasSet(const Peer::pointer& peer, const uint256& set, newcoin::TxSetStatus status); diff --git a/src/LedgerProposal.cpp b/src/LedgerProposal.cpp index 70d9458f6c..cb3ef93ec6 100644 --- a/src/LedgerProposal.cpp +++ b/src/LedgerProposal.cpp @@ -9,14 +9,14 @@ LedgerProposal::LedgerProposal(const uint256& pLgr, uint32 seq, const uint256& tx, uint32 closeTime, const NewcoinAddress& naPeerPublic) : - mPreviousLedger(pLgr), mCurrentHash(tx), mCloseTime(closeTime), mProposeSeq(seq) + mPreviousLedger(pLgr), mCurrentHash(tx), mCloseTime(closeTime), mProposeSeq(seq), mPublicKey(naPeerPublic) { - mPublicKey = naPeerPublic; // XXX Validate key. // if (!mKey->SetPubKey(pubKey)) // throw std::runtime_error("Invalid public key in proposal"); mPeerID = mPublicKey.getNodeID(); + mTime = boost::posix_time::second_clock::universal_time(); } @@ -27,12 +27,13 @@ LedgerProposal::LedgerProposal(const NewcoinAddress& naSeed, const uint256& prev mPublicKey = NewcoinAddress::createNodePublic(naSeed); mPrivateKey = NewcoinAddress::createNodePrivate(naSeed); mPeerID = mPublicKey.getNodeID(); + mTime = boost::posix_time::second_clock::universal_time(); } LedgerProposal::LedgerProposal(const uint256& prevLgr, const uint256& position, uint32 closeTime) : mPreviousLedger(prevLgr), mCurrentHash(position), mCloseTime(closeTime), mProposeSeq(0) { - ; + mTime = boost::posix_time::second_clock::universal_time(); } uint256 LedgerProposal::getSigningHash() const diff --git a/src/LedgerProposal.h b/src/LedgerProposal.h index 70d4bbbe7a..3ecd39efeb 100644 --- a/src/LedgerProposal.h +++ b/src/LedgerProposal.h @@ -22,7 +22,8 @@ protected: NewcoinAddress mPublicKey; NewcoinAddress mPrivateKey; // If ours - std::string mSignature; // set only if needed + std::string mSignature; // set only if needed + boost::posix_time::ptime mTime; public: @@ -55,7 +56,7 @@ public: void setPrevLedger(const uint256& prevLedger) { mPreviousLedger = prevLedger; } void setSignature(const std::string& signature) { mSignature = signature; } - + const boost::posix_time::ptime getCreateTime() { return mTime; } void changePosition(const uint256& newPosition, uint32 newCloseTime); Json::Value getJson() const;