1#include <xrpld/app/ledger/BuildLedger.h>
3#include <xrpld/app/ledger/LedgerReplay.h>
4#include <xrpld/app/ledger/OpenLedger.h>
5#include <xrpld/app/main/Application.h>
7#include <xrpl/basics/Log.h>
8#include <xrpl/basics/chrono.h>
9#include <xrpl/beast/utility/Journal.h>
10#include <xrpl/beast/utility/instrumentation.h>
11#include <xrpl/ledger/ApplyView.h>
12#include <xrpl/ledger/CanonicalTXSet.h>
13#include <xrpl/ledger/Ledger.h>
14#include <xrpl/ledger/OpenView.h>
15#include <xrpl/ledger/entries/FeeSettingsEntry.h>
16#include <xrpl/nodestore/NodeObject.h>
17#include <xrpl/protocol/Indexes.h>
18#include <xrpl/protocol/LedgerHeader.h>
19#include <xrpl/protocol/Protocol.h>
20#include <xrpl/protocol/SystemParameters.h>
21#include <xrpl/protocol/TxFlags.h>
22#include <xrpl/tx/apply.h>
37template <
class ApplyTxs>
38std::shared_ptr<Ledger>
42 bool const closeTimeCorrect,
50 if (built->isFlagLedger())
52 built->updateNegativeUNL();
60 XRPL_ASSERT(!accum.
open(),
"xrpl::buildLedgerImpl : valid ledger state");
61 applyTxs(accum, built);
65 built->updateSkipList();
72 JLOG(j.
debug()) <<
"Flushed " << asf <<
" accounts and " << tmf <<
" transaction nodes";
79 "xrpl::buildLedgerImpl : valid ledger fees");
80 built->setAccepted(closeTime, closeResolution, closeTimeCorrect);
105 bool certainRetry =
true;
109 for (
int pass = 0; pass < LEDGER_TOTAL_PASSES; ++pass)
111 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" begins ("
112 << txns.
size() <<
" transactions)";
115 auto it = txns.
begin();
117 while (it != txns.
end())
119 auto const txid = it->first.getTXID();
123 if (pass == 0 && built->txExists(txid))
147 JLOG(j.
warn()) <<
"Transaction " << txid <<
" throws: " << ex.
what();
153 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" completed ("
154 << changes <<
" changes)";
160 if ((changes == 0) && !certainRetry)
164 if ((changes == 0) || (pass >= LEDGER_RETRY_PASSES))
165 certainRetry =
false;
170 XRPL_ASSERT(txns.
empty() || !certainRetry,
"xrpl::applyTransactions : retry transactions");
179 bool const closeTimeCorrect,
186 JLOG(j.
debug()) <<
"Report: Transaction Set = " << txns.
key() <<
", close "
188 << (closeTimeCorrect ?
"" :
" (incorrect)");
198 JLOG(j.
debug()) <<
"Attempting to apply " << txns.
size() <<
" transactions";
204 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions; " << failedTxns.
size()
205 <<
" failed and " << txns.
size() <<
" will be retried. "
206 <<
"Total transactions in ledger (including Inner Batch): "
211 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions. "
212 <<
"Total transactions in ledger (including Inner Batch): "
226 auto const& replayLedger = replayData.
replay();
228 JLOG(j.
debug()) <<
"Report: Replay Ledger " << replayLedger->header().hash;
232 replayLedger->header().closeTime,
234 replayLedger->header().closeTimeResolution,
238 for (auto& tx : replayData.orderedTxns())
244 if (tx.second->isFlag(tfInnerBatchTxn))
246 applyTransaction(app, accum, *tx.second, false, applyFlags, j);
A generic endpoint for log messages.
Holds transactions which were deferred to the next pass of consensus.
UInt256 const & key() const
const_iterator begin() const
const_iterator erase(const_iterator const &it)
const_iterator end() const
std::shared_ptr< Ledger const > const & replay() const
std::shared_ptr< Ledger const > const & parent() const
std::chrono::time_point< NetClock > time_point
std::chrono::duration< rep, period > duration
Writable ledger view that accumulates state and tx changes.
std::size_t txCount() const
Return the number of tx inserted since creation.
bool open() const override
Returns true if this reflects an open ledger.
void apply(TxsRawView &to) const
Apply changes.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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.
ApplyTransactionResult applyTransaction(ServiceRegistry ®istry, OpenView &view, STTx const &tx, bool retryAssured, ApplyFlags flags, beast::Journal journal)
Transaction application helper.
@ Success
Applied to this ledger.
@ Retry
Should be retried in this ledger.
@ Fail
Should not be retried in this ledger.
static constexpr std::uint32_t kXrpLedgerEarliestFees
The XRP Ledger mainnet's earliest ledger with a FeeSettings object.
std::shared_ptr< Ledger > buildLedger(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, bool const closeTimeCorrect, NetClock::duration closeResolution, Application &app, CanonicalTXSet &txns, std::set< TxID > &failedTxs, beast::Journal j)
Build a new ledger by applying consensus transactions.
static std::uint32_t const kSLcfNoConsensusTime
FeeSettingsEntry< ReadView > FeeSettingsEntryR
std::shared_ptr< Ledger > buildLedgerImpl(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, bool const closeTimeCorrect, NetClock::duration closeResolution, Application &app, beast::Journal j, ApplyTxs &&applyTxs)
T time_since_epoch(T... args)