From 75f85ae519bbe5f82ea4beaffb1def13a7c9b757 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 19 Jun 2012 16:55:04 -0700 Subject: [PATCH] Begin the code to allow a node to enter the consensus process even if it's not proposing and even if it's not validating. This also fixes the bug Arthur reported. --- src/LedgerConsensus.cpp | 45 ++++++++++++++++++++++++++--------------- src/LedgerConsensus.h | 1 + src/LedgerProposal.cpp | 6 ++++++ src/LedgerProposal.h | 3 +++ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index ca556745b1..a9edbf0c38 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -193,6 +193,12 @@ LedgerConsensus::LedgerConsensus(Ledger::pointer previousLedger, uint32 closeTim { Log(lsDEBUG) << "Creating consensus object"; Log(lsTRACE) << "LCL:" << previousLedger->getHash().GetHex() <<", ct=" << closeTime; + if (theConfig.VALIDATION_SEED.isValid()) + { + mValidating = true; + mProposing = theApp->getOPs().getOperatingMode() == NetworkOPs::omFULL; + } + else mProposing = mValidating = false; } void LedgerConsensus::takeInitialPosition(Ledger::pointer initialLedger) @@ -215,10 +221,13 @@ void LedgerConsensus::takeInitialPosition(Ledger::pointer initialLedger) } } - mOurPosition = boost::make_shared - (theConfig.VALIDATION_SEED, initialLedger->getParentHash(), txSet); + if (mProposing) + mOurPosition = boost::make_shared + (theConfig.VALIDATION_SEED, initialLedger->getParentHash(), txSet); + else + mOurPosition = boost::make_shared(initialLedger->getParentHash(), txSet); mapComplete(txSet, initialSet, false); - propose(std::vector(), std::vector()); + if (mProposing) propose(std::vector(), std::vector()); } void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2) @@ -357,7 +366,8 @@ int LedgerConsensus::statePostClose(int secondsSinceClose) int LedgerConsensus::stateEstablish(int secondsSinceClose) { // we are establishing consensus - updateOurPositions(secondsSinceClose); + if (mProposing) + updateOurPositions(secondsSinceClose); if (secondsSinceClose > LEDGER_MAX_CONVERGE) { Log(lsINFO) << "Converge cutoff"; @@ -445,7 +455,7 @@ bool LedgerConsensus::updateOurPositions(int sinceClose) { uint256 newHash = ourPosition->getHash(); mOurPosition->changePosition(newHash); - propose(addedTx, removedTx); + if (mProposing) propose(addedTx, removedTx); mapComplete(newHash, ourPosition, false); Log(lsINFO) << "We change our position to " << newHash.GetHex(); } @@ -608,8 +618,7 @@ void LedgerConsensus::beginAccept() SHAMap::pointer consensusSet = mComplete[mOurPosition->getCurrentHash()]; if (!consensusSet) { - Log(lsFATAL) << "We don't have our own set"; - assert(false); + Log(lsFATAL) << "We don't have a consensus set"; abort(); return; } @@ -805,15 +814,19 @@ void LedgerConsensus::accept(SHAMap::pointer set) } #endif - SerializedValidation::pointer v = boost::make_shared - (newLCLHash, mOurPosition->peekSeed(), true); - v->setTrusted(); - theApp->getValidations().addValidation(v); - std::vector validation = v->getSigned(); - newcoin::TMValidation val; - val.set_validation(&validation[0], validation.size()); - theApp->getConnectionPool().relayMessage(NULL, boost::make_shared(val, newcoin::mtVALIDATION)); - Log(lsINFO) << "Validation sent " << newLCL->getHash().GetHex(); + if (mValidating) + { + SerializedValidation::pointer v = boost::make_shared + (newLCLHash, mOurPosition->peekSeed(), true); + v->setTrusted(); + // FIXME: If not proposing, set not full + theApp->getValidations().addValidation(v); + std::vector validation = v->getSigned(); + newcoin::TMValidation val; + val.set_validation(&validation[0], validation.size()); + theApp->getConnectionPool().relayMessage(NULL, boost::make_shared(val, newcoin::mtVALIDATION)); + Log(lsINFO) << "Validation sent " << newLCL->getHash().GetHex(); + } statusChange(newcoin::neACCEPTED_LEDGER, newOL); } diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 60d4c27962..349722951d 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -85,6 +85,7 @@ protected: uint32 mCloseTime; Ledger::pointer mPreviousLedger; LedgerProposal::pointer mOurPosition; + bool mProposing, mValidating; // Convergence tracking, trusted peers indexed by hash of public key boost::unordered_map mPeerPositions; diff --git a/src/LedgerProposal.cpp b/src/LedgerProposal.cpp index b386e599c1..9f435415bd 100644 --- a/src/LedgerProposal.cpp +++ b/src/LedgerProposal.cpp @@ -28,6 +28,12 @@ LedgerProposal::LedgerProposal(const NewcoinAddress& naSeed, const uint256& prev mPeerID = mPublicKey.getNodeID(); } +LedgerProposal::LedgerProposal(const uint256& prevLgr, const uint256& position) : + mPreviousLedger(prevLgr), mCurrentHash(position), mProposeSeq(0) +{ + ; +} + uint256 LedgerProposal::getSigningHash() const { Serializer s(72); diff --git a/src/LedgerProposal.h b/src/LedgerProposal.h index 52ab4091e9..f7e50cc639 100644 --- a/src/LedgerProposal.h +++ b/src/LedgerProposal.h @@ -32,6 +32,9 @@ public: // our first proposal LedgerProposal(const NewcoinAddress& naSeed, const uint256& prevLedger, const uint256& position); + // an unsigned proposal + LedgerProposal(const uint256& prevLedger, const uint256& position); + uint256 getSigningHash() const; bool checkSign(const std::string& signature);