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/HashRouter.h>
33 #include <ripple/app/misc/LoadFeeTrack.h>
34 #include <ripple/app/misc/NetworkOPs.h>
35 #include <ripple/app/misc/Transaction.h>
36 #include <ripple/app/misc/TxQ.h>
37 #include <ripple/app/misc/ValidatorKeys.h>
38 #include <ripple/app/misc/ValidatorList.h>
39 #include <ripple/app/misc/impl/AccountTxPaging.h>
40 #include <ripple/app/rdb/backend/PostgresDatabase.h>
41 #include <ripple/app/rdb/backend/SQLiteDatabase.h>
42 #include <ripple/app/reporting/ReportingETL.h>
43 #include <ripple/app/tx/apply.h>
44 #include <ripple/basics/PerfLog.h>
45 #include <ripple/basics/UptimeClock.h>
46 #include <ripple/basics/mulDiv.h>
47 #include <ripple/basics/safe_cast.h>
48 #include <ripple/beast/rfc2616.h>
49 #include <ripple/beast/utility/rngfill.h>
50 #include <ripple/consensus/Consensus.h>
51 #include <ripple/consensus/ConsensusParms.h>
52 #include <ripple/crypto/RFC1751.h>
53 #include <ripple/crypto/csprng.h>
54 #include <ripple/json/to_string.h>
55 #include <ripple/net/RPCErr.h>
56 #include <ripple/nodestore/DatabaseShard.h>
57 #include <ripple/overlay/Cluster.h>
58 #include <ripple/overlay/Overlay.h>
59 #include <ripple/overlay/predicates.h>
60 #include <ripple/protocol/BuildInfo.h>
61 #include <ripple/protocol/Feature.h>
62 #include <ripple/protocol/STParsedJSON.h>
63 #include <ripple/resource/Fees.h>
64 #include <ripple/resource/ResourceManager.h>
65 #include <ripple/rpc/BookChanges.h>
66 #include <ripple/rpc/DeliveredAmount.h>
67 #include <ripple/rpc/impl/RPCHelpers.h>
68 #include <boost/asio/ip/host_name.hpp>
69 #include <boost/asio/steady_timer.hpp>
144 std::chrono::steady_clock::time_point
start_ =
205 return !(*
this != b);
224 boost::asio::io_service& io_svc,
238 app_.logs().journal(
"FeeVote")),
241 app.getInboundTransactions(),
242 beast::get_abstract_clock<
std::chrono::steady_clock>(),
244 app_.logs().journal(
"LedgerConsensus"))
423 getServerInfo(
bool human,
bool admin,
bool counters)
override;
450 TER result)
override;
493 bool historyOnly)
override;
499 bool historyOnly)
override;
567 boost::system::error_code ec;
572 <<
"NetworkOPs: heartbeatTimer cancel error: "
581 <<
"NetworkOPs: clusterTimer cancel error: "
590 <<
"NetworkOPs: accountHistoryTxTimer cancel error: "
595 using namespace std::chrono_literals;
605 boost::asio::steady_timer& timer,
620 const STTx& transaction,
780 template <
class Handler>
782 Handler
const& handler,
784 :
hook(collector->make_hook(handler))
787 "Disconnected_duration"))
790 "Connected_duration"))
792 collector->make_gauge(
"State_Accounting",
"Syncing_duration"))
795 "Tracking_duration"))
797 collector->make_gauge(
"State_Accounting",
"Full_duration"))
800 "Disconnected_transitions"))
803 "Connected_transitions"))
806 "Syncing_transitions"))
809 "Tracking_transitions"))
811 collector->make_gauge(
"State_Accounting",
"Full_transitions"))
840 {
"disconnected",
"connected",
"syncing",
"tracking",
"full"}};
902 static std::string const hostname = boost::asio::ip::host_name();
909 static std::string const shroudedHostId = [
this]() {
915 return shroudedHostId;
930 boost::asio::steady_timer& timer,
937 [
this, onExpire, onError](boost::system::error_code
const& e) {
938 if ((e.value() == boost::system::errc::success) &&
939 (!m_job_queue.isStopped()))
944 if (e.value() != boost::system::errc::success &&
945 e.value() != boost::asio::error::operation_aborted)
948 JLOG(m_journal.error())
949 <<
"Timer got error '" << e.message()
950 <<
"'. Restarting timer.";
955 timer.expires_from_now(expiry_time);
956 timer.async_wait(std::move(*optionalCountedHandler));
967 m_job_queue.addJob(jtNETOP_TIMER,
"NetOPs.heartbeat", [this]() {
968 processHeartbeatTimer();
971 [
this]() { setHeartbeatTimer(); });
975 NetworkOPsImp::setClusterTimer()
977 using namespace std::chrono_literals;
984 processClusterTimer();
987 [
this]() { setClusterTimer(); });
993 JLOG(m_journal.debug()) <<
"Scheduling AccountHistory job for account "
995 using namespace std::chrono_literals;
997 accountHistoryTxTimer_,
999 [
this, subInfo]() { addAccountHistoryJob(subInfo); },
1000 [
this, subInfo]() { setAccountHistoryJobTimer(subInfo); });
1004 NetworkOPsImp::processHeartbeatTimer()
1013 std::size_t const numPeers = app_.overlay().size();
1016 if (numPeers < minPeerCount_)
1018 if (mMode != OperatingMode::DISCONNECTED)
1020 setMode(OperatingMode::DISCONNECTED);
1021 JLOG(m_journal.warn())
1022 <<
"Node count (" << numPeers <<
") has fallen "
1023 <<
"below required minimum (" << minPeerCount_ <<
").";
1030 setHeartbeatTimer();
1034 if (mMode == OperatingMode::DISCONNECTED)
1036 setMode(OperatingMode::CONNECTED);
1037 JLOG(m_journal.info())
1038 <<
"Node count (" << numPeers <<
") is sufficient.";
1043 if (mMode == OperatingMode::SYNCING)
1044 setMode(OperatingMode::SYNCING);
1045 else if (mMode == OperatingMode::CONNECTED)
1046 setMode(OperatingMode::CONNECTED);
1049 mConsensus.timerEntry(app_.timeKeeper().closeTime());
1052 if (mLastConsensusPhase != currPhase)
1054 reportConsensusStateChange(currPhase);
1055 mLastConsensusPhase = currPhase;
1058 setHeartbeatTimer();
1062 NetworkOPsImp::processClusterTimer()
1064 if (app_.cluster().size() == 0)
1067 using namespace std::chrono_literals;
1069 bool const update = app_.cluster().update(
1070 app_.nodeIdentity().first,
1072 (m_ledgerMaster.getValidatedLedgerAge() <= 4
min)
1073 ? app_.getFeeTrack().getLocalFee()
1075 app_.timeKeeper().now());
1079 JLOG(m_journal.debug()) <<
"Too soon to send cluster update";
1084 protocol::TMCluster cluster;
1085 app_.cluster().for_each([&cluster](
ClusterNode const& node) {
1086 protocol::TMClusterNode& n = *cluster.add_clusternodes();
1091 n.set_nodename(node.
name());
1095 for (
auto& item : gossip.
items)
1097 protocol::TMLoadSource& node = *cluster.add_loadsources();
1099 node.set_cost(item.balance);
1101 app_.overlay().foreach(
send_if(
1102 std::make_shared<Message>(cluster, protocol::mtCLUSTER),
1113 if (mode == OperatingMode::FULL && admin)
1115 auto const consensusMode = mConsensus.mode();
1116 if (consensusMode != ConsensusMode::wrongLedger)
1118 if (consensusMode == ConsensusMode::proposing)
1121 if (mConsensus.validating())
1122 return "validating";
1132 if (isNeedNetworkLedger())
1141 auto const txid = trans->getTransactionID();
1142 auto const flags = app_.getHashRouter().getFlags(txid);
1144 if ((flags & SF_BAD) != 0)
1146 JLOG(m_journal.warn()) <<
"Submitted transaction cached bad";
1153 app_.getHashRouter(),
1155 m_ledgerMaster.getValidatedRules(),
1158 if (validity != Validity::Valid)
1160 JLOG(m_journal.warn())
1161 <<
"Submitted transaction invalid: " << reason;
1167 JLOG(m_journal.warn())
1168 <<
"Exception checking transaction " << txid <<
": " << ex.
what();
1175 auto tx = std::make_shared<Transaction>(trans, reason, app_);
1177 m_job_queue.addJob(
jtTRANSACTION,
"submitTxn", [
this, tx]() {
1179 processTransaction(t,
false,
false, FailHard::no);
1184 NetworkOPsImp::processTransaction(
1190 auto ev = m_job_queue.makeLoadEvent(
jtTXN_PROC,
"ProcessTXN");
1191 auto const newFlags = app_.getHashRouter().getFlags(transaction->getID());
1193 if ((newFlags & SF_BAD) != 0)
1196 JLOG(m_journal.warn()) << transaction->getID() <<
": cached bad!\n";
1197 transaction->setStatus(
INVALID);
1205 auto const view = m_ledgerMaster.getCurrentLedger();
1207 app_.getHashRouter(),
1208 *transaction->getSTransaction(),
1211 assert(validity == Validity::Valid);
1214 if (validity == Validity::SigBad)
1216 JLOG(m_journal.info()) <<
"Transaction has bad signature: " << reason;
1217 transaction->setStatus(
INVALID);
1219 app_.getHashRouter().setFlags(transaction->getID(), SF_BAD);
1224 app_.getMasterTransaction().canonicalize(&transaction);
1227 doTransactionSync(transaction, bUnlimited, failType);
1229 doTransactionAsync(transaction, bUnlimited, failType);
1233 NetworkOPsImp::doTransactionAsync(
1240 if (transaction->getApplying())
1243 mTransactions.push_back(
1245 transaction->setApplying();
1247 if (mDispatchState == DispatchState::none)
1249 if (m_job_queue.addJob(
1250 jtBATCH,
"transactionBatch", [
this]() { transactionBatch(); }))
1252 mDispatchState = DispatchState::scheduled;
1258 NetworkOPsImp::doTransactionSync(
1265 if (!transaction->getApplying())
1267 mTransactions.push_back(
1269 transaction->setApplying();
1274 if (mDispatchState == DispatchState::running)
1283 if (mTransactions.size())
1286 if (m_job_queue.addJob(
jtBATCH,
"transactionBatch", [
this]() {
1290 mDispatchState = DispatchState::scheduled;
1294 }
while (transaction->getApplying());
1298 NetworkOPsImp::transactionBatch()
1302 if (mDispatchState == DispatchState::running)
1305 while (mTransactions.size())
1316 mTransactions.
swap(transactions);
1317 assert(!transactions.
empty());
1319 assert(mDispatchState != DispatchState::running);
1320 mDispatchState = DispatchState::running;
1326 bool changed =
false;
1329 m_ledgerMaster.peekMutex(), std::defer_lock};
1340 if (e.failType == FailHard::yes)
1343 auto const result = app_.getTxQ().apply(
1344 app_, view, e.transaction->getSTransaction(), flags, j);
1345 e.result = result.first;
1346 e.applied = result.second;
1347 changed = changed || result.second;
1356 if (
auto const l = m_ledgerMaster.getValidatedLedger())
1357 validatedLedgerIndex = l->info().seq;
1359 auto newOL = app_.openLedger().current();
1362 e.transaction->clearSubmitResult();
1366 pubProposedTransaction(
1367 newOL, e.transaction->getSTransaction(), e.result);
1368 e.transaction->setApplied();
1371 e.transaction->setResult(e.result);
1374 app_.getHashRouter().setFlags(e.transaction->getID(), SF_BAD);
1383 JLOG(m_journal.info())
1384 <<
"TransactionResult: " << token <<
": " << human;
1389 bool addLocal = e.local;
1393 JLOG(m_journal.debug())
1394 <<
"Transaction is now included in open ledger";
1395 e.transaction->setStatus(
INCLUDED);
1397 auto const& txCur = e.transaction->getSTransaction();
1398 auto const txNext = m_ledgerMaster.popAcctTransaction(txCur);
1403 auto t = std::make_shared<Transaction>(trans, reason, app_);
1404 submit_held.
emplace_back(t,
false,
false, FailHard::no);
1411 JLOG(m_journal.info()) <<
"Transaction is obsolete";
1412 e.transaction->setStatus(
OBSOLETE);
1416 JLOG(m_journal.debug())
1417 <<
"Transaction is likely to claim a"
1418 <<
" fee, but is queued until fee drops";
1420 e.transaction->setStatus(
HELD);
1424 m_ledgerMaster.addHeldTransaction(e.transaction);
1425 e.transaction->setQueued();
1426 e.transaction->setKept();
1430 if (e.failType != FailHard::yes)
1433 JLOG(m_journal.debug())
1434 <<
"Transaction should be held: " << e.result;
1435 e.transaction->setStatus(
HELD);
1436 m_ledgerMaster.addHeldTransaction(e.transaction);
1437 e.transaction->setKept();
1442 JLOG(m_journal.debug())
1443 <<
"Status other than success " << e.result;
1444 e.transaction->setStatus(
INVALID);
1447 auto const enforceFailHard =
1448 e.failType == FailHard::yes && !
isTesSuccess(e.result);
1450 if (addLocal && !enforceFailHard)
1452 m_localTX->push_back(
1453 m_ledgerMaster.getCurrentLedgerIndex(),
1454 e.transaction->getSTransaction());
1455 e.transaction->setKept();
1459 ((mMode != OperatingMode::FULL) &&
1460 (e.failType != FailHard::yes) && e.local) ||
1465 app_.getHashRouter().shouldRelay(e.transaction->getID());
1469 protocol::TMTransaction tx;
1472 e.transaction->getSTransaction()->add(s);
1473 tx.set_rawtransaction(s.
data(), s.
size());
1474 tx.set_status(protocol::tsCURRENT);
1475 tx.set_receivetimestamp(
1476 app_.timeKeeper().now().time_since_epoch().count());
1479 app_.overlay().relay(e.transaction->getID(), tx, *toSkip);
1480 e.transaction->setBroadcast();
1484 if (validatedLedgerIndex)
1486 auto [fee, accountSeq, availableSeq] =
1487 app_.getTxQ().getTxRequiredFeeAndSeq(
1488 *newOL, e.transaction->getSTransaction());
1489 e.transaction->setCurrentLedgerState(
1490 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1498 e.transaction->clearApplying();
1500 if (!submit_held.
empty())
1502 if (mTransactions.empty())
1503 mTransactions.swap(submit_held);
1505 for (
auto& e : submit_held)
1506 mTransactions.push_back(std::move(e));
1511 mDispatchState = DispatchState::none;
1519 NetworkOPsImp::getOwnerInfo(
1524 auto root = keylet::ownerDir(account);
1525 auto sleNode = lpLedger->read(keylet::page(
root));
1532 for (
auto const& uDirEntry : sleNode->getFieldV256(
sfIndexes))
1534 auto sleCur = lpLedger->read(keylet::child(uDirEntry));
1537 switch (sleCur->getType())
1540 if (!jvObjects.
isMember(jss::offers))
1541 jvObjects[jss::offers] =
1544 jvObjects[jss::offers].
append(
1545 sleCur->getJson(JsonOptions::none));
1549 if (!jvObjects.
isMember(jss::ripple_lines))
1551 jvObjects[jss::ripple_lines] =
1555 jvObjects[jss::ripple_lines].
append(
1556 sleCur->getJson(JsonOptions::none));
1571 sleNode = lpLedger->read(keylet::page(
root, uNodeDir));
1585 NetworkOPsImp::isBlocked()
1587 return isAmendmentBlocked() || isUNLBlocked();
1591 NetworkOPsImp::isAmendmentBlocked()
1593 return amendmentBlocked_;
1597 NetworkOPsImp::setAmendmentBlocked()
1599 amendmentBlocked_ =
true;
1600 setMode(OperatingMode::CONNECTED);
1604 NetworkOPsImp::isAmendmentWarned()
1606 return !amendmentBlocked_ && amendmentWarned_;
1610 NetworkOPsImp::setAmendmentWarned()
1612 amendmentWarned_ =
true;
1616 NetworkOPsImp::clearAmendmentWarned()
1618 amendmentWarned_ =
false;
1622 NetworkOPsImp::isUNLBlocked()
1628 NetworkOPsImp::setUNLBlocked()
1631 setMode(OperatingMode::CONNECTED);
1635 NetworkOPsImp::clearUNLBlocked()
1637 unlBlocked_ =
false;
1641 NetworkOPsImp::checkLastClosedLedger(
1650 JLOG(m_journal.trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
1652 auto const ourClosed = m_ledgerMaster.getClosedLedger();
1657 uint256 closedLedger = ourClosed->info().hash;
1658 uint256 prevClosedLedger = ourClosed->info().parentHash;
1659 JLOG(m_journal.trace()) <<
"OurClosed: " << closedLedger;
1660 JLOG(m_journal.trace()) <<
"PrevClosed: " << prevClosedLedger;
1665 auto& validations = app_.getValidations();
1666 JLOG(m_journal.debug())
1667 <<
"ValidationTrie " <<
Json::Compact(validations.getJsonTrie());
1671 peerCounts[closedLedger] = 0;
1672 if (mMode >= OperatingMode::TRACKING)
1673 peerCounts[closedLedger]++;
1675 for (
auto& peer : peerList)
1677 uint256 peerLedger = peer->getClosedLedgerHash();
1680 ++peerCounts[peerLedger];
1683 for (
auto const& it : peerCounts)
1684 JLOG(m_journal.debug()) <<
"L: " << it.first <<
" n=" << it.second;
1686 uint256 preferredLCL = validations.getPreferredLCL(
1688 m_ledgerMaster.getValidLedgerIndex(),
1691 bool switchLedgers = preferredLCL != closedLedger;
1693 closedLedger = preferredLCL;
1695 if (switchLedgers && (closedLedger == prevClosedLedger))
1698 JLOG(m_journal.info()) <<
"We won't switch to our own previous ledger";
1699 networkClosed = ourClosed->info().hash;
1700 switchLedgers =
false;
1703 networkClosed = closedLedger;
1708 auto consensus = m_ledgerMaster.getLedgerByHash(closedLedger);
1711 consensus = app_.getInboundLedgers().acquire(
1712 closedLedger, 0, InboundLedger::Reason::CONSENSUS);
1715 (!m_ledgerMaster.canBeCurrent(consensus) ||
1716 !m_ledgerMaster.isCompatible(
1717 *consensus, m_journal.debug(),
"Not switching")))
1721 networkClosed = ourClosed->info().hash;
1725 JLOG(m_journal.warn()) <<
"We are not running on the consensus ledger";
1726 JLOG(m_journal.info()) <<
"Our LCL: " <<
getJson({*ourClosed, {}});
1727 JLOG(m_journal.info()) <<
"Net LCL " << closedLedger;
1729 if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
1731 setMode(OperatingMode::CONNECTED);
1739 switchLastClosedLedger(consensus);
1746 NetworkOPsImp::switchLastClosedLedger(
1750 JLOG(m_journal.error())
1751 <<
"JUMP last closed ledger to " << newLCL->info().hash;
1753 clearNeedNetworkLedger();
1756 app_.getTxQ().processClosedLedger(app_, *newLCL,
true);
1763 auto retries = m_localTX->getTxSet();
1764 auto const lastVal = app_.getLedgerMaster().getValidatedLedger();
1769 rules.
emplace(app_.config().features);
1770 app_.openLedger().accept(
1781 return app_.getTxQ().accept(app_, view);
1785 m_ledgerMaster.switchLCL(newLCL);
1787 protocol::TMStatusChange s;
1788 s.set_newevent(protocol::neSWITCHED_LEDGER);
1789 s.set_ledgerseq(newLCL->info().seq);
1790 s.set_networktime(app_.timeKeeper().now().time_since_epoch().count());
1791 s.set_ledgerhashprevious(
1792 newLCL->info().parentHash.begin(), newLCL->info().parentHash.size());
1793 s.set_ledgerhash(newLCL->info().hash.begin(), newLCL->info().hash.size());
1795 app_.overlay().foreach(
1796 send_always(std::make_shared<Message>(s, protocol::mtSTATUS_CHANGE)));
1800 NetworkOPsImp::beginConsensus(
uint256 const& networkClosed)
1804 auto closingInfo = m_ledgerMaster.getCurrentLedger()->info();
1806 JLOG(m_journal.info()) <<
"Consensus time for #" << closingInfo.seq
1807 <<
" with LCL " << closingInfo.parentHash;
1809 auto prevLedger = m_ledgerMaster.getLedgerByHash(closingInfo.parentHash);
1814 if (mMode == OperatingMode::FULL)
1816 JLOG(m_journal.warn()) <<
"Don't have LCL, going to tracking";
1817 setMode(OperatingMode::TRACKING);
1823 assert(prevLedger->info().hash == closingInfo.parentHash);
1825 closingInfo.parentHash ==
1826 m_ledgerMaster.getClosedLedger()->info().hash);
1829 app_.validators().setNegativeUNL(prevLedger->negativeUNL());
1830 TrustChanges const changes = app_.validators().updateTrusted(
1831 app_.getValidations().getCurrentNodeIDs(),
1832 closingInfo.parentCloseTime,
1835 app_.getHashRouter());
1837 if (!changes.
added.empty() || !changes.
removed.empty())
1838 app_.getValidations().trustChanged(changes.
added, changes.
removed);
1840 mConsensus.startRound(
1841 app_.timeKeeper().closeTime(),
1848 if (mLastConsensusPhase != currPhase)
1850 reportConsensusStateChange(currPhase);
1851 mLastConsensusPhase = currPhase;
1854 JLOG(m_journal.debug()) <<
"Initiating consensus engine";
1861 return mConsensus.peerProposal(app_.timeKeeper().closeTime(), peerPos);
1872 protocol::TMHaveTransactionSet msg;
1873 msg.set_hash(map->getHash().as_uint256().begin(), 256 / 8);
1874 msg.set_status(protocol::tsHAVE);
1875 app_.overlay().foreach(
1876 send_always(std::make_shared<Message>(msg, protocol::mtHAVE_SET)));
1880 mConsensus.gotTxSet(app_.timeKeeper().closeTime(),
RCLTxSet{map});
1884 NetworkOPsImp::endConsensus()
1886 uint256 deadLedger = m_ledgerMaster.getClosedLedger()->info().parentHash;
1888 for (
auto const& it : app_.overlay().getActivePeers())
1890 if (it && (it->getClosedLedgerHash() == deadLedger))
1892 JLOG(m_journal.trace()) <<
"Killing obsolete peer status";
1899 checkLastClosedLedger(app_.overlay().getActivePeers(), networkClosed);
1901 if (networkClosed.
isZero())
1910 if (((mMode == OperatingMode::CONNECTED) ||
1911 (mMode == OperatingMode::SYNCING)) &&
1917 if (!needNetworkLedger_)
1918 setMode(OperatingMode::TRACKING);
1921 if (((mMode == OperatingMode::CONNECTED) ||
1922 (mMode == OperatingMode::TRACKING)) &&
1928 auto current = m_ledgerMaster.getCurrentLedger();
1929 if (app_.timeKeeper().now() < (
current->info().parentCloseTime +
1930 2 *
current->info().closeTimeResolution))
1932 setMode(OperatingMode::FULL);
1936 beginConsensus(networkClosed);
1940 NetworkOPsImp::consensusViewChange()
1942 if ((mMode == OperatingMode::FULL) || (mMode == OperatingMode::TRACKING))
1944 setMode(OperatingMode::CONNECTED);
1954 if (!mStreamMaps[sManifests].empty())
1958 jvObj[jss::type] =
"manifestReceived";
1961 jvObj[jss::signing_key] =
1965 jvObj[jss::signature] =
strHex(*sig);
1968 jvObj[jss::domain] = mo.
domain;
1971 for (
auto i = mStreamMaps[sManifests].begin();
1972 i != mStreamMaps[sManifests].end();)
1974 if (
auto p = i->second.lock())
1976 p->send(jvObj,
true);
1981 i = mStreamMaps[sManifests].erase(i);
1987 NetworkOPsImp::ServerFeeSummary::ServerFeeSummary(
1992 , loadBaseServer{loadFeeTrack.getLoadBase()}
1994 , em{std::move(escalationMetrics)}
2004 em.has_value() != b.
em.has_value())
2010 em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
2011 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
2012 em->referenceFeeLevel != b.
em->referenceFeeLevel);
2045 jvObj[jss::type] =
"serverStatus";
2047 jvObj[jss::load_base] = f.loadBaseServer;
2048 jvObj[jss::load_factor_server] = f.loadFactorServer;
2049 jvObj[jss::base_fee] = f.baseFee.jsonClipped();
2054 safe_cast<std::uint64_t>(f.loadFactorServer),
2056 f.em->openLedgerFeeLevel,
2058 f.em->referenceFeeLevel)
2061 jvObj[jss::load_factor] =
trunc32(loadFactor);
2062 jvObj[jss::load_factor_fee_escalation] =
2063 f.em->openLedgerFeeLevel.jsonClipped();
2064 jvObj[jss::load_factor_fee_queue] =
2065 f.em->minProcessingFeeLevel.jsonClipped();
2066 jvObj[jss::load_factor_fee_reference] =
2067 f.em->referenceFeeLevel.jsonClipped();
2070 jvObj[jss::load_factor] = f.loadFactorServer;
2084 p->send(jvObj,
true);
2101 if (!streamMap.empty())
2104 jvObj[jss::type] =
"consensusPhase";
2105 jvObj[jss::consensus] =
to_string(phase);
2107 for (
auto i = streamMap.begin(); i != streamMap.end();)
2109 if (
auto p = i->second.lock())
2111 p->send(jvObj,
true);
2116 i = streamMap.erase(i);
2132 auto const signerPublic = val->getSignerPublic();
2134 jvObj[jss::type] =
"validationReceived";
2135 jvObj[jss::validation_public_key] =
2137 jvObj[jss::ledger_hash] =
to_string(val->getLedgerHash());
2138 jvObj[jss::signature] =
strHex(val->getSignature());
2139 jvObj[jss::full] = val->isFull();
2140 jvObj[jss::flags] = val->getFlags();
2142 jvObj[jss::data] =
strHex(val->getSerializer().slice());
2147 if (
auto cookie = (*val)[~
sfCookie])
2151 jvObj[jss::validated_hash] =
strHex(*hash);
2153 auto const masterKey =
2156 if (masterKey != signerPublic)
2160 jvObj[jss::ledger_index] =
to_string(*seq);
2165 for (
auto const& amendment : val->getFieldV256(
sfAmendments))
2170 jvObj[jss::close_time] = *closeTime;
2172 if (
auto const loadFee = (*val)[~
sfLoadFee])
2173 jvObj[jss::load_fee] = *loadFee;
2175 if (
auto const baseFee = val->at(~
sfBaseFee))
2176 jvObj[jss::base_fee] =
static_cast<double>(*baseFee);
2179 jvObj[jss::reserve_base] = *reserveBase;
2182 jvObj[jss::reserve_inc] = *reserveInc;
2187 baseFeeXRP && baseFeeXRP->native())
2188 jvObj[jss::base_fee] = baseFeeXRP->xrp().jsonClipped();
2191 reserveBaseXRP && reserveBaseXRP->native())
2192 jvObj[jss::reserve_base] = reserveBaseXRP->xrp().jsonClipped();
2195 reserveIncXRP && reserveIncXRP->native())
2196 jvObj[jss::reserve_inc] = reserveIncXRP->xrp().jsonClipped();
2201 if (
auto p = i->second.lock())
2203 p->send(jvObj,
true);
2223 jvObj[jss::type] =
"peerStatusChange";
2232 p->send(jvObj,
true);
2246 using namespace std::chrono_literals;
2278 <<
"recvValidation " << val->getLedgerHash() <<
" from " << source;
2308 "This server is amendment blocked, and must be updated to be "
2309 "able to stay in sync with the network.";
2316 "This server has an expired validator list. validators.txt "
2317 "may be incorrectly configured or some [validator_list_sites] "
2318 "may be unreachable.";
2325 "One or more unsupported amendments have reached majority. "
2326 "Upgrade to the latest version before they are activated "
2327 "to avoid being amendment blocked.";
2328 if (
auto const expected =
2332 d[jss::expected_date] = expected->time_since_epoch().count();
2333 d[jss::expected_date_UTC] =
to_string(*expected);
2337 if (warnings.size())
2338 info[jss::warnings] = std::move(warnings);
2353 info[jss::time] =
to_string(std::chrono::floor<std::chrono::microseconds>(
2357 info[jss::network_ledger] =
"waiting";
2359 info[jss::validation_quorum] =
2367 info[jss::node_size] =
"tiny";
2370 info[jss::node_size] =
"small";
2373 info[jss::node_size] =
"medium";
2376 info[jss::node_size] =
"large";
2379 info[jss::node_size] =
"huge";
2388 info[jss::validator_list_expires] =
2389 safe_cast<Json::UInt>(when->time_since_epoch().count());
2391 info[jss::validator_list_expires] = 0;
2401 if (*when == TimeKeeper::time_point::max())
2403 x[jss::expiration] =
"never";
2404 x[jss::status] =
"active";
2411 x[jss::status] =
"active";
2413 x[jss::status] =
"expired";
2418 x[jss::status] =
"unknown";
2419 x[jss::expiration] =
"unknown";
2423 info[jss::io_latency_ms] =
2430 info[jss::pubkey_validator] =
toBase58(
2435 info[jss::pubkey_validator] =
"none";
2448 info[jss::counters][jss::nodestore] = nodestore;
2452 info[jss::pubkey_node] =
2458 info[jss::amendment_blocked] =
true;
2473 lastClose[jss::converge_time_s] =
2478 lastClose[jss::converge_time] =
2482 info[jss::last_close] = lastClose;
2492 info[jss::network_id] =
static_cast<Json::UInt>(*netid);
2494 auto const escalationMetrics =
2502 auto const loadFactorFeeEscalation =
2504 escalationMetrics.openLedgerFeeLevel,
2506 escalationMetrics.referenceFeeLevel)
2510 safe_cast<std::uint64_t>(loadFactorServer),
2511 loadFactorFeeEscalation);
2515 info[jss::load_base] = loadBaseServer;
2516 info[jss::load_factor] =
trunc32(loadFactor);
2517 info[jss::load_factor_server] = loadFactorServer;
2524 info[jss::load_factor_fee_escalation] =
2525 escalationMetrics.openLedgerFeeLevel.jsonClipped();
2526 info[jss::load_factor_fee_queue] =
2527 escalationMetrics.minProcessingFeeLevel.jsonClipped();
2528 info[jss::load_factor_fee_reference] =
2529 escalationMetrics.referenceFeeLevel.jsonClipped();
2533 info[jss::load_factor] =
2534 static_cast<double>(loadFactor) / loadBaseServer;
2536 if (loadFactorServer != loadFactor)
2537 info[jss::load_factor_server] =
2538 static_cast<double>(loadFactorServer) / loadBaseServer;
2543 if (fee != loadBaseServer)
2544 info[jss::load_factor_local] =
2545 static_cast<double>(fee) / loadBaseServer;
2547 if (fee != loadBaseServer)
2548 info[jss::load_factor_net] =
2549 static_cast<double>(fee) / loadBaseServer;
2551 if (fee != loadBaseServer)
2552 info[jss::load_factor_cluster] =
2553 static_cast<double>(fee) / loadBaseServer;
2555 if (escalationMetrics.openLedgerFeeLevel !=
2556 escalationMetrics.referenceFeeLevel &&
2557 (admin || loadFactorFeeEscalation != loadFactor))
2558 info[jss::load_factor_fee_escalation] =
2559 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
2560 escalationMetrics.referenceFeeLevel);
2561 if (escalationMetrics.minProcessingFeeLevel !=
2562 escalationMetrics.referenceFeeLevel)
2563 info[jss::load_factor_fee_queue] =
2564 escalationMetrics.minProcessingFeeLevel
2565 .decimalFromReference(
2566 escalationMetrics.referenceFeeLevel);
2580 XRPAmount const baseFee = lpClosed->fees().base;
2582 l[jss::seq] =
Json::UInt(lpClosed->info().seq);
2583 l[jss::hash] =
to_string(lpClosed->info().hash);
2588 l[jss::reserve_base] =
2589 lpClosed->fees().accountReserve(0).jsonClipped();
2590 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
2592 lpClosed->info().closeTime.time_since_epoch().count());
2597 l[jss::reserve_base_xrp] =
2598 lpClosed->fees().accountReserve(0).decimalXRP();
2599 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
2602 if (std::abs(nowOffset.count()) >= 60)
2603 l[jss::system_time_offset] = nowOffset.count();
2606 if (std::abs(closeOffset.count()) >= 60)
2607 l[jss::close_time_offset] = closeOffset.count();
2609 #if RIPPLED_REPORTING
2619 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2623 auto lCloseTime = lpClosed->info().closeTime;
2625 if (lCloseTime <= closeTime)
2627 using namespace std::chrono_literals;
2628 auto age = closeTime - lCloseTime;
2630 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2637 info[jss::validated_ledger] = l;
2639 info[jss::closed_ledger] = l;
2643 info[jss::published_ledger] =
"none";
2644 else if (lpPublished->info().seq != lpClosed->info().seq)
2645 info[jss::published_ledger] = lpPublished->info().seq;
2652 info[jss::jq_trans_overflow] =
2654 info[jss::peer_disconnects] =
2656 info[jss::peer_disconnects_resources] =
2697 p->send(jvObj,
true);
2716 if (jvObj[jss::validated].asBool())
2728 p->send(jvObj,
true);
2749 if (
auto p = i->second.lock())
2751 p->send(jvObj,
true);
2769 if (
auto p = i->second.lock())
2771 p->send(jvObj,
true);
2784 for (
auto& jv : jvObj)
2790 else if (jv.isString())
2814 if (jvObj.
isMember(jss::transaction))
2823 << __func__ <<
" : "
2824 <<
"error parsing json for accounts affected";
2833 for (
auto const& affectedAccount : accounts)
2838 auto it = simiIt->second.begin();
2840 while (it != simiIt->second.end())
2851 it = simiIt->second.erase(it);
2858 <<
" iProposed=" << iProposed;
2860 if (!notify.
empty())
2863 isrListener->send(jvObj,
true);
2877 alpAccepted = std::make_shared<AcceptedLedger>(lpAccepted,
app_);
2879 lpAccepted->info().hash, alpAccepted);
2882 assert(alpAccepted->getLedger().
get() == lpAccepted.
get());
2886 <<
"Publishing ledger " << lpAccepted->info().seq <<
" "
2887 << lpAccepted->info().hash;
2895 jvObj[jss::type] =
"ledgerClosed";
2896 jvObj[jss::ledger_index] = lpAccepted->info().seq;
2897 jvObj[jss::ledger_hash] =
to_string(lpAccepted->info().hash);
2899 lpAccepted->info().closeTime.time_since_epoch().count());
2903 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
2904 jvObj[jss::reserve_base] =
2905 lpAccepted->fees().accountReserve(0).jsonClipped();
2906 jvObj[jss::reserve_inc] =
2907 lpAccepted->fees().increment.jsonClipped();
2909 jvObj[jss::txn_count] =
Json::UInt(alpAccepted->size());
2913 jvObj[jss::validated_ledgers] =
2923 p->send(jvObj,
true);
2941 p->send(jvObj,
true);
2950 static bool firstTime =
true;
2957 for (
auto& inner : outer.second)
2959 auto& subInfo = inner.second;
2960 if (subInfo.index_->separationLedgerSeq_ == 0)
2963 alpAccepted->getLedger(), subInfo);
2972 for (
auto const& accTx : *alpAccepted)
3004 "reportConsensusStateChange->pubConsensus",
3023 const STTx& transaction,
3034 jvObj[jss::type] =
"transaction";
3039 jvObj[jss::ledger_index] = ledger->info().seq;
3040 jvObj[jss::ledger_hash] =
to_string(ledger->info().hash);
3041 jvObj[jss::transaction][jss::date] =
3042 ledger->info().closeTime.time_since_epoch().count();
3043 jvObj[jss::validated] =
true;
3049 jvObj[jss::validated] =
false;
3050 jvObj[jss::ledger_current_index] = ledger->info().seq;
3053 jvObj[jss::status] = validated ?
"closed" :
"proposed";
3054 jvObj[jss::engine_result] = sToken;
3055 jvObj[jss::engine_result_code] = result;
3056 jvObj[jss::engine_result_message] = sHuman;
3064 if (account != amount.issue().account)
3072 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3084 auto const& stTxn = transaction.
getTxn();
3090 auto const& meta = transaction.
getMeta();
3105 p->send(jvObj,
true);
3120 p->send(jvObj,
true);
3144 auto const currLedgerSeq = ledger->seq();
3151 for (
auto const& affectedAccount : transaction.
getAffected())
3156 auto it = simiIt->second.begin();
3158 while (it != simiIt->second.end())
3169 it = simiIt->second.erase(it);
3176 auto it = simiIt->second.begin();
3177 while (it != simiIt->second.end())
3188 it = simiIt->second.erase(it);
3195 auto& subs = histoIt->second;
3196 auto it = subs.begin();
3197 while (it != subs.end())
3200 if (currLedgerSeq <= info.index_->separationLedgerSeq_)
3214 it = subs.erase(it);
3225 <<
"pubAccountTransaction: "
3226 <<
"proposed=" << iProposed <<
", accepted=" << iAccepted;
3228 if (!notify.
empty() || !accountHistoryNotify.
empty())
3230 auto const& stTxn = transaction.
getTxn();
3236 auto const& meta = transaction.
getMeta();
3243 isrListener->send(jvObj,
true);
3245 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3246 for (
auto& info : accountHistoryNotify)
3248 auto& index = info.index_;
3249 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3250 jvObj[jss::account_history_tx_first] =
true;
3251 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3252 info.sink_->send(jvObj,
true);
3277 for (
auto const& affectedAccount : tx->getMentionedAccounts())
3282 auto it = simiIt->second.begin();
3284 while (it != simiIt->second.end())
3295 it = simiIt->second.erase(it);
3302 JLOG(
m_journal.
trace()) <<
"pubProposedAccountTransaction: " << iProposed;
3304 if (!notify.
empty() || !accountHistoryNotify.
empty())
3309 isrListener->send(jvObj,
true);
3311 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3312 for (
auto& info : accountHistoryNotify)
3314 auto& index = info.index_;
3315 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3316 jvObj[jss::account_history_tx_first] =
true;
3317 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3318 info.sink_->send(jvObj,
true);
3335 for (
auto const& naAccountID : vnaAccountIDs)
3338 <<
"subAccount: account: " <<
toBase58(naAccountID);
3340 isrListener->insertSubAccountInfo(naAccountID, rt);
3345 for (
auto const& naAccountID : vnaAccountIDs)
3347 auto simIterator = subMap.
find(naAccountID);
3348 if (simIterator == subMap.
end())
3352 usisElement[isrListener->getSeq()] = isrListener;
3354 subMap.
insert(simIterator, make_pair(naAccountID, usisElement));
3359 simIterator->second[isrListener->getSeq()] = isrListener;
3370 for (
auto const& naAccountID : vnaAccountIDs)
3373 isrListener->deleteSubAccountInfo(naAccountID, rt);
3390 for (
auto const& naAccountID : vnaAccountIDs)
3392 auto simIterator = subMap.
find(naAccountID);
3394 if (simIterator != subMap.
end())
3397 simIterator->second.erase(uSeq);
3399 if (simIterator->second.empty())
3402 subMap.
erase(simIterator);
3411 enum DatabaseType { Postgres, Sqlite, None };
3412 static const auto databaseType = [&]() -> DatabaseType {
3413 #ifdef RIPPLED_REPORTING
3420 return DatabaseType::Postgres;
3422 return DatabaseType::None;
3430 return DatabaseType::Sqlite;
3432 return DatabaseType::None;
3439 return DatabaseType::Sqlite;
3441 return DatabaseType::None;
3445 if (databaseType == DatabaseType::None)
3448 <<
"AccountHistory job for account "
3460 "AccountHistoryTxStream",
3461 [
this, dbType = databaseType, subInfo]() {
3462 auto const& accountId = subInfo.
index_->accountId_;
3463 auto& lastLedgerSeq = subInfo.
index_->historyLastLedgerSeq_;
3464 auto& txHistoryIndex = subInfo.
index_->historyTxIndex_;
3467 <<
"AccountHistory job for account " <<
toBase58(accountId)
3468 <<
" started. lastLedgerSeq=" << lastLedgerSeq;
3478 auto stx = tx->getSTransaction();
3479 if (stx->getAccountID(
sfAccount) == accountId &&
3480 stx->getSeqProxy().value() == 1)
3484 for (
auto& node : meta->getNodes())
3491 if (
auto inner =
dynamic_cast<const STObject*
>(
3496 inner->getAccountID(
sfAccount) == accountId)
3508 bool unsubscribe) ->
bool {
3511 sptr->send(jvObj,
true);
3537 auto [txResult, status] = db->getAccountTx(args);
3541 <<
"AccountHistory job for account "
3543 <<
" getAccountTx failed";
3548 std::get_if<RelationalDatabase::AccountTxs>(
3549 &txResult.transactions);
3557 <<
"AccountHistory job for account "
3559 <<
" getAccountTx wrong data";
3567 accountId, minLedger, maxLedger, marker, 0,
true};
3568 return db->newestAccountTxPage(options);
3580 while (lastLedgerSeq >= 2 && !subInfo.
index_->stopHistorical_)
3582 int feeChargeCount = 0;
3591 <<
"AccountHistory job for account "
3592 <<
toBase58(accountId) <<
" no InfoSub. Fee charged "
3593 << feeChargeCount <<
" times.";
3598 auto startLedgerSeq =
3599 (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
3601 <<
"AccountHistory job for account " <<
toBase58(accountId)
3602 <<
", working on ledger range [" << startLedgerSeq <<
","
3603 << lastLedgerSeq <<
"]";
3605 auto haveRange = [&]() ->
bool {
3608 auto haveSomeValidatedLedgers =
3610 validatedMin, validatedMax);
3612 return haveSomeValidatedLedgers &&
3613 validatedMin <= startLedgerSeq &&
3614 lastLedgerSeq <= validatedMax;
3620 <<
"AccountHistory reschedule job for account "
3621 <<
toBase58(accountId) <<
", incomplete ledger range ["
3622 << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
3628 while (!subInfo.
index_->stopHistorical_)
3631 getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
3635 <<
"AccountHistory job for account "
3636 <<
toBase58(accountId) <<
" getMoreTxns failed.";
3641 auto const& txns = dbResult->first;
3642 marker = dbResult->second;
3643 for (
auto const& [tx, meta] : txns)
3648 <<
"AccountHistory job for account "
3649 <<
toBase58(accountId) <<
" empty tx or meta.";
3659 <<
"AccountHistory job for account "
3660 <<
toBase58(accountId) <<
" no ledger.";
3665 tx->getSTransaction();
3669 <<
"AccountHistory job for account "
3671 <<
" getSTransaction failed.";
3676 *stTxn, meta->getResultTER(),
true, curTxLedger);
3678 jvTx[jss::account_history_tx_index] = txHistoryIndex--;
3680 jvTx[jss::meta], *curTxLedger, stTxn, *meta);
3681 if (isFirstTx(tx, meta))
3683 jvTx[jss::account_history_tx_first] =
true;
3687 <<
"AccountHistory job for account "
3689 <<
" done, found last tx.";
3701 <<
"AccountHistory job for account "
3703 <<
" paging, marker=" << marker->ledgerSeq <<
":"
3712 if (!subInfo.
index_->stopHistorical_)
3714 lastLedgerSeq = startLedgerSeq - 1;
3715 if (lastLedgerSeq <= 1)
3718 <<
"AccountHistory job for account "
3720 <<
" done, reached genesis ledger.";
3733 subInfo.
index_->separationLedgerSeq_ = ledger->seq();
3734 auto const& accountId = subInfo.
index_->accountId_;
3736 if (!ledger->exists(accountKeylet))
3739 <<
"subAccountHistoryStart, no account " <<
toBase58(accountId)
3740 <<
", no need to add AccountHistory job.";
3745 if (
auto const sleAcct = ledger->read(accountKeylet); sleAcct)
3750 <<
"subAccountHistoryStart, genesis account "
3752 <<
" does not have tx, no need to add AccountHistory job.";
3762 subInfo.
index_->historyLastLedgerSeq_ = ledger->seq();
3763 subInfo.
index_->haveHistorical_ =
true;
3766 <<
"subAccountHistoryStart, add AccountHistory job: accountId="
3767 <<
toBase58(accountId) <<
", currentLedgerSeq=" << ledger->seq();
3777 if (!isrListener->insertSubAccountHistory(accountId))
3780 <<
"subAccountHistory, already subscribed to account "
3787 isrListener, std::make_shared<SubAccountHistoryIndex>(accountId)};
3792 inner.
emplace(isrListener->getSeq(), ahi);
3798 simIterator->second.emplace(isrListener->getSeq(), ahi);
3812 <<
"subAccountHistory, no validated ledger yet, delay start";
3825 isrListener->deleteSubAccountHistory(account);
3839 auto& subInfoMap = simIterator->second;
3840 auto subInfoIter = subInfoMap.find(seq);
3841 if (subInfoIter != subInfoMap.end())
3843 subInfoIter->second.index_->stopHistorical_ =
true;
3848 simIterator->second.erase(seq);
3849 if (simIterator->second.empty())
3855 <<
"unsubAccountHistory, account " <<
toBase58(account)
3856 <<
", historyOnly = " << (historyOnly ?
"true" :
"false");
3864 listeners->addSubscriber(isrListener);
3874 listeners->removeSubscriber(uSeq);
3888 Throw<std::runtime_error>(
3889 "Operation only possible in STANDALONE mode.");
3904 jvResult[jss::ledger_index] = lpClosed->info().seq;
3905 jvResult[jss::ledger_hash] =
to_string(lpClosed->info().hash);
3907 lpClosed->info().closeTime.time_since_epoch().count());
3910 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
3911 jvResult[jss::reserve_base] =
3912 lpClosed->fees().accountReserve(0).jsonClipped();
3913 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3918 jvResult[jss::validated_ledgers] =
3924 .emplace(isrListener->getSeq(), isrListener)
3934 .emplace(isrListener->getSeq(), isrListener)
3960 .emplace(isrListener->getSeq(), isrListener)
3988 jvResult[jss::random] =
to_string(uRandom);
3990 jvResult[jss::load_base] = feeTrack.getLoadBase();
3991 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
3992 jvResult[jss::hostid] =
getHostId(admin);
3993 jvResult[jss::pubkey_node] =
3998 .emplace(isrListener->getSeq(), isrListener)
4016 .emplace(isrListener->getSeq(), isrListener)
4034 .emplace(isrListener->getSeq(), isrListener)
4052 .emplace(isrListener->getSeq(), isrListener)
4076 .emplace(isrListener->getSeq(), isrListener)
4094 .emplace(isrListener->getSeq(), isrListener)
4142 if (map.find(pInfo->getSeq()) != map.end())
4149 #ifndef USE_NEW_BOOK_PAGE
4160 unsigned int iLimit,
4170 uint256 uTipIndex = uBookBase;
4174 stream <<
"getBookPage:" << book;
4175 stream <<
"getBookPage: uBookBase=" << uBookBase;
4176 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
4177 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
4186 bool bDirectAdvance =
true;
4190 unsigned int uBookEntry;
4196 while (!bDone && iLimit-- > 0)
4200 bDirectAdvance =
false;
4204 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
4208 sleOfferDir.
reset();
4217 uTipIndex = sleOfferDir->key();
4220 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
4223 <<
"getBookPage: uTipIndex=" << uTipIndex;
4225 <<
"getBookPage: offerIndex=" << offerIndex;
4235 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4236 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4237 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4239 bool firstOwnerOffer(
true);
4245 saOwnerFunds = saTakerGets;
4247 else if (bGlobalFreeze)
4255 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4256 if (umBalanceEntry != umBalance.
end())
4260 saOwnerFunds = umBalanceEntry->second;
4261 firstOwnerOffer =
false;
4275 if (saOwnerFunds < beast::zero)
4279 saOwnerFunds.
clear();
4287 STAmount saOwnerFundsLimit = saOwnerFunds;
4299 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4302 if (saOwnerFundsLimit >= saTakerGets)
4305 saTakerGetsFunded = saTakerGets;
4311 saTakerGetsFunded = saOwnerFundsLimit;
4313 saTakerGetsFunded.
setJson(jvOffer[jss::taker_gets_funded]);
4317 saTakerGetsFunded, saDirRate, saTakerPays.
issue()))
4318 .setJson(jvOffer[jss::taker_pays_funded]);
4324 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4326 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4330 jvOf[jss::quality] = saDirRate.
getText();
4332 if (firstOwnerOffer)
4333 jvOf[jss::owner_funds] = saOwnerFunds.
getText();
4340 if (!
cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
4342 bDirectAdvance =
true;
4347 <<
"getBookPage: offerIndex=" << offerIndex;
4367 unsigned int iLimit,
4375 MetaView lesActive(lpLedger,
tapNONE,
true);
4376 OrderBookIterator obIterator(lesActive, book);
4380 const bool bGlobalFreeze = lesActive.isGlobalFrozen(book.
out.
account) ||
4381 lesActive.isGlobalFrozen(book.
in.
account);
4383 while (iLimit-- > 0 && obIterator.nextOffer())
4388 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4389 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4390 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4391 STAmount saDirRate = obIterator.getCurrentRate();
4397 saOwnerFunds = saTakerGets;
4399 else if (bGlobalFreeze)
4407 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4409 if (umBalanceEntry != umBalance.
end())
4413 saOwnerFunds = umBalanceEntry->second;
4419 saOwnerFunds = lesActive.accountHolds(
4425 if (saOwnerFunds.isNegative())
4429 saOwnerFunds.zero();
4436 STAmount saTakerGetsFunded;
4437 STAmount saOwnerFundsLimit = saOwnerFunds;
4449 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4452 if (saOwnerFundsLimit >= saTakerGets)
4455 saTakerGetsFunded = saTakerGets;
4460 saTakerGetsFunded = saOwnerFundsLimit;
4462 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
4468 multiply(saTakerGetsFunded, saDirRate, saTakerPays.issue()))
4469 .setJson(jvOffer[jss::taker_pays_funded]);
4472 STAmount saOwnerPays = (
parityRate == offerRate)
4475 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4477 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4479 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
4483 jvOf[jss::quality] = saDirRate.
getText();
4498 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4538 ++counters_[
static_cast<std::size_t>(om)].transitions;
4540 counters_[
static_cast<std::size_t>(om)].transitions == 1)
4542 initialSyncUs_ = std::chrono::duration_cast<std::chrono::microseconds>(
4543 now - processStart_)
4547 std::chrono::duration_cast<std::chrono::microseconds>(now - start_);
4556 auto [counters, mode, start, initialSync] = getCounterData();
4557 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4567 auto& state = obj[jss::state_accounting][
states_[i]];
4568 state[jss::transitions] =
std::to_string(counters[i].transitions);
4569 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
4573 obj[jss::initial_sync_duration_us] =
std::to_string(initialSync);
4588 boost::asio::io_service& io_svc,
4592 return std::make_unique<NetworkOPsImp>(