1#include <xrpld/app/ledger/LedgerPersistence.h>
3#include <xrpld/app/ledger/LedgerMaster.h>
5#include <xrpl/basics/Log.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/core/HashRouter.h>
9#include <xrpl/core/Job.h>
10#include <xrpl/core/JobQueue.h>
11#include <xrpl/core/ServiceRegistry.h>
12#include <xrpl/ledger/PendingSaves.h>
13#include <xrpl/ledger/entries/FeeSettingsEntry.h>
14#include <xrpl/protocol/Indexes.h>
15#include <xrpl/protocol/Rules.h>
16#include <xrpl/protocol/SystemParameters.h>
17#include <xrpl/rdb/RelationalDatabase.h>
50 auto const seq = ledger->header().seq;
54 JLOG(j.debug()) <<
"Save aborted";
63 res = db.saveValidatedLedger(ledger, current);
95 JLOG(stream) <<
"Double pend save for " << ledger->header().seq;
105 XRPL_ASSERT(ledger->isImmutable(),
"xrpl::pendSaveValidated : immutable ledger");
110 JLOG(stream) <<
"Pend save with seq in pending saves " << ledger->header().seq;
116 if (!isSynchronous &&
120 [®istry, ledger,
isCurrent] { saveValidatedLedger(registry, ledger, isCurrent); }))
168 "xrpl::finishLoadByIndexOrHash : valid ledger fees");
170 if (!ledger->setImmutable())
173 JLOG(j.
error()) <<
"Invalid map for ledger " << ledger->header().seq
174 <<
"; not marking it as loaded";
175 UNREACHABLE(
"xrpl::finishLoadByIndexOrHash : map is invalid");
182 JLOG(j.
trace()) <<
"Loaded ledger: " <<
to_string(ledger->header().hash);
193 return {
loadLedgerHelper(*info, rules, fees, registry,
true), info->seq, info->hash};
228 !ledger || ledger->header().hash == ledgerHash,
229 "xrpl::loadByHash : ledger hash match if loaded");
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
bool setFlags(UInt256 const &key, HashRouterFlags flags)
Set the flags on a hash.
bool clearFlags(UInt256 const &key, HashRouterFlags flags)
Clear flags on a hash.
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
void clearLedger(std::uint32_t seq)
Marks a ledger no longer resident.
void finishWork(LedgerIndex seq)
Finish working on a ledger.
bool shouldWork(LedgerIndex seq, bool isSynchronous)
Check if a ledger should be dispatched.
bool startWork(LedgerIndex seq)
Start working on a ledger.
bool pending(LedgerIndex seq)
Return true if a ledger is in the progress of being saved.
virtual std::optional< LedgerHeader > getNewestLedgerInfo()=0
getNewestLedgerInfo Returns the info of the newest saved ledger.
virtual std::optional< LedgerHeader > getLedgerInfoByHash(UInt256 const &ledgerHash)=0
getLedgerInfoByHash Returns the info of the ledger with given hash.
virtual std::optional< LedgerHeader > getLedgerInfoByIndex(LedgerIndex ledgerSeq)=0
getLedgerInfoByIndex Returns a ledger by its sequence.
Rules controlling protocol behavior.
Service registry for dependency injection.
virtual PendingSaves & getPendingSaves()=0
virtual JobQueue & getJobQueue()=0
virtual RelationalDatabase & getRelationalDatabase()=0
virtual beast::Journal getJournal(std::string const &name)=0
virtual LedgerMaster & getLedgerMaster()=0
virtual HashRouter & getHashRouter()=0
virtual Family & getNodeFamily()=0
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isCurrent(ValidationParms const &p, NetClock::time_point now, NetClock::time_point signTime, NetClock::time_point seenTime)
Whether a validation is still current.
std::tuple< std::shared_ptr< Ledger >, std::uint32_t, UInt256 > getLatestLedger(Rules const &rules, Fees const &fees, ServiceRegistry ®istry)
Fetch the ledger with the highest sequence contained in the database.
bool pendSaveValidated(ServiceRegistry ®istry, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger.
std::shared_ptr< Ledger > loadLedgerHelper(LedgerHeader const &info, Rules const &rules, Fees const &fees, ServiceRegistry ®istry, bool acquire)
Make ledger using info loaded from database.
static void finishLoadByIndexOrHash(std::shared_ptr< Ledger > &ledger, beast::Journal j)
Settle a ledger just loaded from local storage, or discard it.
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Rules const &rules, Fees const &fees, ServiceRegistry ®istry, bool acquire)
Load a ledger by its sequence number.
std::string to_string(BaseUInt< Bits, Tag > const &a)
static constexpr std::uint32_t kXrpLedgerEarliestFees
The XRP Ledger mainnet's earliest ledger with a FeeSettings object.
static bool saveValidatedLedger(ServiceRegistry ®istry, std::shared_ptr< Ledger const > const &ledger, bool current)
Save a validated ledger to the relational database, once.
std::shared_ptr< Ledger > loadByHash(UInt256 const &ledgerHash, Rules const &rules, Fees const &fees, ServiceRegistry ®istry, bool acquire)
Load a ledger by its hash.
FeeSettingsEntry< ReadView > FeeSettingsEntryR
Reflects the fee settings for a particular ledger.