mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Sanitize validation handling.
This commit is contained in:
@@ -261,10 +261,10 @@ void NetworkOPs::setStateTimer(int sec)
|
||||
class ValidationCount
|
||||
{
|
||||
public:
|
||||
int trustedValidations, untrustedValidations, nodesUsing;
|
||||
int trustedValidations, nodesUsing;
|
||||
NewcoinAddress highNode;
|
||||
|
||||
ValidationCount() : trustedValidations(0), untrustedValidations(0), nodesUsing(0) { ; }
|
||||
ValidationCount() : trustedValidations(0), nodesUsing(0) { ; }
|
||||
bool operator>(const ValidationCount& v)
|
||||
{
|
||||
if (trustedValidations > v.trustedValidations) return true;
|
||||
@@ -362,6 +362,19 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
// node is using. THis is kind of fundamental.
|
||||
|
||||
boost::unordered_map<uint256, ValidationCount> ledgers;
|
||||
|
||||
{
|
||||
boost::unordered_map<uint256, int> current = theApp->getValidations().getCurrentValidations();
|
||||
for (boost::unordered_map<uint256, int>::iterator it = current.begin(), end = current.end(); it != end; ++it)
|
||||
ledgers[it->first].trustedValidations += it->second;
|
||||
}
|
||||
|
||||
Ledger::pointer currentClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = currentClosed->getHash();
|
||||
ValidationCount& ourVC = ledgers[closedLedger];
|
||||
++ourVC.nodesUsing;
|
||||
ourVC.highNode = theApp->getWallet().getNodePublic();
|
||||
|
||||
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
|
||||
{
|
||||
if (!*it)
|
||||
@@ -375,13 +388,6 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
{
|
||||
// FIXME: If we have this ledger, don't count it if it's too far past its close time
|
||||
ValidationCount& vc = ledgers[peerLedger];
|
||||
if (vc.nodesUsing == 0)
|
||||
{
|
||||
theApp->getValidations().getValidationCount(peerLedger, true,
|
||||
vc.trustedValidations, vc.untrustedValidations);
|
||||
Log(lsTRACE) << peerLedger.GetHex() << " has " << vc.trustedValidations <<
|
||||
" trusted validations and " << vc.untrustedValidations << " untrusted";
|
||||
}
|
||||
if ((vc.nodesUsing == 0) || ((*it)->getNodePublic() > vc.highNode))
|
||||
vc.highNode = (*it)->getNodePublic();
|
||||
++vc.nodesUsing;
|
||||
@@ -389,17 +395,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
}
|
||||
}
|
||||
|
||||
Ledger::pointer currentClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = currentClosed->getHash();
|
||||
ValidationCount& ourVC = ledgers[closedLedger];
|
||||
if (ourVC.nodesUsing == 0)
|
||||
{
|
||||
ourVC.highNode = theApp->getWallet().getNodePublic();
|
||||
theApp->getValidations().getValidationCount(closedLedger, true,
|
||||
ourVC.trustedValidations, ourVC.untrustedValidations);
|
||||
}
|
||||
++ourVC.nodesUsing;
|
||||
ValidationCount bestVC = ourVC;
|
||||
ValidationCount bestVC = ledgers[closedLedger];
|
||||
|
||||
// 3) Is there a network ledger we'd like to switch to? If so, do we have it?
|
||||
bool switchLedgers = false;
|
||||
@@ -407,8 +403,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
it != end; ++it)
|
||||
{
|
||||
Log(lsTRACE) << "L: " << it->first.GetHex() <<
|
||||
" t=" << it->second.trustedValidations << ", u=" << it->second.untrustedValidations <<
|
||||
", n=" << it->second.nodesUsing;
|
||||
" t=" << it->second.trustedValidations << ", n=" << it->second.nodesUsing;
|
||||
if (it->second > bestVC)
|
||||
{
|
||||
bestVC = it->second;
|
||||
|
||||
Reference in New Issue
Block a user