From 94bc059f87318337e8dfa20f2ca675a0c22c6271 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 20 Jun 2012 13:40:10 -0700 Subject: [PATCH] Fix some mishandling of genesis block close timing. --- src/Ledger.cpp | 10 ++++++++-- src/Ledger.h | 2 ++ src/LedgerConsensus.cpp | 1 + src/ValidationCollection.cpp | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 81e610c33..5549c2343 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -463,12 +463,18 @@ void Ledger::setCloseTime(boost::posix_time::ptime ptm) mCloseTime = iToSeconds(ptm); } +uint64 Ledger::sGenesisClose = 0; + uint64 Ledger::getNextLedgerClose() const { if (mCloseTime == 0) { - uint64 closeTime = theApp->getOPs().getNetworkTimeNC() + mLedgerInterval - 1; - return closeTime - (closeTime % mLedgerInterval); + if (sGenesisClose == 0) + { + uint64 closeTime = theApp->getOPs().getNetworkTimeNC() + mLedgerInterval - 1; + sGenesisClose = closeTime - (closeTime % mLedgerInterval); + } + return sGenesisClose; } return mCloseTime + mLedgerInterval; } diff --git a/src/Ledger.h b/src/Ledger.h index 1f9c8b6c6..598c148b2 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -67,6 +67,8 @@ private: uint16 mLedgerInterval; bool mClosed, mValidHash, mAccepted, mImmutable; + static uint64 sGenesisClose; + SHAMap::pointer mTransactionMap, mAccountStateMap; mutable boost::recursive_mutex mLock; diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index fc6a798c0..30c1b404f 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -824,6 +824,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) if (mValidating) { + assert (theApp->getOPs().getNetworkTimeNC() > newLCL->getCloseTimeNC()); SerializedValidation::pointer v = boost::make_shared (newLCLHash, newLCL->getCloseTimeNC(), mOurPosition->peekSeed(), true); v->setTrusted(); diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index b30ea4a00..59b725f0d 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -15,7 +15,7 @@ bool ValidationCollection::addValidation(SerializedValidation::pointer val) if ((now > valClose) && (now < (valClose + 2 * LEDGER_INTERVAL))) isTrusted = true; else - Log(lsWARNING) << "Received stale validation"; + Log(lsWARNING) << "Received stale validation now=" << now << ", close=" << valClose; } uint256 hash = val->getLedgerHash();