1#include <xrpld/app/ledger/BuildLedger.h>
2#include <xrpld/app/ledger/LedgerReplay.h>
3#include <xrpld/app/ledger/OpenLedger.h>
4#include <xrpld/app/main/Application.h>
6#include <xrpl/ledger/CanonicalTXSet.h>
7#include <xrpl/ledger/Ledger.h>
8#include <xrpl/protocol/Feature.h>
9#include <xrpl/tx/apply.h>
19template <
class ApplyTxs>
24 bool const closeTimeCorrect,
32 if (built->isFlagLedger())
34 built->updateNegativeUNL();
42 XRPL_ASSERT(!accum.
open(),
"xrpl::buildLedgerImpl : valid ledger state");
43 applyTxs(accum, built);
47 built->updateSkipList();
54 JLOG(j.
debug()) <<
"Flushed " << asf <<
" accounts and " << tmf <<
" transaction nodes";
61 "xrpl::buildLedgerImpl : valid ledger fees");
62 built->setAccepted(closeTime, closeResolution, closeTimeCorrect);
86 bool certainRetry =
true;
90 for (
int pass = 0; pass < LEDGER_TOTAL_PASSES; ++pass)
92 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" begins ("
93 << txns.
size() <<
" transactions)";
96 auto it = txns.
begin();
98 while (it != txns.
end())
100 auto const txid = it->first.getTXID();
104 if (pass == 0 && built->txExists(txid))
128 JLOG(j.
warn()) <<
"Transaction " << txid <<
" throws: " << ex.
what();
134 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" completed ("
135 << changes <<
" changes)";
141 if ((changes == 0) && !certainRetry)
145 if ((changes == 0) || (pass >= LEDGER_RETRY_PASSES))
146 certainRetry =
false;
151 XRPL_ASSERT(txns.
empty() || !certainRetry,
"xrpl::applyTransactions : retry transactions");
160 bool const closeTimeCorrect,
167 JLOG(j.
debug()) <<
"Report: Transaction Set = " << txns.
key() <<
", close "
169 << (closeTimeCorrect ?
"" :
" (incorrect)");
179 JLOG(j.
debug()) <<
"Attempting to apply " << txns.
size() <<
" transactions";
185 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions; " << failedTxns.
size()
186 <<
" failed and " << txns.
size() <<
" will be retried. "
187 <<
"Total transactions in ledger (including Inner Batch): "
191 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions. "
192 <<
"Total transactions in ledger (including Inner Batch): "
205 auto const& replayLedger = replayData.
replay();
207 JLOG(j.
debug()) <<
"Report: Replay Ledger " << replayLedger->header().hash;
211 replayLedger->header().closeTime,
213 replayLedger->header().closeTimeResolution,
217 for (auto& tx : replayData.orderedTxns())
218 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.
const_iterator begin() const
const_iterator erase(const_iterator const &it)
const_iterator end() const
uint256 const & key() const
std::shared_ptr< Ledger const > const & replay() const
std::shared_ptr< Ledger const > const & parent() const
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.
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static constexpr std::uint32_t XRP_LEDGER_EARLIEST_FEES
The XRP Ledger mainnet's earliest ledger with a FeeSettings object.
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 std::uint32_t const sLCF_NoConsensusTime
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.
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)