Improve ledger replay logic

Build a replay structure holding the transactions
in execution order along with the close time. Use
this structure when replaying a ledger close.
This commit is contained in:
JoelKatz
2015-09-03 10:51:16 -07:00
committed by Nik Bougalis
parent 0c7a7903b6
commit 8f09d3449d
5 changed files with 85 additions and 18 deletions

View File

@@ -970,8 +970,21 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
consensus_.peekStoredProposals ().clear ();
}
std::uint32_t closeTime = roundCloseTime (
mOurPosition->getCloseTime (), mCloseResolution);
auto closeTime = mOurPosition->getCloseTime();
auto replay = ledgerMaster_.releaseReplay();
if (replay)
{
// If we're replaying a close, use the time the ledger
// we're replaying closed
closeTime = replay->closeTime_;
if ((replay->closeFlags_ & sLCF_NoConsensusTime) != 0)
closeTime = 0;
}
closeTime = roundCloseTime (closeTime, mCloseResolution);
// If we don't have a close time, then we just agree to disagree
bool const closeTimeCorrect = (closeTime != 0);
@@ -1018,8 +1031,18 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
{
OpenView accum(&*newLCL);
assert(accum.closed());
applyTransactions (app_, set.get(), accum,
newLCL, retriableTxs, tapNONE);
if (replay)
{
// Special case, we are replaying a ledger close
for (auto& tx : replay->txns_)
applyTransaction (accum, tx.second, false, tapNO_CHECK_SIGN);
}
else
{
// Normal case, we are not replaying a ledger close
applyTransactions (app_, set.get(), accum,
newLCL, retriableTxs, tapNONE);
}
accum.apply(*newLCL);
}
@@ -1782,14 +1805,6 @@ make_LedgerConsensus (Application& app, ConsensusImp& consensus, int previousPro
//------------------------------------------------------------------------------
/** Apply a transaction to a ledger
@param engine The transaction engine containing the ledger.
@param txn The transaction to be applied to ledger.
@param retryAssured true if the transaction should be retried on failure.
@return One of resultSuccess, resultFail or resultRetry.
*/
static
int
applyTransaction (Application& app, OpenView& view,
std::shared_ptr<STTx const> const& txn,