Return a validated ledger if there is one (RIPD-814)

LedgerMaster::getLedgerBySeq should return a validated
ledger (rather than the the open or closed ledger) for
a sequence number for which it has a fully-validated ledger.
This commit is contained in:
JoelKatz
2015-02-25 18:38:51 -08:00
committed by Tom Ritchford
parent cb92b94d55
commit f3725bdd2e

View File

@@ -1448,6 +1448,28 @@ public:
Ledger::pointer getLedgerBySeq (std::uint32_t index)
{
if (index <= mValidLedgerSeq)
{
// Always prefer a validated ledger
auto valid = mValidLedger.get ();
if (valid)
{
if (valid->getLedgerSeq() == index)
return valid;
try
{
uint256 const& hash = valid->getLedgerHash (index);
if (hash.isNonZero())
return mLedgerHistory.getLedgerByHash (hash);
}
catch (...)
{
// Missing nodes are already handled
}
}
}
Ledger::pointer ret = mLedgerHistory.getLedgerBySeq (index);
if (ret)
return ret;