ledgerhash getledgerhash(ledger::pointer ledger, ledgerindex index) { ledgerhash hash; try { hash = ledger->getledgerhash(index); } catch (shamapmissingnode &) { m_journal.warning << "node missing from ledger " << ledger->getledgerseq(); getapp().getinboundledgers().findcreate ( ledger->gethash(), ledger->getledgerseq(), inboundledger::fcgeneric); } return hash; }
/** returns the hash of the specified ledger. @param ledgerindex the index of the desired ledger. @param referenceledger [out] an optional known good subsequent ledger. @return the hash of the ledger. this will be all-bits-zero if not found. */ ledgerhash gethash( ledgerindex const& ledgerindex, ledger::pointer& referenceledger) { ledgerhash ledgerhash; if (!referenceledger || (referenceledger->getledgerseq() < ledgerindex)) { referenceledger = getapp().getledgermaster().getvalidatedledger(); if (!referenceledger) { m_journal.warning << "no validated ledger"; return ledgerhash; // nothing we can do. no validated ledger. } } if (referenceledger->getledgerseq() >= ledgerindex) { // see if the hash for the ledger we need is in the reference ledger ledgerhash = getledgerhash(referenceledger, ledgerindex); if (ledgerhash.iszero()) { // no, try to get another ledger that might have the hash we need // compute the index and hash of a ledger that will have the hash we need ledgerindex refindex = (ledgerindex + 255) & (~255); ledgerhash refhash = getledgerhash (referenceledger, refindex); bool const nonzero (refhash.isnonzero ()); assert (nonzero); if (nonzero) { // we found the hash and sequence of a better reference ledger referenceledger = getapp().getledgermaster().findacquireledger (refindex, refhash); if (referenceledger) ledgerhash = getledgerhash(referenceledger, ledgerindex); } } } else m_journal.warning << "validated ledger is prior to target ledger"; return ledgerhash; }