20 #include <ripple/app/ledger/BuildLedger.h>
21 #include <ripple/app/ledger/Ledger.h>
22 #include <ripple/app/ledger/LedgerReplay.h>
23 #include <ripple/app/ledger/OpenLedger.h>
24 #include <ripple/app/main/Application.h>
25 #include <ripple/app/misc/CanonicalTXSet.h>
26 #include <ripple/app/tx/apply.h>
27 #include <ripple/protocol/Feature.h>
37 template <
class ApplyTxs>
42 const bool closeTimeCorrect,
48 auto built = std::make_shared<Ledger>(*parent, closeTime);
55 assert(!accum.
open());
56 applyTxs(accum, built);
60 built->updateSkipList();
65 int const asf = built->stateMap().flushDirty(
67 int const tmf = built->txMap().flushDirty(
69 JLOG(j.
debug()) <<
"Flushed " << asf <<
" accounts and " << tmf
70 <<
" transaction nodes";
76 closeTime, closeResolution, closeTimeCorrect, app.
config());
100 bool certainRetry =
true;
104 for (
int pass = 0; pass < LEDGER_TOTAL_PASSES; ++pass)
107 << (certainRetry ?
"Pass: " :
"Final pass: ") << pass
108 <<
" begins (" << txns.
size() <<
" transactions)";
111 auto it = txns.
begin();
113 while (it != txns.
end())
115 auto const txid = it->first.getTXID();
119 if (pass == 0 && built->
txExists(txid))
126 app, view, *it->second, certainRetry,
tapNONE, j))
144 JLOG(j.
warn()) <<
"Transaction " << txid <<
" throws";
151 << (certainRetry ?
"Pass: " :
"Final pass: ") << pass
152 <<
" completed (" << changes <<
" changes)";
158 if (!changes && !certainRetry)
162 if (!changes || (pass >= LEDGER_RETRY_PASSES))
163 certainRetry =
false;
168 assert(txns.
empty() || !certainRetry);
177 const bool closeTimeCorrect,
184 JLOG(j.
debug()) <<
"Report: Transaction Set = " << txns.
key()
186 << (closeTimeCorrect ?
"" :
" (incorrect)");
189 closeResolution, app, j,
193 <<
"Attempting to apply " << txns.
size()
197 failedTxns, accum, j);
201 <<
"Applied " << applied <<
" transactions; "
202 << failedTxns.
size() <<
" failed and "
203 << txns.
size() <<
" will be retried.";
206 <<
"Applied " << applied
219 auto const& replayLedger = replayData.
replay();
221 JLOG(j.
debug()) <<
"Report: Replay Ledger " << replayLedger->info().hash;
225 replayLedger->info().closeTime,
227 replayLedger->info().closeTimeResolution,
232 for (auto& tx : replayData.orderedTxns())
233 applyTransaction(app, accum, *tx.second, false, applyFlags, j);
uint256 const & key() const
void apply(TxsRawView &to) const
Apply changes.
const_iterator erase(const_iterator const &it)
Writable ledger view that accumulates state and tx changes.
ApplyResult applyTransaction(Application &app, OpenView &view, STTx const &tx, bool retryAssured, ApplyFlags flags, beast::Journal journal)
Transaction application helper.
Holds transactions which were deferred to the next pass of consensus.
const_iterator begin() const
T time_since_epoch(T... args)
std::shared_ptr< Ledger const > const & parent() const
bool txExists(uint256 const &key) const override
Returns true if a tx exists in the tx map.
std::shared_ptr< Ledger > buildLedgerImpl(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, const bool closeTimeCorrect, NetClock::duration closeResolution, Application &app, beast::Journal j, ApplyTxs &&applyTxs)
virtual Config & config()=0
@ Retry
Should be retried in this ledger.
bool open() const override
Returns true if this reflects an open ledger.
A generic endpoint for log messages.
std::shared_ptr< Ledger const > const & replay() const
std::size_t applyTransactions(Application &app, std::shared_ptr< Ledger const > const &built, CanonicalTXSet &txns, std::set< TxID > &failed, OpenView &view, beast::Journal j)
Apply a set of consensus transactions to a ledger.
@ Success
Applied to this ledger.
const_iterator end() const
@ Fail
Should not be retried in this ledger.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::shared_ptr< Ledger > buildLedger(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, const bool closeTimeCorrect, NetClock::duration closeResolution, Application &app, CanonicalTXSet &txns, std::set< TxID > &failedTxs, beast::Journal j)
Build a new ledger by applying consensus transactions.
static const std::uint32_t sLCF_NoConsensusTime