mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 23:15:52 +00:00
Use the new OpenView/OpenLedger classes
The server's open ledger is now an instance of the OpenView class, managed by an instance of the OpenLedger class. This should improve the performance of operations on open ledgers because they are no longer Ledger/SHAMap operation.
This commit is contained in:
@@ -722,8 +722,7 @@ void LedgerConsensusImp::timerEntry ()
|
||||
void LedgerConsensusImp::statePreClose ()
|
||||
{
|
||||
// it is shortly before ledger close time
|
||||
bool anyTransactions = ledgerMaster_.getCurrentLedger ()
|
||||
->txMap ().getHash ().isNonZero ();
|
||||
bool anyTransactions = ! getApp().openLedger().empty();
|
||||
int proposersClosed = mPeerPositions.size ();
|
||||
int proposersValidated
|
||||
= app_.getValidations ().getTrustedValidationCount
|
||||
@@ -1002,7 +1001,7 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
<< ", close " << closeTime << (closeTimeCorrect ? "" : "X");
|
||||
|
||||
// Put failed transactions into a deterministic order
|
||||
CanonicalTXSet retriableTransactions (set->getHash ());
|
||||
CanonicalTXSet retriableTxs (set->getHash ());
|
||||
|
||||
// Build the new last closed ledger
|
||||
auto newLCL = std::make_shared<Ledger>(
|
||||
@@ -1020,20 +1019,14 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
OpenView accum(&*newLCL);
|
||||
assert(accum.closed());
|
||||
applyTransactions (app_, set.get(), accum,
|
||||
newLCL, retriableTransactions, tapNONE);
|
||||
newLCL, retriableTxs, tapNONE);
|
||||
accum.apply(*newLCL);
|
||||
}
|
||||
|
||||
// retriableTransactions will include any transactions that
|
||||
// retriableTxs will include any transactions that
|
||||
// made it into the consensus set but failed during application
|
||||
// to the ledger.
|
||||
|
||||
// Make a copy for OpenLedger
|
||||
#if RIPPLE_OPEN_LEDGER
|
||||
CanonicalTXSet retries =
|
||||
retriableTransactions;
|
||||
#endif
|
||||
|
||||
newLCL->updateSkipList ();
|
||||
|
||||
int asf = newLCL->stateMap().flushDirty (
|
||||
@@ -1144,12 +1137,7 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
|
||||
auto txn = std::make_shared<STTx>(sit);
|
||||
|
||||
retriableTransactions.insert (txn);
|
||||
|
||||
// For OpenLedger
|
||||
#if RIPPLE_OPEN_LEDGER
|
||||
retries.insert(txn);
|
||||
#endif
|
||||
retriableTxs.insert (txn);
|
||||
|
||||
anyDisputes = true;
|
||||
}
|
||||
@@ -1161,12 +1149,6 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
}
|
||||
}
|
||||
|
||||
if (anyDisputes)
|
||||
{
|
||||
applyTransactions (app_, nullptr, accum,
|
||||
newLCL, retriableTransactions, tapNONE);
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = beast::make_lock(
|
||||
app_.getMasterMutex(), std::defer_lock);
|
||||
@@ -1177,26 +1159,6 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
auto const localTx = m_localTX.getTxSet();
|
||||
auto const oldOL = ledgerMaster_.getCurrentLedger();
|
||||
|
||||
#if RIPPLE_OPEN_LEDGER
|
||||
app_.openLedger().verify(*oldOL, "consensus before");
|
||||
#endif
|
||||
if (oldOL->txMap().getHash().isNonZero ())
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerConsensus)
|
||||
<< "Applying transactions from current open ledger";
|
||||
applyTransactions (app_, &oldOL->txMap(), accum,
|
||||
newLCL, retriableTransactions, tapNONE);
|
||||
}
|
||||
for (auto const& item : localTx)
|
||||
apply (app_, accum, *item.second, tapNONE,
|
||||
app_.getHashRouter().sigVerify(),
|
||||
getConfig(), deprecatedLogs().
|
||||
journal("LedgerConsensus"));
|
||||
accum.apply(*newOL);
|
||||
// We have a new Last Closed Ledger and new Open Ledger
|
||||
ledgerMaster_.pushLedger (newLCL, newOL);
|
||||
|
||||
#if RIPPLE_OPEN_LEDGER
|
||||
auto const lastVal =
|
||||
app_.getLedgerMaster().getValidatedLedger();
|
||||
boost::optional<Rules> rules;
|
||||
@@ -1204,16 +1166,18 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
rules.emplace(*lastVal);
|
||||
else
|
||||
rules.emplace();
|
||||
app_.openLedger().accept(*rules,
|
||||
newLCL, localTx, anyDisputes, retries, tapNONE,
|
||||
app_.openLedger().accept(app_, *rules,
|
||||
newLCL, localTx, anyDisputes, retriableTxs, tapNONE,
|
||||
app_.getHashRouter(), "consensus");
|
||||
app_.openLedger().verify(*newOL, "consensus after");
|
||||
#endif
|
||||
}
|
||||
|
||||
mNewLedgerHash = newLCL->getHash ();
|
||||
ledgerMaster_.switchLCL (newLCL);
|
||||
state_ = State::accepted;
|
||||
|
||||
assert (ledgerMaster_.getClosedLedger()->getHash() == newLCL->getHash());
|
||||
assert (getApp().openLedger().current()->info().parentHash == newLCL->getHash());
|
||||
|
||||
if (mValidating)
|
||||
{
|
||||
// see how close our close time is to other node's
|
||||
@@ -1433,25 +1397,34 @@ void LedgerConsensusImp::statusChange (
|
||||
WriteLog (lsTRACE, LedgerConsensus) << "send status change to peer";
|
||||
}
|
||||
|
||||
void LedgerConsensusImp::takeInitialPosition (Ledger& initialLedger)
|
||||
void LedgerConsensusImp::takeInitialPosition (
|
||||
std::shared_ptr<ReadView const> const& initialLedger)
|
||||
{
|
||||
std::shared_ptr<SHAMap> initialSet;
|
||||
std::shared_ptr<SHAMap> initialSet = std::make_shared <SHAMap> (
|
||||
SHAMapType::TRANSACTION, getApp().family(), deprecatedLogs().journal("SHAMap"));
|
||||
|
||||
// Build SHAMap containing all transactions in our open ledger
|
||||
for (auto const& tx : initialLedger->txs)
|
||||
{
|
||||
Serializer s (2048);
|
||||
tx.first->add(s);
|
||||
initialSet->addItem (
|
||||
SHAMapItem (tx.first->getTransactionID(), std::move (s)), true, false);
|
||||
}
|
||||
|
||||
if ((getConfig ().RUN_STANDALONE || (mProposing && mHaveCorrectLCL))
|
||||
&& ((mPreviousLedger->info().seq % 256) == 0))
|
||||
{
|
||||
// previous ledger was flag ledger
|
||||
std::shared_ptr<SHAMap> preSet
|
||||
= initialLedger.txMap().snapShot (true);
|
||||
ValidationSet parentSet = app_.getValidations().getValidations (
|
||||
// previous ledger was flag ledger, add pseudo-transactions
|
||||
ValidationSet parentSet = getApp().getValidations().getValidations (
|
||||
mPreviousLedger->info().parentHash);
|
||||
m_feeVote.doVoting (mPreviousLedger, parentSet, preSet);
|
||||
m_feeVote.doVoting (mPreviousLedger, parentSet, initialSet);
|
||||
app_.getAmendmentTable ().doVoting (
|
||||
mPreviousLedger, parentSet, preSet);
|
||||
initialSet = preSet->snapShot (false);
|
||||
mPreviousLedger, parentSet, initialSet);
|
||||
}
|
||||
else
|
||||
initialSet = initialLedger.txMap().snapShot (false);
|
||||
|
||||
// Set should be immutable snapshot
|
||||
initialSet = initialSet->snapShot (false);
|
||||
|
||||
// Tell the ledger master not to acquire the ledger we're probably building
|
||||
ledgerMaster_.setBuildingLedger (mPreviousLedger->info().seq + 1);
|
||||
@@ -1461,11 +1434,11 @@ void LedgerConsensusImp::takeInitialPosition (Ledger& initialLedger)
|
||||
mapCompleteInternal (txSet, initialSet, false);
|
||||
|
||||
mOurPosition = std::make_shared<LedgerProposal>
|
||||
(mValPublic, initialLedger.info().parentHash, txSet, mCloseTime);
|
||||
(mValPublic, initialLedger->info().parentHash, txSet, mCloseTime);
|
||||
|
||||
for (auto& it : mDisputes)
|
||||
{
|
||||
it.second->setOurVote (initialLedger.txExists(it.first));
|
||||
it.second->setOurVote (initialLedger->txExists (it.first));
|
||||
}
|
||||
|
||||
// if any peers have taken a contrary position, process disputes
|
||||
@@ -1710,7 +1683,7 @@ void LedgerConsensusImp::closeLedger ()
|
||||
consensus_.setLastCloseTime (mCloseTime);
|
||||
statusChange (protocol::neCLOSING_LEDGER, *mPreviousLedger);
|
||||
ledgerMaster_.applyHeldTransactions ();
|
||||
takeInitialPosition (*ledgerMaster_.getCurrentLedger ());
|
||||
takeInitialPosition (getApp().openLedger().current());
|
||||
}
|
||||
|
||||
void LedgerConsensusImp::checkOurValidation ()
|
||||
@@ -1875,7 +1848,7 @@ void applyTransactions (
|
||||
SHAMap const* set,
|
||||
OpenView& view,
|
||||
Ledger::ref checkLedger,
|
||||
CanonicalTXSet& retriableTransactions,
|
||||
CanonicalTXSet& retriableTxs,
|
||||
ApplyFlags flags)
|
||||
{
|
||||
if (set)
|
||||
@@ -1905,7 +1878,7 @@ void applyTransactions (
|
||||
{
|
||||
// On failure, stash the failed transaction for
|
||||
// later retry.
|
||||
retriableTransactions.insert (txn);
|
||||
retriableTxs.insert (txn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1916,13 +1889,13 @@ void applyTransactions (
|
||||
for (int pass = 0; pass < LEDGER_TOTAL_PASSES; ++pass)
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerConsensus) << "Pass: " << pass << " Txns: "
|
||||
<< retriableTransactions.size ()
|
||||
<< retriableTxs.size ()
|
||||
<< (certainRetry ? " retriable" : " final");
|
||||
int changes = 0;
|
||||
|
||||
auto it = retriableTransactions.begin ();
|
||||
auto it = retriableTxs.begin ();
|
||||
|
||||
while (it != retriableTransactions.end ())
|
||||
while (it != retriableTxs.end ())
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -1930,12 +1903,12 @@ void applyTransactions (
|
||||
it->second, certainRetry, flags))
|
||||
{
|
||||
case LedgerConsensusImp::resultSuccess:
|
||||
it = retriableTransactions.erase (it);
|
||||
it = retriableTxs.erase (it);
|
||||
++changes;
|
||||
break;
|
||||
|
||||
case LedgerConsensusImp::resultFail:
|
||||
it = retriableTransactions.erase (it);
|
||||
it = retriableTxs.erase (it);
|
||||
break;
|
||||
|
||||
case LedgerConsensusImp::resultRetry:
|
||||
@@ -1946,7 +1919,7 @@ void applyTransactions (
|
||||
{
|
||||
WriteLog (lsWARNING, LedgerConsensus)
|
||||
<< "Transaction throws";
|
||||
it = retriableTransactions.erase (it);
|
||||
it = retriableTxs.erase (it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1964,7 +1937,7 @@ void applyTransactions (
|
||||
|
||||
// If there are any transactions left, we must have
|
||||
// tried them in at least one final pass
|
||||
assert (retriableTransactions.empty() || !certainRetry);
|
||||
assert (retriableTxs.empty() || !certainRetry);
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
Reference in New Issue
Block a user