20 #include <ripple/app/consensus/RCLValidations.h>
21 #include <ripple/app/ledger/Ledger.h>
22 #include <ripple/app/ledger/LedgerMaster.h>
23 #include <ripple/app/ledger/LedgerReplayer.h>
24 #include <ripple/app/ledger/OpenLedger.h>
25 #include <ripple/app/ledger/OrderBookDB.h>
26 #include <ripple/app/ledger/PendingSaves.h>
27 #include <ripple/app/main/Application.h>
28 #include <ripple/app/misc/AmendmentTable.h>
29 #include <ripple/app/misc/HashRouter.h>
30 #include <ripple/app/misc/LoadFeeTrack.h>
31 #include <ripple/app/misc/NetworkOPs.h>
32 #include <ripple/app/misc/SHAMapStore.h>
33 #include <ripple/app/misc/Transaction.h>
34 #include <ripple/app/misc/TxQ.h>
35 #include <ripple/app/misc/ValidatorList.h>
36 #include <ripple/app/paths/PathRequests.h>
37 #include <ripple/app/rdb/backend/PostgresDatabase.h>
38 #include <ripple/app/tx/apply.h>
39 #include <ripple/basics/Log.h>
40 #include <ripple/basics/MathUtilities.h>
41 #include <ripple/basics/TaggedCache.h>
42 #include <ripple/basics/UptimeClock.h>
43 #include <ripple/basics/contract.h>
44 #include <ripple/basics/safe_cast.h>
45 #include <ripple/core/DatabaseCon.h>
46 #include <ripple/core/Pg.h>
47 #include <ripple/core/TimeKeeper.h>
48 #include <ripple/nodestore/DatabaseShard.h>
49 #include <ripple/overlay/Overlay.h>
50 #include <ripple/overlay/Peer.h>
51 #include <ripple/protocol/BuildInfo.h>
52 #include <ripple/protocol/HashPrefix.h>
53 #include <ripple/protocol/digest.h>
54 #include <ripple/resource/Fees.h>
104 template <
class MutexType>
122 assert(lock_.owns_lock());
126 ScopedUnlock(ScopedUnlock
const&) =
delete;
128 operator=(ScopedUnlock
const&) =
delete;
137 ~ScopedUnlock() noexcept(false)
164 bool const ret = [&]() {
166 if (candidateLedger >= currentLedger)
170 if (currentLedger - candidateLedger <= ledgerHistory)
175 return minimumOnline.
has_value() && candidateLedger >= *minimumOnline;
178 JLOG(j.
trace()) <<
"Missing ledger " << candidateLedger
179 << (ret ?
" should" :
" should NOT") <<
" be acquired";
190 , mLedgerHistory(collector, app)
191 , standalone_(app_.config().standalone())
193 app_.getSHAMapStore().clampFetchDepth(app_.config().FETCH_DEPTH))
194 , ledger_history_(app_.config().LEDGER_HISTORY)
199 std::chrono::seconds{45},
201 app_.journal(
"TaggedCache"))
226 if (validLedger && !
areCompatible(*validLedger, view, s, reason))
252 using namespace std::chrono_literals;
262 ret = (ret > 0s) ? ret : 0s;
276 using namespace std::chrono_literals;
278 #ifdef RIPPLED_REPORTING
293 ret = (ret > 0s) ? ret : 0s;
307 using namespace std::chrono_literals;
309 #ifdef RIPPLED_REPORTING
317 reason =
"No recently-published ledger";
322 if (!validClose || !pubClose)
324 reason =
"No published ledger";
327 if (validClose > (pubClose + 90))
329 reason =
"Published ledger lags validated ledger";
345 l->info().hash, l->info().seq));
346 times.
reserve(validations.size());
347 for (
auto const& val : validations)
350 if (!validations.empty())
351 consensusHash = validations.front()->getConsensusHash();
360 auto const t0 = times[(times.
size() - 1) / 2];
361 auto const t1 = times[times.
size() / 2];
362 signTime = t0 + (t1 - t0) / 2;
366 signTime = l->info().closeTime;
386 "activated: server blocked.";
400 if (
auto const first =
404 "reached majority. Upgrade before "
406 <<
" to prevent your server from "
407 "becoming amendment blocked.";
444 if (validLedger && (ledger->info().seq < validLedger->info().seq))
447 <<
"Candidate for current ledger has low seq " << ledger->info().seq
448 <<
" < " << validLedger->info().seq;
458 auto ledgerClose = ledger->info().parentCloseTime;
460 using namespace std::chrono_literals;
461 if ((validLedger || (ledger->info().seq > 10)) &&
466 <<
"Candidate for current ledger has close time "
467 <<
to_string(ledgerClose) <<
" at network time "
468 <<
to_string(closeTime) <<
" seq " << ledger->info().seq;
481 if (closeTime > validLedger->info().parentCloseTime)
482 maxSeq += std::chrono::duration_cast<std::chrono::seconds>(
483 closeTime - validLedger->info().parentCloseTime)
487 if (ledger->info().seq > maxSeq)
490 <<
"Candidate for current ledger has high seq "
491 << ledger->info().seq <<
" > " << maxSeq;
496 <<
"Acceptable seq range: " << validLedger->info().seq
497 <<
" <= " << ledger->info().seq <<
" <= " << maxSeq;
507 if (!lastClosed->isImmutable())
510 if (lastClosed->open())
511 LogicError(
"The new last closed ledger is open!");
538 bool validated = ledger->info().validated;
613 auto const seq = ledger.
info().
seq;
621 if (!hash || ledger.
info().
hash != *hash)
626 assert(hash->isNonZero());
668 if (maybeMin == std::nullopt)
671 minVal = 1 + *maybeMin;
685 if (res ==
"empty" || res ==
"error" || res.
empty())
687 else if (
size_t delim = res.
find(
'-'); delim != std::string::npos)
701 "exception parsing complete ledgers: "
714 if (!pendingSaves.empty() && ((minVal != 0) || (maxVal != 0)))
719 while (pendingSaves.count(maxVal) > 0)
721 while (pendingSaves.count(minVal) > 0)
725 for (
auto v : pendingSaves)
727 if ((v.first >= minVal) && (v.first <= maxVal))
729 if (v.first > ((minVal + maxVal) / 2))
730 maxVal = v.first - 1;
732 minVal = v.first + 1;
762 uint256 prevHash = ledger->info().parentHash;
781 auto it(ledgerHashes.
find(seq));
783 if (it == ledgerHashes.
end())
794 (seq < 500) ? 0 : (seq - 499), seq);
795 it = ledgerHashes.
find(seq);
797 if (it == ledgerHashes.
end())
800 if (!nodeStore.fetchNodeObject(
801 ledgerHashes.
begin()->second.ledgerHash,
802 ledgerHashes.
begin()->first))
806 <<
" mismatches node store";
811 if (it->second.ledgerHash != prevHash)
814 prevHash = it->second.parentHash;
840 return std::min(missing + 1, shardStore->lastLedgerSeq(shardIndex));
846 if (!haveHash || haveHash->isZero())
852 if (missing < shardStore->lastLedgerSeq(shardIndex))
855 <<
"No hash for fetch pack. "
856 <<
"Missing ledger sequence " << missing
857 <<
" while acquiring shard " << shardIndex;
863 <<
"No hash for fetch pack. Missing Index " << missing;
874 for (
auto const& peer : peerList)
876 if (peer->hasRange(missing, missing + 1))
878 int score = peer->getScore(
true);
879 if (!target || (score > maxScore))
890 protocol::TMGetObjectByHash tmBH;
891 tmBH.set_query(
true);
892 tmBH.set_type(protocol::TMGetObjectByHash::otFETCH_PACK);
893 tmBH.set_ledgerhash(haveHash->begin(), 32);
894 auto packet = std::make_shared<Message>(tmBH, protocol::mtGET_OBJECTS);
896 target->send(packet);
897 JLOG(
m_journal.
trace()) <<
"Requested fetch pack for " << missing;
920 <<
"fixMismatch encounters partial ledger. Exception: "
931 if (otherLedger && (otherLedger->info().hash == *hash))
937 <<
"Match at " << lSeq <<
", " << invalidate
938 <<
" prior ledgers invalidated";
954 <<
"All " << invalidate <<
" prior ledgers invalidated";
966 <<
" accepted :" << ledger->info().hash;
967 assert(ledger->stateMap().getHash().isNonZero());
969 ledger->setValidated();
980 if (prevHash.
isNonZero() && prevHash != ledger->info().parentHash)
1002 if (ledger->info().seq != 0 &&
haveLedger(ledger->info().seq - 1))
1008 (prevLedger->info().hash != ledger->info().parentHash))
1011 <<
"Acquired ledger invalidates previous ledger: "
1012 << (prevLedger ?
"hashMismatch" :
"missingLedger");
1041 valCount = validations.size();
1107 ledger->info().hash, ledger->info().seq));
1108 auto const tvc = validations.size();
1112 <<
"Only " << tvc <<
" validations for " << ledger->info().hash;
1117 << ledger->info().seq <<
" with >= " << minVal
1120 ledger->setValidated();
1135 fees.reserve(fees.size() + fees2.size());
1145 s <<
"Received fees from validations: (" << fees.size() <<
") ";
1146 for (
auto const fee1 : fees)
1152 fee = fees[fees.size() / 2];
1163 if (ledger->seq() % 256 == 0)
1174 bool needPrint =
false;
1182 ledger->info().parentHash, ledger->info().seq - 1);
1185 for (
auto const& v : vals)
1190 higherVersionCount +=
1200 if (higherVersionCount > 0 && rippledCount > 0)
1206 needPrint = unlSize > 0 &&
1226 auto const upgradeMsg =
1227 "Check for upgrade: "
1228 "A majority of trusted validators are "
1229 "running a newer version.";
1255 JLOG(stream) <<
"Consensus built old ledger: " << ledger->info().seq
1266 JLOG(stream) <<
"Consensus ledger fully validated";
1280 valSeq() : valCount_(0), ledgerSeq_(0)
1291 if (ledgerSeq_ == 0)
1301 for (
auto const& v : validations)
1303 valSeq& vs = count[v->getLedgerHash()];
1309 auto maxLedger = ledger->info().hash;
1313 for (
auto& v : count)
1314 if (v.second.valCount_ > neededValidations)
1317 if (v.second.ledgerSeq_ == 0)
1320 v.second.ledgerSeq_ = l->info().seq;
1323 if (v.second.ledgerSeq_ > maxSeq)
1325 maxSeq = v.second.ledgerSeq_;
1326 maxLedger = v.first;
1333 JLOG(stream) <<
"Consensus triggered check of ledger";
1348 if (l && l->info().seq >= index)
1372 JLOG(
m_journal.
trace()) <<
"No valid journal, nothing to publish.";
1398 JLOG(
m_journal.
trace()) <<
"No valid journal, nothing to publish.";
1408 ScopedUnlock sul{sl};
1414 <<
"Trying to fetch/publish valid ledger " << seq;
1428 else if (hash->isZero())
1431 <<
" does not have hash for " << seq;
1448 if (ledger && (ledger->info().seq == pubSeq))
1450 ledger->setValidated();
1457 <<
"ready to publish " << ret.
size() <<
" ledgers.";
1462 <<
"Exception while trying to find ledgers to publish: "
1475 auto finishLedger = valLedger;
1476 while (startLedger->seq() + 1 < finishLedger->seq())
1479 finishLedger->info().parentHash);
1482 finishLedger = parent;
1486 auto numberLedgers =
1487 finishLedger->seq() - startLedger->seq() + 1;
1489 <<
"Publish LedgerReplays " << numberLedgers
1490 <<
" ledgers, from seq=" << startLedger->info().seq <<
", "
1491 << startLedger->info().hash
1492 <<
" to seq=" << finishLedger->info().seq <<
", "
1493 << finishLedger->info().hash;
1496 finishLedger->info().hash,
1547 JLOG(
m_journal.
debug()) <<
"Need network ledger for updating paths";
1582 lastLedger->info().closeTime;
1586 <<
"Published ledger too old for updating paths";
1599 if (!pathRequests.requestsPending())
1604 <<
"No path requests found. Nothing to do for updating "
1611 pathRequests.updateAll(lastLedger);
1614 if (!pathRequests.requestsPending())
1617 <<
"No path requests left. No need for further updating "
1627 if (lastLedger->open())
1631 lastLedger->info().parentHash,
1632 lastLedger->info().seq - 1,
1639 lastLedger->info().hash,
1640 lastLedger->info().seq,
1686 <<
"newPFWork: Creating job. path find threads: "
1711 Throw<ReportingShouldProxy>();
1719 #ifdef RIPPLED_REPORTING
1739 return ledger->rules();
1756 #ifdef RIPPLED_REPORTING
1779 if (nodeObject && (nodeObject->getData().size() >= 120))
1782 nodeObject->getData().data(), nodeObject->getData().size());
1792 return std::nullopt;
1823 if (!referenceLedger || (referenceLedger->info().seq < index))
1826 return std::nullopt;
1860 *refHash, refIndex, reason))
1878 if (valid->info().seq == index)
1899 if (ret && (ret->info().seq == index))
1913 if (ret && (ret->info().hash == hash))
1972 ScopedUnlock sul{sl};
1975 assert(hash->isNonZero());
1987 <<
"fetchForHistory want fetch pack " << missing;
1993 <<
"fetchForHistory no fetch pack for " << missing;
1997 <<
"fetchForHistory found failed acquire";
2001 auto seq = ledger->info().seq;
2002 assert(seq == missing);
2011 if (!ledger->stateMap().family().isShardBacked())
2023 if (fillInProgress == 0 &&
2025 ledger->info().parentHash)
2033 jtADVANCE,
"tryFill", [
this, ledger]() {
2052 fetchSz = missing >= fetchSz
2062 assert(h->isNonZero());
2070 <<
"Threw while prefetching: " << ex.
what();
2077 <<
"Can't find ledger following prevMissing " << missing;
2083 <<
"Acquire reason: "
2097 bool progress =
false;
2100 if (pubLedgers.empty())
2121 <<
"tryAdvance discovered missing " << *missing;
2131 <<
"advanceThread should acquire";
2134 missing = std::nullopt;
2151 <<
"tryAdvance found last valid changed";
2165 JLOG(
m_journal.
trace()) <<
"tryAdvance found " << pubLedgers.size()
2166 <<
" ledgers to publish";
2167 for (
auto const& ledger : pubLedgers)
2170 ScopedUnlock sul{sl};
2172 <<
"tryAdvance publishing seq " << ledger->info().seq;
2179 ScopedUnlock sul{sl};
2185 progress =
newPFWork(
"pf:newLedger", sl);
2208 return std::nullopt;
2253 protocol::TMGetObjectByHash* into,
2255 bool withLeaves =
true)
2263 [&s, withLeaves, &cnt, into, seq](
SHAMapTreeNode const& n) ->
bool {
2264 if (!withLeaves && n.
isLeaf())
2272 protocol::TMIndexedObject* obj = into->add_objects();
2273 obj->set_ledgerseq(seq);
2274 obj->set_hash(hash.data(), hash.size());
2288 using namespace std::chrono_literals;
2301 auto peer = wPeer.
lock();
2311 <<
"Peer requests fetch pack for ledger we don't have: " << have;
2319 <<
"Peer requests fetch pack from open ledger: " << have;
2326 JLOG(
m_journal.
debug()) <<
"Peer requests fetch pack that is too early";
2336 <<
"Peer requests fetch pack for ledger whose predecessor we "
2337 <<
"don't have: " << have;
2346 protocol::TMGetObjectByHash reply;
2347 reply.set_query(
false);
2349 if (request->has_seq())
2350 reply.set_seq(request->seq());
2352 reply.set_ledgerhash(request->ledgerhash());
2353 reply.set_type(protocol::TMGetObjectByHash::otFETCH_PACK);
2372 addRaw(want->info(), hdr);
2375 protocol::TMIndexedObject* obj = reply.add_objects();
2377 want->info().hash.data(), want->info().hash.size());
2379 obj->set_ledgerseq(lSeq);
2383 want->stateMap(), &have->stateMap(), 16384, &reply, lSeq);
2387 if (want->info().txHash.isNonZero())
2390 if (reply.objects().size() >= 512)
2393 have = std::move(want);
2397 auto msg = std::make_shared<Message>(reply, protocol::mtGET_OBJECTS);
2400 <<
"Built fetch pack with " << reply.objects().size() <<
" nodes ("
2401 << msg->getBufferSize() <<
" bytes)";
2408 <<
"Exception building fetch pach. Exception: " << ex.
what();
2428 uint32_t first = 0, last = 0;
2434 if (!lgr || lgr->txs.empty())
2437 for (
auto it = lgr->txs.begin(); it != lgr->txs.end(); ++it)
2438 if (it->first && it->second &&
2441 return it->first->getTransactionID();
virtual void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted)=0
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
bool getValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
std::shared_ptr< Ledger const > mPubLedger
const Charge feeInvalidRequest
Schedule of fees charged for imposing load on the server.
virtual std::optional< LedgerIndex > getMaxLedgerSeq()=0
getMaxLedgerSeq Returns the maximum ledger sequence in the Ledgers table.
LedgerHolder mClosedLedger
virtual OrderBookDB & getOrderBookDB()=0
@ ledgerMaster
ledger master data for signing
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)
virtual std::int32_t getWriteLoad() const =0
Retrieve the estimated number of pending write operations.
std::shared_ptr< ReadView const > getPublishedLedger()
std::uint32_t LedgerIndex
A ledger index.
TaggedCache< uint256, Blob > fetch_packs_
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Persistency layer for NodeObject.
void makeFetchPack(std::weak_ptr< Peer > const &wPeer, std::shared_ptr< protocol::TMGetObjectByHash > const &request, uint256 haveLedgerHash, UptimeClock::time_point uptime)
void clearLedgerCachePrior(LedgerIndex seq)
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)
Stream trace() const
Severity stream access functions.
std::atomic< LedgerIndex > mBuildingLedgerSeq
const SF_UINT32 sfLedgerSequence
virtual std::optional< LedgerIndex > minimumOnline() const =0
The minimum ledger to try and maintain in our database.
std::pair< TER, bool > apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
LedgerHistory mLedgerHistory
T test_and_set(T... args)
CanonicalTXSet mHeldTransactions
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
Repair a hash to index mapping.
std::vector< std::uint32_t > fees(ID const &ledgerID, std::uint32_t baseFee)
Returns fees reported by trusted full validators in the given ledger.
void set(std::shared_ptr< Ledger const > ledger)
LedgerIndex getValidLedgerIndex()
virtual AmendmentTable & getAmendmentTable()=0
Writable ledger view that accumulates state and tx changes.
std::shared_ptr< Ledger const > mHistLedger
std::chrono::seconds getPublishedLedgerAge()
T back_inserter(T... args)
TimeKeeper::time_point upgradeWarningPrevTime_
virtual void serializeWithPrefix(Serializer &) const =0
Serialize the node in a format appropriate for hashing.
QuorumKeys getQuorumKeys() const
Get the quorum and all of the trusted keys.
std::unique_ptr< LedgerReplay > releaseReplay()
virtual void onLedgerClosed(std::shared_ptr< Ledger const > const &ledger)=0
Called by LedgerMaster every time a ledger validates.
Rules getValidatedRules()
void doValidatedLedger(std::shared_ptr< ReadView const > const &lastValidatedLedger)
Called when a new fully-validated ledger is accepted.
std::recursive_mutex mCompleteLock
void applyHeldTransactions()
Apply held transactions to the open ledger This is normally called as we close the ledger.
void switchLCL(std::shared_ptr< Ledger const > const &lastClosed)
bool newPFWork(const char *name, std::unique_lock< std::recursive_mutex > &)
A thread needs to be dispatched to handle pathfinding work of some kind.
virtual void setAmendmentBlocked()=0
virtual NodeStore::DatabaseShard * getShardStore()=0
virtual bool isAmendmentWarned()=0
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
virtual bool isStopping() const =0
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
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.
Stopwatch & stopwatch()
Returns an instance of a wall clock.
std::uint32_t getLoadBase() const
virtual TimeKeeper & timeKeeper()=0
std::uint32_t getEarliestFetch()
virtual OpenLedger & openLedger()=0
std::optional< LedgerHash > walkHashBySeq(std::uint32_t index, InboundLedger::Reason reason)
Walk to a ledger's hash using the skip list.
void sweep()
Remove stale cache entries.
const Charge feeRequestNoReply
LedgerHash getLedgerHash(LedgerIndex ledgerIndex)
Get a ledger's hash given its sequence number.
bool insert(std::shared_ptr< Ledger const > const &ledger, bool validated)
Track a ledger.
time_point closeTime() const
Returns the predicted close time, in network time.
void setFullLedger(std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
virtual NetworkOPs & getOPs()=0
bool requestsPending() const
void fixMismatch(ReadView const &ledger)
const std::uint32_t fetch_depth_
virtual InboundLedgers & getInboundLedgers()=0
void builtLedger(std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, Json::Value)
Report that we have locally built a particular ledger.
virtual LoadFeeTrack & getFeeTrack()=0
std::string getCompleteLedgers()
const std::uint32_t ledger_fetch_size_
bool isRippledVersion(std::uint64_t version)
Check if the encoded software version is a rippled software version.
int getJobCount(JobType t) const
Jobs waiting at this priority.
std::recursive_mutex & peekMutex()
std::atomic_flag mGotFetchPackThread
bool isLoadedLocal() const
T time_since_epoch(T... args)
RangeSet< std::uint32_t > mCompleteLedgers
std::uint32_t firstLedgerSeq(std::uint32_t shardIndex) const noexcept
Calculates the first ledger sequence for a given shard index.
virtual bool isNeedNetworkLedger()=0
const SF_UINT64 sfServerVersion
std::unique_ptr< LedgerReplay > replayData
void gotFetchPack(bool progress, std::uint32_t seq)
void fetchForHistory(std::uint32_t missing, bool &progress, InboundLedger::Reason reason, std::unique_lock< std::recursive_mutex > &)
std::optional< Blob > getFetchPack(uint256 const &hash) override
Retrieves partial ledger data of the coresponding hash from peers.
void failedSave(std::uint32_t seq, uint256 const &hash)
virtual LedgerMaster & getLedgerMaster()=0
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
virtual void setAmendmentWarned()=0
virtual PendingSaves & pendingSaves()=0
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
const void * getDataPtr() const
static constexpr int MAX_LEDGER_GAP
virtual uint256 getHashByIndex(LedgerIndex ledgerIndex)=0
getHashByIndex Returns the hash of the ledger with the given sequence.
bool getFullValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
virtual void updateLocalTx(ReadView const &newValidLedger)=0
virtual Config & config()=0
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
bool isCurrent(ValidationParms const &p, NetClock::time_point now, NetClock::time_point signTime, NetClock::time_point seenTime)
Whether a validation is still current.
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
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.
virtual RelationalDatabase & getRelationalDatabase()=0
void validatedLedger(std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
Report that we have validated a particular ledger.
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...
virtual JobQueue & getJobQueue()=0
bool haveLedger(std::uint32_t seq)
virtual std::optional< NetClock::time_point > firstUnsupportedExpected() const =0
constexpr std::size_t calculatePercent(std::size_t count, std::size_t total)
Calculate one number divided by another number in percentage.
Provide a light-weight way to check active() before string formatting.
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.
bool isCompatible(ReadView const &, beast::Journal::Stream, char const *reason)
std::optional< LedgerIndex > minSqlSeq()
virtual bool isLeaf() const =0
Determines if this is a leaf node.
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
void setup(std::shared_ptr< ReadView const > const &ledger)
std::shared_ptr< Ledger const > getLedgerBySeq(std::uint32_t index)
std::optional< uint256 > txnIdFromIndex(uint32_t ledgerSeq, uint32_t txnIndex)
virtual PeerSequence getActivePeers() const =0
Returns a sequence representing the current list of peers.
A generic endpoint for log messages.
virtual RCLValidations & getValidations()=0
void replay(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
Replay a range of ledgers.
void addHeldTransaction(std::shared_ptr< Transaction > const &trans)
void setValidLedger(std::shared_ptr< Ledger const > const &l)
virtual void clearNeedNetworkLedger()=0
std::shared_ptr< Ledger const > getLedgerBySeq(LedgerIndex ledgerIndex)
Get a ledger given its sequence number.
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
virtual PathRequests & getPathRequests()=0
std::shared_ptr< Ledger const > get()
void insert(std::shared_ptr< STTx const > const &txn)
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.
std::shared_ptr< ReadView const > getCurrentLedger()
time_point now() const override
Returns the current time, using the server's clock.
std::map< LedgerIndex, bool > getSnapshot() const
Get a snapshot of the pending saves.
std::size_t getNeededValidations()
Determines how many validations are needed to fully validate a 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.
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 checkAccept(std::shared_ptr< Ledger const > const &ledger)
virtual ValidatorList & validators()=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...
const SF_UINT32 sfTransactionIndex
SHAMapHash const & getHash() const
Return the hash of this node.
const LedgerIndex max_ledger_difference_
std::size_t getFetchPackCacheSize() const
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's rippled software version.
std::shared_ptr< Ledger const > mPathLedger
std::chrono::seconds getValidatedLedgerAge()
std::shared_ptr< Ledger const > getClosedLedger()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual bool isBlocked()=0
std::unordered_set< uint256, beast::uhash<> > features
virtual bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger)=0
Store a ledger from a different database.
std::atomic< std::uint32_t > mPubLedgerClose
virtual NodeStore::Database & getNodeStore()=0
virtual beast::Journal journal(std::string const &name)=0
void addRaw(LedgerHeader const &info, Serializer &s, bool includeHash)
const std::uint32_t ledger_history_
std::atomic< LedgerIndex > mPubLedgerSeq
float getCacheHitRate()
Get the ledgers_by_hash cache hit rate.
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
bool isValidated(ReadView const &ledger)
void addFetchPack(uint256 const &hash, std::shared_ptr< Blob > data)
void clearLedger(std::uint32_t seq)
std::uint32_t seqToShardIndex(std::uint32_t ledgerSeq) const noexcept
Calculates the shard index for a given ledger sequence.
virtual void clearAmendmentWarned()=0
std::optional< LedgerHash > getLedgerHashForHistory(LedgerIndex index, InboundLedger::Reason reason)
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
static constexpr std::chrono::minutes MAX_LEDGER_AGE_ACQUIRE
std::atomic< LedgerIndex > mValidLedgerSeq
LedgerIndex getCurrentLedgerIndex()
virtual Overlay & overlay()=0
void takeReplay(std::unique_ptr< LedgerReplay > replay)
std::shared_ptr< Ledger const > getValidatedLedger()
std::pair< uint256, LedgerIndex > mLastValidLedger
Rules controlling protocol behavior.
void clearLedgerCachePrior(LedgerIndex seq)
virtual void checkTracking(std::uint32_t index)=0
Calls the checkTracking function on each peer.
std::shared_ptr< Ledger const > mShardLedger
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
int add32(std::uint32_t i)
bool storeLedger(std::shared_ptr< Ledger const > ledger)
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 LedgerReplayer & getLedgerReplayer()=0
uint256 const & as_uint256() const
virtual SHAMapStore & getSHAMapStore()=0
void setLedgerRangePresent(std::uint32_t minV, std::uint32_t maxV)
std::uint32_t earliestLedgerSeq() const noexcept
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
void consensusBuilt(std::shared_ptr< Ledger const > const &ledger, uint256 const &consensusHash, Json::Value consensus)
Report that the consensus process built a particular ledger.
void tryFill(std::shared_ptr< Ledger const > ledger)
LedgerHolder mValidLedger
void setRemoteFee(std::uint32_t f)
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
std::vector< std::shared_ptr< Ledger const > > findNewLedgersToPublish(std::unique_lock< std::recursive_mutex > &)
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.
bool isCaughtUp(std::string &reason)
std::optional< NetClock::time_point > getCloseTimeByHash(LedgerHash const &ledgerHash, LedgerIndex ledgerIndex)
std::vector< WrappedValidationType > getTrustedForLedger(ID const &ledgerID, Seq const &seq)
Get trusted full validations for a specific ledger.
std::atomic< std::uint32_t > mValidLedgerSign
void setBuildingLedger(LedgerIndex index)
void doAdvance(std::unique_lock< std::recursive_mutex > &)
virtual bool open() const =0
Returns true if this reflects an open ledger.
void clearPriorLedgers(LedgerIndex seq)
void setPubLedger(std::shared_ptr< Ledger const > const &l)
virtual std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex)=0
getHashesByIndex Returns the hashes of the ledger and its parent as specified by the ledgerIndex.
typename NetClock ::time_point time_point
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Get the next transaction held for a particular account if any.
bool modify(modify_type const &f)
Modify the open ledger.
LedgerMaster(Application &app, Stopwatch &stopwatch, beast::insight::Collector::ptr const &collector, beast::Journal journal)
virtual bool isFailure(uint256 const &h)=0
void reset(LedgerHash const &salt)
static constexpr int MAX_WRITE_LOAD_ACQUIRE
std::size_t quorum() const
Get quorum value for current trusted key set.
virtual LedgerIndex getMaxDisallowedLedger()=0
Ensure that a newly-started validator does not sign proposals older than the last ledger it persisted...
std::recursive_mutex m_mutex
std::vector< WrappedValidationType > currentTrusted()
Get the currently trusted full validations.