Fix some cases where ledger flags are incorrectly set.

This commit is contained in:
JoelKatz
2013-02-01 16:11:32 -08:00
parent db7e69164b
commit 9781c10736
8 changed files with 44 additions and 14 deletions

View File

@@ -113,14 +113,31 @@ Ledger::Ledger(const std::string& rawLedger, bool hasPrefix) :
zeroFees();
}
void Ledger::setImmutable()
{
if (!mImmutable)
{
updateHash();
mImmutable = true;
if (mTransactionMap)
mTransactionMap->setImmutable();
if (mAccountStateMap)
mAccountStateMap->setImmutable();
}
}
void Ledger::updateHash()
{
if (!mImmutable)
{
if (mTransactionMap) mTransHash = mTransactionMap->getHash();
else mTransHash.zero();
if (mAccountStateMap) mAccountHash = mAccountStateMap->getHash();
else mAccountHash.zero();
if (mTransactionMap)
mTransHash = mTransactionMap->getHash();
else
mTransHash.zero();
if (mAccountStateMap)
mAccountHash = mAccountStateMap->getHash();
else
mAccountHash.zero();
}
Serializer s(118);
@@ -170,18 +187,17 @@ void Ledger::setAccepted(uint32 closeTime, int closeResolution, bool correctClos
mCloseTime = correctCloseTime ? (closeTime - (closeTime % closeResolution)) : closeTime;
mCloseResolution = closeResolution;
mCloseFlags = correctCloseTime ? 0 : sLCF_NoConsensusTime;
updateHash();
mAccepted = true;
mImmutable = true;
setImmutable();
}
void Ledger::setAccepted()
{ // used when we acquired the ledger
// FIXME assert(mClosed && (mCloseTime != 0) && (mCloseResolution != 0));
mCloseTime -= mCloseTime % mCloseResolution;
updateHash();
if ((mCloseFlags & sLCF_NoConsensusTime) == 0)
mCloseTime -= mCloseTime % mCloseResolution;
mAccepted = true;
mImmutable = true;
setImmutable();
}
AccountState::pointer Ledger::getAccountState(const RippleAddress& accountID)
@@ -527,6 +543,8 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
Ledger::pointer ret = boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins,
closingTime, prevClosingTime, closeFlags, closeResolution, ledgerSeq);
ret->setClosed();
if (theApp->getOPs().haveLedger(ledgerSeq))
ret->setAccepted();
if (ret->getHash() != ledgerHash)
{
if (sLog(lsERROR))

View File

@@ -124,7 +124,7 @@ public:
void setClosed() { mClosed = true; }
void setAccepted(uint32 closeTime, int closeResolution, bool correctCloseTime);
void setAccepted();
void setImmutable() { updateHash(); mImmutable = true; }
void setImmutable();
bool isClosed() { return mClosed; }
bool isAccepted() { return mAccepted; }
bool isImmutable() { return mImmutable; }

View File

@@ -160,6 +160,7 @@ bool LedgerAcquire::tryLocal()
{
cLog(lsDEBUG) << "Had everything locally";
mComplete = true;
mLedger->setClosed();
}
return mComplete;
@@ -244,11 +245,9 @@ void LedgerAcquire::done()
if (isComplete() && !isFailed() && mLedger)
{
mLedger->setClosed();
if (mAccept)
{
mLedger->setClosed();
mLedger->setAccepted();
}
theApp->getLedgerMaster().storeLedger(mLedger);
}
else

View File

@@ -82,7 +82,7 @@ Ledger::pointer LedgerHistory::getLedgerByHash(const uint256& hash)
if (ret)
{
assert(ret->isImmutable());
assert(ret->getHash() == hash);
assert(ret->getHash() == hash); // FIXME: We seem to be getting these
return ret;
}

View File

@@ -133,6 +133,12 @@ bool LedgerMaster::haveLedgerRange(uint32 from, uint32 to)
return (prevMissing == RangeSet::RangeSetAbsent) || (prevMissing < from);
}
bool LedgerMaster::haveLedger(uint32 seq)
{
boost::recursive_mutex::scoped_lock sl(mLock);
return mCompleteLedgers.hasValue(seq);
}
void LedgerMaster::asyncAccept(Ledger::pointer ledger)
{
uint32 seq = ledger->getLedgerSeq();

View File

@@ -126,6 +126,7 @@ public:
void fixMismatch(Ledger::ref ledger);
bool haveLedgerRange(uint32 from, uint32 to);
bool haveLedger(uint32 seq);
void resumeAcquiring();

View File

@@ -113,6 +113,11 @@ bool NetworkOPs::haveLedgerRange(uint32 from, uint32 to)
return mLedgerMaster->haveLedgerRange(from, to);
}
bool NetworkOPs::haveLedger(uint32 seq)
{
return mLedgerMaster->haveLedger(seq);
}
bool NetworkOPs::addWantedHash(const uint256& h)
{
boost::recursive_mutex::scoped_lock sl(mWantedHashLock);

View File

@@ -150,6 +150,7 @@ public:
// Do we have this inclusive range of ledgers in our database
bool haveLedgerRange(uint32 from, uint32 to);
bool haveLedger(uint32 seq);
SerializedValidation::ref getLastValidation() { return mLastValidation; }
void setLastValidation(SerializedValidation::ref v) { mLastValidation = v; }