Remove a ledger from the set of present ledgers where needed

* If we encounter it in RPC
* If we fully-validate a ledger that doesn't have it in its history
This commit is contained in:
JoelKatz
2015-07-27 14:38:06 -07:00
committed by Nik Bougalis
parent f0dc2bc425
commit cfdf0d2f0a
2 changed files with 22 additions and 0 deletions

View File

@@ -695,6 +695,15 @@ public:
if (isCurrent)
mLedgerHistory.addLedger(ledger, true);
{
// Check the SQL database's entry for the sequence before this ledger,
// if it's not this ledger's parent, invalidate it
uint256 prevHash = Ledger::getHashByIndex (ledger->info().seq - 1);
if (prevHash.isNonZero () && (prevHash != ledger->info().parentHash))
clearLedger (ledger->info().seq - 1);
}
ledger->pendSaveValidated (isSynchronous, isCurrent);
{

View File

@@ -152,8 +152,21 @@ bool isValidated (LedgerMaster& ledgerMaster, ReadView const& ledger)
// comes before the last validated ledger (and thus has been
// validated).
auto hash = ledgerMaster.walkHashBySeq (seq);
if (ledger.info().hash != hash)
{
// This ledger's hash is not the hash of the validated ledger
if (hash.isNonZero ())
{
uint256 valHash = Ledger::getHashByIndex (seq);
if (valHash == ledger.info().hash)
{
// SQL database doesn't match ledger chain
ledgerMaster.clearLedger (seq);
}
}
return false;
}
}
catch (SHAMapMissingNode const&)
{