1#include <xrpl/server/NetworkOPs.h>
3#include <xrpld/app/consensus/RCLConsensus.h>
4#include <xrpld/app/consensus/RCLCxPeerPos.h>
5#include <xrpld/app/consensus/RCLValidations.h>
6#include <xrpld/app/ledger/AcceptedLedger.h>
7#include <xrpld/app/ledger/InboundLedger.h>
8#include <xrpld/app/ledger/InboundLedgers.h>
9#include <xrpld/app/ledger/LedgerMaster.h>
10#include <xrpld/app/ledger/LedgerToJson.h>
11#include <xrpld/app/ledger/LocalTxs.h>
12#include <xrpld/app/ledger/OpenLedger.h>
13#include <xrpld/app/ledger/TransactionMaster.h>
14#include <xrpld/app/main/LoadManager.h>
15#include <xrpld/app/main/Tuning.h>
16#include <xrpld/app/misc/DeliverMax.h>
17#include <xrpld/app/misc/FeeVote.h>
18#include <xrpld/app/misc/Transaction.h>
19#include <xrpld/app/misc/TxQ.h>
20#include <xrpld/app/misc/ValidatorKeys.h>
21#include <xrpld/app/misc/ValidatorList.h>
22#include <xrpld/app/misc/make_NetworkOPs.h>
23#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
24#include <xrpld/core/Config.h>
25#include <xrpld/overlay/Cluster.h>
26#include <xrpld/overlay/ClusterNode.h>
27#include <xrpld/overlay/Overlay.h>
28#include <xrpld/overlay/predicates.h>
29#include <xrpld/rpc/BookChanges.h>
30#include <xrpld/rpc/CTID.h>
31#include <xrpld/rpc/ServerHandler.h>
32#include <xrpld/rpc/detail/SyntheticFields.h>
34#include <xrpl/basics/Log.h>
35#include <xrpl/basics/Number.h>
36#include <xrpl/basics/ToString.h>
37#include <xrpl/basics/UnorderedContainers.h>
38#include <xrpl/basics/UptimeClock.h>
39#include <xrpl/basics/base_uint.h>
40#include <xrpl/basics/chrono.h>
41#include <xrpl/basics/contract.h>
42#include <xrpl/basics/mulDiv.h>
43#include <xrpl/basics/safe_cast.h>
44#include <xrpl/basics/scope.h>
45#include <xrpl/basics/strHex.h>
46#include <xrpl/beast/clock/abstract_clock.h>
47#include <xrpl/beast/insight/Collector.h>
48#include <xrpl/beast/insight/Gauge.h>
49#include <xrpl/beast/insight/Hook.h>
50#include <xrpl/beast/net/IPEndpoint.h>
51#include <xrpl/beast/utility/Zero.h>
52#include <xrpl/beast/utility/instrumentation.h>
53#include <xrpl/beast/utility/rngfill.h>
54#include <xrpl/config/Constants.h>
55#include <xrpl/consensus/ConsensusParms.h>
56#include <xrpl/consensus/ConsensusTypes.h>
57#include <xrpl/core/ClosureCounter.h>
58#include <xrpl/core/HashRouter.h>
59#include <xrpl/core/Job.h>
60#include <xrpl/core/NetworkIDService.h>
61#include <xrpl/core/PerfLog.h>
62#include <xrpl/core/ServiceRegistry.h>
63#include <xrpl/crypto/RFC1751.h>
64#include <xrpl/crypto/csprng.h>
65#include <xrpl/git/Git.h>
66#include <xrpl/json/json_forwards.h>
67#include <xrpl/json/json_value.h>
68#include <xrpl/json/json_writer.h>
69#include <xrpl/ledger/AcceptedLedgerTx.h>
70#include <xrpl/ledger/AmendmentTable.h>
71#include <xrpl/ledger/ApplyView.h>
72#include <xrpl/ledger/CanonicalTXSet.h>
73#include <xrpl/ledger/Ledger.h>
74#include <xrpl/ledger/OpenView.h>
75#include <xrpl/ledger/OrderBookDB.h>
76#include <xrpl/ledger/ReadView.h>
77#include <xrpl/ledger/helpers/DirectoryHelpers.h>
78#include <xrpl/ledger/helpers/MPTokenHelpers.h>
79#include <xrpl/ledger/helpers/TokenHelpers.h>
80#include <xrpl/protocol/AccountID.h>
81#include <xrpl/protocol/AmountConversions.h>
82#include <xrpl/protocol/ApiVersion.h>
83#include <xrpl/protocol/Book.h>
84#include <xrpl/protocol/BuildInfo.h>
85#include <xrpl/protocol/ErrorCodes.h>
86#include <xrpl/protocol/Feature.h>
87#include <xrpl/protocol/Fees.h>
88#include <xrpl/protocol/Indexes.h>
89#include <xrpl/protocol/Issue.h>
90#include <xrpl/protocol/KeyType.h>
91#include <xrpl/protocol/LedgerFormats.h>
92#include <xrpl/protocol/MPTAmount.h>
93#include <xrpl/protocol/MPTIssue.h>
94#include <xrpl/protocol/MultiApiJson.h>
95#include <xrpl/protocol/Protocol.h>
96#include <xrpl/protocol/PublicKey.h>
97#include <xrpl/protocol/RPCErr.h>
98#include <xrpl/protocol/Rate.h>
99#include <xrpl/protocol/SField.h>
100#include <xrpl/protocol/STAmount.h>
101#include <xrpl/protocol/STTx.h>
102#include <xrpl/protocol/SecretKey.h>
103#include <xrpl/protocol/Seed.h>
104#include <xrpl/protocol/Serializer.h>
105#include <xrpl/protocol/TER.h>
106#include <xrpl/protocol/TxFlags.h>
107#include <xrpl/protocol/TxFormats.h>
108#include <xrpl/protocol/UintTypes.h>
109#include <xrpl/protocol/Units.h>
110#include <xrpl/protocol/XRPAmount.h>
111#include <xrpl/protocol/jss.h>
112#include <xrpl/protocol/tokens.h>
113#include <xrpl/rdb/RelationalDatabase.h>
114#include <xrpl/resource/Fees.h>
115#include <xrpl/resource/Gossip.h>
116#include <xrpl/resource/ResourceManager.h>
117#include <xrpl/server/InfoSub.h>
118#include <xrpl/server/LoadFeeTrack.h>
119#include <xrpl/server/Manifest.h>
120#include <xrpl/shamap/SHAMap.h>
121#include <xrpl/tx/apply.h>
123#include <boost/asio/error.hpp>
124#include <boost/asio/io_context.hpp>
125#include <boost/asio/ip/host_name.hpp>
126#include <boost/asio/steady_timer.hpp>
127#include <boost/system/detail/errc.hpp>
128#include <boost/system/detail/error_code.hpp>
129#include <boost/system/system_error.hpp>
189 "xrpl::NetworkOPsImp::TransactionStatus::TransactionStatus : "
298 return !(*
this != b);
317 boost::asio::io_context& ioCtx,
334 registry.getInboundTransactions(),
335 beast::getAbstractClock<
std::chrono::steady_clock>(),
339 validatorKeys.keys ? validatorKeys.keys->publicKey : decltype(
validatorPK_){})
341 validatorKeys.keys ? validatorKeys.keys->masterPublicKey
529 getServerInfo(
bool human,
bool admin,
bool counters)
override;
557 TER result)
override;
692 catch (boost::system::system_error
const& e)
694 JLOG(
journal_.error()) <<
"NetworkOPs: heartbeatTimer cancel error: " << e.what();
701 catch (boost::system::system_error
const& e)
703 JLOG(
journal_.error()) <<
"NetworkOPs: clusterTimer cancel error: " << e.what();
710 catch (boost::system::system_error
const& e)
713 <<
"NetworkOPs: accountHistoryTxTimer cancel error: " << e.what();
717 using namespace std::chrono_literals;
727 boost::asio::steady_timer& timer,
910 template <
typename OuterMap,
typename BeforeErase>
916 BeforeErase&& beforeErase);
1045 template <
class Handler>
1047 :
hook(collector->makeHook(handler))
1049 collector->makeGauge(
"State_Accounting",
"Disconnected_duration"))
1050 ,
connectedDuration(collector->makeGauge(
"State_Accounting",
"Connected_duration"))
1051 ,
syncingDuration(collector->makeGauge(
"State_Accounting",
"Syncing_duration"))
1052 ,
trackingDuration(collector->makeGauge(
"State_Accounting",
"Tracking_duration"))
1053 ,
fullDuration(collector->makeGauge(
"State_Accounting",
"Full_duration"))
1055 collector->makeGauge(
"State_Accounting",
"Disconnected_transitions"))
1057 collector->makeGauge(
"State_Accounting",
"Connected_transitions"))
1058 ,
syncingTransitions(collector->makeGauge(
"State_Accounting",
"Syncing_transitions"))
1060 ,
fullTransitions(collector->makeGauge(
"State_Accounting",
"Full_transitions"))
1089 {
"disconnected",
"connected",
"syncing",
"tracking",
"full"},
1153 static std::string const kHostname = boost::asio::ip::host_name();
1160 static std::string const kShroudedHostId = [
this] {
1161 auto const&
id =
registry_.get().getApp().nodeIdentity();
1166 return kShroudedHostId;
1175 if (
registry_.get().getCluster().size() != 0)
1181 boost::asio::steady_timer& timer,
1187 if (
auto optionalCountedHandler =
1189 if ((e.value() == boost::system::errc::success) && (!jobQueue_.isStopped()))
1194 if (e.value() != boost::system::errc::success &&
1195 e.value() != boost::asio::error::operation_aborted)
1198 JLOG(journal_.error())
1199 <<
"Timer got error '" << e.message() <<
"'. Restarting timer.";
1204 timer.expires_after(expiryTime);
1205 timer.async_wait(std::move(*optionalCountedHandler));
1215 [
this] { jobQueue_.addJob(JtNetopTimer,
"NetHeart", [this] { processHeartbeatTimer(); }); },
1216 [
this] { setHeartbeatTimer(); });
1222 using namespace std::chrono_literals;
1236 JLOG(
journal_.debug()) <<
"Scheduling AccountHistory job for account "
1238 using namespace std::chrono_literals;
1266 ss <<
"Node count (" << numPeers <<
") has fallen "
1269 CLOG(clog.
ss()) <<
"set mode to DISCONNECTED: " << ss.
str();
1273 CLOG(clog.
ss()) <<
"already DISCONNECTED. too few peers (" << numPeers
1289 JLOG(
journal_.info()) <<
"Node count (" << numPeers <<
") is sufficient.";
1290 CLOG(clog.
ss()) <<
"setting mode to CONNECTED based on " << numPeers <<
" peers. ";
1295 auto const origMode =
mode_.load();
1305 auto const newMode =
mode_.load();
1306 if (origMode != newMode)
1310 CLOG(clog.
ss()) <<
". ";
1323 CLOG(clog.
ss()) <<
". ";
1331 if (
registry_.get().getCluster().size() == 0)
1334 using namespace std::chrono_literals;
1336 bool const update =
registry_.get().getCluster().update(
1337 registry_.get().getApp().nodeIdentity().first,
1340 ?
registry_.get().getFeeTrack().getLocalFee()
1346 JLOG(
journal_.debug()) <<
"Too soon to send cluster update";
1351 protocol::TMCluster cluster;
1353 protocol::TMClusterNode& n = *cluster.add_clusternodes();
1358 n.set_nodename(node.
name());
1362 for (
auto& item : gossip.
items)
1364 protocol::TMLoadSource& node = *cluster.add_loadsources();
1366 node.set_cost(item.balance);
1380 auto const consensusMode =
consensus_.mode();
1387 return "validating";
1407 JLOG(
journal_.error()) <<
"Submitted transaction invalid: tfInnerBatchTxn flag present.";
1414 auto const txid = trans->getTransactionID();
1415 auto const flags =
registry_.get().getHashRouter().getFlags(txid);
1419 JLOG(
journal_.warn()) <<
"Submitted transaction cached bad";
1430 JLOG(
journal_.warn()) <<
"Submitted transaction invalid: " << reason;
1436 JLOG(
journal_.warn()) <<
"Exception checking transaction " << txid <<
": " << ex.
what();
1454 auto const newFlags =
registry_.get().getHashRouter().getFlags(transaction->getID());
1459 JLOG(
journal_.warn()) << transaction->getID() <<
": cached bad!\n";
1470 auto const& sttx = *transaction->getSTransaction();
1490 auto const& viewRules = view->rules();
1496 JLOG(
journal_.info()) <<
"Transaction has bad signature: " << reason;
1502 if (viewRules.enabled(fixCleanup3_4_0) ||
1503 (!sttx.isFieldPresent(sfSponsorSignature) &&
1504 !sttx.isFieldPresent(sfCounterpartySignature)))
1512 registry_.get().getMasterTransaction().canonicalize(&transaction);
1548 if (transaction->getApplying())
1551 transactions_.emplace_back(transaction, bUnlimited,
false, failType);
1552 transaction->setApplying();
1556 if (
jobQueue_.addJob(
JtBatch,
"TxBatchAsync", [
this] { transactionBatch(); }))
1571 if (!transaction->getApplying())
1573 transactions_.emplace_back(transaction, bUnlimited,
true, failType);
1574 transaction->setApplying();
1578 return transaction->getApplying();
1601 if (
jobQueue_.addJob(
JtBatch,
"TxBatchSync", [
this] { transactionBatch(); }))
1607 }
while (retryCallback(lock));
1616 for (
auto const& [_, tx] :
set)
1623 if (!reason.
empty())
1625 JLOG(
journal_.trace()) <<
"Exception checking transaction: " << reason;
1643 for (
auto const& transaction : candidates)
1645 if (!transaction->getApplying())
1648 transaction->setApplying();
1664 JLOG(
journal_.debug()) <<
"No transaction to process!";
1669 XRPL_ASSERT(lock.owns_lock(),
"xrpl::NetworkOPsImp::processTransactionSet has lock");
1671 transactions_, [](
auto const& t) {
return t.transaction->getApplying(); });
1695 XRPL_ASSERT(!
transactions.empty(),
"xrpl::NetworkOPsImp::apply : non-empty transactions");
1705 bool changed =
false;
1720 auto const result =
registry_.get().getTxQ().apply(
1721 registry_.get().getApp(), view, e.transaction->getSTransaction(), flags, j);
1722 e.result = result.ter;
1723 e.applied = result.applied;
1724 changed = changed || result.applied;
1734 validatedLedgerIndex = l->header().seq;
1736 auto const newOL =
registry_.get().getOpenLedger().current();
1739 e.transaction->clearSubmitResult();
1744 e.transaction->setApplied();
1747 e.transaction->setResult(e.result);
1751 registry_.get().getHashRouter().setFlags(
1755 bool const addLocal = e.local;
1759 JLOG(
journal_.debug()) <<
"Transaction is now included in open ledger";
1765 auto const& txCur = e.transaction->getSTransaction();
1778 if (t->getApplying())
1789 JLOG(
journal_.debug()) <<
"Transaction is obsolete";
1794 JLOG(
journal_.debug()) <<
"Transaction is likely to claim a"
1795 <<
" fee, but is queued until fee drops";
1802 e.transaction->setQueued();
1803 e.transaction->setKept();
1809 auto const lastLedgerSeq =
1810 e.transaction->getSTransaction()->at(~sfLastLedgerSequence);
1811 auto const ledgersLeft = lastLedgerSeq
1831 registry_.get().getHashRouter().setFlags(
1835 JLOG(
journal_.debug()) <<
"Transaction should be held: " << e.result;
1838 e.transaction->setKept();
1843 <<
"Not holding transaction " << e.transaction->getID() <<
": "
1844 << (e.local ?
"local" :
"network") <<
", "
1845 <<
"result: " << e.result <<
" ledgers left: "
1846 << (ledgersLeft ?
to_string(*ledgersLeft) :
"unspecified");
1852 JLOG(
journal_.debug()) <<
"Status other than success " << e.result;
1858 if (addLocal && !enforceFailHard)
1861 ledgerMaster_.getCurrentLedgerIndex(), e.transaction->getSTransaction());
1862 e.transaction->setKept();
1871 registry_.get().getHashRouter().shouldRelay(e.transaction->getID());
1872 if (
auto const& sttx = *e.transaction->getSTransaction(); toSkip &&
1879 protocol::TMTransaction tx;
1883 tx.set_rawtransaction(s.
data(), s.
size());
1884 tx.set_status(protocol::tsCURRENT);
1887 registry_.get().getOverlay().relay(sttx, tx, *toSkip);
1888 e.transaction->setBroadcast();
1892 if (validatedLedgerIndex)
1894 auto maybeFeeAndSeq =
registry_.get().getTxQ().getTxRequiredFeeAndSeq(
1895 *newOL, e.transaction->getSTransaction());
1896 if (maybeFeeAndSeq.has_value())
1898 auto [fee, accountSeq, availableSeq] = *maybeFeeAndSeq;
1899 e.transaction->setCurrentLedgerState(
1900 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1905 <<
"Unable to compute current ledger state for tx "
1906 << e.transaction->getID() <<
" in validated ledger "
1907 << *validatedLedgerIndex <<
": " <<
transToken(maybeFeeAndSeq.error());
1916 e.transaction->clearApplying();
1918 if (!submitHeld.
empty())
1927 for (
auto& e : submitHeld)
1953 for (
auto const& uDirEntry : sleNode->getFieldV256(sfIndexes))
1955 auto const sleCur = lpLedger->read(
keylet::child(uDirEntry));
1956 XRPL_ASSERT(sleCur,
"xrpl::NetworkOPsImp::getOwnerInfo : non-null child SLE");
1958 switch (sleCur->getType())
1961 if (!jvObjects.
isMember(jss::offers))
1967 case ltRIPPLE_STATE:
1968 if (!jvObjects.
isMember(jss::ripple_lines))
1973 jvObjects[jss::ripple_lines].
append(
1977 case ltACCOUNT_ROOT:
1982 "xrpl::NetworkOPsImp::getOwnerInfo : invalid "
1989 uNodeDir = sleNode->getFieldU64(sfIndexNext);
1994 XRPL_ASSERT(sleNode,
"xrpl::NetworkOPsImp::getOwnerInfo : read next page");
1996 }
while (uNodeDir != 0u);
2070 JLOG(
journal_.trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
2077 UInt256 closedLedger = ourClosed->header().hash;
2078 UInt256 const prevClosedLedger = ourClosed->header().parentHash;
2079 JLOG(
journal_.trace()) <<
"OurClosed: " << closedLedger;
2080 JLOG(
journal_.trace()) <<
"PrevClosed: " << prevClosedLedger;
2085 auto& validations =
registry_.get().getValidations();
2090 peerCounts[closedLedger] = 0;
2092 peerCounts[closedLedger]++;
2094 for (
auto& peer : peerList)
2096 UInt256 const peerLedger = peer->getClosedLedgerHash();
2099 ++peerCounts[peerLedger];
2102 for (
auto const& it : peerCounts)
2103 JLOG(
journal_.debug()) <<
"L: " << it.first <<
" n=" << it.second;
2105 UInt256 const preferredLCL = validations.getPreferredLCL(
2110 bool switchLedgers = preferredLCL != closedLedger;
2112 closedLedger = preferredLCL;
2114 if (switchLedgers && (closedLedger == prevClosedLedger))
2117 JLOG(
journal_.info()) <<
"We won't switch to our own previous ledger";
2118 networkClosed = ourClosed->header().hash;
2119 switchLedgers =
false;
2123 networkClosed = closedLedger;
2129 auto consensus =
ledgerMaster_.getLedgerByHash(closedLedger);
2133 consensus =
registry_.get().getInboundLedgers().acquire(
2143 networkClosed = ourClosed->header().hash;
2147 JLOG(
journal_.warn()) <<
"We are not running on the consensus ledger";
2148 JLOG(
journal_.info()) <<
"Our LCL: " << ourClosed->header().hash <<
getJson({*ourClosed, {}});
2149 JLOG(
journal_.info()) <<
"Net LCL " << closedLedger;
2171 JLOG(
journal_.error()) <<
"JUMP last closed ledger to " << newLCL->header().hash;
2176 registry_.get().getTxQ().processClosedLedger(
registry_.get().getApp(), *newLCL,
true);
2183 auto retries =
localTX_->getTxSet();
2184 auto const lastVal =
registry_.get().getLedgerMaster().getValidatedLedger();
2211 protocol::TMStatusChange s;
2212 s.set_newevent(protocol::neSWITCHED_LEDGER);
2213 s.set_ledgerseq(newLCL->header().seq);
2214 s.set_networktime(
registry_.get().getTimeKeeper().now().time_since_epoch().count());
2215 s.set_ledgerhashprevious(
2216 newLCL->header().parentHash.begin(), newLCL->header().parentHash.size());
2217 s.set_ledgerhash(newLCL->header().hash.begin(), newLCL->header().hash.size());
2227 XRPL_ASSERT(networkClosed.
isNonZero(),
"xrpl::NetworkOPsImp::beginConsensus : nonzero input");
2229 auto const closingInfo =
ledgerMaster_.getCurrentLedger()->header();
2231 JLOG(
journal_.info()) <<
"Consensus time for #" << closingInfo.seq <<
" with LCL "
2232 << closingInfo.parentHash;
2234 auto const prevLedger =
ledgerMaster_.getLedgerByHash(closingInfo.parentHash);
2241 JLOG(
journal_.warn()) <<
"Don't have LCL, going to tracking";
2243 CLOG(clog) <<
"beginConsensus Don't have LCL, going to tracking. ";
2246 CLOG(clog) <<
"beginConsensus no previous ledger. ";
2251 prevLedger->header().hash == closingInfo.parentHash,
2252 "xrpl::NetworkOPsImp::beginConsensus : prevLedger hash matches "
2255 closingInfo.parentHash ==
ledgerMaster_.getClosedLedger()->header().hash,
2256 "xrpl::NetworkOPsImp::beginConsensus : closedLedger parent matches "
2259 registry_.get().getValidators().setNegativeUNL(prevLedger->negativeUNL());
2261 registry_.get().getValidations().getCurrentNodeIDs(),
2262 closingInfo.parentCloseTime,
2267 if (!changes.
added.empty() || !changes.
removed.empty())
2271 registry_.get().getAmendmentTable().trustChanged(
2272 registry_.get().getValidators().getQuorumKeys().second);
2276 registry_.get().getTimeKeeper().closeTime(),
2290 JLOG(
journal_.debug()) <<
"Initiating consensus engine";
2297 auto const& peerKey = peerPos.
publicKey();
2309 JLOG(
journal_.error()) <<
"Received a proposal signed by MY KEY from a peer. This may "
2310 "indicate a misconfiguration where another node has the same "
2311 "validator key, or may be caused by unusual message routing and "
2324 protocol::TMHaveTransactionSet msg;
2325 msg.set_hash(map->getHash().asUInt256().begin(), 256 / 8);
2326 msg.set_status(protocol::tsHAVE);
2339 for (
auto const& it :
registry_.get().getOverlay().getActivePeers())
2341 if (it && (it->getClosedLedgerHash() == deadLedger))
2343 JLOG(
journal_.trace()) <<
"Killing obsolete peer status";
2349 bool const ledgerChange =
2352 if (networkClosed.
isZero())
2354 CLOG(clog) <<
"endConsensus last closed ledger is zero. ";
2380 if (
registry_.get().getTimeKeeper().now() <
2381 (current->header().parentCloseTime + 2 * current->header().closeTimeResolution))
2415 jvObj[jss::type] =
"manifestReceived";
2421 jvObj[jss::signature] =
strHex(*sig);
2424 jvObj[jss::domain] = mo.
domain;
2429 if (
auto p = i->second.lock())
2431 p->send(jvObj,
true);
2450 ,
em{escalationMetrics}
2464 em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
2465 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
2466 em->referenceFeeLevel != b.
em->referenceFeeLevel);
2500 registry_.get().getOpenLedger().current()->fees().base,
2504 jvObj[jss::type] =
"serverStatus";
2517 jvObj[jss::load_factor] =
trunc32(loadFactor);
2518 jvObj[jss::load_factor_fee_escalation] = f.
em->openLedgerFeeLevel.jsonClipped();
2519 jvObj[jss::load_factor_fee_queue] = f.
em->minProcessingFeeLevel.jsonClipped();
2520 jvObj[jss::load_factor_fee_reference] = f.
em->referenceFeeLevel.jsonClipped();
2538 p->send(jvObj,
true);
2561 if (!streamMap.empty())
2564 jvObj[jss::type] =
"consensusPhase";
2565 jvObj[jss::consensus] =
to_string(phase);
2567 for (
auto i = streamMap.begin(); i != streamMap.end();)
2569 if (
auto p = i->second.lock())
2571 p->send(jvObj,
true);
2577 i = streamMap.erase(i);
2598 auto const signerPublic = val->getSignerPublic();
2600 jvObj[jss::type] =
"validationReceived";
2602 jvObj[jss::ledger_hash] =
to_string(val->getLedgerHash());
2603 jvObj[jss::signature] =
strHex(val->getSignature());
2604 jvObj[jss::full] = val->isFull();
2605 jvObj[jss::flags] = val->getFlags();
2606 jvObj[jss::signing_time] = *(*val)[~sfSigningTime];
2607 jvObj[jss::data] =
strHex(val->getSerializer().slice());
2608 jvObj[jss::network_id] =
registry_.get().getNetworkIDService().getNetworkID();
2610 if (
auto const version = (*val)[~sfServerVersion])
2613 if (
auto const cookie = (*val)[~sfCookie])
2616 if (
auto const hash = (*val)[~sfValidatedHash])
2617 jvObj[jss::validated_hash] =
strHex(*hash);
2619 auto const masterKey =
registry_.get().getValidatorManifests().getMasterKey(signerPublic);
2621 if (masterKey != signerPublic)
2626 if (
auto const seq = (*val)[~sfLedgerSequence])
2627 jvObj[jss::ledger_index] = *seq;
2629 if (val->isFieldPresent(sfAmendments))
2632 for (
auto const& amendment : val->getFieldV256(sfAmendments))
2636 if (
auto const closeTime = (*val)[~sfCloseTime])
2637 jvObj[jss::close_time] = *closeTime;
2639 if (
auto const loadFee = (*val)[~sfLoadFee])
2640 jvObj[jss::load_fee] = *loadFee;
2644 if (
auto const baseFeeXRP = ~val->at(~sfBaseFeeDrops); baseFeeXRP && baseFeeXRP->native())
2645 jvObj[jss::base_fee] = baseFeeXRP->xrp().jsonClipped();
2647 if (
auto const reserveBaseXRP = ~val->at(~sfReserveBaseDrops);
2648 reserveBaseXRP && reserveBaseXRP->native())
2649 jvObj[jss::reserve_base] = reserveBaseXRP->xrp().jsonClipped();
2651 if (
auto const reserveIncXRP = ~val->at(~sfReserveIncrementDrops);
2652 reserveIncXRP && reserveIncXRP->native())
2653 jvObj[jss::reserve_inc] = reserveIncXRP->xrp().jsonClipped();
2655 if (
auto const gasLimit = ~val->at(~sfGasLimit); gasLimit)
2656 jvObj[jss::gas_limit] = *gasLimit;
2658 if (
auto const bytecodeSizeLimit = ~val->at(~sfBytecodeSizeLimit); bytecodeSizeLimit)
2659 jvObj[jss::bytecode_size_limit] = *bytecodeSizeLimit;
2661 if (
auto const gasPrice = ~val->at(~sfGasPrice); gasPrice)
2662 jvObj[jss::gas_price] = *gasPrice;
2671 if (jvTx.
isMember(jss::ledger_index))
2673 jvTx[jss::ledger_index] =
std::to_string(jvTx[jss::ledger_index].asUInt());
2679 if (
auto p = i->second.lock())
2683 [&](
json::Value const& jv) { p->send(jv, true); });
2709 jvObj[jss::type] =
"peerStatusChange";
2717 p->send(jvObj,
true);
2732 using namespace std::chrono_literals;
2735 if (
registry_.get().getLedgerMaster().getValidatedLedgerAge() < 1min)
2740 if (
registry_.get().getLedgerMaster().getValidatedLedgerAge() >= 1min)
2761 JLOG(
journal_.trace()) <<
"recvValidation " << val->getLedgerHash() <<
" from " << source;
2780 JLOG(
journal_.warn()) <<
"Exception thrown for handling new validation "
2781 << val->getLedgerHash() <<
": " << e.
what();
2785 JLOG(
journal_.warn()) <<
"Unknown exception thrown for handling new validation "
2786 << val->getLedgerHash();
2796 JLOG(
journal_.debug()) << [
this, &val] ->
auto {
2798 ss <<
"VALIDATION: " << val->render() <<
" master_key: ";
2799 auto master =
registry_.get().getValidators().getTrustedKey(val->getSignerPublic());
2813 return registry_.get().getApp().config().relayUntrustedValidations == 1 || val->isTrusted();
2835 "This server is amendment blocked, and must be updated to be "
2836 "able to stay in sync with the network.";
2843 "This server has an expired validator list. validators.txt "
2844 "may be incorrectly configured or some [validator_list_sites] "
2845 "may be unreachable.";
2852 "One or more unsupported amendments have reached majority. "
2853 "Upgrade to the latest version before they are activated "
2854 "to avoid being amendment blocked.";
2855 if (
auto const expected =
2856 registry_.get().getAmendmentTable().firstUnsupportedExpected())
2859 d[jss::expected_date] = expected->time_since_epoch().count();
2860 d[jss::expected_date_UTC] =
to_string(*expected);
2864 if (warnings.
size() != 0u)
2865 info[jss::warnings] = std::move(warnings);
2873 if (!
registry_.get().getApp().config().serverDomain.empty())
2874 info[jss::server_domain] =
registry_.get().getApp().config().serverDomain;
2884 info[jss::network_ledger] =
"waiting";
2886 info[jss::validation_quorum] =
2894 switch (
registry_.get().getApp().config().nodeSize)
2897 info[jss::node_size] =
"tiny";
2900 info[jss::node_size] =
"small";
2903 info[jss::node_size] =
"medium";
2906 info[jss::node_size] =
"large";
2909 info[jss::node_size] =
"huge";
2913 auto when =
registry_.get().getValidators().expires();
2919 info[jss::validator_list_expires] =
2924 info[jss::validator_list_expires] = 0;
2935 if (*when == TimeKeeper::time_point::max())
2937 x[jss::expiration] =
"never";
2938 x[jss::status] =
"active";
2944 if (*when >
registry_.get().getTimeKeeper().now())
2946 x[jss::status] =
"active";
2950 x[jss::status] =
"expired";
2956 x[jss::status] =
"unknown";
2957 x[jss::expiration] =
"unknown";
2970 info[jss::io_latency_ms] =
2975 if (
auto const localPubKey =
registry_.get().getValidators().localPublicKey();
2976 localPubKey &&
registry_.get().getApp().getValidationPublicKey())
2982 info[jss::pubkey_validator] =
"none";
2988 info[jss::counters] =
registry_.get().getPerfLog().countersJson();
2991 registry_.get().getNodeStore().getCountsJson(nodestore);
2992 info[jss::counters][jss::nodestore] = nodestore;
2993 info[jss::current_activities] =
registry_.get().getPerfLog().currentJson();
2996 info[jss::pubkey_node] =
2999 info[jss::complete_ledgers] =
registry_.get().getLedgerMaster().getCompleteLedgers();
3002 info[jss::amendment_blocked] =
true;
3016 lastClose[jss::converge_time_s] =
3024 info[jss::last_close] = lastClose;
3031 if (
auto const netid =
registry_.get().getOverlay().networkID())
3032 info[jss::network_id] =
static_cast<json::UInt>(*netid);
3034 auto const escalationMetrics =
3037 auto const loadFactorServer =
registry_.get().getFeeTrack().getLoadFactor();
3038 auto const loadBaseServer =
registry_.get().getFeeTrack().getLoadBase();
3042 auto const loadFactorFeeEscalation =
mulDiv(
3043 escalationMetrics.openLedgerFeeLevel,
3045 escalationMetrics.referenceFeeLevel)
3048 auto const loadFactor =
3053 info[jss::load_base] = loadBaseServer;
3054 info[jss::load_factor] =
trunc32(loadFactor);
3055 info[jss::load_factor_server] = loadFactorServer;
3062 info[jss::load_factor_fee_escalation] = escalationMetrics.openLedgerFeeLevel.jsonClipped();
3063 info[jss::load_factor_fee_queue] = escalationMetrics.minProcessingFeeLevel.jsonClipped();
3064 info[jss::load_factor_fee_reference] = escalationMetrics.referenceFeeLevel.jsonClipped();
3068 info[jss::load_factor] =
static_cast<double>(loadFactor) / loadBaseServer;
3070 if (loadFactorServer != loadFactor)
3071 info[jss::load_factor_server] =
static_cast<double>(loadFactorServer) / loadBaseServer;
3076 if (fee != loadBaseServer)
3077 info[jss::load_factor_local] =
static_cast<double>(fee) / loadBaseServer;
3078 fee =
registry_.get().getFeeTrack().getRemoteFee();
3079 if (fee != loadBaseServer)
3080 info[jss::load_factor_net] =
static_cast<double>(fee) / loadBaseServer;
3081 fee =
registry_.get().getFeeTrack().getClusterFee();
3082 if (fee != loadBaseServer)
3083 info[jss::load_factor_cluster] =
static_cast<double>(fee) / loadBaseServer;
3085 if (escalationMetrics.openLedgerFeeLevel != escalationMetrics.referenceFeeLevel &&
3086 (admin || loadFactorFeeEscalation != loadFactor))
3088 info[jss::load_factor_fee_escalation] =
3089 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
3090 escalationMetrics.referenceFeeLevel);
3092 if (escalationMetrics.minProcessingFeeLevel != escalationMetrics.referenceFeeLevel)
3094 info[jss::load_factor_fee_queue] =
3095 escalationMetrics.minProcessingFeeLevel.decimalFromReference(
3096 escalationMetrics.referenceFeeLevel);
3114 XRPAmount const baseFee = lpClosed->fees().base;
3116 l[jss::seq] =
json::UInt(lpClosed->header().seq);
3117 l[jss::hash] =
to_string(lpClosed->header().hash);
3119 bool const smartEscrowEnabled = lpClosed->rules().enabled(featureSmartEscrow);
3123 l[jss::reserve_base] = lpClosed->fees().reserve.jsonClipped();
3124 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3125 if (smartEscrowEnabled)
3127 l[jss::gas_limit] = lpClosed->fees().gasLimit;
3128 l[jss::bytecode_size_limit] = lpClosed->fees().bytecodeSizeLimit;
3129 l[jss::gas_price] = lpClosed->fees().gasPrice;
3131 l[jss::close_time] =
3137 l[jss::reserve_base_xrp] = lpClosed->fees().reserve.decimalXRP();
3138 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
3139 if (smartEscrowEnabled)
3141 l[jss::gas_limit] = lpClosed->fees().gasLimit;
3142 l[jss::bytecode_size_limit] = lpClosed->fees().bytecodeSizeLimit;
3143 l[jss::gas_price] = lpClosed->fees().gasPrice;
3146 if (
auto const closeOffset =
registry_.get().getTimeKeeper().closeOffset();
3147 std::abs(closeOffset.count()) >= 60)
3148 l[jss::close_time_offset] =
static_cast<std::uint32_t>(closeOffset.count());
3158 auto const lCloseTime = lpClosed->header().closeTime;
3159 auto const closeTime =
registry_.get().getTimeKeeper().closeTime();
3160 if (lCloseTime <= closeTime)
3162 using namespace std::chrono_literals;
3163 auto const age = closeTime - lCloseTime;
3171 info[jss::validated_ledger] = l;
3175 info[jss::closed_ledger] = l;
3178 auto const lpPublished =
ledgerMaster_.getPublishedLedger();
3181 info[jss::published_ledger] =
"none";
3183 else if (lpPublished->header().seq != lpClosed->header().seq)
3185 info[jss::published_ledger] = lpPublished->header().seq;
3191 info[jss::jq_trans_overflow] =
3194 info[jss::peer_disconnects_resources] =
3210 for (
auto const& port :
registry_.get().getServerHandler().setup().ports)
3214 !(port.adminNetsV4.empty() && port.adminNetsV6.empty() && port.adminUser.empty() &&
3215 port.adminPassword.empty()))
3230 for (
auto const& p : proto)
3231 jv[jss::protocol].
append(p);
3237 auto const& grpcSection =
3239 auto const optPort = grpcSection.get(
Keys::kPort);
3240 if (optPort && grpcSection.get(
Keys::kIp))
3243 jv[jss::port] = *optPort;
3245 jv[jss::protocol].
append(
"grpc");
3248 info[jss::ports] = std::move(ports);
3257 registry_.get().getInboundLedgers().clearFailures();
3263 return registry_.get().getInboundLedgers().getInfo();
3299 [&](
json::Value const& jv) { p->send(jv, true); });
3320 registry_.get().getAcceptedLedgerCache().fetch(lpAccepted->header().hash);
3324 registry_.get().getAcceptedLedgerCache().canonicalizeReplaceClient(
3325 lpAccepted->header().hash, alpAccepted);
3329 alpAccepted->getLedger().get() == lpAccepted.
get(),
3330 "xrpl::NetworkOPsImp::pubLedger : accepted input");
3332 JLOG(
journal_.debug()) <<
"Publishing ledger " << lpAccepted->header().seq <<
" "
3333 << lpAccepted->header().hash;
3342 for (
auto const& accTx : *alpAccepted)
3344 JLOG(
journal_.trace()) <<
"pubAccepted: " << accTx->getJson();
3345 bool const last = &*accTx == &alpAccepted->back();
3367 jvObj[jss::type] =
"ledgerClosed";
3368 jvObj[jss::ledger_index] = lpAccepted->header().seq;
3369 jvObj[jss::ledger_hash] =
to_string(lpAccepted->header().hash);
3370 jvObj[jss::ledger_time] =
3373 jvObj[jss::network_id] =
registry_.get().getNetworkIDService().getNetworkID();
3375 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
3376 jvObj[jss::reserve_base] = lpAccepted->fees().reserve.jsonClipped();
3377 jvObj[jss::reserve_inc] = lpAccepted->fees().increment.jsonClipped();
3378 if (lpAccepted->rules().enabled(featureSmartEscrow))
3380 jvObj[jss::gas_limit] = lpAccepted->fees().gasLimit;
3381 jvObj[jss::bytecode_size_limit] = lpAccepted->fees().bytecodeSizeLimit;
3382 jvObj[jss::gas_price] = lpAccepted->fees().gasPrice;
3385 jvObj[jss::txn_count] =
json::UInt(alpAccepted->size());
3389 jvObj[jss::validated_ledgers] =
registry_.get().getLedgerMaster().getCompleteLedgers();
3397 p->send(jvObj,
true);
3418 p->send(jvObj,
true);
3445 for (
auto& inner : outer.second)
3447 auto& subInfo = inner.second;
3448 if (subInfo.index->separationLedgerSeq == 0)
3458 registry_.get().getOpenLedger().current()->fees().base,
3491 for (
auto const& [_, subs] :
subBook_)
3492 total += subs.size();
3512 jvObj[jss::type] =
"transaction";
3525 if (
auto const& lookup = ledger->txRead(transaction->getTransactionID());
3526 lookup.second && lookup.second->isFieldPresent(sfTransactionIndex))
3528 uint32_t
const txnSeq = lookup.second->getFieldU32(sfTransactionIndex);
3529 uint32_t netID =
registry_.get().getNetworkIDService().getNetworkID();
3530 if (transaction->isFieldPresent(sfNetworkID))
3531 netID = transaction->getFieldU32(sfNetworkID);
3535 jvObj[jss::ctid] = *ctid;
3537 if (!ledger->open())
3538 jvObj[jss::ledger_hash] =
to_string(ledger->header().hash);
3542 jvObj[jss::ledger_index] = ledger->header().seq;
3543 jvObj[jss::transaction][jss::date] = ledger->header().closeTime.time_since_epoch().count();
3544 jvObj[jss::validated] =
true;
3545 jvObj[jss::close_time_iso] =
toStringIso(ledger->header().closeTime);
3551 jvObj[jss::validated] =
false;
3552 jvObj[jss::ledger_current_index] = ledger->header().seq;
3555 jvObj[jss::status] = validated ?
"closed" :
"proposed";
3556 jvObj[jss::engine_result] = sToken;
3557 jvObj[jss::engine_result_code] = result;
3558 jvObj[jss::engine_result_message] = sHuman;
3560 if (transaction->getTxnType() == ttOFFER_CREATE)
3562 auto const account = transaction->getAccountID(sfAccount);
3563 auto const amount = transaction->getFieldAmount(sfTakerGets);
3566 if (account != amount.getIssuer())
3575 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3584 rpc::insertDeliverMax(jvTx[jss::transaction], transaction->getTxnType(), Version);
3586 if constexpr (Version > 1)
3588 jvTx[jss::tx_json] = jvTx.removeMember(jss::transaction);
3589 jvTx[jss::hash] = hash;
3593 jvTx[jss::transaction][jss::hash] = hash;
3606 auto const& stTxn = transaction.
getTxn();
3610 auto const trResult = transaction.
getResult();
3631 [&](
json::Value const& jv) { p->send(jv, true); });
3651 [&](
json::Value const& jv) { p->send(jv, true); });
3701 listeners.
reserve(books.size());
3707 for (
auto const& book : books)
3709 auto const it =
subBook_.find(book);
3713 for (
auto sit = it->second.begin(); sit != it->second.end();)
3715 if (
auto p = sit->second.lock())
3722 if (seen.
emplace(p->getSeq()).second)
3729 <<
"pubBookTransaction: pruning expired weak_ptr for seq=" << sit->first;
3730 sit = it->second.erase(sit);
3734 if (it->second.empty())
3739 for (
auto const& p : listeners)
3741 jvObj.
visit(p->getApiVersion(), [&](
json::Value const& jv) { p->send(jv, true); });
3758 auto const currLedgerSeq = ledger->seq();
3764 for (
auto const& affectedAccount : transaction.
getAffected())
3766 if (
auto const simiIt =
subRTAccount_.find(affectedAccount);
3769 auto it = simiIt->second.begin();
3771 while (it != simiIt->second.end())
3783 it = simiIt->second.erase(it);
3788 if (
auto const simiIt =
subAccount_.find(affectedAccount);
3791 auto it = simiIt->second.begin();
3792 while (it != simiIt->second.end())
3804 it = simiIt->second.erase(it);
3812 auto& subs = historyIt->second;
3813 auto it = subs.begin();
3814 while (it != subs.end())
3817 if (currLedgerSeq <= info.index->separationLedgerSeq)
3831 it = subs.erase(it);
3841 JLOG(
journal_.trace()) <<
"pubAccountTransaction: "
3842 <<
"proposed=" << iProposed <<
", accepted=" << iAccepted;
3844 if (!notify.
empty() || !accountHistoryNotify.
empty())
3846 auto const& stTxn = transaction.
getTxn();
3850 auto const trResult = transaction.
getResult();
3856 isrListener->getApiVersion(),
3857 [&](
json::Value const& jv) { isrListener->send(jv, true); });
3861 jvObj.
set(jss::account_history_boundary,
true);
3864 jvObj.
isMember(jss::account_history_tx_stream) == MultiApiJson::IsMemberResult::None,
3865 "xrpl::NetworkOPsImp::pubAccountTransaction : "
3866 "account_history_tx_stream not set");
3867 for (
auto& info : accountHistoryNotify)
3869 auto const& index = info.index;
3870 if (index->forwardTxIndex == 0 && !index->haveHistorical)
3871 jvObj.
set(jss::account_history_tx_first,
true);
3873 jvObj.
set(jss::account_history_tx_index, index->forwardTxIndex++);
3876 info.sink->getApiVersion(),
3877 [&](
json::Value const& jv) { info.sink->send(jv, true); });
3897 for (
auto const& affectedAccount : tx->getMentionedAccounts())
3899 if (
auto const simiIt =
subRTAccount_.find(affectedAccount);
3902 auto it = simiIt->second.begin();
3904 while (it != simiIt->second.end())
3916 it = simiIt->second.erase(it);
3923 JLOG(
journal_.trace()) <<
"pubProposedAccountTransaction: " << iProposed;
3925 if (!notify.
empty())
3933 isrListener->getApiVersion(),
3934 [&](
json::Value const& jv) { isrListener->send(jv, true); });
3951 for (
auto const& naAccountID : vnaAccountIDs)
3953 JLOG(
journal_.trace()) <<
"subAccount: account: " <<
toBase58(naAccountID);
3955 isrListener->insertSubAccountInfo(naAccountID, rt);
3960 for (
auto const& naAccountID : vnaAccountIDs)
3962 auto const simIterator = subMap.
find(naAccountID);
3963 if (simIterator == subMap.
end())
3967 usisElement[isrListener->getSeq()] = isrListener;
3969 subMap.
insert(simIterator, make_pair(naAccountID, usisElement));
3974 simIterator->second[isrListener->getSeq()] = isrListener;
3985 for (
auto const& naAccountID : vnaAccountIDs)
3988 isrListener->deleteSubAccountInfo(naAccountID, rt);
4005 for (
auto const& naAccountID : vnaAccountIDs)
4007 auto const simIterator = subMap.
find(naAccountID);
4009 if (simIterator != subMap.
end())
4012 simIterator->second.erase(uSeq);
4014 if (simIterator->second.empty())
4017 subMap.
erase(simIterator);
4023template <
typename OuterMap,
typename BeforeErase>
4029 BeforeErase&& beforeErase)
4036 auto it = accounts.
begin();
4037 auto const end = accounts.
end();
4044 auto const outerIter = outerMap.find(*it);
4045 if (outerIter != outerMap.end())
4050 auto const innerIter = outerIter->second.find(seq);
4051 if (innerIter != outerIter->second.end())
4052 beforeErase(innerIter->second);
4056 outerIter->second.erase(seq);
4057 if (outerIter->second.empty())
4058 outerMap.erase(outerIter);
4085 info.
index->stopHistorical =
true;
4097 if (rtAccounts.
empty() && normalAccounts.
empty() && historyAccounts.
empty())
4119 rt = std::move(rtAccounts),
4120 normal = std::move(normalAccounts),
4121 history = std::move(historyAccounts)]
noexcept {
4130 JLOG(
journal_.error()) <<
"SubCleanup[seq=" << seq <<
"]: " << e.
what();
4134 JLOG(
journal_.error()) <<
"SubCleanup[seq=" << seq <<
"]: unknown exception";
4153 if (affectedMPTs.empty())
4163 for (
auto const& affectedMPT : affectedMPTs)
4165 if (
auto const simiIt =
subMPT_.find(affectedMPT); simiIt !=
subMPT_.end())
4167 auto it = simiIt->second.begin();
4168 while (it != simiIt->second.end())
4179 it = simiIt->second.erase(it);
4192 isrListener->send(jv, true);
4206 for (
auto const& mptID : mptIDs)
4210 auto const simIterator =
subMPT_.find(mptID);
4211 if (simIterator ==
subMPT_.end())
4215 usisElement[isrListener->getSeq()] = isrListener;
4216 subMPT_.insert(simIterator, make_pair(mptID, usisElement));
4221 simIterator->second[isrListener->getSeq()] = isrListener;
4226 for (
auto const& mptID : mptIDs)
4227 isrListener->insertSubMPTInfo(mptID);
4233 for (
auto const& mptID : mptIDs)
4238 isrListener->deleteSubMPTInfo(mptID);
4249 auto const simIterator =
subMPT_.find(mptID);
4250 if (simIterator ==
subMPT_.end())
4253 simIterator->second.erase(uSeq);
4254 if (simIterator->second.empty())
4265 auto const& accountId = subInfo.
index->accountId;
4266 auto& lastLedgerSeq = subInfo.
index->historyLastLedgerSeq;
4267 auto& txHistoryIndex = subInfo.
index->historyTxIndex;
4269 JLOG(
journal_.trace()) <<
"AccountHistory job for account " <<
toBase58(accountId)
4270 <<
" started. lastLedgerSeq=" << lastLedgerSeq;
4280 auto const stx = tx->getSTransaction();
4281 if (stx->getAccountID(sfAccount) == accountId && stx->getSeqProxy().value() == 1)
4286 if (node.getFieldU16(sfLedgerEntryType) != ltACCOUNT_ROOT)
4289 if (node.isFieldPresent(sfNewFields))
4291 if (auto inner = dynamic_cast<STObject const*>(node.peekAtPField(sfNewFields));
4294 if (inner->isFieldPresent(sfAccount) &&
4295 inner->getAccountID(sfAccount) == accountId)
4305 auto const send = [&](
json::Value const& jvObj,
bool unsubscribe) ->
bool {
4308 sptr->send(jvObj,
true);
4317 auto const sendMultiApiJson = [&](
MultiApiJson const& jvObj,
bool unsubscribe) ->
bool {
4321 sptr->getApiVersion(),
4322 [&](
json::Value const& jv) { sptr->send(jv, true); });
4338 auto& db =
registry_.get().getRelationalDatabase();
4340 .account = accountId,
4341 .ledgerRange = {.min = minLedger, .max = maxLedger},
4345 .delegate = std::nullopt,
4347 return db.newestAccountTxPage(options);
4353 while (lastLedgerSeq >= 2 && !subInfo.
index->stopHistorical)
4355 int feeChargeCount = 0;
4356 if (auto const sptr = subInfo.sinkWptr.lock(); sptr)
4358 sptr->getConsumer().charge(resource::kFeeMediumBurdenRpc);
4363 JLOG(journal_.trace())
4364 <<
"AccountHistory job for account " << toBase58(accountId)
4365 <<
" no InfoSub. Fee charged " << feeChargeCount <<
" times.";
4370 auto startLedgerSeq = (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
4372 <<
"AccountHistory job for account " <<
toBase58(accountId)
4373 <<
", working on ledger range [" << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
4375 auto const haveRange = [&] ->
bool {
4378 auto const haveSomeValidatedLedgers =
4379 registry_.get().getLedgerMaster().getValidatedRange(validatedMin, validatedMax);
4381 return haveSomeValidatedLedgers && validatedMin <= startLedgerSeq &&
4382 lastLedgerSeq <= validatedMax;
4387 JLOG(
journal_.debug()) <<
"AccountHistory reschedule job for account "
4388 <<
toBase58(accountId) <<
", incomplete ledger range ["
4389 << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
4395 while (!subInfo.
index->stopHistorical)
4397 auto const dbResult = getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
4399 auto const& txns = dbResult.first;
4400 marker = dbResult.second;
4401 size_t const numTxns = txns.size();
4402 for (size_t i = 0; i < numTxns; ++i)
4404 auto const& [tx, meta] = txns[i];
4408 JLOG(journal_.debug()) <<
"AccountHistory job for account "
4409 << toBase58(accountId) <<
" empty tx or meta.";
4410 send(rpcError(RpcInternal), true);
4413 auto const curTxLedger =
4414 registry_.get().getLedgerMaster().getLedgerBySeq(tx->getLedger());
4419 "xrpl::NetworkOPsImp::addAccountHistoryJob : "
4420 "getLedgerBySeq failed");
4421 JLOG(journal_.debug()) <<
"AccountHistory job for account "
4422 << toBase58(accountId) <<
" no ledger.";
4423 send(rpcError(RpcInternal), true);
4427 std::shared_ptr<STTx const> const stTxn = tx->getSTransaction();
4432 "NetworkOPsImp::addAccountHistoryJob : "
4433 "getSTransaction failed");
4434 JLOG(journal_.debug()) <<
"AccountHistory job for account "
4435 << toBase58(accountId) <<
" getSTransaction failed.";
4436 send(rpcError(RpcInternal), true);
4441 auto const ref = std::ref(*meta);
4442 auto const trR = meta->getResultTER();
4443 MultiApiJson jvTx = transJson(stTxn, trR, true, curTxLedger, ref);
4445 jvTx.set(jss::account_history_tx_index, txHistoryIndex--);
4446 if (i + 1 == numTxns || txns[i + 1].first->getLedger() != tx->getLedger())
4447 jvTx.set(jss::account_history_boundary, true);
4449 if (isFirstTx(tx, meta))
4451 jvTx.set(jss::account_history_tx_first, true);
4452 sendMultiApiJson(jvTx, false);
4454 JLOG(journal_.trace()) <<
"AccountHistory job for account "
4455 << toBase58(accountId) <<
" done, found last tx.";
4459 sendMultiApiJson(jvTx, false);
4465 <<
"AccountHistory job for account " <<
toBase58(accountId)
4466 <<
" paging, marker=" << marker->ledgerSeq <<
":" << marker->txnSeq;
4474 if (!subInfo.index->stopHistorical)
4476 lastLedgerSeq = startLedgerSeq - 1;
4477 if (lastLedgerSeq <= 1)
4479 JLOG(journal_.trace())
4480 <<
"AccountHistory job for account " << toBase58(accountId)
4481 <<
" done, reached genesis ledger.";
4494 subInfo.
index->separationLedgerSeq = ledger->seq();
4495 auto const& accountId = subInfo.
index->accountId;
4497 if (!ledger->exists(accountKeylet))
4499 JLOG(
journal_.debug()) <<
"subAccountHistoryStart, no account " <<
toBase58(accountId)
4500 <<
", no need to add AccountHistory job.";
4505 if (
auto const sleAcct = ledger->read(accountKeylet); sleAcct)
4507 if (sleAcct->getFieldU32(sfSequence) == 1)
4510 <<
"subAccountHistoryStart, genesis account " <<
toBase58(accountId)
4511 <<
" does not have tx, no need to add AccountHistory job.";
4519 "xrpl::NetworkOPsImp::subAccountHistoryStart : failed to "
4520 "access genesis account");
4525 subInfo.
index->historyLastLedgerSeq = ledger->seq();
4526 subInfo.
index->haveHistorical =
true;
4528 JLOG(
journal_.debug()) <<
"subAccountHistoryStart, add AccountHistory job: accountId="
4529 <<
toBase58(accountId) <<
", currentLedgerSeq=" << ledger->seq();
4537 if (!isrListener->insertSubAccountHistory(accountId))
4539 JLOG(
journal_.debug()) <<
"subAccountHistory, already subscribed to account "
4546 .sinkWptr = isrListener,
4553 inner.
emplace(isrListener->getSeq(), ahi);
4558 simIterator->second.emplace(isrListener->getSeq(), ahi);
4561 auto const ledger =
registry_.get().getLedgerMaster().getValidatedLedger();
4571 JLOG(
journal_.debug()) <<
"subAccountHistory, no validated ledger yet, delay start";
4584 isrListener->deleteSubAccountHistory(account);
4598 auto& subInfoMap = simIterator->second;
4599 auto const subInfoIter = subInfoMap.find(seq);
4600 if (subInfoIter != subInfoMap.end())
4602 subInfoIter->second.index->stopHistorical =
true;
4607 simIterator->second.erase(seq);
4608 if (simIterator->second.empty())
4613 JLOG(
journal_.debug()) <<
"unsubAccountHistory, account " <<
toBase58(account)
4614 <<
", historyOnly = " << (historyOnly ?
"true" :
"false");
4627 subBook_[book].try_emplace(isrListener->getSeq(), isrListener);
4629 isrListener->insertBookSubscription(book);
4639 isrListener->deleteBookSubscription(book);
4647 auto const it =
subBook_.find(book);
4650 bool const erased = it->second.erase(uSeq) != 0u;
4651 if (it->second.empty())
4661 XRPL_ASSERT(
standalone_,
"xrpl::NetworkOPsImp::acceptLedger : is standalone");
4677 if (
auto const lpClosed =
ledgerMaster_.getValidatedLedger())
4679 jvResult[jss::ledger_index] = lpClosed->header().seq;
4680 jvResult[jss::ledger_hash] =
to_string(lpClosed->header().hash);
4681 jvResult[jss::ledger_time] =
4683 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
4684 jvResult[jss::reserve_base] = lpClosed->fees().reserve.jsonClipped();
4685 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
4686 jvResult[jss::network_id] =
registry_.get().getNetworkIDService().getNetworkID();
4687 if (lpClosed->rules().enabled(featureSmartEscrow))
4689 jvResult[jss::gas_limit] = lpClosed->fees().gasLimit;
4690 jvResult[jss::bytecode_size_limit] = lpClosed->fees().bytecodeSizeLimit;
4691 jvResult[jss::gas_price] = lpClosed->fees().gasPrice;
4697 jvResult[jss::validated_ledgers] =
registry_.get().getLedgerMaster().getCompleteLedgers();
4756 auto const& feeTrack =
registry_.get().getFeeTrack();
4757 jvResult[jss::random] =
to_string(uRandom);
4759 jvResult[jss::load_base] = feeTrack.getLoadBase();
4760 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
4761 jvResult[jss::hostid] =
getHostId(admin);
4762 jvResult[jss::pubkey_node] =
4914 if (map.contains(pInfo->getSeq()))
4923#ifndef USE_NEW_BOOK_PAGE
4933 if (product >=
Number{takerPays})
4947 unsigned int iLimit,
4956 UInt256 uTipIndex = uBookBase;
4958 if (
auto const stream =
journal_.trace())
4960 stream <<
"getBookPage:" << book;
4961 stream <<
"getBookPage: uBookBase=" << uBookBase;
4962 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
4963 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
4971 bool bDirectAdvance =
true;
4975 unsigned int uBookEntry = 0;
4979 auto const viewJ =
registry_.get().getJournal(
"View");
4981 while (!bDone && iLimit-- > 0)
4985 bDirectAdvance =
false;
4987 JLOG(
journal_.trace()) <<
"getBookPage: bDirectAdvance";
4989 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
4996 sleOfferDir.
reset();
5001 JLOG(
journal_.trace()) <<
"getBookPage: bDone";
5006 uTipIndex = sleOfferDir->key();
5009 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
5011 JLOG(
journal_.trace()) <<
"getBookPage: uTipIndex=" << uTipIndex;
5012 JLOG(
journal_.trace()) <<
"getBookPage: offerIndex=" << offerIndex;
5022 auto const uOfferOwnerID = sleOffer->getAccountID(sfAccount);
5023 auto const& saTakerGets = sleOffer->getFieldAmount(sfTakerGets);
5024 auto const& saTakerPays = sleOffer->getFieldAmount(sfTakerPays);
5026 bool firstOwnerOffer(
true);
5027 auto foundBalance = [&] {
5028 auto const umBalanceEntry = umBalance.
find(uOfferOwnerID);
5029 if (umBalanceEntry == umBalance.
end())
5033 saOwnerFunds = umBalanceEntry->second;
5034 firstOwnerOffer =
false;
5038 if (book.out.getIssuer() == uOfferOwnerID)
5044 saOwnerFunds = saTakerGets;
5051 if (!foundBalance())
5059 else if (bGlobalFreeze)
5063 saOwnerFunds.
clear(book.out);
5067 if (!foundBalance())
5083 saOwnerFunds.
clear();
5091 STAmount saOwnerFundsLimit = saOwnerFunds;
5096 && uTakerID != book.out.getIssuer()
5098 && book.out.getIssuer() != uOfferOwnerID)
5123 saOwnerFunds.
asset())
5124 :
divide(saOwnerFunds, offerRate);
5127 if (saOwnerFundsLimit >= saTakerGets)
5130 saTakerGetsFunded = saTakerGets;
5136 saTakerGetsFunded = saOwnerFundsLimit;
5138 saTakerGetsFunded.
setJson(jvOffer[jss::taker_gets_funded]);
5140 .
setJson(jvOffer[jss::taker_pays_funded]);
5149 auto const grossed = [&] {
5153 saTakerGetsFunded.
mpt(),
5159 [&](
Issue const&) {
return multiply(saTakerGetsFunded, offerRate); });
5163 :
std::min(saOwnerFunds, grossed());
5165 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
5169 jvOf[jss::quality] = saDirRate.
getText();
5171 if (firstOwnerOffer)
5172 jvOf[jss::owner_funds] = saOwnerFunds.
getText();
5176 JLOG(
journal_.warn()) <<
"Missing offer";
5179 if (!
cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
5181 bDirectAdvance =
true;
5185 JLOG(
journal_.trace()) <<
"getBookPage: offerIndex=" << offerIndex;
5207 unsigned int iLimit,
5215 MetaView lesActive(lpLedger, tapNONE,
true);
5216 OrderBookIterator obIterator(lesActive, book);
5218 auto const rate =
transferRate(lesActive, book.out.account);
5220 bool const bGlobalFreeze =
5221 lesActive.isGlobalFrozen(book.out.account) || lesActive.isGlobalFrozen(book.in.account);
5223 while (iLimit-- > 0 && obIterator.nextOffer())
5228 auto const uOfferOwnerID = sleOffer->getAccountID(sfAccount);
5229 auto const& saTakerGets = sleOffer->getFieldAmount(sfTakerGets);
5230 auto const& saTakerPays = sleOffer->getFieldAmount(sfTakerPays);
5231 STAmount saDirRate = obIterator.getCurrentRate();
5234 if (book.out.account == uOfferOwnerID)
5237 saOwnerFunds = saTakerGets;
5239 else if (bGlobalFreeze)
5243 saOwnerFunds.
clear(book.out);
5247 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
5249 if (umBalanceEntry != umBalance.
end())
5253 saOwnerFunds = umBalanceEntry->second;
5259 saOwnerFunds = lesActive.accountHolds(
5265 if (saOwnerFunds.isNegative())
5269 saOwnerFunds.zero();
5276 STAmount saTakerGetsFunded;
5277 STAmount saOwnerFundsLimit = saOwnerFunds;
5278 Rate offerRate = parityRate;
5280 if (rate != parityRate
5282 && uTakerID !=
book.out.account
5284 &&
book.out.account != uOfferOwnerID)
5289 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
5292 if (saOwnerFundsLimit >= saTakerGets)
5295 saTakerGetsFunded = saTakerGets;
5300 saTakerGetsFunded = saOwnerFundsLimit;
5302 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
5306 std::min(saTakerPays,
multiply(saTakerGetsFunded, saDirRate, saTakerPays.asset()))
5307 .setJson(jvOffer[jss::taker_pays_funded]);
5310 STAmount saOwnerPays = (parityRate == offerRate)
5312 : std::
min(saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
5314 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
5316 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
5319 json::Value& jvOf = jvOffers.append(jvOffer);
5320 jvOf[jss::quality] = saDirRate.getText();
5334 auto [counters, mode, start, initialSync] =
accounting_.getCounterData();
5337 counters[
static_cast<std::size_t>(mode)].dur += current;
5340 stats_.disconnectedDuration.set(
5342 stats_.connectedDuration.set(
5344 stats_.syncingDuration.set(
5346 stats_.trackingDuration.set(
5350 stats_.disconnectedTransitions.set(
5352 stats_.connectedTransitions.set(
5354 stats_.syncingTransitions.set(
5356 stats_.trackingTransitions.set(
5394 auto& state = obj[jss::state_accounting][
kStates[i]];
5395 state[jss::transitions] =
std::to_string(counters[i].transitions);
5396 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
5398 obj[jss::server_state_duration_us] =
std::to_string(current.count());
5399 if (initialSync != 0u)
5400 obj[jss::initial_sync_duration_us] =
std::to_string(initialSync);
5415 boost::asio::io_context& ioCtx,
T back_inserter(T... args)
A generic endpoint for log messages.
std::shared_ptr< Collector > Ptr
A metric for measuring an integral value.
A reference to a handler for performing polled collection.
Decorator for streaming out compact json.
Lightweight wrapper to tag static string.
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
bool isMember(char const *key) const
Return true if the object has a member named key.
A transaction that is in a closed ledger.
TxMeta const & getMeta() const
boost::container::flat_set< AccountID > const & getAffected() const
std::shared_ptr< STTx const > const & getTxn() const
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
static constexpr std::size_t size()
Holds transactions which were deferred to the next pass of consensus.
The role of a ClosureCounter is to assist in shutdown by letting callers wait for the completion of c...
std::uint32_t getLoadFee() const
NetClock::time_point getReportTime() const
PublicKey const & identity() const
std::string const & name() const
std::shared_ptr< InfoSub > const & Ref
std::shared_ptr< InfoSub > pointer
std::weak_ptr< InfoSub > Wptr
A currency issued by an account.
A pool of threads to perform work.
Tracks the current ledger and any ledgers in the process of closing.
Manages the current fee schedule.
void heartbeat()
Reset the stall detection timer.
static constexpr int kHoldLedgers
State accounting records two attributes for each possible server state: 1) Amount of time spent in ea...
void json(json::Value &obj) const
Output state counters in JSON format.
std::chrono::steady_clock::time_point const processStart_
CounterData getCounterData() const
std::uint64_t initialSyncUs_
static std::array< json::StaticString const, 5 > const kStates
std::array< Counters, 5 > counters_
void mode(OperatingMode om)
Record state transition.
std::chrono::steady_clock::time_point start_
Transaction with input flags and results to be applied in batches.
std::shared_ptr< Transaction > const transaction
TransactionStatus(std::shared_ptr< Transaction > t, bool a, bool l, FailHard f)
SubBookMapType subBook_
Guarded by bookLock_.
std::string getHostId(bool forAdmin)
void reportConsensusStateChange(ConsensusPhase phase)
void addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo)
void clearNeedNetworkLedger() override
SubInfoMapType subAccount_
HashMap< AccountID, HashMap< std::uint64_t, SubAccountHistoryInfoWeak > > SubAccountHistoryMapType
static constexpr std::size_t kAccountCleanupChunk
Maximum number of account entries erased per accountLock_ acquisition during disconnect-time cleanup.
bool subManifests(InfoSub::Ref ispListener) override
std::size_t const minPeerCount_
bool subServer(InfoSub::Ref ispListener, json::Value &jvResult, bool admin) override
std::vector< TransactionStatus > transactions_
bool subPeerStatus(InfoSub::Ref ispListener) override
void pubAccountTransaction(std::shared_ptr< ReadView const > const &ledger, AcceptedLedgerTx const &transaction, bool last)
void subMPT(InfoSub::Ref ispListener, HashSet< MPTID > const &mptIDs) override
void unsubAccount(InfoSub::Ref ispListener, HashSet< AccountID > const &vnaAccountIDs, bool rt) override
void pubPeerStatus(std::function< json::Value()> const &) override
bool subValidations(InfoSub::Ref ispListener) override
ClosureCounter< void, boost::system::error_code const & > waitHandlerCounter_
std::condition_variable cond_
MultiApiJson transJson(std::shared_ptr< STTx const > const &transaction, TER result, bool validated, std::shared_ptr< ReadView const > const &ledger, std::optional< std::reference_wrapper< TxMeta const > > meta)
bool unsubManifests(std::uint64_t uListener) override
json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account) override
void unsubMPTInternal(std::uint64_t seq, MPTID const &mptID) override
Remove an MPT issuance subscription during InfoSub teardown.
HashMap< Book, SubMapType > SubBookMapType
Maps each order book to its current set of subscribers.
void cleanupAccountHistorySubscriptions(std::uint64_t seq, HashSet< AccountID > const &accounts)
Erase one connection's entries from subAccountHistory_ in accountLock_-bounded chunks.
void stateAccounting(json::Value &obj) override
void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted) override
DispatchState dispatchState_
InfoSub::pointer addRpcSub(std::string const &strUrl, InfoSub::Ref) override
void transactionBatch()
Apply transactions in batches.
void setTimer(boost::asio::steady_timer &timer, std::chrono::milliseconds const &expiryTime, std::function< void()> onExpire, std::function< void()> onError)
bool unsubRTTransactions(std::uint64_t uListener) override
beast::Journal const & journal() const override
Journal used by InfoSub for diagnostics that occur after the owning subsystem (e.g.
json::Value getLedgerFetchInfo() override
bool processTrustedProposal(RCLCxPeerPos proposal) override
InfoSub::pointer findRpcSubLocked(std::string const &strUrl)
Look up an RPC subscription without taking streamLock_.
void kickoffAccountHistory(std::shared_ptr< AcceptedLedger const > const &alpAccepted)
On the first published ledger only, start the delayed account-history streaming for any subscriptions...
void subAccountHistoryStart(std::shared_ptr< ReadView const > const &ledger, SubAccountHistoryInfoWeak &subInfo)
void pubValidation(std::shared_ptr< STValidation > const &val) override
json::Value getConsensusInfo() override
ConsensusPhase lastConsensusPhase_
void endConsensus(std::unique_ptr< std::stringstream > const &clog) override
bool beginConsensus(UInt256 const &networkClosed, std::unique_ptr< std::stringstream > const &clog) override
void setMode(OperatingMode om) override
void setAmendmentBlocked() override
bool subBook(InfoSub::Ref ispListener, Book const &) override
ErrorCodeI subAccountHistory(InfoSub::Ref ispListener, AccountID const &account) override
subscribe an account's new transactions and retrieve the account's historical transactions
HashMap< AccountID, SubMapType > SubInfoMapType
void pubConsensus(ConsensusPhase phase)
bool isNeedNetworkLedger() override
bool unsubBookInternal(std::uint64_t uListener, Book const &) override
Remove a book subscription during InfoSub teardown.
DispatchState
Synchronization states for transaction batches.
SubInfoMapType subRTAccount_
std::atomic< bool > needNetworkLedger_
boost::asio::steady_timer heartbeatTimer_
std::mutex mptLock_
Guards subMPT_.
std::array< SubMapType, SubTypes::SLastEntry > streamMaps_
One weak_ptr subscriber map per stream type.
std::reference_wrapper< ServiceRegistry > registry_
static std::array< char const *, 5 > const kStates
bool unsubLedger(std::uint64_t uListener) override
void pubProposedAccountTransaction(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &transaction, TER result)
void unsubAccountHistoryInternal(std::uint64_t seq, AccountID const &account, bool historyOnly) override
void pubValidatedTransaction(std::shared_ptr< ReadView const > const &ledger, AcceptedLedgerTx const &transaction, bool last)
void pubBookTransaction(AcceptedLedgerTx const &transaction, MultiApiJson const &jvObj)
Fan transaction notifications out to all book subscribers.
void cleanupAccountSubscriptions(std::uint64_t seq, HashSet< AccountID > const &accounts, SubInfoMapType &subMap)
Erase one connection's entries from the given account map (subAccount_ or subRTAccount_) in accountLo...
void switchLastClosedLedger(std::shared_ptr< Ledger const > const &newLCL)
std::optional< PublicKey > const validatorPK_
std::mutex streamLock_
Guards streamMaps_[] and rpcSubMap_.
std::atomic< bool > amendmentBlocked_
bool unsubBook(InfoSub::Ref ispListener, Book const &) override
Remove a book subscription for a live subscriber.
void clearAmendmentWarned() override
LedgerMaster & ledgerMaster_
void publishLedgerStreams(std::shared_ptr< ReadView const > const &lpAccepted, std::shared_ptr< AcceptedLedger const > const &alpAccepted)
Send the ledgerClosed and book-changes stream updates for a ledger.
std::atomic< OperatingMode > mode_
void updateLocalTx(ReadView const &view) override
void clearLedgerFetch() override
std::unique_ptr< LocalTxs > localTX_
void apply(std::unique_lock< std::mutex > &batchLock)
Attempt to apply transactions and post-process based on the results.
InfoSub::pointer findRpcSub(std::string const &strUrl) override
bool isAmendmentBlocked() override
std::string strOperatingMode(OperatingMode const mode, bool const admin) const override
bool subBookChanges(InfoSub::Ref ispListener) override
HashMap< std::string, InfoSub::pointer > SubRpcMapType
void setStandAlone() override
void setNeedNetworkLedger() override
HashMap< MPTID, SubMapType > SubMPTInfoMapType
std::size_t getBookSubscribersCount() override
Total number of (book, subscriber) entries currently tracked.
std::mutex bookLock_
Guards subBook_.
bool unsubServer(std::uint64_t uListener) override
void processClusterTimer()
bool unsubConsensus(std::uint64_t uListener) override
bool subConsensus(InfoSub::Ref ispListener) override
void pubManifest(Manifest const &) override
std::mutex accountLock_
Guards subAccount_, subRTAccount_, subAccountHistory_.
void consensusViewChange() override
boost::asio::steady_timer accountHistoryTxTimer_
NetworkOPsImp(ServiceRegistry ®istry, NetworkOPs::ClockType &clock, bool standalone, std::size_t minPeerCount, bool startValid, JobQueue &jobQueue, LedgerMaster &ledgerMaster, ValidatorKeys const &validatorKeys, boost::asio::io_context &ioCtx, beast::Journal journal, beast::insight::Collector::Ptr const &collector)
bool recvValidation(std::shared_ptr< STValidation > const &val, std::string const &source) override
void setUNLBlocked() override
bool unsubValidations(std::uint64_t uListener) override
void scheduleAccountCleanup(std::uint64_t seq, HashSet< AccountID > rtAccounts, HashSet< AccountID > normalAccounts, HashSet< AccountID > historyAccounts) override
Schedule the server-side teardown of a disconnecting connection's account subscriptions off the destr...
void pubMPTTransaction(AcceptedLedgerTx const &transaction, MultiApiJson const &jvObj)
void doTransactionAsync(std::shared_ptr< Transaction > transaction, bool bUnlimited, FailHard failtype)
For transactions not submitted by a locally connected client, fire and forget.
std::set< UInt256 > pendingValidations_
bool subRTTransactions(InfoSub::Ref ispListener) override
OperatingMode getOperatingMode() const override
std::optional< PublicKey > const validatorMasterPK_
void doTransactionSyncBatch(std::unique_lock< std::mutex > &lock, std::function< bool(std::unique_lock< std::mutex > const &)> retryCallback)
HashMap< std::uint64_t, InfoSub::Wptr > SubMapType
bool tryRemoveRpcSub(std::string const &strUrl) override
void processHeartbeatTimer()
void doTransactionSync(std::shared_ptr< Transaction > transaction, bool bUnlimited, FailHard failType)
For transactions submitted directly by a client, apply batch of transactions and wait for this transa...
void submitTransaction(std::shared_ptr< STTx const > const &) override
bool subTransactions(InfoSub::Ref ispListener) override
void setAmendmentWarned() override
void unsubMPT(InfoSub::Ref ispListener, HashSet< MPTID > const &mptIDs) override
StateAccounting accounting_
SubAccountHistoryMapType subAccountHistory_
SubMPTInfoMapType subMPT_
Guarded by mptLock_.
void setAccountHistoryJobTimer(SubAccountHistoryInfoWeak subInfo)
std::atomic< bool > unlBlocked_
void unsubAccountHistory(InfoSub::Ref ispListener, AccountID const &account, bool historyOnly) override
unsubscribe an account's transactions
bool subLedger(InfoSub::Ref ispListener, json::Value &jvResult) override
bool unsubBookChanges(std::uint64_t uListener) override
void unsubAccountInternal(std::uint64_t seq, HashSet< AccountID > const &vnaAccountIDs, bool rt) override
void setStateTimer() override
Called to initially start our timers.
std::size_t getLocalTxCount() override
bool preProcessTransaction(std::shared_ptr< Transaction > &transaction)
void processTransaction(std::shared_ptr< Transaction > &transaction, bool bUnlimited, bool bLocal, FailHard failType) override
Process transactions as they arrive from the network or which are submitted by clients.
bool unsubTransactions(std::uint64_t uListener) override
bool isAmendmentWarned() override
void getBookPage(std::shared_ptr< ReadView const > &lpLedger, Book const &, AccountID const &uTakerID, bool const bProof, unsigned int iLimit, json::Value const &jvMarker, json::Value &jvResult) override
std::mutex validationsMutex_
std::uint32_t acceptLedger(std::optional< std::chrono::milliseconds > consensusDelay) override
Accepts the current transaction tree, return the new ledger's sequence.
void clearUNLBlocked() override
void subAccount(InfoSub::Ref ispListener, HashSet< AccountID > const &vnaAccountIDs, bool rt) override
bool isUNLBlocked() override
void pubProposedTransaction(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &transaction, TER result) override
std::atomic< bool > amendmentWarned_
boost::asio::steady_timer clusterTimer_
void cleanupSubscriptionMap(std::uint64_t seq, HashSet< AccountID > const &accounts, OuterMap &outerMap, BeforeErase &&beforeErase)
Erase one connection's entries from a subscription map in accountLock_-bounded chunks.
bool checkLastClosedLedger(Overlay::PeerSequence const &, UInt256 &networkClosed)
bool unsubPeerStatus(std::uint64_t uListener) override
void reportFeeChange() override
ServerFeeSummary lastFeeSummary_
void processTransactionSet(CanonicalTXSet const &set) override
Process a set of transactions synchronously, and ensuring that they are processed in one batch.
void mapComplete(std::shared_ptr< SHAMap > const &map, bool fromAcquire) override
bool isBlocked() override
~NetworkOPsImp() override
json::Value getServerInfo(bool human, bool admin, bool counters) override
Provides server functionality for clients.
beast::AbstractClock< std::chrono::steady_clock > ClockType
Number is a floating point type that can represent a wide range of values.
Writable ledger view that accumulates state and tx changes.
std::vector< std::shared_ptr< Peer > > PeerSequence
Manages the generic consensus algorithm for use by the RCL.
A peer's signed, proposed position for use in RCLConsensus.
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Represents a set of transactions in RCLConsensus.
Wraps a ledger instance for use in generic Validations LedgerTrie.
static std::string getWordFromBlob(void const *blob, size_t bytes)
Chooses a single dictionary word from the data.
Collects logging information.
std::unique_ptr< std::stringstream > const & ss()
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
std::vector< AccountTx > AccountTxs
constexpr bool holds() const noexcept
std::string getText() const override
Asset const & asset() const
void setJson(json::Value &) const
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const_pointer
Automatically unlocks and re-locks a unique_lock object.
std::size_t size() const noexcept
void const * data() const noexcept
Service registry for dependency injection.
Validator keys and manifest as set in configuration file.
json::Value jsonClipped() const
constexpr double decimalXRP() const
T duration_cast(T... args)
T emplace_back(T... args)
void rngfill(void *const buffer, std::size_t const bytes, Generator &g)
JSON (JavaScript Object Notation).
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
std::string const & getVersionString()
Server version.
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
std::string const & getCommitHash()
std::string const & getBuildBranch()
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Keylet book(Book const &b)
The beginning of an order book.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet page(UInt256 const &root, std::uint64_t const index=0) noexcept
A page in a directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet child(UInt256 const &key) noexcept
Any item that can be in an owner dir.
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
static constexpr std::integral_constant< unsigned, Version > kApiVersion
void insertAllSyntheticInJson(json::Value &metadata, ReadView const &ledger, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
Adds all synthetic fields to transaction metadata JSON.
json::Value computeBookChanges(std::shared_ptr< L const > const &lpAccepted)
Rate rate(Env const &env, Account const &account, std::uint32_t const &seq)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool cdirFirst(ReadView const &view, UInt256 const &root, SLE::const_pointer &page, unsigned int &index, UInt256 &entry)
Returns the first entry in the directory, advancing the index.
@ WarnRpcAmendmentBlocked
@ WarnRpcUnsupportedMajority
@ WarnRpcExpiredValidatorList
STAmount divide(STAmount const &amount, Rate const &rate)
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
constexpr FlagValue tfInnerBatchTxn
bool isTerRetry(TER x) noexcept
void handleNewValidation(Application &app, std::shared_ptr< STValidation > const &val, std::string const &source, BypassAccept const bypassAccept, std::optional< beast::Journal > j)
Handle a new validation.
UInt256 getBookBase(Book const &book)
@ WrongLedger
We have the wrong ledger and are attempting to acquire it.
@ Proposing
We are normal participant in consensus and propose our position.
std::optional< std::uint64_t > mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
Return value*mul/div accurately.
SendIfPred< Predicate > sendIf(std::shared_ptr< Message > const &m, Predicate const &f)
Helper function to aid in type deduction.
void forAllApiVersions(Fn const &fn, Args &&... args)
@ SigBad
Signature is bad.
@ Valid
Signature and local checks are good / passed.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
constexpr std::size_t kMaxPoppedTransactions
std::string strHex(FwdIt begin, FwdIt end)
std::uint64_t getQuality(UInt256 const &uBase)
std::unique_ptr< FeeVote > makeFeeVote(FeeSetup const &setup, beast::Journal journal)
Create an instance of the FeeVote logic.
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules)
Checks transaction signature and local checks.
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const ¤t)
FeeSetup setupFeeVote(Section const §ion)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::unique_ptr< NetworkOPs > makeNetworkOPs(ServiceRegistry ®istry, NetworkOPs::ClockType &clock, bool standalone, std::size_t minPeerCount, bool startValid, JobQueue &jobQueue, LedgerMaster &ledgerMaster, ValidatorKeys const &validatorKeys, boost::asio::io_context &ioSvc, beast::Journal journal, beast::insight::Collector::Ptr const &collector)
UInt256 getQualityNext(UInt256 const &uBase)
Number root(Number f, unsigned d)
CsprngEngine & cryptoPrng()
The default cryptographically secure PRNG.
bool transResultInfo(TER code, std::string &token, std::string &text)
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
constexpr Dest safeCast(Src s) noexcept
std::string transToken(TER code)
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
std::string to_string(BaseUInt< Bits, Tag > const &a)
std::string toStringIso(date::sys_time< Duration > tp)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Check if the issuer has the global freeze flag set.
STAmount amountFromQuality(std::uint64_t rate)
bool isTefFailure(TER x) noexcept
HashSet< Book > affectedBooks(AcceptedLedgerTx const &alTx, beast::Journal const &j)
Extract the set of books affected by a transaction.
std::unique_ptr< LocalTxs > makeLocalTxs()
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
ConsensusPhase
Phases of consensus for a single ledger round.
@ Open
We haven't closed our ledger yet, but others might have.
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
json::Value getJson(LedgerFill const &fill)
Return a new json::Value representing the ledger with given options.
std::unordered_set< Value, Hash, Pred, Allocator > HashSet
bool cdirNext(ReadView const &view, UInt256 const &root, SLE::const_pointer &page, unsigned int &index, UInt256 &entry)
Returns the next entry in the directory, advancing the index.
AccountID calcAccountID(PublicKey const &pk)
static std::array< char const *, 5 > const kStateNames
constexpr auto kMuldivMax
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
detail::MultiApiJson< rpc::kApiMinimumSupportedVersion, rpc::kApiMaximumValidVersion > MultiApiJson
bool isTelLocal(TER x) noexcept
bool isTesSuccess(TER x) noexcept
static std::uint32_t trunc32(std::uint64_t v)
TERSubset< CanCvtToTER > TER
STAmount multiply(STAmount const &amount, Number const &frac, Number::RoundingMode rm)
std::unordered_map< Key, Value, Hash, Pred, Allocator > HashMap
OperatingMode
Specifies the mode under which the server believes it's operating.
@ TRACKING
convinced we agree with the network
@ DISCONNECTED
not ready to process requests
@ CONNECTED
convinced we are talking to the network
@ FULL
we have the ledger and can even validate
@ SYNCING
fallen slightly behind
static STAmount takerPaysFunded(STAmount const &takerPays, STAmount const &takerGetsFunded, STAmount const &rate)
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
STAmount issuerFundsToSelfIssue(ReadView const &view, MPTIssue const &issue)
Determine funds available for an issuer to sell in an issuer owned offer.
static auto const kGenesisAccountId
bool isTemMalformed(TER x) noexcept
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=SpendableHandling::SimpleBalance)
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
STAmount toSTAmount(IOUAmount const &iou, Asset const &asset)
CanonicalTXSet OrderedTxs
T set_intersection(T... args)
static constexpr auto kPort
static constexpr auto kIp
PublicKey masterKey
The master key associated with this manifest.
std::string serialized
The manifest in serialized form.
Blob getMasterSignature() const
Returns manifest master key signature.
std::string domain
The domain, if one was specified in the manifest; empty otherwise.
std::optional< Blob > getSignature() const
Returns manifest signature.
std::optional< PublicKey > signingKey
The ephemeral key associated with this manifest.
std::uint32_t sequence
The sequence number of this manifest.
Server fees published on server subscription.
std::optional< TxQ::Metrics > em
bool operator!=(ServerFeeSummary const &b) const
bool operator==(ServerFeeSummary const &b) const
std::uint32_t loadBaseServer
ServerFeeSummary()=default
std::uint32_t loadFactorServer
decltype(initialSyncUs_) initialSyncUs
decltype(counters_) counters
std::chrono::microseconds dur
std::uint64_t transitions
beast::insight::Gauge fullTransitions
beast::insight::Gauge disconnectedTransitions
beast::insight::Gauge connectedDuration
beast::insight::Gauge trackingTransitions
beast::insight::Gauge fullDuration
beast::insight::Gauge syncingDuration
Stats(Handler const &handler, beast::insight::Collector::Ptr const &collector)
beast::insight::Gauge disconnectedDuration
beast::insight::Gauge connectedTransitions
beast::insight::Gauge trackingDuration
beast::insight::Hook hook
beast::insight::Gauge syncingTransitions
std::uint32_t historyLastLedgerSeq
std::atomic< bool > stopHistorical
SubAccountHistoryIndex(AccountID const &accountId)
AccountID const accountId
std::int32_t historyTxIndex
std::uint32_t separationLedgerSeq
std::uint32_t forwardTxIndex
std::shared_ptr< SubAccountHistoryIndex > index
std::shared_ptr< SubAccountHistoryIndex > index
Select all peers (except optional excluded) that are in our cluster.
Represents a transfer rate.
static constexpr auto kPortGrpc
Sends a message to all peers.
Changes in trusted nodes after updating validator list.
HashSet< NodeID > removed
Structure returned by TxQ::getMetrics, expressed in reference fee level units.
void set(char const *key, auto const &v)
IsMemberResult isMember(char const *key) const
Data format for exchanging consumption information across peers.
std::vector< Item > items
T time_since_epoch(T... args)