mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 08:48:03 +00:00
Fix set:
1) Create validation structure even if not proposing (but if validating) 2) Fix hashes in status change messages, do it only one way 3) Don't spin right at wobble time. 4) Report accept status change on new last-closed ledger, not new open ledger. 5) Make sure validation count is correct even if we first encounter a ledger on ourselves (not a peer) 6) At end of consensus, assume nodes cycled (until they report otherwise). By doing nothing, we effectively assumed they didn't. 7) Miscellaneous cleanups and fixes.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
// #define LC_DEBUG
|
||||
|
||||
// TODO: If we don't have the previousLCL, check if we got it. If so, change modes
|
||||
|
||||
TransactionAcquire::TransactionAcquire(const uint256& hash)
|
||||
: PeerSet(hash, 1), mFilter(&theApp->getNodeCache()), mHaveRoot(false)
|
||||
{
|
||||
@@ -224,7 +226,7 @@ void LedgerConsensus::takeInitialPosition(Ledger::pointer initialLedger)
|
||||
}
|
||||
}
|
||||
|
||||
if (mProposing)
|
||||
if (mValidating)
|
||||
mOurPosition = boost::make_shared<LedgerProposal>
|
||||
(mValSeed, initialLedger->getParentHash(), txSet);
|
||||
else
|
||||
@@ -319,15 +321,22 @@ void LedgerConsensus::adjustCount(SHAMap::pointer map, const std::vector<uint160
|
||||
|
||||
void LedgerConsensus::statusChange(newcoin::NodeEvent event, Ledger::pointer ledger)
|
||||
{ // Send a node status change message to our peers
|
||||
if (!mHaveCorrectLCL) return;
|
||||
newcoin::TMStatusChange s;
|
||||
s.set_newevent(event);
|
||||
s.set_ledgerseq(ledger->getLedgerSeq());
|
||||
s.set_networktime(theApp->getOPs().getNetworkTimeNC());
|
||||
uint256 plhash = ledger->getParentHash();
|
||||
s.set_previousledgerhash(plhash.begin(), plhash.size());
|
||||
if (!mHaveCorrectLCL)
|
||||
s.set_newevent(newcoin::neLOST_SYNC);
|
||||
else
|
||||
{
|
||||
s.set_newevent(event);
|
||||
s.set_ledgerseq(ledger->getLedgerSeq());
|
||||
s.set_networktime(theApp->getOPs().getNetworkTimeNC());
|
||||
uint256 hash = ledger->getParentHash();
|
||||
s.set_previousledgerhash(hash.begin(), hash.size());
|
||||
hash = ledger->getHash();
|
||||
s.set_ledgerhash(hash.begin(), hash.size());
|
||||
}
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage>(s, newcoin::mtSTATUS_CHANGE);
|
||||
theApp->getConnectionPool().relayMessage(NULL, packet);
|
||||
Log(lsINFO) << "send status change to peer";
|
||||
}
|
||||
|
||||
void LedgerConsensus::abort()
|
||||
@@ -751,15 +760,6 @@ void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
uint256 newLCLHash = newLCL->getHash();
|
||||
Log(lsTRACE) << "newLCL " << newLCLHash.GetHex();
|
||||
|
||||
#ifdef DEBUG
|
||||
if (1)
|
||||
{
|
||||
Log(lsTRACE) << "newLCL after transactions";
|
||||
Json::Value p;
|
||||
newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE);
|
||||
ssw.write(Log(lsTRACE).ref(), p);
|
||||
}
|
||||
#endif
|
||||
|
||||
Ledger::pointer newOL = boost::make_shared<Ledger>(true, boost::ref(*newLCL));
|
||||
|
||||
@@ -815,6 +815,10 @@ void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
Json::Value p;
|
||||
newOL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE);
|
||||
ssw.write(Log(lsTRACE).ref(), p);
|
||||
Log(lsINFO) << "newLCL after transactions";
|
||||
Json::Value p;
|
||||
newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE);
|
||||
ssw.write(Log(lsTRACE).ref(), p);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -831,7 +835,8 @@ void LedgerConsensus::accept(SHAMap::pointer set)
|
||||
theApp->getConnectionPool().relayMessage(NULL, boost::make_shared<PackedMessage>(val, newcoin::mtVALIDATION));
|
||||
Log(lsINFO) << "Validation sent " << newLCL->getHash().GetHex();
|
||||
}
|
||||
statusChange(newcoin::neACCEPTED_LEDGER, newOL);
|
||||
else Log(lsWARNING) << "Not validating";
|
||||
statusChange(newcoin::neACCEPTED_LEDGER, newLCL);
|
||||
}
|
||||
|
||||
void LedgerConsensus::endConsensus()
|
||||
|
||||
@@ -251,7 +251,7 @@ void NetworkOPs::setStateTimer(int sec)
|
||||
uint64 consensusTime = mLedgerMaster->getCurrentLedger()->getCloseTimeNC() - LEDGER_WOBBLE_TIME;
|
||||
uint64 now = getNetworkTimeNC();
|
||||
|
||||
if (now >= consensusTime) sec = 0;
|
||||
if (now >= consensusTime) sec = 1;
|
||||
else if (sec > (consensusTime - now)) sec = (consensusTime - now);
|
||||
}
|
||||
mNetTimer.expires_from_now(boost::posix_time::seconds(sec));
|
||||
@@ -308,7 +308,6 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 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))
|
||||
@@ -374,9 +373,8 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
if (!!peerLedger)
|
||||
{
|
||||
// FIXME: If we have this ledger, don't count it if it's too far past its close time
|
||||
bool isNew = ledgers.find(peerLedger) == ledgers.end();
|
||||
ValidationCount& vc = ledgers[peerLedger];
|
||||
if (isNew)
|
||||
if (vc.nodesUsing == 0)
|
||||
{
|
||||
theApp->getValidations().getValidationCount(peerLedger,
|
||||
vc.trustedValidations, vc.untrustedValidations);
|
||||
@@ -392,19 +390,27 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
|
||||
Ledger::pointer currentClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = currentClosed->getHash();
|
||||
ValidationCount& vc = ledgers[closedLedger];
|
||||
if ((vc.nodesUsing == 0) || (theApp->getWallet().getNodePublic() > vc.highNode))
|
||||
vc.highNode = theApp->getWallet().getNodePublic();
|
||||
++ledgers[closedLedger].nodesUsing;
|
||||
ValidationCount& ourVC = ledgers[closedLedger];
|
||||
if (ourVC.nodesUsing == 0)
|
||||
{
|
||||
ourVC.highNode = theApp->getWallet().getNodePublic();
|
||||
theApp->getValidations().getValidationCount(closedLedger,
|
||||
ourVC.trustedValidations, ourVC.untrustedValidations);
|
||||
}
|
||||
++ourVC.nodesUsing;
|
||||
ValidationCount bestVC = ourVC;
|
||||
|
||||
// 3) Is there a network ledger we'd like to switch to? If so, do we have it?
|
||||
bool switchLedgers = false;
|
||||
for(boost::unordered_map<uint256, ValidationCount>::iterator it = ledgers.begin(), end = ledgers.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
if (it->second > vc)
|
||||
Log(lsTRACE) << "L: " << it->first.GetHex() <<
|
||||
" t=" << it->second.trustedValidations << ", u=" << it->second.untrustedValidations <<
|
||||
", n=" << it->second.nodesUsing;
|
||||
if (it->second > bestVC)
|
||||
{
|
||||
vc = it->second;
|
||||
bestVC = it->second;
|
||||
closedLedger = it->first;
|
||||
switchLedgers = true;
|
||||
}
|
||||
@@ -464,8 +470,10 @@ void NetworkOPs::switchLastClosedLedger(Ledger::pointer newLedger)
|
||||
s.set_newevent(newcoin::neSWITCHED_LEDGER);
|
||||
s.set_ledgerseq(newLedger->getLedgerSeq());
|
||||
s.set_networktime(theApp->getOPs().getNetworkTimeNC());
|
||||
uint256 plhash = newLedger->getParentHash();
|
||||
s.set_previousledgerhash(plhash.begin(), plhash.size());
|
||||
uint256 hash = newLedger->getParentHash();
|
||||
s.set_previousledgerhash(hash.begin(), hash.size());
|
||||
hash = newLedger->getHash();
|
||||
s.set_ledgerhash(hash.begin(), hash.size());
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage>(s, newcoin::mtSTATUS_CHANGE);
|
||||
theApp->getConnectionPool().relayMessage(NULL, packet);
|
||||
}
|
||||
@@ -566,6 +574,12 @@ void NetworkOPs::mapComplete(const uint256& hash, SHAMap::pointer map)
|
||||
|
||||
void NetworkOPs::endConsensus()
|
||||
{
|
||||
uint256 deadLedger = theApp->getMasterLedger().getClosedLedger()->getParentHash();
|
||||
Log(lsTRACE) << "Ledger " << deadLedger.GetHex() << " is now dead";
|
||||
std::vector<Peer::pointer> peerList = theApp->getConnectionPool().getPeerVector();
|
||||
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
|
||||
if (*it && ((*it)->getClosedLedgerHash() == deadLedger))
|
||||
(*it)->cycleStatus();
|
||||
mConsensus = boost::shared_ptr<LedgerConsensus>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user