20#include <xrpld/app/consensus/RCLValidations.h>
21#include <xrpld/app/ledger/Ledger.h>
22#include <xrpld/app/ledger/LedgerMaster.h>
23#include <xrpld/app/ledger/LedgerReplayer.h>
24#include <xrpld/app/ledger/OpenLedger.h>
25#include <xrpld/app/ledger/OrderBookDB.h>
26#include <xrpld/app/ledger/PendingSaves.h>
27#include <xrpld/app/main/Application.h>
28#include <xrpld/app/misc/AmendmentTable.h>
29#include <xrpld/app/misc/HashRouter.h>
30#include <xrpld/app/misc/LoadFeeTrack.h>
31#include <xrpld/app/misc/NetworkOPs.h>
32#include <xrpld/app/misc/SHAMapStore.h>
33#include <xrpld/app/misc/Transaction.h>
34#include <xrpld/app/misc/TxQ.h>
35#include <xrpld/app/misc/ValidatorList.h>
36#include <xrpld/app/paths/PathRequests.h>
37#include <xrpld/app/rdb/RelationalDatabase.h>
38#include <xrpld/app/tx/apply.h>
39#include <xrpld/core/DatabaseCon.h>
40#include <xrpld/core/TimeKeeper.h>
41#include <xrpld/overlay/Overlay.h>
42#include <xrpld/overlay/Peer.h>
43#include <xrpl/basics/Log.h>
44#include <xrpl/basics/MathUtilities.h>
45#include <xrpl/basics/TaggedCache.h>
46#include <xrpl/basics/UptimeClock.h>
47#include <xrpl/basics/contract.h>
48#include <xrpl/basics/safe_cast.h>
49#include <xrpl/basics/scope.h>
50#include <xrpl/beast/utility/instrumentation.h>
51#include <xrpl/protocol/BuildInfo.h>
52#include <xrpl/protocol/HashPrefix.h>
53#include <xrpl/protocol/digest.h>
54#include <xrpl/resource/Fees.h>
84 bool const ret = [&]() {
86 if (candidateLedger >= currentLedger)
90 if (currentLedger - candidateLedger <= ledgerHistory)
95 return minimumOnline.
has_value() && candidateLedger >= *minimumOnline;
98 JLOG(j.
trace()) <<
"Missing ledger " << candidateLedger
99 << (ret ?
" should" :
" should NOT") <<
" be acquired";
110 , mLedgerHistory(collector, app)
111 , standalone_(app_.config().standalone())
113 app_.getSHAMapStore().clampFetchDepth(app_.config().FETCH_DEPTH))
114 , ledger_history_(app_.config().LEDGER_HISTORY)
119 std::chrono::seconds{45},
121 app_.journal(
"TaggedCache"))
146 if (validLedger && !
areCompatible(*validLedger, view, s, reason))
172 using namespace std::chrono_literals;
182 ret = (ret > 0s) ? ret : 0s;
196 using namespace std::chrono_literals;
207 ret = (ret > 0s) ? ret : 0s;
221 using namespace std::chrono_literals;
225 reason =
"No recently-published ledger";
230 if (!validClose || !pubClose)
232 reason =
"No published ledger";
235 if (validClose > (pubClose + 90))
237 reason =
"Published ledger lags validated ledger";
253 l->info().hash, l->info().seq));
254 times.
reserve(validations.size());
255 for (
auto const& val : validations)
258 if (!validations.empty())
259 consensusHash = validations.front()->getConsensusHash();
268 auto const t0 = times[(times.
size() - 1) / 2];
269 auto const t1 = times[times.
size() / 2];
270 signTime = t0 + (t1 - t0) / 2;
274 signTime = l->info().closeTime;
283 "ripple::LedgerMaster::setValidLedger : valid ledger sequence");
296 "activated: server blocked.";
310 if (
auto const first =
314 "reached majority. Upgrade before "
316 <<
" to prevent your server from "
317 "becoming amendment blocked.";
348 XRPL_ASSERT(ledger,
"ripple::LedgerMaster::canBeCurrent : non-null input");
354 if (validLedger && (ledger->info().seq < validLedger->info().seq))
357 <<
"Candidate for current ledger has low seq " << ledger->info().seq
358 <<
" < " << validLedger->info().seq;
368 auto ledgerClose = ledger->info().parentCloseTime;
370 using namespace std::chrono_literals;
371 if ((validLedger || (ledger->info().seq > 10)) &&
376 <<
"Candidate for current ledger has close time "
377 <<
to_string(ledgerClose) <<
" at network time "
378 <<
to_string(closeTime) <<
" seq " << ledger->info().seq;
391 if (closeTime > validLedger->info().parentCloseTime)
392 maxSeq += std::chrono::duration_cast<std::chrono::seconds>(
393 closeTime - validLedger->info().parentCloseTime)
397 if (ledger->info().seq > maxSeq)
400 <<
"Candidate for current ledger has high seq "
401 << ledger->info().seq <<
" > " << maxSeq;
406 <<
"Acceptable seq range: " << validLedger->info().seq
407 <<
" <= " << ledger->info().seq <<
" <= " << maxSeq;
416 XRPL_ASSERT(lastClosed,
"ripple::LedgerMaster::switchLCL : non-null input");
417 if (!lastClosed->isImmutable())
420 if (lastClosed->open())
421 LogicError(
"The new last closed ledger is open!");
448 bool validated = ledger->info().validated;
470 any |= result.applied;
519 auto const seq = ledger.
info().
seq;
527 if (!hash || ledger.
info().
hash != *hash)
534 "ripple::LedgerMaster::isValidated : nonzero hash");
576 if (maybeMin == std::nullopt)
579 minVal = 1 + *maybeMin;
596 if (!pendingSaves.empty() && ((minVal != 0) || (maxVal != 0)))
601 while (pendingSaves.count(maxVal) > 0)
603 while (pendingSaves.count(minVal) > 0)
607 for (
auto v : pendingSaves)
609 if ((v.first >= minVal) && (v.first <= maxVal))
611 if (v.first > ((minVal + maxVal) / 2))
612 maxVal = v.first - 1;
614 minVal = v.first + 1;
644 uint256 prevHash = ledger->info().parentHash;
663 auto it(ledgerHashes.
find(seq));
665 if (it == ledgerHashes.
end())
676 (seq < 500) ? 0 : (seq - 499), seq);
677 it = ledgerHashes.
find(seq);
679 if (it == ledgerHashes.
end())
682 if (!nodeStore.fetchNodeObject(
683 ledgerHashes.
begin()->second.ledgerHash,
684 ledgerHashes.
begin()->first))
688 <<
" mismatches node store";
693 if (it->second.ledgerHash != prevHash)
696 prevHash = it->second.parentHash;
718 if (!haveHash || haveHash->isZero())
721 <<
"No hash for fetch pack. Missing Index " << missing;
731 for (
auto const& peer : peerList)
733 if (peer->hasRange(missing, missing + 1))
735 int score = peer->getScore(
true);
736 if (!target || (score > maxScore))
747 protocol::TMGetObjectByHash tmBH;
748 tmBH.set_query(
true);
749 tmBH.set_type(protocol::TMGetObjectByHash::otFETCH_PACK);
750 tmBH.set_ledgerhash(haveHash->begin(), 32);
751 auto packet = std::make_shared<Message>(tmBH, protocol::mtGET_OBJECTS);
753 target->send(packet);
754 JLOG(
m_journal.
trace()) <<
"Requested fetch pack for " << missing;
777 <<
"fixMismatch encounters partial ledger. Exception: "
788 if (otherLedger && (otherLedger->info().hash == *hash))
794 <<
"Match at " << lSeq <<
", " << invalidate
795 <<
" prior ledgers invalidated";
811 <<
"All " << invalidate <<
" prior ledgers invalidated";
823 <<
" accepted :" << ledger->info().hash;
825 ledger->stateMap().getHash().isNonZero(),
826 "ripple::LedgerMaster::setFullLedger : nonzero ledger state hash");
828 ledger->setValidated();
839 if (prevHash.
isNonZero() && prevHash != ledger->info().parentHash)
861 if (ledger->info().seq != 0 &&
haveLedger(ledger->info().seq - 1))
867 (prevLedger->info().hash != ledger->info().parentHash))
870 <<
"Acquired ledger invalidates previous ledger: "
871 << (prevLedger ?
"hashMismatch" :
"missingLedger");
900 valCount = validations.size();
966 ledger->info().hash, ledger->info().seq));
967 auto const tvc = validations.size();
971 <<
"Only " << tvc <<
" validations for " << ledger->info().hash;
976 << ledger->info().seq <<
" with >= " << minVal
979 ledger->setValidated();
994 fees.reserve(fees.size() + fees2.size());
1004 s <<
"Received fees from validations: (" << fees.size() <<
") ";
1005 for (
auto const fee1 : fees)
1011 fee = fees[fees.size() / 2];
1022 if (ledger->seq() % 256 == 0)
1033 bool needPrint =
false;
1041 ledger->info().parentHash, ledger->info().seq - 1);
1044 for (
auto const& v : vals)
1046 if (v->isFieldPresent(sfServerVersion))
1048 auto version = v->getFieldU64(sfServerVersion);
1049 higherVersionCount +=
1059 if (higherVersionCount > 0 && rippledCount > 0)
1065 needPrint = unlSize > 0 &&
1085 auto const upgradeMsg =
1086 "Check for upgrade: "
1087 "A majority of trusted validators are "
1088 "running a newer version.";
1114 JLOG(stream) <<
"Consensus built old ledger: " << ledger->info().seq
1125 JLOG(stream) <<
"Consensus ledger fully validated";
1139 valSeq() : valCount_(0), ledgerSeq_(0)
1150 if (ledgerSeq_ == 0)
1160 for (
auto const& v : validations)
1162 valSeq& vs = count[v->getLedgerHash()];
1163 vs.mergeValidation(v->getFieldU32(sfLedgerSequence));
1168 auto maxLedger = ledger->info().hash;
1172 for (
auto& v : count)
1173 if (v.second.valCount_ > neededValidations)
1176 if (v.second.ledgerSeq_ == 0)
1179 v.second.ledgerSeq_ = l->info().seq;
1182 if (v.second.ledgerSeq_ > maxSeq)
1184 maxSeq = v.second.ledgerSeq_;
1185 maxLedger = v.first;
1192 JLOG(stream) <<
"Consensus triggered check of ledger";
1206 if (l && l->info().seq >= index)
1230 JLOG(
m_journal.
trace()) <<
"No valid journal, nothing to publish.";
1256 JLOG(
m_journal.
trace()) <<
"No valid journal, nothing to publish.";
1272 <<
"Trying to fetch/publish valid ledger " << seq;
1286 else if (hash->isZero())
1289 <<
" does not have hash for " << seq;
1291 "ripple::LedgerMaster::findNewLedgersToPublish : ledger "
1308 if (ledger && (ledger->info().seq == pubSeq))
1310 ledger->setValidated();
1317 <<
"ready to publish " << ret.
size() <<
" ledgers.";
1322 <<
"Exception while trying to find ledgers to publish: "
1335 auto finishLedger = valLedger;
1336 while (startLedger->seq() + 1 < finishLedger->seq())
1339 finishLedger->info().parentHash);
1342 finishLedger = parent;
1346 auto numberLedgers =
1347 finishLedger->seq() - startLedger->seq() + 1;
1349 <<
"Publish LedgerReplays " << numberLedgers
1350 <<
" ledgers, from seq=" << startLedger->info().seq <<
", "
1351 << startLedger->info().hash
1352 <<
" to seq=" << finishLedger->info().seq <<
", "
1353 << finishLedger->info().hash;
1356 finishLedger->info().hash,
1381 "ripple::LedgerMaster::tryAdvance : has valid ledger");
1409 JLOG(
m_journal.
debug()) <<
"Need network ledger for updating paths";
1444 lastLedger->info().closeTime;
1448 <<
"Published ledger too old for updating paths";
1461 if (!pathRequests.requestsPending())
1466 <<
"No path requests found. Nothing to do for updating "
1473 pathRequests.updateAll(lastLedger);
1476 if (!pathRequests.requestsPending())
1479 <<
"No path requests left. No need for further updating "
1489 if (lastLedger->open())
1493 lastLedger->info().parentHash,
1494 lastLedger->info().seq - 1,
1501 lastLedger->info().hash,
1502 lastLedger->info().seq,
1548 <<
"newPFWork: Creating job. path find threads: "
1588 return ledger->rules();
1623 if (nodeObject && (nodeObject->getData().size() >= 120))
1626 nodeObject->getData().data(), nodeObject->getData().size());
1636 return std::nullopt;
1644 if (
hash.isNonZero())
1667 if (!referenceLedger || (referenceLedger->info().seq < index))
1670 return std::nullopt;
1682 XRPL_ASSERT(refHash,
"ripple::LedgerMaster::walkHashBySeq : found ledger");
1704 *refHash, refIndex, reason))
1709 "ripple::LedgerMaster::walkHashBySeq : has complete "
1725 if (
valid->info().seq == index)
1746 if (ret && (ret->info().seq == index))
1760 if (ret && (ret->info().hash ==
hash))
1824 "ripple::LedgerMaster::fetchForHistory : found ledger");
1836 <<
"fetchForHistory want fetch pack " << missing;
1842 <<
"fetchForHistory no fetch pack for " << missing;
1846 <<
"fetchForHistory found failed acquire";
1850 auto seq = ledger->info().seq;
1853 "ripple::LedgerMaster::fetchForHistory : sequence match");
1862 if (fillInProgress == 0 &&
1864 ledger->info().parentHash)
1872 jtADVANCE,
"tryFill", [
this, ledger]() {
1884 fetchSz = missing >= fetchSz
1896 "ripple::LedgerMaster::fetchForHistory : "
1897 "prefetched ledger");
1905 <<
"Threw while prefetching: " << ex.
what();
1912 <<
"Can't find ledger following prevMissing " << missing;
1918 <<
"Acquire reason: "
1933 bool progress =
false;
1936 if (pubLedgers.empty())
1957 <<
"tryAdvance discovered missing " << *missing;
1967 <<
"advanceThread should acquire";
1970 missing = std::nullopt;
1978 <<
"tryAdvance found last valid changed";
1991 JLOG(
m_journal.
trace()) <<
"tryAdvance found " << pubLedgers.size()
1992 <<
" ledgers to publish";
1993 for (
auto const& ledger : pubLedgers)
1998 <<
"tryAdvance publishing seq " << ledger->info().seq;
2011 progress =
newPFWork(
"pf:newLedger", sl);
2034 return std::nullopt;
2079 protocol::TMGetObjectByHash* into,
2081 bool withLeaves =
true)
2083 XRPL_ASSERT(cnt,
"ripple::populateFetchPack : nonzero count input");
2089 [&s, withLeaves, &cnt, into, seq](
SHAMapTreeNode const& n) ->
bool {
2090 if (!withLeaves && n.
isLeaf())
2098 protocol::TMIndexedObject* obj = into->add_objects();
2099 obj->set_ledgerseq(seq);
2100 obj->set_hash(
hash.data(),
hash.size());
2114 using namespace std::chrono_literals;
2127 auto peer = wPeer.
lock();
2137 <<
"Peer requests fetch pack for ledger we don't have: " << have;
2145 <<
"Peer requests fetch pack from open ledger: " << have;
2152 JLOG(
m_journal.
debug()) <<
"Peer requests fetch pack that is too early";
2162 <<
"Peer requests fetch pack for ledger whose predecessor we "
2163 <<
"don't have: " << have;
2173 protocol::TMGetObjectByHash reply;
2174 reply.set_query(
false);
2176 if (request->has_seq())
2177 reply.set_seq(request->seq());
2179 reply.set_ledgerhash(request->ledgerhash());
2180 reply.set_type(protocol::TMGetObjectByHash::otFETCH_PACK);
2199 addRaw(want->info(), hdr);
2202 protocol::TMIndexedObject* obj = reply.add_objects();
2204 want->info().hash.data(), want->info().hash.size());
2206 obj->set_ledgerseq(lSeq);
2210 want->stateMap(), &have->stateMap(), 16384, &reply, lSeq);
2214 if (want->info().txHash.isNonZero())
2217 if (reply.objects().size() >= 512)
2220 have = std::move(want);
2224 auto msg = std::make_shared<Message>(reply, protocol::mtGET_OBJECTS);
2227 <<
"Built fetch pack with " << reply.objects().size() <<
" nodes ("
2228 << msg->getBufferSize() <<
" bytes)";
2235 <<
"Exception building fetch pach. Exception: " << ex.
what();
2261 if (!lgr || lgr->txs.empty())
2264 for (
auto it = lgr->txs.begin(); it != lgr->txs.end(); ++it)
2265 if (it->first && it->second &&
2266 it->second->isFieldPresent(sfTransactionIndex) &&
2267 it->second->getFieldU32(sfTransactionIndex) == txnIndex)
2268 return it->first->getTransactionID();
T back_inserter(T... args)
Provide a light-weight way to check active() before string formatting.
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
typename Clock::time_point time_point
virtual std::optional< NetClock::time_point > firstUnsupportedExpected() const =0
virtual bool hasUnsupportedEnabled() const =0
returns true if one or more amendments on the network have been enabled that this server does not sup...
void doValidatedLedger(std::shared_ptr< ReadView const > const &lastValidatedLedger)
Called when a new fully-validated ledger is accepted.
virtual Config & config()=0
virtual Overlay & overlay()=0
virtual LoadFeeTrack & getFeeTrack()=0
virtual OpenLedger & openLedger()=0
virtual beast::Journal journal(std::string const &name)=0
virtual SHAMapStore & getSHAMapStore()=0
virtual bool isStopping() const =0
virtual NodeStore::Database & getNodeStore()=0
virtual RCLValidations & getValidations()=0
virtual OrderBookDB & getOrderBookDB()=0
virtual LedgerReplayer & getLedgerReplayer()=0
virtual TimeKeeper & timeKeeper()=0
virtual JobQueue & getJobQueue()=0
virtual NetworkOPs & getOPs()=0
virtual InboundLedgers & getInboundLedgers()=0
virtual ValidatorList & validators()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual RelationalDatabase & getRelationalDatabase()=0
virtual PathRequests & getPathRequests()=0
virtual LedgerIndex getMaxDisallowedLedger()=0
Ensure that a newly-started validator does not sign proposals older than the last ledger it persisted...
virtual AmendmentTable & getAmendmentTable()=0
virtual PendingSaves & pendingSaves()=0
void insert(std::shared_ptr< STTx const > const &txn)
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
void reset(LedgerHash const &salt)
std::unordered_set< uint256, beast::uhash<> > features
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
virtual bool isFailure(uint256 const &h)=0
int getJobCount(JobType t) const
Jobs waiting at this priority.
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
float getCacheHitRate()
Get the ledgers_by_hash cache hit rate.
void builtLedger(std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, Json::Value)
Report that we have locally built a particular ledger.
void sweep()
Remove stale cache entries.
LedgerHash getLedgerHash(LedgerIndex ledgerIndex)
Get a ledger's hash given its sequence number.
void clearLedgerCachePrior(LedgerIndex seq)
std::shared_ptr< Ledger const > getLedgerBySeq(LedgerIndex ledgerIndex)
Get a ledger given its sequence number.
bool insert(std::shared_ptr< Ledger const > const &ledger, bool validated)
Track a ledger.
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
Repair a hash to index mapping.
void validatedLedger(std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
Report that we have validated a particular ledger.
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
std::shared_ptr< Ledger const > get()
void set(std::shared_ptr< Ledger const > ledger)
bool haveLedger(std::uint32_t seq)
std::shared_ptr< Ledger const > getValidatedLedger()
void clearLedgerCachePrior(LedgerIndex seq)
RangeSet< std::uint32_t > mCompleteLedgers
void setBuildingLedger(LedgerIndex index)
std::unique_ptr< LedgerReplay > releaseReplay()
void failedSave(std::uint32_t seq, uint256 const &hash)
void takeReplay(std::unique_ptr< LedgerReplay > replay)
std::uint32_t const ledger_history_
void addHeldTransaction(std::shared_ptr< Transaction > const &trans)
void checkAccept(std::shared_ptr< Ledger const > const &ledger)
std::optional< NetClock::time_point > getCloseTimeByHash(LedgerHash const &ledgerHash, LedgerIndex ledgerIndex)
std::size_t getNeededValidations()
Determines how many validations are needed to fully validate a ledger.
std::unique_ptr< LedgerReplay > replayData
void setLedgerRangePresent(std::uint32_t minV, std::uint32_t maxV)
TimeKeeper::time_point upgradeWarningPrevTime_
LedgerHistory mLedgerHistory
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
void fixMismatch(ReadView const &ledger)
std::atomic< LedgerIndex > mPubLedgerSeq
void clearPriorLedgers(LedgerIndex seq)
std::shared_ptr< Ledger const > mPubLedger
void makeFetchPack(std::weak_ptr< Peer > const &wPeer, std::shared_ptr< protocol::TMGetObjectByHash > const &request, uint256 haveLedgerHash, UptimeClock::time_point uptime)
std::atomic< LedgerIndex > mBuildingLedgerSeq
std::shared_ptr< ReadView const > getCurrentLedger()
void tryFill(std::shared_ptr< Ledger const > ledger)
std::uint32_t const fetch_depth_
bool canBeCurrent(std::shared_ptr< Ledger const > const &ledger)
Check the sequence number and parent close time of a ledger against our clock and last validated ledg...
bool isValidated(ReadView const &ledger)
std::uint32_t getEarliestFetch()
std::recursive_mutex m_mutex
std::optional< LedgerHash > walkHashBySeq(std::uint32_t index, InboundLedger::Reason reason)
Walk to a ledger's hash using the skip list.
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Get the next transaction held for a particular account if any.
LedgerIndex const max_ledger_difference_
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
TaggedCache< uint256, Blob > fetch_packs_
bool isCaughtUp(std::string &reason)
void setPubLedger(std::shared_ptr< Ledger const > const &l)
bool newPFWork(const char *name, std::unique_lock< std::recursive_mutex > &)
A thread needs to be dispatched to handle pathfinding work of some kind.
std::optional< uint256 > txnIdFromIndex(uint32_t ledgerSeq, uint32_t txnIndex)
bool getValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
void clearLedger(std::uint32_t seq)
std::pair< uint256, LedgerIndex > mLastValidLedger
std::shared_ptr< Ledger const > getClosedLedger()
std::optional< LedgerIndex > minSqlSeq()
void setFullLedger(std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
LedgerMaster(Application &app, Stopwatch &stopwatch, beast::insight::Collector::ptr const &collector, beast::Journal journal)
std::atomic< std::uint32_t > mValidLedgerSign
CanonicalTXSet mHeldTransactions
std::uint32_t const ledger_fetch_size_
void applyHeldTransactions()
Apply held transactions to the open ledger This is normally called as we close the ledger.
std::chrono::seconds getPublishedLedgerAge()
std::shared_ptr< Ledger const > mHistLedger
std::recursive_mutex mCompleteLock
std::string getCompleteLedgers()
std::atomic< LedgerIndex > mValidLedgerSeq
std::size_t getFetchPackCacheSize() const
bool getFullValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
std::optional< Blob > getFetchPack(uint256 const &hash) override
Retrieves partial ledger data of the coresponding hash from peers.
void gotFetchPack(bool progress, std::uint32_t seq)
std::recursive_mutex & peekMutex()
void consensusBuilt(std::shared_ptr< Ledger const > const &ledger, uint256 const &consensusHash, Json::Value consensus)
Report that the consensus process built a particular ledger.
Rules getValidatedRules()
std::shared_ptr< Ledger const > mPathLedger
void setValidLedger(std::shared_ptr< Ledger const > const &l)
std::optional< LedgerHash > getLedgerHashForHistory(LedgerIndex index, InboundLedger::Reason reason)
void addFetchPack(uint256 const &hash, std::shared_ptr< Blob > data)
std::atomic< std::uint32_t > mPubLedgerClose
void switchLCL(std::shared_ptr< Ledger const > const &lastClosed)
LedgerHolder mValidLedger
std::shared_ptr< ReadView const > getPublishedLedger()
std::atomic_flag mGotFetchPackThread
void doAdvance(std::unique_lock< std::recursive_mutex > &)
LedgerHolder mClosedLedger
bool storeLedger(std::shared_ptr< Ledger const > ledger)
std::vector< std::shared_ptr< Ledger const > > findNewLedgersToPublish(std::unique_lock< std::recursive_mutex > &)
LedgerIndex getCurrentLedgerIndex()
bool isCompatible(ReadView const &, beast::Journal::Stream, char const *reason)
std::shared_ptr< Ledger const > getLedgerBySeq(std::uint32_t index)
void fetchForHistory(std::uint32_t missing, bool &progress, InboundLedger::Reason reason, std::unique_lock< std::recursive_mutex > &)
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
LedgerIndex getValidLedgerIndex()
std::chrono::seconds getValidatedLedgerAge()
void replay(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
Replay a range of ledgers.
void setRemoteFee(std::uint32_t f)
bool isLoadedLocal() const
std::uint32_t getLoadBase() const
virtual bool isBlocked()=0
virtual void setAmendmentWarned()=0
virtual void setAmendmentBlocked()=0
virtual void clearNeedNetworkLedger()=0
virtual bool isAmendmentWarned()=0
virtual bool isNeedNetworkLedger()=0
virtual void updateLocalTx(ReadView const &newValidLedger)=0
virtual void clearAmendmentWarned()=0
virtual void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted)=0
Persistency layer for NodeObject.
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous, bool duplicate=false)
Fetch a node object.
virtual std::int32_t getWriteLoad() const =0
Retrieve the estimated number of pending write operations.
std::uint32_t earliestLedgerSeq() const noexcept
bool modify(modify_type const &f)
Modify the open ledger.
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Writable ledger view that accumulates state and tx changes.
void setup(std::shared_ptr< ReadView const > const &ledger)
virtual PeerSequence getActivePeers() const =0
Returns a sequence representing the current list of peers.
virtual void checkTracking(std::uint32_t index)=0
Calls the checkTracking function on each peer.
bool requestsPending() const
std::map< LedgerIndex, bool > getSnapshot() const
Get a snapshot of the pending saves.
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
virtual std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex)=0
getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex.
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.
virtual uint256 getHashByIndex(LedgerIndex ledgerIndex)=0
getHashByIndex Returns the hash of the ledger with the given sequence.
Rules controlling protocol behavior.
uint256 const & as_uint256() const
virtual void onLedgerClosed(std::shared_ptr< Ledger const > const &ledger)=0
Called by LedgerMaster every time a ledger validates.
virtual std::optional< LedgerIndex > minimumOnline() const =0
The minimum ledger to try and maintain in our database.
virtual bool isLeaf() const =0
Determines if this is a leaf node.
SHAMapHash const & getHash() const
Return the hash of this node.
virtual void serializeWithPrefix(Serializer &) const =0
Serialize the node in a format appropriate for hashing.
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
void visitDifferences(SHAMap const *have, std::function< bool(SHAMapTreeNode const &)> const &) const
Visit every node in this SHAMap that is not present in the specified SHAMap.
const void * getDataPtr() const
time_point now() const override
Returns the current time, using the server's clock.
time_point closeTime() const
Returns the predicted close time, in network time.
std::vector< WrappedValidationType > getTrustedForLedger(ID const &ledgerID, Seq const &seq)
Get trusted full validations for a specific ledger.
std::vector< WrappedValidationType > currentTrusted()
Get the currently trusted full validations.
std::vector< std::uint32_t > fees(ID const &ledgerID, std::uint32_t baseFee)
Returns fees reported by trusted full validators in the given ledger.
std::vector< std::shared_ptr< STValidation > > negativeUNLFilter(std::vector< std::shared_ptr< STValidation > > &&validations) const
Remove validations that are from validators on the negative UNL.
std::size_t quorum() const
Get quorum value for current trusted key set.
QuorumKeys getQuorumKeys() const
Get the quorum and all of the trusted keys.
Automatically unlocks and re-locks a unique_lock object.
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's rippled software version.
bool isRippledVersion(std::uint64_t version)
Check if the encoded software version is a rippled software version.
Charge const feeMalformedRequest
Schedule of fees charged for imposing load on the server.
Charge const feeRequestNoReply
TER valid(PreclaimContext const &ctx, AccountID const &src)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
static bool shouldAcquire(std::uint32_t const currentLedger, std::uint32_t const ledgerHistory, std::optional< LedgerIndex > const minimumOnline, std::uint32_t const candidateLedger, beast::Journal j)
std::optional< T > prevMissing(RangeSet< T > const &rs, T t, T minVal=0)
Find the largest value not in the set that is less than a given value.
bool isCurrent(ValidationParms const &p, NetClock::time_point now, NetClock::time_point signTime, NetClock::time_point seenTime)
Whether a validation is still current.
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
static constexpr int MAX_LEDGER_GAP
constexpr std::size_t calculatePercent(std::size_t count, std::size_t total)
Calculate one number divided by another number in percentage.
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Stopwatch & stopwatch()
Returns an instance of a wall clock.
ApplyResult apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
std::string to_string(base_uint< Bits, Tag > const &a)
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
static void populateFetchPack(SHAMap const &want, SHAMap const *have, std::uint32_t cnt, protocol::TMGetObjectByHash *into, std::uint32_t seq, bool withLeaves=true)
Populate a fetch pack with data from the map the recipient wants.
static constexpr std::chrono::minutes MAX_LEDGER_AGE_ACQUIRE
@ ledgerMaster
ledger master data for signing
static constexpr int MAX_WRITE_LOAD_ACQUIRE
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, const char *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
bool pendSaveValidated(Application &app, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger Returns false on error.
T test_and_set(T... args)
T time_since_epoch(T... args)