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/nodestore/NodeObject.h>
16#include <xrpl/protocol/Indexes.h>
17#include <xrpl/protocol/LedgerHeader.h>
18#include <xrpl/protocol/Protocol.h>
19#include <xrpl/protocol/SystemParameters.h>
20#include <xrpl/tx/apply.h>
35template <
class ApplyTxs>
36std::shared_ptr<Ledger>
40 bool const closeTimeCorrect,
48 if (built->isFlagLedger())
50 built->updateNegativeUNL();
58 XRPL_ASSERT(!accum.
open(),
"xrpl::buildLedgerImpl : valid ledger state");
59 applyTxs(accum, built);
63 built->updateSkipList();
70 JLOG(j.
debug()) <<
"Flushed " << asf <<
" accounts and " << tmf <<
" transaction nodes";
77 "xrpl::buildLedgerImpl : valid ledger fees");
78 built->setAccepted(closeTime, closeResolution, closeTimeCorrect);
102 bool certainRetry =
true;
106 for (
int pass = 0; pass < LEDGER_TOTAL_PASSES; ++pass)
108 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" begins ("
109 << txns.
size() <<
" transactions)";
112 auto it = txns.
begin();
114 while (it != txns.
end())
116 auto const txid = it->first.getTXID();
120 if (pass == 0 && built->txExists(txid))
144 JLOG(j.
warn()) <<
"Transaction " << txid <<
" throws: " << ex.
what();
150 JLOG(j.
debug()) << (certainRetry ?
"Pass: " :
"Final pass: ") << pass <<
" completed ("
151 << changes <<
" changes)";
157 if ((changes == 0) && !certainRetry)
161 if ((changes == 0) || (pass >= LEDGER_RETRY_PASSES))
162 certainRetry =
false;
167 XRPL_ASSERT(txns.
empty() || !certainRetry,
"xrpl::applyTransactions : retry transactions");
176 bool const closeTimeCorrect,
183 JLOG(j.
debug()) <<
"Report: Transaction Set = " << txns.
key() <<
", close "
185 << (closeTimeCorrect ?
"" :
" (incorrect)");
195 JLOG(j.
debug()) <<
"Attempting to apply " << txns.
size() <<
" transactions";
201 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions; " << failedTxns.
size()
202 <<
" failed and " << txns.
size() <<
" will be retried. "
203 <<
"Total transactions in ledger (including Inner Batch): "
208 JLOG(j.
debug()) <<
"Applied " << applied <<
" transactions. "
209 <<
"Total transactions in ledger (including Inner Batch): "
223 auto const& replayLedger = replayData.
replay();
225 JLOG(j.
debug()) <<
"Report: Replay Ledger " << replayLedger->header().hash;
229 replayLedger->header().closeTime,
231 replayLedger->header().closeTimeResolution,
235 for (auto& tx : replayData.orderedTxns())
236 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
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.
Keylet const & feeSettings() 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.
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
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)