Don't blow up if we have a ledger in the ledger DB but not its root map node in the node DB.

This commit is contained in:
JoelKatz
2013-03-30 19:53:34 -07:00
parent 7ac5f3f34c
commit fbe8823439
2 changed files with 34 additions and 9 deletions

View File

@@ -44,7 +44,8 @@ Ledger::Ledger(const RippleAddress& masterID, uint64 startAmount) : mTotCoins(st
} }
Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash, Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
uint64 totCoins, uint32 closeTime, uint32 parentCloseTime, int closeFlags, int closeResolution, uint32 ledgerSeq) uint64 totCoins, uint32 closeTime, uint32 parentCloseTime,
int closeFlags, int closeResolution, uint32 ledgerSeq, bool& loaded)
: mParentHash(parentHash), mTransHash(transHash), mAccountHash(accountHash), mTotCoins(totCoins), : mParentHash(parentHash), mTransHash(transHash), mAccountHash(accountHash), mTotCoins(totCoins),
mLedgerSeq(ledgerSeq), mCloseTime(closeTime), mParentCloseTime(parentCloseTime), mLedgerSeq(ledgerSeq), mCloseTime(closeTime), mParentCloseTime(parentCloseTime),
mCloseResolution(closeResolution), mCloseFlags(closeFlags), mCloseResolution(closeResolution), mCloseFlags(closeFlags),
@@ -53,10 +54,27 @@ Ledger::Ledger(const uint256 &parentHash, const uint256 &transHash, const uint25
mAccountStateMap(boost::make_shared<SHAMap>(smtSTATE, accountHash)) mAccountStateMap(boost::make_shared<SHAMap>(smtSTATE, accountHash))
{ // This will throw if the root nodes are not available locally { // This will throw if the root nodes are not available locally
updateHash(); updateHash();
loaded = true;
try
{
if (mTransHash.isNonZero()) if (mTransHash.isNonZero())
mTransactionMap->fetchRoot(mTransHash); mTransactionMap->fetchRoot(mTransHash);
}
catch (...)
{
loaded = false;
cLog(lsWARNING) << "Don't have TX root for ledger";
}
try
{
if (mAccountHash.isNonZero()) if (mAccountHash.isNonZero())
mAccountStateMap->fetchRoot(mAccountHash); mAccountStateMap->fetchRoot(mAccountHash);
}
catch (...)
{
loaded = false;
cLog(lsWARNING) << "Don't have AS root for ledger";
}
mTransactionMap->setImmutable(); mTransactionMap->setImmutable();
mAccountStateMap->setImmutable(); mAccountStateMap->setImmutable();
zeroFees(); zeroFees();
@@ -610,8 +628,11 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
} }
// CAUTION: code below appears in two places // CAUTION: code below appears in two places
bool loaded;
Ledger::pointer ret = boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins, Ledger::pointer ret = boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins,
closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq); closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq, loaded);
if (!loaded)
return Ledger::pointer();
ret->setClosed(); ret->setClosed();
if (theApp->getOPs().haveLedger(ledgerSeq)) if (theApp->getOPs().haveLedger(ledgerSeq))
ret->setAccepted(); ret->setAccepted();
@@ -662,8 +683,12 @@ Ledger::pointer Ledger::getSQL1(SqliteStatement *stmt)
ledgerSeq = stmt->getUInt32(9); ledgerSeq = stmt->getUInt32(9);
// CAUTION: code below appears in two places // CAUTION: code below appears in two places
return boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins, bool loaded;
closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq); Ledger::pointer ret = boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins,
closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq, loaded);
if (!loaded)
return Ledger::pointer();
return ret;
} }
void Ledger::getSQL2(Ledger::ref ret) void Ledger::getSQL2(Ledger::ref ret)

View File

@@ -109,7 +109,7 @@ public:
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash, Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
uint64 totCoins, uint32 closeTime, uint32 parentCloseTime, int closeFlags, int closeResolution, uint64 totCoins, uint32 closeTime, uint32 parentCloseTime, int closeFlags, int closeResolution,
uint32 ledgerSeq); // used for database ledgers uint32 ledgerSeq, bool& loaded); // used for database ledgers
Ledger(const std::vector<unsigned char>& rawLedger, bool hasPrefix); Ledger(const std::vector<unsigned char>& rawLedger, bool hasPrefix);
Ledger(const std::string& rawLedger, bool hasPrefix); Ledger(const std::string& rawLedger, bool hasPrefix);