mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Begin fixing consensus without having the full consensus LCL.
This commit is contained in:
@@ -413,6 +413,20 @@ int LedgerConsensus::stateAccepted(int secondsSinceClose)
|
||||
|
||||
int LedgerConsensus::timerEntry()
|
||||
{
|
||||
if (!mHaveCorrectLCL)
|
||||
{
|
||||
Ledger::pointer consensus = theApp->getMasterLedger().getLedgerByHash(mPrevLedgerHash);
|
||||
if (consensus)
|
||||
{
|
||||
Log(lsINFO) << "We have acquired the conensus ledger";
|
||||
if (theApp->getMasterLedger().getClosedLedger()->getHash() != mPrevLedgerHash)
|
||||
theApp->getOPs().switchLastClosedLedger(consensus);
|
||||
mPreviousLedger = consensus;
|
||||
mHaveCorrectLCL = true;
|
||||
// FIXME: We need some kind of idea what the consensus transaction set is
|
||||
}
|
||||
}
|
||||
|
||||
int sinceClose = theApp->getOPs().getNetworkTimeNC() - mCloseTime;
|
||||
|
||||
switch (mState)
|
||||
@@ -836,6 +850,7 @@ void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
}
|
||||
else Log(lsWARNING) << "Not validating";
|
||||
statusChange(newcoin::neACCEPTED_LEDGER, newLCL);
|
||||
// FIXME: If necessary, change state to TRACKING/FULL
|
||||
}
|
||||
|
||||
void LedgerConsensus::endConsensus()
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
int startup();
|
||||
|
||||
Ledger::pointer peekPreviousLedger() { return mPreviousLedger; }
|
||||
uint256 getLCL() { return mPreviousLedger->getHash(); }
|
||||
uint256 getLCL() { return mPrevLedgerHash; }
|
||||
|
||||
SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire);
|
||||
TransactionAcquire::pointer getAcquiring(const uint256& hash);
|
||||
|
||||
@@ -308,13 +308,8 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
|
||||
// FIXME: Don't check unless last closed ledger is at least some seconds old
|
||||
// If full or tracking, check only at wobble time!
|
||||
if (checkLastClosedLedger(peerList))
|
||||
{
|
||||
// FIXME: if connected, go to ledger close process if it's time, marking that we have
|
||||
// the wrong LCL
|
||||
setStateTimer(3);
|
||||
return;
|
||||
}
|
||||
uint256 networkClosed;
|
||||
bool ledgerChange = checkLastClosedLedger(peerList, networkClosed);
|
||||
|
||||
// WRITEME: Unless we are in omFULL and in the process of doing a consensus,
|
||||
// we must count how many nodes share our LCL, how many nodes disagree with our LCL,
|
||||
@@ -322,13 +317,13 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
// there shouldn't be a newer LCL. We need this information to do the next three
|
||||
// tests.
|
||||
|
||||
if (mMode == omCONNECTED)
|
||||
if ((mMode == omCONNECTED) && !ledgerChange)
|
||||
{ // count number of peers that agree with us and UNL nodes whose validations we have for LCL
|
||||
// if the ledger is good enough, go to omTRACKING - TODO
|
||||
setMode(omTRACKING);
|
||||
}
|
||||
|
||||
if (mMode == omTRACKING)
|
||||
if ((mMode == omTRACKING) && !ledgerChange)
|
||||
{
|
||||
// check if the ledger is good enough to go to omFULL
|
||||
// Note: Do not go to omFULL if we don't have the previous ledger
|
||||
@@ -348,13 +343,13 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
int secondsToClose = theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC() -
|
||||
theApp->getOPs().getNetworkTimeNC();
|
||||
if ((!mConsensus) && (secondsToClose < LEDGER_WOBBLE_TIME)) // pre close wobble
|
||||
beginConsensus(theApp->getMasterLedger().getCurrentLedger());
|
||||
beginConsensus(networkClosed, theApp->getMasterLedger().getCurrentLedger());
|
||||
if (mConsensus)
|
||||
setStateTimer(mConsensus->timerEntry());
|
||||
else setStateTimer(4);
|
||||
}
|
||||
|
||||
bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerList)
|
||||
bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerList, uint256& networkClosed)
|
||||
{ // Returns true if there's an *abnormal* ledger issue, normal changing in TRACKING mode should return false
|
||||
// Do we have sufficient validations for our last closed ledger? Or do sufficient nodes
|
||||
// agree? And do we have no better ledger available?
|
||||
@@ -372,8 +367,8 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
ledgers[it->first].trustedValidations += it->second;
|
||||
}
|
||||
|
||||
Ledger::pointer currentClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = currentClosed->getHash();
|
||||
Ledger::pointer ourClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = ourClosed->getHash();
|
||||
ValidationCount& ourVC = ledgers[closedLedger];
|
||||
++ourVC.nodesUsing;
|
||||
ourVC.highNode = theApp->getWallet().getNodePublic();
|
||||
@@ -414,14 +409,16 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
switchLedgers = true;
|
||||
}
|
||||
}
|
||||
networkClosed = closedLedger;
|
||||
|
||||
if (!switchLedgers)
|
||||
return false;
|
||||
|
||||
Log(lsWARNING) << "We are not running on the consensus ledger";
|
||||
Log(lsINFO) << "Our LCL " << currentClosed->getHash().GetHex();
|
||||
Log(lsINFO) << "Our LCL " << ourClosed->getHash().GetHex();
|
||||
Log(lsINFO) << "Net LCL " << closedLedger.GetHex();
|
||||
if ((mMode == omTRACKING) || (mMode == omFULL)) setMode(omCONNECTED);
|
||||
|
||||
Ledger::pointer consensus = mLedgerMaster->getLedgerByHash(closedLedger);
|
||||
if (!consensus)
|
||||
{
|
||||
@@ -490,7 +487,7 @@ void NetworkOPs::switchLastClosedLedger(Ledger::pointer newLedger)
|
||||
theApp->getConnectionPool().relayMessage(NULL, packet);
|
||||
}
|
||||
|
||||
int NetworkOPs::beginConsensus(Ledger::pointer closingLedger)
|
||||
int NetworkOPs::beginConsensus(const uint256& networkClosed, Ledger::pointer closingLedger)
|
||||
{
|
||||
Log(lsINFO) << "Ledger close time for ledger " << closingLedger->getLedgerSeq() ;
|
||||
Log(lsINFO) << " LCL is " << closingLedger->getParentHash().GetHex();
|
||||
@@ -509,7 +506,7 @@ int NetworkOPs::beginConsensus(Ledger::pointer closingLedger)
|
||||
if (!!mConsensus) mConsensus->abort();
|
||||
prevLedger->setImmutable();
|
||||
mConsensus = boost::make_shared<LedgerConsensus>(
|
||||
prevLedger->getHash(), // FIXME: Only do this if the previous ledger is the consensus previous ledger
|
||||
networkClosed,
|
||||
prevLedger, theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC());
|
||||
|
||||
Log(lsDEBUG) << "Pre-close time, initiating consensus engine";
|
||||
|
||||
@@ -124,8 +124,8 @@ public:
|
||||
// network state machine
|
||||
void checkState(const boost::system::error_code& result);
|
||||
void switchLastClosedLedger(Ledger::pointer newLedger); // Used for the "jump" case
|
||||
bool checkLastClosedLedger(const std::vector<Peer::pointer> &);
|
||||
int beginConsensus(Ledger::pointer closingLedger);
|
||||
bool checkLastClosedLedger(const std::vector<Peer::pointer>&, uint256& networkClosed);
|
||||
int beginConsensus(const uint256& networkClosed, Ledger::pointer closingLedger);
|
||||
void endConsensus();
|
||||
void setStateTimer(int seconds);
|
||||
Json::Value getServerInfo();
|
||||
|
||||
Reference in New Issue
Block a user