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/basics/contract.h>
10#include <xrpl/beast/utility/Journal.h>
11#include <xrpl/beast/utility/instrumentation.h>
12#include <xrpl/ledger/ApplyView.h>
13#include <xrpl/ledger/CanonicalTXSet.h>
14#include <xrpl/ledger/Ledger.h>
15#include <xrpl/ledger/OpenView.h>
16#include <xrpl/ledger/entries/FeeSettingsEntry.h>
17#include <xrpl/nodestore/NodeObject.h>
18#include <xrpl/protocol/Indexes.h>
19#include <xrpl/protocol/LedgerHeader.h>
20#include <xrpl/protocol/Protocol.h>
21#include <xrpl/protocol/SystemParameters.h>
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/tx/apply.h>
38template <
class ApplyTxs>
39std::shared_ptr<Ledger>
43 bool const closeTimeCorrect,
51 if (built->isFlagLedger())
53 built->updateNegativeUNL();
61 XRPL_ASSERT(!accum.
open(),
"xrpl::buildLedgerImpl : valid ledger state");
62 applyTxs(accum, built);
66 built->updateSkipList();
73 JLOG(j.
debug()) <<
"Flushed " << asf <<
" accounts and " << tmf <<
" transaction nodes";
80 "xrpl::buildLedgerImpl : valid ledger fees");
87 if (!built->setAccepted(closeTime, closeResolution, closeTimeCorrect))
90 logicError(
"buildLedgerImpl: accepted ledger map is invalid");
117 bool certainRetry =
true;
121 for (
int pass = 0; pass < LEDGER_TOTAL_PASSES; ++pass)
123 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" begins ("
124 << txns.
size() <<
" transactions)";
127 auto it = txns.
begin();
129 while (it != txns.
end())
131 auto const txid = it->first.getTXID();
135 if (pass == 0 && built->txExists(txid))
159 JLOG(j.
warn()) <<
"Transaction " << txid <<
" throws: " << ex.
what();
165 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" completed ("
166 << changes <<
" changes)";
172 if ((changes == 0) && !certainRetry)
176 if ((changes == 0) || (pass >= LEDGER_RETRY_PASSES))
177 certainRetry =
false;
182 XRPL_ASSERT(txns.
empty() || !certainRetry,
"xrpl::applyTransactions : retry transactions");
191 bool const closeTimeCorrect,
198 JLOG(j.
debug()) <<
"Report: Transaction Set = " << txns.
key() <<
", close "
200 << (closeTimeCorrect ?
"" :
" (incorrect)");
210 JLOG(j.
debug()) <<
"Attempting to apply " << txns.
size() <<
" transactions";
216 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions; " << failedTxns.
size()
217 <<
" failed and " << txns.
size() <<
" will be retried. "
218 <<
"Total transactions in ledger (including Inner Batch): "
223 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions. "
224 <<
"Total transactions in ledger (including Inner Batch): "
238 auto const& replayLedger = replayData.
replay();
240 JLOG(j.
debug()) <<
"Report: Replay Ledger " << replayLedger->header().hash;
244 replayLedger->header().closeTime,
246 replayLedger->header().closeTimeResolution,
250 for (auto& tx : replayData.orderedTxns())
256 if (tx.second->isFlag(tfInnerBatchTxn))
258 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.
void logicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
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)