20 #include <ripple/app/consensus/RCLConsensus.h>
21 #include <ripple/app/consensus/RCLValidations.h>
22 #include <ripple/app/ledger/AcceptedLedger.h>
23 #include <ripple/app/ledger/InboundLedgers.h>
24 #include <ripple/app/ledger/LedgerMaster.h>
25 #include <ripple/app/ledger/LedgerToJson.h>
26 #include <ripple/app/ledger/LocalTxs.h>
27 #include <ripple/app/ledger/OpenLedger.h>
28 #include <ripple/app/ledger/OrderBookDB.h>
29 #include <ripple/app/ledger/TransactionMaster.h>
30 #include <ripple/app/main/LoadManager.h>
31 #include <ripple/app/misc/AmendmentTable.h>
32 #include <ripple/app/misc/DeliverMax.h>
33 #include <ripple/app/misc/HashRouter.h>
34 #include <ripple/app/misc/LoadFeeTrack.h>
35 #include <ripple/app/misc/NetworkOPs.h>
36 #include <ripple/app/misc/Transaction.h>
37 #include <ripple/app/misc/TxQ.h>
38 #include <ripple/app/misc/ValidatorKeys.h>
39 #include <ripple/app/misc/ValidatorList.h>
40 #include <ripple/app/misc/impl/AccountTxPaging.h>
41 #include <ripple/app/rdb/backend/PostgresDatabase.h>
42 #include <ripple/app/rdb/backend/SQLiteDatabase.h>
43 #include <ripple/app/reporting/ReportingETL.h>
44 #include <ripple/app/tx/apply.h>
45 #include <ripple/basics/PerfLog.h>
46 #include <ripple/basics/UptimeClock.h>
47 #include <ripple/basics/mulDiv.h>
48 #include <ripple/basics/safe_cast.h>
49 #include <ripple/beast/rfc2616.h>
50 #include <ripple/beast/utility/rngfill.h>
51 #include <ripple/consensus/Consensus.h>
52 #include <ripple/consensus/ConsensusParms.h>
53 #include <ripple/crypto/RFC1751.h>
54 #include <ripple/crypto/csprng.h>
55 #include <ripple/json/MultivarJson.h>
56 #include <ripple/json/to_string.h>
57 #include <ripple/net/RPCErr.h>
58 #include <ripple/nodestore/DatabaseShard.h>
59 #include <ripple/overlay/Cluster.h>
60 #include <ripple/overlay/Overlay.h>
61 #include <ripple/overlay/predicates.h>
62 #include <ripple/protocol/BuildInfo.h>
63 #include <ripple/protocol/Feature.h>
64 #include <ripple/protocol/STParsedJSON.h>
65 #include <ripple/protocol/jss.h>
66 #include <ripple/resource/Fees.h>
67 #include <ripple/resource/ResourceManager.h>
68 #include <ripple/rpc/BookChanges.h>
69 #include <ripple/rpc/DeliveredAmount.h>
70 #include <ripple/rpc/ServerHandler.h>
71 #include <ripple/rpc/impl/RPCHelpers.h>
72 #include <boost/asio/ip/host_name.hpp>
73 #include <boost/asio/steady_timer.hpp>
150 std::chrono::steady_clock::time_point
start_ =
211 return !(*
this != b);
230 boost::asio::io_service& io_svc,
244 app_.logs().journal(
"FeeVote")),
247 app.getInboundTransactions(),
248 beast::get_abstract_clock<
std::chrono::steady_clock>(),
250 app_.logs().journal(
"LedgerConsensus"))
429 getServerInfo(
bool human,
bool admin,
bool counters)
override;
456 TER result)
override;
499 bool historyOnly)
override;
505 bool historyOnly)
override;
573 boost::system::error_code ec;
578 <<
"NetworkOPs: heartbeatTimer cancel error: "
587 <<
"NetworkOPs: clusterTimer cancel error: "
596 <<
"NetworkOPs: accountHistoryTxTimer cancel error: "
601 using namespace std::chrono_literals;
611 boost::asio::steady_timer& timer,
788 template <
class Handler>
790 Handler
const& handler,
792 :
hook(collector->make_hook(handler))
795 "Disconnected_duration"))
798 "Connected_duration"))
800 collector->make_gauge(
"State_Accounting",
"Syncing_duration"))
803 "Tracking_duration"))
805 collector->make_gauge(
"State_Accounting",
"Full_duration"))
808 "Disconnected_transitions"))
811 "Connected_transitions"))
814 "Syncing_transitions"))
817 "Tracking_transitions"))
819 collector->make_gauge(
"State_Accounting",
"Full_transitions"))
848 {
"disconnected",
"connected",
"syncing",
"tracking",
"full"}};
910 static std::string const hostname = boost::asio::ip::host_name();
917 static std::string const shroudedHostId = [
this]() {
923 return shroudedHostId;
938 boost::asio::steady_timer& timer,
945 [
this, onExpire, onError](boost::system::error_code
const& e) {
946 if ((e.value() == boost::system::errc::success) &&
947 (!m_job_queue.isStopped()))
952 if (e.value() != boost::system::errc::success &&
953 e.value() != boost::asio::error::operation_aborted)
956 JLOG(m_journal.error())
957 <<
"Timer got error '" << e.message()
958 <<
"'. Restarting timer.";
963 timer.expires_from_now(expiry_time);
964 timer.async_wait(std::move(*optionalCountedHandler));
975 m_job_queue.addJob(jtNETOP_TIMER,
"NetOPs.heartbeat", [this]() {
976 processHeartbeatTimer();
979 [
this]() { setHeartbeatTimer(); });
983 NetworkOPsImp::setClusterTimer()
985 using namespace std::chrono_literals;
992 processClusterTimer();
995 [
this]() { setClusterTimer(); });
1001 JLOG(m_journal.debug()) <<
"Scheduling AccountHistory job for account "
1003 using namespace std::chrono_literals;
1005 accountHistoryTxTimer_,
1007 [
this, subInfo]() { addAccountHistoryJob(subInfo); },
1008 [
this, subInfo]() { setAccountHistoryJobTimer(subInfo); });
1012 NetworkOPsImp::processHeartbeatTimer()
1021 std::size_t const numPeers = app_.overlay().size();
1024 if (numPeers < minPeerCount_)
1026 if (mMode != OperatingMode::DISCONNECTED)
1028 setMode(OperatingMode::DISCONNECTED);
1029 JLOG(m_journal.warn())
1030 <<
"Node count (" << numPeers <<
") has fallen "
1031 <<
"below required minimum (" << minPeerCount_ <<
").";
1038 setHeartbeatTimer();
1042 if (mMode == OperatingMode::DISCONNECTED)
1044 setMode(OperatingMode::CONNECTED);
1045 JLOG(m_journal.info())
1046 <<
"Node count (" << numPeers <<
") is sufficient.";
1051 if (mMode == OperatingMode::SYNCING)
1052 setMode(OperatingMode::SYNCING);
1053 else if (mMode == OperatingMode::CONNECTED)
1054 setMode(OperatingMode::CONNECTED);
1057 mConsensus.timerEntry(app_.timeKeeper().closeTime());
1060 if (mLastConsensusPhase != currPhase)
1062 reportConsensusStateChange(currPhase);
1063 mLastConsensusPhase = currPhase;
1066 setHeartbeatTimer();
1070 NetworkOPsImp::processClusterTimer()
1072 if (app_.cluster().size() == 0)
1075 using namespace std::chrono_literals;
1077 bool const update = app_.cluster().update(
1078 app_.nodeIdentity().first,
1080 (m_ledgerMaster.getValidatedLedgerAge() <= 4
min)
1081 ? app_.getFeeTrack().getLocalFee()
1083 app_.timeKeeper().now());
1087 JLOG(m_journal.debug()) <<
"Too soon to send cluster update";
1092 protocol::TMCluster cluster;
1093 app_.cluster().for_each([&cluster](
ClusterNode const& node) {
1094 protocol::TMClusterNode& n = *cluster.add_clusternodes();
1099 n.set_nodename(node.
name());
1103 for (
auto& item : gossip.
items)
1105 protocol::TMLoadSource& node = *cluster.add_loadsources();
1107 node.set_cost(item.balance);
1109 app_.overlay().foreach(
send_if(
1110 std::make_shared<Message>(cluster, protocol::mtCLUSTER),
1121 if (mode == OperatingMode::FULL && admin)
1123 auto const consensusMode = mConsensus.mode();
1124 if (consensusMode != ConsensusMode::wrongLedger)
1126 if (consensusMode == ConsensusMode::proposing)
1129 if (mConsensus.validating())
1130 return "validating";
1140 if (isNeedNetworkLedger())
1149 auto const txid = trans->getTransactionID();
1150 auto const flags = app_.getHashRouter().getFlags(txid);
1152 if ((flags & SF_BAD) != 0)
1154 JLOG(m_journal.warn()) <<
"Submitted transaction cached bad";
1161 app_.getHashRouter(),
1163 m_ledgerMaster.getValidatedRules(),
1166 if (validity != Validity::Valid)
1168 JLOG(m_journal.warn())
1169 <<
"Submitted transaction invalid: " << reason;
1175 JLOG(m_journal.warn())
1176 <<
"Exception checking transaction " << txid <<
": " << ex.
what();
1183 auto tx = std::make_shared<Transaction>(trans, reason, app_);
1185 m_job_queue.addJob(
jtTRANSACTION,
"submitTxn", [
this, tx]() {
1187 processTransaction(t,
false,
false, FailHard::no);
1192 NetworkOPsImp::processTransaction(
1198 auto ev = m_job_queue.makeLoadEvent(
jtTXN_PROC,
"ProcessTXN");
1199 auto const newFlags = app_.getHashRouter().getFlags(transaction->getID());
1201 if ((newFlags & SF_BAD) != 0)
1204 JLOG(m_journal.warn()) << transaction->getID() <<
": cached bad!\n";
1205 transaction->setStatus(
INVALID);
1213 auto const view = m_ledgerMaster.getCurrentLedger();
1215 app_.getHashRouter(),
1216 *transaction->getSTransaction(),
1219 assert(validity == Validity::Valid);
1222 if (validity == Validity::SigBad)
1224 JLOG(m_journal.info()) <<
"Transaction has bad signature: " << reason;
1225 transaction->setStatus(
INVALID);
1227 app_.getHashRouter().setFlags(transaction->getID(), SF_BAD);
1232 app_.getMasterTransaction().canonicalize(&transaction);
1235 doTransactionSync(transaction, bUnlimited, failType);
1237 doTransactionAsync(transaction, bUnlimited, failType);
1241 NetworkOPsImp::doTransactionAsync(
1248 if (transaction->getApplying())
1251 mTransactions.push_back(
1253 transaction->setApplying();
1255 if (mDispatchState == DispatchState::none)
1257 if (m_job_queue.addJob(
1258 jtBATCH,
"transactionBatch", [
this]() { transactionBatch(); }))
1260 mDispatchState = DispatchState::scheduled;
1266 NetworkOPsImp::doTransactionSync(
1273 if (!transaction->getApplying())
1275 mTransactions.push_back(
1277 transaction->setApplying();
1282 if (mDispatchState == DispatchState::running)
1291 if (mTransactions.size())
1294 if (m_job_queue.addJob(
jtBATCH,
"transactionBatch", [
this]() {
1298 mDispatchState = DispatchState::scheduled;
1302 }
while (transaction->getApplying());
1306 NetworkOPsImp::transactionBatch()
1310 if (mDispatchState == DispatchState::running)
1313 while (mTransactions.size())
1324 mTransactions.
swap(transactions);
1325 assert(!transactions.
empty());
1327 assert(mDispatchState != DispatchState::running);
1328 mDispatchState = DispatchState::running;
1334 bool changed =
false;
1337 m_ledgerMaster.peekMutex(), std::defer_lock};
1348 if (e.failType == FailHard::yes)
1351 auto const result = app_.getTxQ().apply(
1352 app_, view, e.transaction->getSTransaction(), flags, j);
1353 e.result = result.first;
1354 e.applied = result.second;
1355 changed = changed || result.second;
1364 if (
auto const l = m_ledgerMaster.getValidatedLedger())
1365 validatedLedgerIndex = l->info().seq;
1367 auto newOL = app_.openLedger().current();
1370 e.transaction->clearSubmitResult();
1374 pubProposedTransaction(
1375 newOL, e.transaction->getSTransaction(), e.result);
1376 e.transaction->setApplied();
1379 e.transaction->setResult(e.result);
1382 app_.getHashRouter().setFlags(e.transaction->getID(), SF_BAD);
1391 JLOG(m_journal.info())
1392 <<
"TransactionResult: " << token <<
": " << human;
1397 bool addLocal = e.local;
1401 JLOG(m_journal.debug())
1402 <<
"Transaction is now included in open ledger";
1403 e.transaction->setStatus(
INCLUDED);
1405 auto const& txCur = e.transaction->getSTransaction();
1406 auto const txNext = m_ledgerMaster.popAcctTransaction(txCur);
1411 auto t = std::make_shared<Transaction>(trans, reason, app_);
1412 submit_held.
emplace_back(t,
false,
false, FailHard::no);
1419 JLOG(m_journal.info()) <<
"Transaction is obsolete";
1420 e.transaction->setStatus(
OBSOLETE);
1424 JLOG(m_journal.debug())
1425 <<
"Transaction is likely to claim a"
1426 <<
" fee, but is queued until fee drops";
1428 e.transaction->setStatus(
HELD);
1432 m_ledgerMaster.addHeldTransaction(e.transaction);
1433 e.transaction->setQueued();
1434 e.transaction->setKept();
1438 if (e.failType != FailHard::yes)
1441 JLOG(m_journal.debug())
1442 <<
"Transaction should be held: " << e.result;
1443 e.transaction->setStatus(
HELD);
1444 m_ledgerMaster.addHeldTransaction(e.transaction);
1445 e.transaction->setKept();
1450 JLOG(m_journal.debug())
1451 <<
"Status other than success " << e.result;
1452 e.transaction->setStatus(
INVALID);
1455 auto const enforceFailHard =
1456 e.failType == FailHard::yes && !
isTesSuccess(e.result);
1458 if (addLocal && !enforceFailHard)
1460 m_localTX->push_back(
1461 m_ledgerMaster.getCurrentLedgerIndex(),
1462 e.transaction->getSTransaction());
1463 e.transaction->setKept();
1467 ((mMode != OperatingMode::FULL) &&
1468 (e.failType != FailHard::yes) && e.local) ||
1473 app_.getHashRouter().shouldRelay(e.transaction->getID());
1477 protocol::TMTransaction tx;
1480 e.transaction->getSTransaction()->add(s);
1481 tx.set_rawtransaction(s.
data(), s.
size());
1482 tx.set_status(protocol::tsCURRENT);
1483 tx.set_receivetimestamp(
1484 app_.timeKeeper().now().time_since_epoch().count());
1487 app_.overlay().relay(e.transaction->getID(), tx, *toSkip);
1488 e.transaction->setBroadcast();
1492 if (validatedLedgerIndex)
1494 auto [fee, accountSeq, availableSeq] =
1495 app_.getTxQ().getTxRequiredFeeAndSeq(
1496 *newOL, e.transaction->getSTransaction());
1497 e.transaction->setCurrentLedgerState(
1498 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1506 e.transaction->clearApplying();
1508 if (!submit_held.
empty())
1510 if (mTransactions.empty())
1511 mTransactions.swap(submit_held);
1513 for (
auto& e : submit_held)
1514 mTransactions.push_back(std::move(e));
1519 mDispatchState = DispatchState::none;
1527 NetworkOPsImp::getOwnerInfo(
1532 auto root = keylet::ownerDir(account);
1533 auto sleNode = lpLedger->read(keylet::page(
root));
1540 for (
auto const& uDirEntry : sleNode->getFieldV256(
sfIndexes))
1542 auto sleCur = lpLedger->read(keylet::child(uDirEntry));
1545 switch (sleCur->getType())
1548 if (!jvObjects.
isMember(jss::offers))
1549 jvObjects[jss::offers] =
1552 jvObjects[jss::offers].
append(
1553 sleCur->getJson(JsonOptions::none));
1557 if (!jvObjects.
isMember(jss::ripple_lines))
1559 jvObjects[jss::ripple_lines] =
1563 jvObjects[jss::ripple_lines].
append(
1564 sleCur->getJson(JsonOptions::none));
1579 sleNode = lpLedger->read(keylet::page(
root, uNodeDir));
1593 NetworkOPsImp::isBlocked()
1595 return isAmendmentBlocked() || isUNLBlocked();
1599 NetworkOPsImp::isAmendmentBlocked()
1601 return amendmentBlocked_;
1605 NetworkOPsImp::setAmendmentBlocked()
1607 amendmentBlocked_ =
true;
1608 setMode(OperatingMode::CONNECTED);
1612 NetworkOPsImp::isAmendmentWarned()
1614 return !amendmentBlocked_ && amendmentWarned_;
1618 NetworkOPsImp::setAmendmentWarned()
1620 amendmentWarned_ =
true;
1624 NetworkOPsImp::clearAmendmentWarned()
1626 amendmentWarned_ =
false;
1630 NetworkOPsImp::isUNLBlocked()
1636 NetworkOPsImp::setUNLBlocked()
1639 setMode(OperatingMode::CONNECTED);
1643 NetworkOPsImp::clearUNLBlocked()
1645 unlBlocked_ =
false;
1649 NetworkOPsImp::checkLastClosedLedger(
1658 JLOG(m_journal.trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
1660 auto const ourClosed = m_ledgerMaster.getClosedLedger();
1665 uint256 closedLedger = ourClosed->info().hash;
1666 uint256 prevClosedLedger = ourClosed->info().parentHash;
1667 JLOG(m_journal.trace()) <<
"OurClosed: " << closedLedger;
1668 JLOG(m_journal.trace()) <<
"PrevClosed: " << prevClosedLedger;
1673 auto& validations = app_.getValidations();
1674 JLOG(m_journal.debug())
1675 <<
"ValidationTrie " <<
Json::Compact(validations.getJsonTrie());
1679 peerCounts[closedLedger] = 0;
1680 if (mMode >= OperatingMode::TRACKING)
1681 peerCounts[closedLedger]++;
1683 for (
auto& peer : peerList)
1685 uint256 peerLedger = peer->getClosedLedgerHash();
1688 ++peerCounts[peerLedger];
1691 for (
auto const& it : peerCounts)
1692 JLOG(m_journal.debug()) <<
"L: " << it.first <<
" n=" << it.second;
1694 uint256 preferredLCL = validations.getPreferredLCL(
1696 m_ledgerMaster.getValidLedgerIndex(),
1699 bool switchLedgers = preferredLCL != closedLedger;
1701 closedLedger = preferredLCL;
1703 if (switchLedgers && (closedLedger == prevClosedLedger))
1706 JLOG(m_journal.info()) <<
"We won't switch to our own previous ledger";
1707 networkClosed = ourClosed->info().hash;
1708 switchLedgers =
false;
1711 networkClosed = closedLedger;
1716 auto consensus = m_ledgerMaster.getLedgerByHash(closedLedger);
1719 consensus = app_.getInboundLedgers().acquire(
1720 closedLedger, 0, InboundLedger::Reason::CONSENSUS);
1723 (!m_ledgerMaster.canBeCurrent(consensus) ||
1724 !m_ledgerMaster.isCompatible(
1725 *consensus, m_journal.debug(),
"Not switching")))
1729 networkClosed = ourClosed->info().hash;
1733 JLOG(m_journal.warn()) <<
"We are not running on the consensus ledger";
1734 JLOG(m_journal.info()) <<
"Our LCL: " <<
getJson({*ourClosed, {}});
1735 JLOG(m_journal.info()) <<
"Net LCL " << closedLedger;
1737 if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
1739 setMode(OperatingMode::CONNECTED);
1747 switchLastClosedLedger(consensus);
1754 NetworkOPsImp::switchLastClosedLedger(
1758 JLOG(m_journal.error())
1759 <<
"JUMP last closed ledger to " << newLCL->info().hash;
1761 clearNeedNetworkLedger();
1764 app_.getTxQ().processClosedLedger(app_, *newLCL,
true);
1771 auto retries = m_localTX->getTxSet();
1772 auto const lastVal = app_.getLedgerMaster().getValidatedLedger();
1777 rules.
emplace(app_.config().features);
1778 app_.openLedger().accept(
1789 return app_.getTxQ().accept(app_, view);
1793 m_ledgerMaster.switchLCL(newLCL);
1795 protocol::TMStatusChange s;
1796 s.set_newevent(protocol::neSWITCHED_LEDGER);
1797 s.set_ledgerseq(newLCL->info().seq);
1798 s.set_networktime(app_.timeKeeper().now().time_since_epoch().count());
1799 s.set_ledgerhashprevious(
1800 newLCL->info().parentHash.begin(), newLCL->info().parentHash.size());
1801 s.set_ledgerhash(newLCL->info().hash.begin(), newLCL->info().hash.size());
1803 app_.overlay().foreach(
1804 send_always(std::make_shared<Message>(s, protocol::mtSTATUS_CHANGE)));
1808 NetworkOPsImp::beginConsensus(
uint256 const& networkClosed)
1812 auto closingInfo = m_ledgerMaster.getCurrentLedger()->info();
1814 JLOG(m_journal.info()) <<
"Consensus time for #" << closingInfo.seq
1815 <<
" with LCL " << closingInfo.parentHash;
1817 auto prevLedger = m_ledgerMaster.getLedgerByHash(closingInfo.parentHash);
1822 if (mMode == OperatingMode::FULL)
1824 JLOG(m_journal.warn()) <<
"Don't have LCL, going to tracking";
1825 setMode(OperatingMode::TRACKING);
1831 assert(prevLedger->info().hash == closingInfo.parentHash);
1833 closingInfo.parentHash ==
1834 m_ledgerMaster.getClosedLedger()->info().hash);
1837 app_.validators().setNegativeUNL(prevLedger->negativeUNL());
1838 TrustChanges const changes = app_.validators().updateTrusted(
1839 app_.getValidations().getCurrentNodeIDs(),
1840 closingInfo.parentCloseTime,
1843 app_.getHashRouter());
1845 if (!changes.
added.empty() || !changes.
removed.empty())
1847 app_.getValidations().trustChanged(changes.
added, changes.
removed);
1849 app_.getAmendmentTable().trustChanged(
1850 app_.validators().getQuorumKeys().second);
1853 mConsensus.startRound(
1854 app_.timeKeeper().closeTime(),
1861 if (mLastConsensusPhase != currPhase)
1863 reportConsensusStateChange(currPhase);
1864 mLastConsensusPhase = currPhase;
1867 JLOG(m_journal.debug()) <<
"Initiating consensus engine";
1874 return mConsensus.peerProposal(app_.timeKeeper().closeTime(), peerPos);
1885 protocol::TMHaveTransactionSet msg;
1886 msg.set_hash(map->getHash().as_uint256().begin(), 256 / 8);
1887 msg.set_status(protocol::tsHAVE);
1888 app_.overlay().foreach(
1889 send_always(std::make_shared<Message>(msg, protocol::mtHAVE_SET)));
1893 mConsensus.gotTxSet(app_.timeKeeper().closeTime(),
RCLTxSet{map});
1897 NetworkOPsImp::endConsensus()
1899 uint256 deadLedger = m_ledgerMaster.getClosedLedger()->info().parentHash;
1901 for (
auto const& it : app_.overlay().getActivePeers())
1903 if (it && (it->getClosedLedgerHash() == deadLedger))
1905 JLOG(m_journal.trace()) <<
"Killing obsolete peer status";
1912 checkLastClosedLedger(app_.overlay().getActivePeers(), networkClosed);
1914 if (networkClosed.
isZero())
1923 if (((mMode == OperatingMode::CONNECTED) ||
1924 (mMode == OperatingMode::SYNCING)) &&
1930 if (!needNetworkLedger_)
1931 setMode(OperatingMode::TRACKING);
1934 if (((mMode == OperatingMode::CONNECTED) ||
1935 (mMode == OperatingMode::TRACKING)) &&
1941 auto current = m_ledgerMaster.getCurrentLedger();
1942 if (app_.timeKeeper().now() < (
current->info().parentCloseTime +
1943 2 *
current->info().closeTimeResolution))
1945 setMode(OperatingMode::FULL);
1949 beginConsensus(networkClosed);
1953 NetworkOPsImp::consensusViewChange()
1955 if ((mMode == OperatingMode::FULL) || (mMode == OperatingMode::TRACKING))
1957 setMode(OperatingMode::CONNECTED);
1967 if (!mStreamMaps[sManifests].empty())
1971 jvObj[jss::type] =
"manifestReceived";
1974 jvObj[jss::signing_key] =
1978 jvObj[jss::signature] =
strHex(*sig);
1981 jvObj[jss::domain] = mo.
domain;
1984 for (
auto i = mStreamMaps[sManifests].begin();
1985 i != mStreamMaps[sManifests].end();)
1987 if (
auto p = i->second.lock())
1989 p->send(jvObj,
true);
1994 i = mStreamMaps[sManifests].erase(i);
2000 NetworkOPsImp::ServerFeeSummary::ServerFeeSummary(
2005 , loadBaseServer{loadFeeTrack.getLoadBase()}
2007 , em{std::move(escalationMetrics)}
2017 em.has_value() != b.
em.has_value())
2023 em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
2024 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
2025 em->referenceFeeLevel != b.
em->referenceFeeLevel);
2058 jvObj[jss::type] =
"serverStatus";
2060 jvObj[jss::load_base] = f.loadBaseServer;
2061 jvObj[jss::load_factor_server] = f.loadFactorServer;
2062 jvObj[jss::base_fee] = f.baseFee.jsonClipped();
2067 safe_cast<std::uint64_t>(f.loadFactorServer),
2069 f.em->openLedgerFeeLevel,
2071 f.em->referenceFeeLevel)
2074 jvObj[jss::load_factor] =
trunc32(loadFactor);
2075 jvObj[jss::load_factor_fee_escalation] =
2076 f.em->openLedgerFeeLevel.jsonClipped();
2077 jvObj[jss::load_factor_fee_queue] =
2078 f.em->minProcessingFeeLevel.jsonClipped();
2079 jvObj[jss::load_factor_fee_reference] =
2080 f.em->referenceFeeLevel.jsonClipped();
2083 jvObj[jss::load_factor] = f.loadFactorServer;
2097 p->send(jvObj,
true);
2114 if (!streamMap.empty())
2117 jvObj[jss::type] =
"consensusPhase";
2118 jvObj[jss::consensus] =
to_string(phase);
2120 for (
auto i = streamMap.begin(); i != streamMap.end();)
2122 if (
auto p = i->second.lock())
2124 p->send(jvObj,
true);
2129 i = streamMap.erase(i);
2145 auto const signerPublic = val->getSignerPublic();
2147 jvObj[jss::type] =
"validationReceived";
2148 jvObj[jss::validation_public_key] =
2150 jvObj[jss::ledger_hash] =
to_string(val->getLedgerHash());
2151 jvObj[jss::signature] =
strHex(val->getSignature());
2152 jvObj[jss::full] = val->isFull();
2153 jvObj[jss::flags] = val->getFlags();
2155 jvObj[jss::data] =
strHex(val->getSerializer().slice());
2160 if (
auto cookie = (*val)[~
sfCookie])
2164 jvObj[jss::validated_hash] =
strHex(*hash);
2166 auto const masterKey =
2169 if (masterKey != signerPublic)
2175 jvObj[jss::ledger_index] = *seq;
2180 for (
auto const& amendment : val->getFieldV256(
sfAmendments))
2185 jvObj[jss::close_time] = *closeTime;
2187 if (
auto const loadFee = (*val)[~
sfLoadFee])
2188 jvObj[jss::load_fee] = *loadFee;
2190 if (
auto const baseFee = val->at(~
sfBaseFee))
2191 jvObj[jss::base_fee] =
static_cast<double>(*baseFee);
2194 jvObj[jss::reserve_base] = *reserveBase;
2197 jvObj[jss::reserve_inc] = *reserveInc;
2202 baseFeeXRP && baseFeeXRP->native())
2203 jvObj[jss::base_fee] = baseFeeXRP->xrp().jsonClipped();
2206 reserveBaseXRP && reserveBaseXRP->native())
2207 jvObj[jss::reserve_base] = reserveBaseXRP->xrp().jsonClipped();
2210 reserveIncXRP && reserveIncXRP->native())
2211 jvObj[jss::reserve_inc] = reserveIncXRP->xrp().jsonClipped();
2216 visit<RPC::apiMinimumSupportedVersion, RPC::apiMaximumValidVersion>(
2220 if (jvTx.
isMember(jss::ledger_index) && apiVersion < 2)
2222 jvTx[jss::ledger_index] =
2223 std::to_string(jvTx[jss::ledger_index].asUInt());
2230 if (
auto p = i->second.lock())
2254 jvObj[jss::type] =
"peerStatusChange";
2263 p->send(jvObj,
true);
2277 using namespace std::chrono_literals;
2309 <<
"recvValidation " << val->getLedgerHash() <<
" from " << source;
2339 "This server is amendment blocked, and must be updated to be "
2340 "able to stay in sync with the network.";
2347 "This server has an expired validator list. validators.txt "
2348 "may be incorrectly configured or some [validator_list_sites] "
2349 "may be unreachable.";
2356 "One or more unsupported amendments have reached majority. "
2357 "Upgrade to the latest version before they are activated "
2358 "to avoid being amendment blocked.";
2359 if (
auto const expected =
2363 d[jss::expected_date] = expected->time_since_epoch().count();
2364 d[jss::expected_date_UTC] =
to_string(*expected);
2368 if (warnings.size())
2369 info[jss::warnings] = std::move(warnings);
2384 info[jss::time] =
to_string(std::chrono::floor<std::chrono::microseconds>(
2388 info[jss::network_ledger] =
"waiting";
2390 info[jss::validation_quorum] =
2398 info[jss::node_size] =
"tiny";
2401 info[jss::node_size] =
"small";
2404 info[jss::node_size] =
"medium";
2407 info[jss::node_size] =
"large";
2410 info[jss::node_size] =
"huge";
2419 info[jss::validator_list_expires] =
2420 safe_cast<Json::UInt>(when->time_since_epoch().count());
2422 info[jss::validator_list_expires] = 0;
2432 if (*when == TimeKeeper::time_point::max())
2434 x[jss::expiration] =
"never";
2435 x[jss::status] =
"active";
2442 x[jss::status] =
"active";
2444 x[jss::status] =
"expired";
2449 x[jss::status] =
"unknown";
2450 x[jss::expiration] =
"unknown";
2454 info[jss::io_latency_ms] =
2461 info[jss::pubkey_validator] =
toBase58(
2466 info[jss::pubkey_validator] =
"none";
2479 info[jss::counters][jss::nodestore] = nodestore;
2483 info[jss::pubkey_node] =
2489 info[jss::amendment_blocked] =
true;
2504 lastClose[jss::converge_time_s] =
2509 lastClose[jss::converge_time] =
2513 info[jss::last_close] = lastClose;
2523 info[jss::network_id] =
static_cast<Json::UInt>(*netid);
2525 auto const escalationMetrics =
2533 auto const loadFactorFeeEscalation =
2535 escalationMetrics.openLedgerFeeLevel,
2537 escalationMetrics.referenceFeeLevel)
2541 safe_cast<std::uint64_t>(loadFactorServer),
2542 loadFactorFeeEscalation);
2546 info[jss::load_base] = loadBaseServer;
2547 info[jss::load_factor] =
trunc32(loadFactor);
2548 info[jss::load_factor_server] = loadFactorServer;
2555 info[jss::load_factor_fee_escalation] =
2556 escalationMetrics.openLedgerFeeLevel.jsonClipped();
2557 info[jss::load_factor_fee_queue] =
2558 escalationMetrics.minProcessingFeeLevel.jsonClipped();
2559 info[jss::load_factor_fee_reference] =
2560 escalationMetrics.referenceFeeLevel.jsonClipped();
2564 info[jss::load_factor] =
2565 static_cast<double>(loadFactor) / loadBaseServer;
2567 if (loadFactorServer != loadFactor)
2568 info[jss::load_factor_server] =
2569 static_cast<double>(loadFactorServer) / loadBaseServer;
2574 if (fee != loadBaseServer)
2575 info[jss::load_factor_local] =
2576 static_cast<double>(fee) / loadBaseServer;
2578 if (fee != loadBaseServer)
2579 info[jss::load_factor_net] =
2580 static_cast<double>(fee) / loadBaseServer;
2582 if (fee != loadBaseServer)
2583 info[jss::load_factor_cluster] =
2584 static_cast<double>(fee) / loadBaseServer;
2586 if (escalationMetrics.openLedgerFeeLevel !=
2587 escalationMetrics.referenceFeeLevel &&
2588 (admin || loadFactorFeeEscalation != loadFactor))
2589 info[jss::load_factor_fee_escalation] =
2590 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
2591 escalationMetrics.referenceFeeLevel);
2592 if (escalationMetrics.minProcessingFeeLevel !=
2593 escalationMetrics.referenceFeeLevel)
2594 info[jss::load_factor_fee_queue] =
2595 escalationMetrics.minProcessingFeeLevel
2596 .decimalFromReference(
2597 escalationMetrics.referenceFeeLevel);
2611 XRPAmount const baseFee = lpClosed->fees().base;
2613 l[jss::seq] =
Json::UInt(lpClosed->info().seq);
2614 l[jss::hash] =
to_string(lpClosed->info().hash);
2619 l[jss::reserve_base] =
2620 lpClosed->fees().accountReserve(0).jsonClipped();
2621 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
2623 lpClosed->info().closeTime.time_since_epoch().count());
2628 l[jss::reserve_base_xrp] =
2629 lpClosed->fees().accountReserve(0).decimalXRP();
2630 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
2633 std::abs(closeOffset.count()) >= 60)
2634 l[jss::close_time_offset] =
2637 #if RIPPLED_REPORTING
2647 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2651 auto lCloseTime = lpClosed->info().closeTime;
2653 if (lCloseTime <= closeTime)
2655 using namespace std::chrono_literals;
2656 auto age = closeTime - lCloseTime;
2658 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2665 info[jss::validated_ledger] = l;
2667 info[jss::closed_ledger] = l;
2671 info[jss::published_ledger] =
"none";
2672 else if (lpPublished->info().seq != lpClosed->info().seq)
2673 info[jss::published_ledger] = lpPublished->info().seq;
2680 info[jss::jq_trans_overflow] =
2682 info[jss::peer_disconnects] =
2684 info[jss::peer_disconnects_resources] =
2694 "http",
"https",
"peer",
"ws",
"ws2",
"wss",
"wss2"};
2702 !(port.admin_nets_v4.empty() && port.admin_nets_v6.empty() &&
2703 port.admin_user.empty() && port.admin_password.empty()))
2717 for (
auto const& p : proto)
2718 jv[jss::protocol].append(p);
2725 auto const optPort = grpcSection.
get(
"port");
2726 if (optPort && grpcSection.get(
"ip"))
2729 jv[jss::port] = *optPort;
2731 jv[jss::protocol].append(
"grpc");
2734 info[jss::ports] = std::move(ports);
2759 transJson(transaction, result,
false, ledger, std::nullopt);
2791 if (jvObj[jss::validated].asBool())
2803 p->send(jvObj,
true);
2824 if (
auto p = i->second.lock())
2826 p->send(jvObj,
true);
2844 if (
auto p = i->second.lock())
2846 p->send(jvObj,
true);
2859 for (
auto& jv : jvObj)
2865 else if (jv.isString())
2889 if (jvObj.
isMember(jss::transaction))
2898 << __func__ <<
" : "
2899 <<
"error parsing json for accounts affected";
2908 for (
auto const& affectedAccount : accounts)
2913 auto it = simiIt->second.begin();
2915 while (it != simiIt->second.end())
2926 it = simiIt->second.erase(it);
2933 <<
" iProposed=" << iProposed;
2935 if (!notify.
empty())
2938 isrListener->send(jvObj,
true);
2952 alpAccepted = std::make_shared<AcceptedLedger>(lpAccepted,
app_);
2954 lpAccepted->info().hash, alpAccepted);
2957 assert(alpAccepted->getLedger().
get() == lpAccepted.
get());
2961 <<
"Publishing ledger " << lpAccepted->info().seq <<
" "
2962 << lpAccepted->info().hash;
2970 jvObj[jss::type] =
"ledgerClosed";
2971 jvObj[jss::ledger_index] = lpAccepted->info().seq;
2972 jvObj[jss::ledger_hash] =
to_string(lpAccepted->info().hash);
2974 lpAccepted->info().closeTime.time_since_epoch().count());
2978 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
2979 jvObj[jss::reserve_base] =
2980 lpAccepted->fees().accountReserve(0).jsonClipped();
2981 jvObj[jss::reserve_inc] =
2982 lpAccepted->fees().increment.jsonClipped();
2984 jvObj[jss::txn_count] =
Json::UInt(alpAccepted->size());
2988 jvObj[jss::validated_ledgers] =
2998 p->send(jvObj,
true);
3016 p->send(jvObj,
true);
3025 static bool firstTime =
true;
3032 for (
auto& inner : outer.second)
3034 auto& subInfo = inner.second;
3035 if (subInfo.index_->separationLedgerSeq_ == 0)
3038 alpAccepted->getLedger(), subInfo);
3047 for (
auto const& accTx : *alpAccepted)
3051 lpAccepted, *accTx, accTx == *(--alpAccepted->end()));
3080 "reportConsensusStateChange->pubConsensus",
3111 jvObj[jss::type] =
"transaction";
3115 jvObj[jss::transaction] =
3122 jvObj[jss::meta], *ledger, transaction, meta->
get());
3125 if (!ledger->open())
3126 jvObj[jss::ledger_hash] =
to_string(ledger->info().hash);
3130 jvObj[jss::ledger_index] = ledger->info().seq;
3131 jvObj[jss::transaction][jss::date] =
3132 ledger->info().closeTime.time_since_epoch().count();
3133 jvObj[jss::validated] =
true;
3134 jvObj[jss::close_time_iso] =
to_string_iso(ledger->info().closeTime);
3140 jvObj[jss::validated] =
false;
3141 jvObj[jss::ledger_current_index] = ledger->info().seq;
3144 jvObj[jss::status] = validated ?
"closed" :
"proposed";
3145 jvObj[jss::engine_result] = sToken;
3146 jvObj[jss::engine_result_code] = result;
3147 jvObj[jss::engine_result_message] = sHuman;
3151 auto const account = transaction->getAccountID(
sfAccount);
3152 auto const amount = transaction->getFieldAmount(
sfTakerGets);
3155 if (account != amount.issue().account)
3163 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3169 visit<RPC::apiMinimumSupportedVersion, RPC::apiMaximumValidVersion>(
3173 jvTx[jss::transaction], transaction->getTxnType(), apiVersion);
3177 jvTx[jss::tx_json] = jvTx.
removeMember(jss::transaction);
3178 jvTx[jss::hash] = hash;
3182 jvTx[jss::transaction][jss::hash] = hash;
3195 auto const& stTxn = transaction.
getTxn();
3199 auto const trResult = transaction.
getResult();
3254 auto const currLedgerSeq = ledger->seq();
3261 for (
auto const& affectedAccount : transaction.
getAffected())
3266 auto it = simiIt->second.begin();
3268 while (it != simiIt->second.end())
3279 it = simiIt->second.erase(it);
3286 auto it = simiIt->second.begin();
3287 while (it != simiIt->second.end())
3298 it = simiIt->second.erase(it);
3305 auto& subs = histoIt->second;
3306 auto it = subs.begin();
3307 while (it != subs.end())
3310 if (currLedgerSeq <= info.index_->separationLedgerSeq_)
3324 it = subs.erase(it);
3335 <<
"pubAccountTransaction: "
3336 <<
"proposed=" << iProposed <<
", accepted=" << iAccepted;
3338 if (!notify.
empty() || !accountHistoryNotify.
empty())
3340 auto const& stTxn = transaction.
getTxn();
3344 auto const trResult = transaction.
getResult();
3355 jvObj.set(jss::account_history_boundary,
true);
3358 jvObj.
isMember(jss::account_history_tx_stream) ==
3359 MultiApiJson::none);
3360 for (
auto& info : accountHistoryNotify)
3362 auto& index = info.index_;
3363 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3364 jvObj.set(jss::account_history_tx_first,
true);
3366 jvObj.set(jss::account_history_tx_index, index->forwardTxIndex_++);
3395 for (
auto const& affectedAccount : tx->getMentionedAccounts())
3400 auto it = simiIt->second.begin();
3402 while (it != simiIt->second.end())
3413 it = simiIt->second.erase(it);
3420 JLOG(
m_journal.
trace()) <<
"pubProposedAccountTransaction: " << iProposed;
3422 if (!notify.
empty() || !accountHistoryNotify.
empty())
3433 jvObj.
isMember(jss::account_history_tx_stream) ==
3434 MultiApiJson::none);
3435 for (
auto& info : accountHistoryNotify)
3437 auto& index = info.index_;
3438 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3439 jvObj.set(jss::account_history_tx_first,
true);
3440 jvObj.set(jss::account_history_tx_index, index->forwardTxIndex_++);
3460 for (
auto const& naAccountID : vnaAccountIDs)
3463 <<
"subAccount: account: " <<
toBase58(naAccountID);
3465 isrListener->insertSubAccountInfo(naAccountID, rt);
3470 for (
auto const& naAccountID : vnaAccountIDs)
3472 auto simIterator = subMap.
find(naAccountID);
3473 if (simIterator == subMap.
end())
3477 usisElement[isrListener->getSeq()] = isrListener;
3479 subMap.
insert(simIterator, make_pair(naAccountID, usisElement));
3484 simIterator->second[isrListener->getSeq()] = isrListener;
3495 for (
auto const& naAccountID : vnaAccountIDs)
3498 isrListener->deleteSubAccountInfo(naAccountID, rt);
3515 for (
auto const& naAccountID : vnaAccountIDs)
3517 auto simIterator = subMap.
find(naAccountID);
3519 if (simIterator != subMap.
end())
3522 simIterator->second.erase(uSeq);
3524 if (simIterator->second.empty())
3527 subMap.
erase(simIterator);
3536 enum DatabaseType { Postgres, Sqlite, None };
3537 static const auto databaseType = [&]() -> DatabaseType {
3538 #ifdef RIPPLED_REPORTING
3545 return DatabaseType::Postgres;
3547 return DatabaseType::None;
3555 return DatabaseType::Sqlite;
3557 return DatabaseType::None;
3564 return DatabaseType::Sqlite;
3566 return DatabaseType::None;
3570 if (databaseType == DatabaseType::None)
3573 <<
"AccountHistory job for account "
3585 "AccountHistoryTxStream",
3586 [
this, dbType = databaseType, subInfo]() {
3587 auto const& accountId = subInfo.
index_->accountId_;
3588 auto& lastLedgerSeq = subInfo.
index_->historyLastLedgerSeq_;
3589 auto& txHistoryIndex = subInfo.
index_->historyTxIndex_;
3592 <<
"AccountHistory job for account " <<
toBase58(accountId)
3593 <<
" started. lastLedgerSeq=" << lastLedgerSeq;
3603 auto stx = tx->getSTransaction();
3604 if (stx->getAccountID(
sfAccount) == accountId &&
3605 stx->getSeqProxy().value() == 1)
3609 for (
auto& node : meta->getNodes())
3616 if (
auto inner =
dynamic_cast<const STObject*
>(
3621 inner->getAccountID(
sfAccount) == accountId)
3633 bool unsubscribe) ->
bool {
3636 sptr->send(jvObj,
true);
3646 bool unsubscribe) ->
bool {
3678 auto [txResult, status] = db->getAccountTx(args);
3682 <<
"AccountHistory job for account "
3684 <<
" getAccountTx failed";
3689 std::get_if<RelationalDatabase::AccountTxs>(
3690 &txResult.transactions);
3698 <<
"AccountHistory job for account "
3700 <<
" getAccountTx wrong data";
3708 accountId, minLedger, maxLedger, marker, 0,
true};
3709 return db->newestAccountTxPage(options);
3721 while (lastLedgerSeq >= 2 && !subInfo.
index_->stopHistorical_)
3723 int feeChargeCount = 0;
3732 <<
"AccountHistory job for account "
3733 <<
toBase58(accountId) <<
" no InfoSub. Fee charged "
3734 << feeChargeCount <<
" times.";
3739 auto startLedgerSeq =
3740 (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
3742 <<
"AccountHistory job for account " <<
toBase58(accountId)
3743 <<
", working on ledger range [" << startLedgerSeq <<
","
3744 << lastLedgerSeq <<
"]";
3746 auto haveRange = [&]() ->
bool {
3749 auto haveSomeValidatedLedgers =
3751 validatedMin, validatedMax);
3753 return haveSomeValidatedLedgers &&
3754 validatedMin <= startLedgerSeq &&
3755 lastLedgerSeq <= validatedMax;
3761 <<
"AccountHistory reschedule job for account "
3762 <<
toBase58(accountId) <<
", incomplete ledger range ["
3763 << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
3769 while (!subInfo.
index_->stopHistorical_)
3772 getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
3776 <<
"AccountHistory job for account "
3777 <<
toBase58(accountId) <<
" getMoreTxns failed.";
3782 auto const& txns = dbResult->first;
3783 marker = dbResult->second;
3784 size_t num_txns = txns.size();
3785 for (
size_t i = 0; i < num_txns; ++i)
3787 auto const& [tx, meta] = txns[i];
3792 <<
"AccountHistory job for account "
3793 <<
toBase58(accountId) <<
" empty tx or meta.";
3803 <<
"AccountHistory job for account "
3804 <<
toBase58(accountId) <<
" no ledger.";
3809 tx->getSTransaction();
3813 <<
"AccountHistory job for account "
3815 <<
" getSTransaction failed.";
3821 auto const trR = meta->getResultTER();
3823 transJson(stTxn, trR,
true, curTxLedger, mRef);
3826 jss::account_history_tx_index, txHistoryIndex--);
3827 if (i + 1 == num_txns ||
3828 txns[i + 1].first->getLedger() != tx->getLedger())
3829 jvTx.set(jss::account_history_boundary,
true);
3831 if (isFirstTx(tx, meta))
3833 jvTx.set(jss::account_history_tx_first,
true);
3834 sendMultiApiJson(jvTx,
false);
3837 <<
"AccountHistory job for account "
3839 <<
" done, found last tx.";
3844 sendMultiApiJson(jvTx,
false);
3851 <<
"AccountHistory job for account "
3853 <<
" paging, marker=" << marker->ledgerSeq <<
":"
3862 if (!subInfo.
index_->stopHistorical_)
3864 lastLedgerSeq = startLedgerSeq - 1;
3865 if (lastLedgerSeq <= 1)
3868 <<
"AccountHistory job for account "
3870 <<
" done, reached genesis ledger.";
3883 subInfo.
index_->separationLedgerSeq_ = ledger->seq();
3884 auto const& accountId = subInfo.
index_->accountId_;
3886 if (!ledger->exists(accountKeylet))
3889 <<
"subAccountHistoryStart, no account " <<
toBase58(accountId)
3890 <<
", no need to add AccountHistory job.";
3895 if (
auto const sleAcct = ledger->read(accountKeylet); sleAcct)
3900 <<
"subAccountHistoryStart, genesis account "
3902 <<
" does not have tx, no need to add AccountHistory job.";
3912 subInfo.
index_->historyLastLedgerSeq_ = ledger->seq();
3913 subInfo.
index_->haveHistorical_ =
true;
3916 <<
"subAccountHistoryStart, add AccountHistory job: accountId="
3917 <<
toBase58(accountId) <<
", currentLedgerSeq=" << ledger->seq();
3927 if (!isrListener->insertSubAccountHistory(accountId))
3930 <<
"subAccountHistory, already subscribed to account "
3937 isrListener, std::make_shared<SubAccountHistoryIndex>(accountId)};
3942 inner.
emplace(isrListener->getSeq(), ahi);
3948 simIterator->second.emplace(isrListener->getSeq(), ahi);
3962 <<
"subAccountHistory, no validated ledger yet, delay start";
3975 isrListener->deleteSubAccountHistory(account);
3989 auto& subInfoMap = simIterator->second;
3990 auto subInfoIter = subInfoMap.find(seq);
3991 if (subInfoIter != subInfoMap.end())
3993 subInfoIter->second.index_->stopHistorical_ =
true;
3998 simIterator->second.erase(seq);
3999 if (simIterator->second.empty())
4005 <<
"unsubAccountHistory, account " <<
toBase58(account)
4006 <<
", historyOnly = " << (historyOnly ?
"true" :
"false");
4014 listeners->addSubscriber(isrListener);
4024 listeners->removeSubscriber(uSeq);
4038 Throw<std::runtime_error>(
4039 "Operation only possible in STANDALONE mode.");
4054 jvResult[jss::ledger_index] = lpClosed->info().seq;
4055 jvResult[jss::ledger_hash] =
to_string(lpClosed->info().hash);
4057 lpClosed->info().closeTime.time_since_epoch().count());
4060 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
4061 jvResult[jss::reserve_base] =
4062 lpClosed->fees().accountReserve(0).jsonClipped();
4063 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
4068 jvResult[jss::validated_ledgers] =
4074 .emplace(isrListener->getSeq(), isrListener)
4084 .emplace(isrListener->getSeq(), isrListener)
4110 .emplace(isrListener->getSeq(), isrListener)
4138 jvResult[jss::random] =
to_string(uRandom);
4140 jvResult[jss::load_base] = feeTrack.getLoadBase();
4141 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
4142 jvResult[jss::hostid] =
getHostId(admin);
4143 jvResult[jss::pubkey_node] =
4148 .emplace(isrListener->getSeq(), isrListener)
4166 .emplace(isrListener->getSeq(), isrListener)
4184 .emplace(isrListener->getSeq(), isrListener)
4202 .emplace(isrListener->getSeq(), isrListener)
4226 .emplace(isrListener->getSeq(), isrListener)
4244 .emplace(isrListener->getSeq(), isrListener)
4292 if (map.find(pInfo->getSeq()) != map.end())
4299 #ifndef USE_NEW_BOOK_PAGE
4310 unsigned int iLimit,
4320 uint256 uTipIndex = uBookBase;
4324 stream <<
"getBookPage:" << book;
4325 stream <<
"getBookPage: uBookBase=" << uBookBase;
4326 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
4327 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
4336 bool bDirectAdvance =
true;
4340 unsigned int uBookEntry;
4346 while (!bDone && iLimit-- > 0)
4350 bDirectAdvance =
false;
4354 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
4358 sleOfferDir.
reset();
4367 uTipIndex = sleOfferDir->key();
4370 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
4373 <<
"getBookPage: uTipIndex=" << uTipIndex;
4375 <<
"getBookPage: offerIndex=" << offerIndex;
4385 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4386 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4387 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4389 bool firstOwnerOffer(
true);
4395 saOwnerFunds = saTakerGets;
4397 else if (bGlobalFreeze)
4405 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4406 if (umBalanceEntry != umBalance.
end())
4410 saOwnerFunds = umBalanceEntry->second;
4411 firstOwnerOffer =
false;
4425 if (saOwnerFunds < beast::zero)
4429 saOwnerFunds.
clear();
4437 STAmount saOwnerFundsLimit = saOwnerFunds;
4449 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4452 if (saOwnerFundsLimit >= saTakerGets)
4455 saTakerGetsFunded = saTakerGets;
4461 saTakerGetsFunded = saOwnerFundsLimit;
4463 saTakerGetsFunded.
setJson(jvOffer[jss::taker_gets_funded]);
4467 saTakerGetsFunded, saDirRate, saTakerPays.
issue()))
4468 .setJson(jvOffer[jss::taker_pays_funded]);
4474 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4476 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4480 jvOf[jss::quality] = saDirRate.
getText();
4482 if (firstOwnerOffer)
4483 jvOf[jss::owner_funds] = saOwnerFunds.
getText();
4490 if (!
cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
4492 bDirectAdvance =
true;
4497 <<
"getBookPage: offerIndex=" << offerIndex;
4517 unsigned int iLimit,
4525 MetaView lesActive(lpLedger,
tapNONE,
true);
4526 OrderBookIterator obIterator(lesActive, book);
4530 const bool bGlobalFreeze = lesActive.isGlobalFrozen(book.
out.
account) ||
4531 lesActive.isGlobalFrozen(book.
in.
account);
4533 while (iLimit-- > 0 && obIterator.nextOffer())
4538 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4539 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4540 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4541 STAmount saDirRate = obIterator.getCurrentRate();
4547 saOwnerFunds = saTakerGets;
4549 else if (bGlobalFreeze)
4557 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4559 if (umBalanceEntry != umBalance.
end())
4563 saOwnerFunds = umBalanceEntry->second;
4569 saOwnerFunds = lesActive.accountHolds(
4575 if (saOwnerFunds.isNegative())
4579 saOwnerFunds.zero();
4586 STAmount saTakerGetsFunded;
4587 STAmount saOwnerFundsLimit = saOwnerFunds;
4599 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4602 if (saOwnerFundsLimit >= saTakerGets)
4605 saTakerGetsFunded = saTakerGets;
4610 saTakerGetsFunded = saOwnerFundsLimit;
4612 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
4618 multiply(saTakerGetsFunded, saDirRate, saTakerPays.issue()))
4619 .setJson(jvOffer[jss::taker_pays_funded]);
4622 STAmount saOwnerPays = (
parityRate == offerRate)
4625 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4627 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4629 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
4633 jvOf[jss::quality] = saDirRate.
getText();
4648 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4688 ++counters_[
static_cast<std::size_t>(om)].transitions;
4690 counters_[
static_cast<std::size_t>(om)].transitions == 1)
4692 initialSyncUs_ = std::chrono::duration_cast<std::chrono::microseconds>(
4693 now - processStart_)
4697 std::chrono::duration_cast<std::chrono::microseconds>(now - start_);
4706 auto [counters, mode, start, initialSync] = getCounterData();
4707 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4717 auto& state = obj[jss::state_accounting][
states_[i]];
4718 state[jss::transitions] =
std::to_string(counters[i].transitions);
4719 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
4723 obj[jss::initial_sync_duration_us] =
std::to_string(initialSync);
4738 boost::asio::io_service& io_svc,
4742 return std::make_unique<NetworkOPsImp>(