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/DeliveredAmount.h>
66 #include <ripple/rpc/impl/RPCHelpers.h>
67 #include <boost/asio/ip/host_name.hpp>
68 #include <boost/asio/steady_timer.hpp>
143 std::chrono::steady_clock::time_point
start_ =
204 return !(*
this != b);
223 boost::asio::io_service& io_svc,
237 app_.logs().journal(
"FeeVote")),
240 app.getInboundTransactions(),
241 beast::get_abstract_clock<
std::chrono::steady_clock>(),
243 app_.logs().journal(
"LedgerConsensus"))
422 getServerInfo(
bool human,
bool admin,
bool counters)
override;
449 TER result)
override;
492 bool historyOnly)
override;
498 bool historyOnly)
override;
561 boost::system::error_code ec;
566 <<
"NetworkOPs: heartbeatTimer cancel error: "
575 <<
"NetworkOPs: clusterTimer cancel error: "
584 <<
"NetworkOPs: accountHistoryTxTimer cancel error: "
589 using namespace std::chrono_literals;
599 boost::asio::steady_timer& timer,
614 const STTx& transaction,
773 template <
class Handler>
775 Handler
const& handler,
777 :
hook(collector->make_hook(handler))
780 "Disconnected_duration"))
783 "Connected_duration"))
785 collector->make_gauge(
"State_Accounting",
"Syncing_duration"))
788 "Tracking_duration"))
790 collector->make_gauge(
"State_Accounting",
"Full_duration"))
793 "Disconnected_transitions"))
796 "Connected_transitions"))
799 "Syncing_transitions"))
802 "Tracking_transitions"))
804 collector->make_gauge(
"State_Accounting",
"Full_transitions"))
833 {
"disconnected",
"connected",
"syncing",
"tracking",
"full"}};
895 static std::string const hostname = boost::asio::ip::host_name();
902 static std::string const shroudedHostId = [
this]() {
908 return shroudedHostId;
920 boost::asio::steady_timer& timer,
927 [
this, onExpire, onError](boost::system::error_code
const& e) {
928 if ((e.value() == boost::system::errc::success) &&
929 (!m_job_queue.isStopped()))
934 if (e.value() != boost::system::errc::success &&
935 e.value() != boost::asio::error::operation_aborted)
938 JLOG(m_journal.error())
939 <<
"Timer got error '" << e.message()
940 <<
"'. Restarting timer.";
945 timer.expires_from_now(expiry_time);
946 timer.async_wait(std::move(*optionalCountedHandler));
957 m_job_queue.addJob(jtNETOP_TIMER,
"NetOPs.heartbeat", [this]() {
958 processHeartbeatTimer();
961 [
this]() { setHeartbeatTimer(); });
965 NetworkOPsImp::setClusterTimer()
967 using namespace std::chrono_literals;
973 processClusterTimer();
976 [
this]() { setClusterTimer(); });
982 JLOG(m_journal.debug()) <<
"Scheduling AccountHistory job for account "
984 using namespace std::chrono_literals;
986 accountHistoryTxTimer_,
988 [
this, subInfo]() { addAccountHistoryJob(subInfo); },
989 [
this, subInfo]() { setAccountHistoryJobTimer(subInfo); });
993 NetworkOPsImp::processHeartbeatTimer()
1002 std::size_t const numPeers = app_.overlay().size();
1005 if (numPeers < minPeerCount_)
1007 if (mMode != OperatingMode::DISCONNECTED)
1009 setMode(OperatingMode::DISCONNECTED);
1010 JLOG(m_journal.warn())
1011 <<
"Node count (" << numPeers <<
") has fallen "
1012 <<
"below required minimum (" << minPeerCount_ <<
").";
1019 setHeartbeatTimer();
1023 if (mMode == OperatingMode::DISCONNECTED)
1025 setMode(OperatingMode::CONNECTED);
1026 JLOG(m_journal.info())
1027 <<
"Node count (" << numPeers <<
") is sufficient.";
1032 if (mMode == OperatingMode::SYNCING)
1033 setMode(OperatingMode::SYNCING);
1034 else if (mMode == OperatingMode::CONNECTED)
1035 setMode(OperatingMode::CONNECTED);
1038 mConsensus.timerEntry(app_.timeKeeper().closeTime());
1041 if (mLastConsensusPhase != currPhase)
1043 reportConsensusStateChange(currPhase);
1044 mLastConsensusPhase = currPhase;
1047 setHeartbeatTimer();
1051 NetworkOPsImp::processClusterTimer()
1053 using namespace std::chrono_literals;
1054 bool const update = app_.cluster().update(
1055 app_.nodeIdentity().first,
1057 (m_ledgerMaster.getValidatedLedgerAge() <= 4
min)
1058 ? app_.getFeeTrack().getLocalFee()
1060 app_.timeKeeper().now());
1064 JLOG(m_journal.debug()) <<
"Too soon to send cluster update";
1069 protocol::TMCluster cluster;
1070 app_.cluster().for_each([&cluster](
ClusterNode const& node) {
1071 protocol::TMClusterNode& n = *cluster.add_clusternodes();
1076 n.set_nodename(node.
name());
1080 for (
auto& item : gossip.
items)
1082 protocol::TMLoadSource& node = *cluster.add_loadsources();
1084 node.set_cost(item.balance);
1086 app_.overlay().foreach(
send_if(
1087 std::make_shared<Message>(cluster, protocol::mtCLUSTER),
1098 if (mode == OperatingMode::FULL && admin)
1100 auto const consensusMode = mConsensus.mode();
1101 if (consensusMode != ConsensusMode::wrongLedger)
1103 if (consensusMode == ConsensusMode::proposing)
1106 if (mConsensus.validating())
1107 return "validating";
1117 if (isNeedNetworkLedger())
1126 auto const txid = trans->getTransactionID();
1127 auto const flags = app_.getHashRouter().getFlags(txid);
1129 if ((flags & SF_BAD) != 0)
1131 JLOG(m_journal.warn()) <<
"Submitted transaction cached bad";
1138 app_.getHashRouter(),
1140 m_ledgerMaster.getValidatedRules(),
1143 if (validity != Validity::Valid)
1145 JLOG(m_journal.warn())
1146 <<
"Submitted transaction invalid: " << reason;
1152 JLOG(m_journal.warn()) <<
"Exception checking transaction" << txid;
1159 auto tx = std::make_shared<Transaction>(trans, reason, app_);
1161 m_job_queue.addJob(
jtTRANSACTION,
"submitTxn", [
this, tx]() {
1163 processTransaction(t,
false,
false, FailHard::no);
1168 NetworkOPsImp::processTransaction(
1174 auto ev = m_job_queue.makeLoadEvent(
jtTXN_PROC,
"ProcessTXN");
1175 auto const newFlags = app_.getHashRouter().getFlags(transaction->getID());
1177 if ((newFlags & SF_BAD) != 0)
1180 JLOG(m_journal.warn()) << transaction->getID() <<
": cached bad!\n";
1181 transaction->setStatus(
INVALID);
1189 auto const view = m_ledgerMaster.getCurrentLedger();
1191 app_.getHashRouter(),
1192 *transaction->getSTransaction(),
1195 assert(validity == Validity::Valid);
1198 if (validity == Validity::SigBad)
1200 JLOG(m_journal.info()) <<
"Transaction has bad signature: " << reason;
1201 transaction->setStatus(
INVALID);
1203 app_.getHashRouter().setFlags(transaction->getID(), SF_BAD);
1208 app_.getMasterTransaction().canonicalize(&transaction);
1211 doTransactionSync(transaction, bUnlimited, failType);
1213 doTransactionAsync(transaction, bUnlimited, failType);
1217 NetworkOPsImp::doTransactionAsync(
1224 if (transaction->getApplying())
1227 mTransactions.push_back(
1229 transaction->setApplying();
1231 if (mDispatchState == DispatchState::none)
1233 if (m_job_queue.addJob(
1234 jtBATCH,
"transactionBatch", [
this]() { transactionBatch(); }))
1236 mDispatchState = DispatchState::scheduled;
1242 NetworkOPsImp::doTransactionSync(
1249 if (!transaction->getApplying())
1251 mTransactions.push_back(
1253 transaction->setApplying();
1258 if (mDispatchState == DispatchState::running)
1267 if (mTransactions.size())
1270 if (m_job_queue.addJob(
jtBATCH,
"transactionBatch", [
this]() {
1274 mDispatchState = DispatchState::scheduled;
1278 }
while (transaction->getApplying());
1282 NetworkOPsImp::transactionBatch()
1286 if (mDispatchState == DispatchState::running)
1289 while (mTransactions.size())
1300 mTransactions.
swap(transactions);
1301 assert(!transactions.
empty());
1303 assert(mDispatchState != DispatchState::running);
1304 mDispatchState = DispatchState::running;
1310 bool changed =
false;
1313 m_ledgerMaster.peekMutex(), std::defer_lock};
1324 if (e.failType == FailHard::yes)
1327 auto const result = app_.getTxQ().apply(
1328 app_, view, e.transaction->getSTransaction(), flags, j);
1329 e.result = result.first;
1330 e.applied = result.second;
1331 changed = changed || result.second;
1340 if (
auto const l = m_ledgerMaster.getValidatedLedger())
1341 validatedLedgerIndex = l->info().seq;
1343 auto newOL = app_.openLedger().current();
1346 e.transaction->clearSubmitResult();
1350 pubProposedTransaction(
1351 newOL, e.transaction->getSTransaction(), e.result);
1352 e.transaction->setApplied();
1355 e.transaction->setResult(e.result);
1358 app_.getHashRouter().setFlags(e.transaction->getID(), SF_BAD);
1367 JLOG(m_journal.info())
1368 <<
"TransactionResult: " << token <<
": " << human;
1373 bool addLocal = e.local;
1377 JLOG(m_journal.debug())
1378 <<
"Transaction is now included in open ledger";
1379 e.transaction->setStatus(
INCLUDED);
1381 auto const& txCur = e.transaction->getSTransaction();
1382 auto const txNext = m_ledgerMaster.popAcctTransaction(txCur);
1387 auto t = std::make_shared<Transaction>(trans, reason, app_);
1388 submit_held.
emplace_back(t,
false,
false, FailHard::no);
1395 JLOG(m_journal.info()) <<
"Transaction is obsolete";
1396 e.transaction->setStatus(
OBSOLETE);
1400 JLOG(m_journal.debug())
1401 <<
"Transaction is likely to claim a"
1402 <<
" fee, but is queued until fee drops";
1404 e.transaction->setStatus(
HELD);
1408 m_ledgerMaster.addHeldTransaction(e.transaction);
1409 e.transaction->setQueued();
1410 e.transaction->setKept();
1414 if (e.failType != FailHard::yes)
1417 JLOG(m_journal.debug())
1418 <<
"Transaction should be held: " << e.result;
1419 e.transaction->setStatus(
HELD);
1420 m_ledgerMaster.addHeldTransaction(e.transaction);
1421 e.transaction->setKept();
1426 JLOG(m_journal.debug())
1427 <<
"Status other than success " << e.result;
1428 e.transaction->setStatus(
INVALID);
1431 auto const enforceFailHard =
1432 e.failType == FailHard::yes && !
isTesSuccess(e.result);
1434 if (addLocal && !enforceFailHard)
1436 m_localTX->push_back(
1437 m_ledgerMaster.getCurrentLedgerIndex(),
1438 e.transaction->getSTransaction());
1439 e.transaction->setKept();
1443 ((mMode != OperatingMode::FULL) &&
1444 (e.failType != FailHard::yes) && e.local) ||
1449 app_.getHashRouter().shouldRelay(e.transaction->getID());
1453 protocol::TMTransaction tx;
1456 e.transaction->getSTransaction()->add(s);
1457 tx.set_rawtransaction(s.
data(), s.
size());
1458 tx.set_status(protocol::tsCURRENT);
1459 tx.set_receivetimestamp(
1460 app_.timeKeeper().now().time_since_epoch().count());
1463 app_.overlay().relay(e.transaction->getID(), tx, *toSkip);
1464 e.transaction->setBroadcast();
1468 if (validatedLedgerIndex)
1470 auto [fee, accountSeq, availableSeq] =
1471 app_.getTxQ().getTxRequiredFeeAndSeq(
1472 *newOL, e.transaction->getSTransaction());
1473 e.transaction->setCurrentLedgerState(
1474 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1482 e.transaction->clearApplying();
1484 if (!submit_held.
empty())
1486 if (mTransactions.empty())
1487 mTransactions.swap(submit_held);
1489 for (
auto& e : submit_held)
1490 mTransactions.push_back(std::move(e));
1495 mDispatchState = DispatchState::none;
1503 NetworkOPsImp::getOwnerInfo(
1508 auto root = keylet::ownerDir(account);
1509 auto sleNode = lpLedger->read(keylet::page(root));
1516 for (
auto const& uDirEntry : sleNode->getFieldV256(
sfIndexes))
1518 auto sleCur = lpLedger->read(keylet::child(uDirEntry));
1521 switch (sleCur->getType())
1524 if (!jvObjects.
isMember(jss::offers))
1525 jvObjects[jss::offers] =
1528 jvObjects[jss::offers].
append(
1529 sleCur->getJson(JsonOptions::none));
1533 if (!jvObjects.
isMember(jss::ripple_lines))
1535 jvObjects[jss::ripple_lines] =
1539 jvObjects[jss::ripple_lines].
append(
1540 sleCur->getJson(JsonOptions::none));
1555 sleNode = lpLedger->read(keylet::page(root, uNodeDir));
1569 NetworkOPsImp::isBlocked()
1571 return isAmendmentBlocked() || isUNLBlocked();
1575 NetworkOPsImp::isAmendmentBlocked()
1577 return amendmentBlocked_;
1581 NetworkOPsImp::setAmendmentBlocked()
1583 amendmentBlocked_ =
true;
1584 setMode(OperatingMode::CONNECTED);
1588 NetworkOPsImp::isAmendmentWarned()
1590 return !amendmentBlocked_ && amendmentWarned_;
1594 NetworkOPsImp::setAmendmentWarned()
1596 amendmentWarned_ =
true;
1600 NetworkOPsImp::clearAmendmentWarned()
1602 amendmentWarned_ =
false;
1606 NetworkOPsImp::isUNLBlocked()
1612 NetworkOPsImp::setUNLBlocked()
1615 setMode(OperatingMode::CONNECTED);
1619 NetworkOPsImp::clearUNLBlocked()
1621 unlBlocked_ =
false;
1625 NetworkOPsImp::checkLastClosedLedger(
1634 JLOG(m_journal.trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
1636 auto const ourClosed = m_ledgerMaster.getClosedLedger();
1641 uint256 closedLedger = ourClosed->info().hash;
1642 uint256 prevClosedLedger = ourClosed->info().parentHash;
1643 JLOG(m_journal.trace()) <<
"OurClosed: " << closedLedger;
1644 JLOG(m_journal.trace()) <<
"PrevClosed: " << prevClosedLedger;
1649 auto& validations = app_.getValidations();
1650 JLOG(m_journal.debug())
1651 <<
"ValidationTrie " <<
Json::Compact(validations.getJsonTrie());
1655 peerCounts[closedLedger] = 0;
1656 if (mMode >= OperatingMode::TRACKING)
1657 peerCounts[closedLedger]++;
1659 for (
auto& peer : peerList)
1661 uint256 peerLedger = peer->getClosedLedgerHash();
1664 ++peerCounts[peerLedger];
1667 for (
auto const& it : peerCounts)
1668 JLOG(m_journal.debug()) <<
"L: " << it.first <<
" n=" << it.second;
1670 uint256 preferredLCL = validations.getPreferredLCL(
1672 m_ledgerMaster.getValidLedgerIndex(),
1675 bool switchLedgers = preferredLCL != closedLedger;
1677 closedLedger = preferredLCL;
1679 if (switchLedgers && (closedLedger == prevClosedLedger))
1682 JLOG(m_journal.info()) <<
"We won't switch to our own previous ledger";
1683 networkClosed = ourClosed->info().hash;
1684 switchLedgers =
false;
1687 networkClosed = closedLedger;
1692 auto consensus = m_ledgerMaster.getLedgerByHash(closedLedger);
1695 consensus = app_.getInboundLedgers().acquire(
1696 closedLedger, 0, InboundLedger::Reason::CONSENSUS);
1699 (!m_ledgerMaster.canBeCurrent(consensus) ||
1700 !m_ledgerMaster.isCompatible(
1701 *consensus, m_journal.debug(),
"Not switching")))
1705 networkClosed = ourClosed->info().hash;
1709 JLOG(m_journal.warn()) <<
"We are not running on the consensus ledger";
1710 JLOG(m_journal.info()) <<
"Our LCL: " <<
getJson({*ourClosed, {}});
1711 JLOG(m_journal.info()) <<
"Net LCL " << closedLedger;
1713 if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
1715 setMode(OperatingMode::CONNECTED);
1723 switchLastClosedLedger(consensus);
1730 NetworkOPsImp::switchLastClosedLedger(
1734 JLOG(m_journal.error())
1735 <<
"JUMP last closed ledger to " << newLCL->info().hash;
1737 clearNeedNetworkLedger();
1740 app_.getTxQ().processClosedLedger(app_, *newLCL,
true);
1747 auto retries = m_localTX->getTxSet();
1748 auto const lastVal = app_.getLedgerMaster().getValidatedLedger();
1753 rules.
emplace(app_.config().features);
1754 app_.openLedger().accept(
1765 return app_.getTxQ().accept(app_, view);
1769 m_ledgerMaster.switchLCL(newLCL);
1771 protocol::TMStatusChange s;
1772 s.set_newevent(protocol::neSWITCHED_LEDGER);
1773 s.set_ledgerseq(newLCL->info().seq);
1774 s.set_networktime(app_.timeKeeper().now().time_since_epoch().count());
1775 s.set_ledgerhashprevious(
1776 newLCL->info().parentHash.begin(), newLCL->info().parentHash.size());
1777 s.set_ledgerhash(newLCL->info().hash.begin(), newLCL->info().hash.size());
1779 app_.overlay().foreach(
1780 send_always(std::make_shared<Message>(s, protocol::mtSTATUS_CHANGE)));
1784 NetworkOPsImp::beginConsensus(
uint256 const& networkClosed)
1788 auto closingInfo = m_ledgerMaster.getCurrentLedger()->info();
1790 JLOG(m_journal.info()) <<
"Consensus time for #" << closingInfo.seq
1791 <<
" with LCL " << closingInfo.parentHash;
1793 auto prevLedger = m_ledgerMaster.getLedgerByHash(closingInfo.parentHash);
1798 if (mMode == OperatingMode::FULL)
1800 JLOG(m_journal.warn()) <<
"Don't have LCL, going to tracking";
1801 setMode(OperatingMode::TRACKING);
1807 assert(prevLedger->info().hash == closingInfo.parentHash);
1809 closingInfo.parentHash ==
1810 m_ledgerMaster.getClosedLedger()->info().hash);
1813 app_.validators().setNegativeUNL(prevLedger->negativeUNL());
1814 TrustChanges const changes = app_.validators().updateTrusted(
1815 app_.getValidations().getCurrentNodeIDs(),
1816 closingInfo.parentCloseTime,
1819 app_.getHashRouter());
1821 if (!changes.
added.empty() || !changes.
removed.empty())
1822 app_.getValidations().trustChanged(changes.
added, changes.
removed);
1824 mConsensus.startRound(
1825 app_.timeKeeper().closeTime(),
1832 if (mLastConsensusPhase != currPhase)
1834 reportConsensusStateChange(currPhase);
1835 mLastConsensusPhase = currPhase;
1838 JLOG(m_journal.debug()) <<
"Initiating consensus engine";
1845 return mConsensus.peerProposal(app_.timeKeeper().closeTime(), peerPos);
1856 protocol::TMHaveTransactionSet msg;
1857 msg.set_hash(map->getHash().as_uint256().begin(), 256 / 8);
1858 msg.set_status(protocol::tsHAVE);
1859 app_.overlay().foreach(
1860 send_always(std::make_shared<Message>(msg, protocol::mtHAVE_SET)));
1864 mConsensus.gotTxSet(app_.timeKeeper().closeTime(),
RCLTxSet{map});
1868 NetworkOPsImp::endConsensus()
1870 uint256 deadLedger = m_ledgerMaster.getClosedLedger()->info().parentHash;
1872 for (
auto const& it : app_.overlay().getActivePeers())
1874 if (it && (it->getClosedLedgerHash() == deadLedger))
1876 JLOG(m_journal.trace()) <<
"Killing obsolete peer status";
1883 checkLastClosedLedger(app_.overlay().getActivePeers(), networkClosed);
1885 if (networkClosed.
isZero())
1894 if (((mMode == OperatingMode::CONNECTED) ||
1895 (mMode == OperatingMode::SYNCING)) &&
1901 if (!needNetworkLedger_)
1902 setMode(OperatingMode::TRACKING);
1905 if (((mMode == OperatingMode::CONNECTED) ||
1906 (mMode == OperatingMode::TRACKING)) &&
1912 auto current = m_ledgerMaster.getCurrentLedger();
1913 if (app_.timeKeeper().now() < (
current->info().parentCloseTime +
1914 2 *
current->info().closeTimeResolution))
1916 setMode(OperatingMode::FULL);
1920 beginConsensus(networkClosed);
1924 NetworkOPsImp::consensusViewChange()
1926 if ((mMode == OperatingMode::FULL) || (mMode == OperatingMode::TRACKING))
1928 setMode(OperatingMode::CONNECTED);
1938 if (!mStreamMaps[sManifests].empty())
1942 jvObj[jss::type] =
"manifestReceived";
1945 jvObj[jss::signing_key] =
1949 jvObj[jss::signature] =
strHex(*sig);
1952 jvObj[jss::domain] = mo.
domain;
1955 for (
auto i = mStreamMaps[sManifests].begin();
1956 i != mStreamMaps[sManifests].end();)
1958 if (
auto p = i->second.lock())
1960 p->send(jvObj,
true);
1965 i = mStreamMaps[sManifests].erase(i);
1971 NetworkOPsImp::ServerFeeSummary::ServerFeeSummary(
1976 , loadBaseServer{loadFeeTrack.getLoadBase()}
1978 , em{std::move(escalationMetrics)}
1988 em.has_value() != b.
em.has_value())
1994 em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
1995 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
1996 em->referenceFeeLevel != b.
em->referenceFeeLevel);
2029 jvObj[jss::type] =
"serverStatus";
2031 jvObj[jss::load_base] = f.loadBaseServer;
2032 jvObj[jss::load_factor_server] = f.loadFactorServer;
2033 jvObj[jss::base_fee] = f.baseFee.jsonClipped();
2038 safe_cast<std::uint64_t>(f.loadFactorServer),
2040 f.em->openLedgerFeeLevel,
2042 f.em->referenceFeeLevel)
2045 jvObj[jss::load_factor] =
trunc32(loadFactor);
2046 jvObj[jss::load_factor_fee_escalation] =
2047 f.em->openLedgerFeeLevel.jsonClipped();
2048 jvObj[jss::load_factor_fee_queue] =
2049 f.em->minProcessingFeeLevel.jsonClipped();
2050 jvObj[jss::load_factor_fee_reference] =
2051 f.em->referenceFeeLevel.jsonClipped();
2054 jvObj[jss::load_factor] = f.loadFactorServer;
2068 p->send(jvObj,
true);
2085 if (!streamMap.empty())
2088 jvObj[jss::type] =
"consensusPhase";
2089 jvObj[jss::consensus] =
to_string(phase);
2091 for (
auto i = streamMap.begin(); i != streamMap.end();)
2093 if (
auto p = i->second.lock())
2095 p->send(jvObj,
true);
2100 i = streamMap.erase(i);
2116 auto const signerPublic = val->getSignerPublic();
2118 jvObj[jss::type] =
"validationReceived";
2119 jvObj[jss::validation_public_key] =
2121 jvObj[jss::ledger_hash] =
to_string(val->getLedgerHash());
2122 jvObj[jss::signature] =
strHex(val->getSignature());
2123 jvObj[jss::full] = val->isFull();
2124 jvObj[jss::flags] = val->getFlags();
2126 jvObj[jss::data] =
strHex(val->getSerializer().slice());
2131 if (
auto cookie = (*val)[~
sfCookie])
2135 jvObj[jss::validated_hash] =
strHex(*hash);
2137 auto const masterKey =
2140 if (masterKey != signerPublic)
2144 jvObj[jss::ledger_index] =
to_string(*seq);
2149 for (
auto const& amendment : val->getFieldV256(
sfAmendments))
2154 jvObj[jss::close_time] = *closeTime;
2156 if (
auto const loadFee = (*val)[~
sfLoadFee])
2157 jvObj[jss::load_fee] = *loadFee;
2159 if (
auto const baseFee = (*val)[~
sfBaseFee])
2160 jvObj[jss::base_fee] =
static_cast<double>(*baseFee);
2163 jvObj[jss::reserve_base] = *reserveBase;
2166 jvObj[jss::reserve_inc] = *reserveInc;
2171 if (
auto p = i->second.lock())
2173 p->send(jvObj,
true);
2193 jvObj[jss::type] =
"peerStatusChange";
2202 p->send(jvObj,
true);
2216 using namespace std::chrono_literals;
2248 <<
"recvValidation " << val->getLedgerHash() <<
" from " << source;
2278 "This server is amendment blocked, and must be updated to be "
2279 "able to stay in sync with the network.";
2286 "This server has an expired validator list. validators.txt "
2287 "may be incorrectly configured or some [validator_list_sites] "
2288 "may be unreachable.";
2295 "One or more unsupported amendments have reached majority. "
2296 "Upgrade to the latest version before they are activated "
2297 "to avoid being amendment blocked.";
2298 if (
auto const expected =
2302 d[jss::expected_date] = expected->time_since_epoch().count();
2303 d[jss::expected_date_UTC] =
to_string(*expected);
2307 if (warnings.size())
2308 info[jss::warnings] = std::move(warnings);
2321 info[jss::network_id] =
static_cast<Json::UInt>(*netid);
2327 info[jss::time] =
to_string(std::chrono::floor<std::chrono::microseconds>(
2331 info[jss::network_ledger] =
"waiting";
2333 info[jss::validation_quorum] =
2341 info[jss::node_size] =
"tiny";
2344 info[jss::node_size] =
"small";
2347 info[jss::node_size] =
"medium";
2350 info[jss::node_size] =
"large";
2353 info[jss::node_size] =
"huge";
2362 info[jss::validator_list_expires] =
2363 safe_cast<Json::UInt>(when->time_since_epoch().count());
2365 info[jss::validator_list_expires] = 0;
2375 if (*when == TimeKeeper::time_point::max())
2377 x[jss::expiration] =
"never";
2378 x[jss::status] =
"active";
2385 x[jss::status] =
"active";
2387 x[jss::status] =
"expired";
2392 x[jss::status] =
"unknown";
2393 x[jss::expiration] =
"unknown";
2397 info[jss::io_latency_ms] =
2404 info[jss::pubkey_validator] =
toBase58(
2409 info[jss::pubkey_validator] =
"none";
2422 info[jss::counters][jss::nodestore] = nodestore;
2426 info[jss::pubkey_node] =
2432 info[jss::amendment_blocked] =
true;
2447 lastClose[jss::converge_time_s] =
2452 lastClose[jss::converge_time] =
2456 info[jss::last_close] = lastClose;
2465 auto const escalationMetrics =
2473 auto const loadFactorFeeEscalation =
2475 escalationMetrics.openLedgerFeeLevel,
2477 escalationMetrics.referenceFeeLevel)
2481 safe_cast<std::uint64_t>(loadFactorServer),
2482 loadFactorFeeEscalation);
2486 info[jss::load_base] = loadBaseServer;
2487 info[jss::load_factor] =
trunc32(loadFactor);
2488 info[jss::load_factor_server] = loadFactorServer;
2495 info[jss::load_factor_fee_escalation] =
2496 escalationMetrics.openLedgerFeeLevel.jsonClipped();
2497 info[jss::load_factor_fee_queue] =
2498 escalationMetrics.minProcessingFeeLevel.jsonClipped();
2499 info[jss::load_factor_fee_reference] =
2500 escalationMetrics.referenceFeeLevel.jsonClipped();
2504 info[jss::load_factor] =
2505 static_cast<double>(loadFactor) / loadBaseServer;
2507 if (loadFactorServer != loadFactor)
2508 info[jss::load_factor_server] =
2509 static_cast<double>(loadFactorServer) / loadBaseServer;
2514 if (fee != loadBaseServer)
2515 info[jss::load_factor_local] =
2516 static_cast<double>(fee) / loadBaseServer;
2518 if (fee != loadBaseServer)
2519 info[jss::load_factor_net] =
2520 static_cast<double>(fee) / loadBaseServer;
2522 if (fee != loadBaseServer)
2523 info[jss::load_factor_cluster] =
2524 static_cast<double>(fee) / loadBaseServer;
2526 if (escalationMetrics.openLedgerFeeLevel !=
2527 escalationMetrics.referenceFeeLevel &&
2528 (admin || loadFactorFeeEscalation != loadFactor))
2529 info[jss::load_factor_fee_escalation] =
2530 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
2531 escalationMetrics.referenceFeeLevel);
2532 if (escalationMetrics.minProcessingFeeLevel !=
2533 escalationMetrics.referenceFeeLevel)
2534 info[jss::load_factor_fee_queue] =
2535 escalationMetrics.minProcessingFeeLevel
2536 .decimalFromReference(
2537 escalationMetrics.referenceFeeLevel);
2551 XRPAmount const baseFee = lpClosed->fees().base;
2553 l[jss::seq] =
Json::UInt(lpClosed->info().seq);
2554 l[jss::hash] =
to_string(lpClosed->info().hash);
2559 l[jss::reserve_base] =
2560 lpClosed->fees().accountReserve(0).jsonClipped();
2561 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
2563 lpClosed->info().closeTime.time_since_epoch().count());
2568 l[jss::reserve_base_xrp] =
2569 lpClosed->fees().accountReserve(0).decimalXRP();
2570 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
2573 if (std::abs(nowOffset.count()) >= 60)
2574 l[jss::system_time_offset] = nowOffset.count();
2577 if (std::abs(closeOffset.count()) >= 60)
2578 l[jss::close_time_offset] = closeOffset.count();
2580 #if RIPPLED_REPORTING
2590 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2594 auto lCloseTime = lpClosed->info().closeTime;
2596 if (lCloseTime <= closeTime)
2598 using namespace std::chrono_literals;
2599 auto age = closeTime - lCloseTime;
2601 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2608 info[jss::validated_ledger] = l;
2610 info[jss::closed_ledger] = l;
2614 info[jss::published_ledger] =
"none";
2615 else if (lpPublished->info().seq != lpClosed->info().seq)
2616 info[jss::published_ledger] = lpPublished->info().seq;
2623 info[jss::jq_trans_overflow] =
2625 info[jss::peer_disconnects] =
2627 info[jss::peer_disconnects_resources] =
2668 p->send(jvObj,
true);
2687 if (jvObj[jss::validated].asBool())
2699 p->send(jvObj,
true);
2720 if (
auto p = i->second.lock())
2722 p->send(jvObj,
true);
2740 if (
auto p = i->second.lock())
2742 p->send(jvObj,
true);
2755 for (
auto& jv : jvObj)
2761 else if (jv.isString())
2785 if (jvObj.
isMember(jss::transaction))
2794 << __func__ <<
" : "
2795 <<
"error parsing json for accounts affected";
2804 for (
auto const& affectedAccount : accounts)
2809 auto it = simiIt->second.begin();
2811 while (it != simiIt->second.end())
2822 it = simiIt->second.erase(it);
2829 <<
" iProposed=" << iProposed;
2831 if (!notify.
empty())
2834 isrListener->send(jvObj,
true);
2848 alpAccepted = std::make_shared<AcceptedLedger>(lpAccepted,
app_);
2850 lpAccepted->info().hash, alpAccepted);
2853 assert(alpAccepted->getLedger().
get() == lpAccepted.
get());
2857 <<
"Publishing ledger " << lpAccepted->info().seq <<
" "
2858 << lpAccepted->info().hash;
2866 jvObj[jss::type] =
"ledgerClosed";
2867 jvObj[jss::ledger_index] = lpAccepted->info().seq;
2868 jvObj[jss::ledger_hash] =
to_string(lpAccepted->info().hash);
2870 lpAccepted->info().closeTime.time_since_epoch().count());
2872 jvObj[jss::fee_ref] = lpAccepted->fees().units.jsonClipped();
2873 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
2874 jvObj[jss::reserve_base] =
2875 lpAccepted->fees().accountReserve(0).jsonClipped();
2876 jvObj[jss::reserve_inc] =
2877 lpAccepted->fees().increment.jsonClipped();
2879 jvObj[jss::txn_count] =
Json::UInt(alpAccepted->size());
2883 jvObj[jss::validated_ledgers] =
2893 p->send(jvObj,
true);
2902 static bool firstTime =
true;
2909 for (
auto& inner : outer.second)
2911 auto& subInfo = inner.second;
2912 if (subInfo.index_->separationLedgerSeq_ == 0)
2915 alpAccepted->getLedger(), subInfo);
2924 for (
auto const& accTx : *alpAccepted)
2956 "reportConsensusStateChange->pubConsensus",
2975 const STTx& transaction,
2986 jvObj[jss::type] =
"transaction";
2991 jvObj[jss::ledger_index] = ledger->info().seq;
2992 jvObj[jss::ledger_hash] =
to_string(ledger->info().hash);
2993 jvObj[jss::transaction][jss::date] =
2994 ledger->info().closeTime.time_since_epoch().count();
2995 jvObj[jss::validated] =
true;
3001 jvObj[jss::validated] =
false;
3002 jvObj[jss::ledger_current_index] = ledger->info().seq;
3005 jvObj[jss::status] = validated ?
"closed" :
"proposed";
3006 jvObj[jss::engine_result] = sToken;
3007 jvObj[jss::engine_result_code] = result;
3008 jvObj[jss::engine_result_message] = sHuman;
3016 if (account != amount.issue().account)
3024 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3036 auto const& stTxn = transaction.
getTxn();
3042 auto const& meta = transaction.
getMeta();
3057 p->send(jvObj,
true);
3072 p->send(jvObj,
true);
3096 auto const currLedgerSeq = ledger->seq();
3103 for (
auto const& affectedAccount : transaction.
getAffected())
3108 auto it = simiIt->second.begin();
3110 while (it != simiIt->second.end())
3121 it = simiIt->second.erase(it);
3128 auto it = simiIt->second.begin();
3129 while (it != simiIt->second.end())
3140 it = simiIt->second.erase(it);
3147 auto& subs = histoIt->second;
3148 auto it = subs.begin();
3149 while (it != subs.end())
3152 if (currLedgerSeq <= info.index_->separationLedgerSeq_)
3166 it = subs.erase(it);
3177 <<
"pubAccountTransaction: "
3178 <<
"proposed=" << iProposed <<
", accepted=" << iAccepted;
3180 if (!notify.
empty() || !accountHistoryNotify.
empty())
3182 auto const& stTxn = transaction.
getTxn();
3188 auto const& meta = transaction.
getMeta();
3195 isrListener->send(jvObj,
true);
3197 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3198 for (
auto& info : accountHistoryNotify)
3200 auto& index = info.index_;
3201 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3202 jvObj[jss::account_history_tx_first] =
true;
3203 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3204 info.sink_->send(jvObj,
true);
3229 for (
auto const& affectedAccount : tx->getMentionedAccounts())
3234 auto it = simiIt->second.begin();
3236 while (it != simiIt->second.end())
3247 it = simiIt->second.erase(it);
3254 JLOG(
m_journal.
trace()) <<
"pubProposedAccountTransaction: " << iProposed;
3256 if (!notify.
empty() || !accountHistoryNotify.
empty())
3261 isrListener->send(jvObj,
true);
3263 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3264 for (
auto& info : accountHistoryNotify)
3266 auto& index = info.index_;
3267 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3268 jvObj[jss::account_history_tx_first] =
true;
3269 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3270 info.sink_->send(jvObj,
true);
3287 for (
auto const& naAccountID : vnaAccountIDs)
3290 <<
"subAccount: account: " <<
toBase58(naAccountID);
3292 isrListener->insertSubAccountInfo(naAccountID, rt);
3297 for (
auto const& naAccountID : vnaAccountIDs)
3299 auto simIterator = subMap.
find(naAccountID);
3300 if (simIterator == subMap.
end())
3304 usisElement[isrListener->getSeq()] = isrListener;
3306 subMap.
insert(simIterator, make_pair(naAccountID, usisElement));
3311 simIterator->second[isrListener->getSeq()] = isrListener;
3322 for (
auto const& naAccountID : vnaAccountIDs)
3325 isrListener->deleteSubAccountInfo(naAccountID, rt);
3342 for (
auto const& naAccountID : vnaAccountIDs)
3344 auto simIterator = subMap.
find(naAccountID);
3346 if (simIterator != subMap.
end())
3349 simIterator->second.erase(uSeq);
3351 if (simIterator->second.empty())
3354 subMap.
erase(simIterator);
3363 enum DatabaseType { Postgres, Sqlite, None };
3364 static const auto databaseType = [&]() -> DatabaseType {
3365 #ifdef RIPPLED_REPORTING
3372 return DatabaseType::Postgres;
3374 return DatabaseType::None;
3382 return DatabaseType::Sqlite;
3384 return DatabaseType::None;
3391 return DatabaseType::Sqlite;
3393 return DatabaseType::None;
3397 if (databaseType == DatabaseType::None)
3400 <<
"AccountHistory job for account "
3412 "AccountHistoryTxStream",
3413 [
this, dbType = databaseType, subInfo]() {
3414 auto const& accountId = subInfo.
index_->accountId_;
3415 auto& lastLedgerSeq = subInfo.
index_->historyLastLedgerSeq_;
3416 auto& txHistoryIndex = subInfo.
index_->historyTxIndex_;
3419 <<
"AccountHistory job for account " <<
toBase58(accountId)
3420 <<
" started. lastLedgerSeq=" << lastLedgerSeq;
3430 auto stx = tx->getSTransaction();
3431 if (stx->getAccountID(
sfAccount) == accountId &&
3432 stx->getSeqProxy().value() == 1)
3436 for (
auto& node : meta->getNodes())
3443 if (
auto inner =
dynamic_cast<const STObject*
>(
3448 inner->getAccountID(
sfAccount) == accountId)
3460 bool unsubscribe) ->
bool {
3463 sptr->send(jvObj,
true);
3489 auto [txResult, status] = db->getAccountTx(args);
3493 <<
"AccountHistory job for account "
3495 <<
" getAccountTx failed";
3500 std::get_if<RelationalDatabase::AccountTxs>(
3501 &txResult.transactions);
3509 <<
"AccountHistory job for account "
3511 <<
" getAccountTx wrong data";
3519 accountId, minLedger, maxLedger, marker, 0,
true};
3520 return db->newestAccountTxPage(options);
3532 while (lastLedgerSeq >= 2 && !subInfo.
index_->stopHistorical_)
3534 int feeChargeCount = 0;
3543 <<
"AccountHistory job for account "
3544 <<
toBase58(accountId) <<
" no InfoSub. Fee charged "
3545 << feeChargeCount <<
" times.";
3550 auto startLedgerSeq =
3551 (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
3553 <<
"AccountHistory job for account " <<
toBase58(accountId)
3554 <<
", working on ledger range [" << startLedgerSeq <<
","
3555 << lastLedgerSeq <<
"]";
3557 auto haveRange = [&]() ->
bool {
3560 auto haveSomeValidatedLedgers =
3562 validatedMin, validatedMax);
3564 return haveSomeValidatedLedgers &&
3565 validatedMin <= startLedgerSeq &&
3566 lastLedgerSeq <= validatedMax;
3572 <<
"AccountHistory reschedule job for account "
3573 <<
toBase58(accountId) <<
", incomplete ledger range ["
3574 << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
3580 while (!subInfo.
index_->stopHistorical_)
3583 getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
3587 <<
"AccountHistory job for account "
3588 <<
toBase58(accountId) <<
" getMoreTxns failed.";
3593 auto const& txns = dbResult->first;
3594 marker = dbResult->second;
3595 for (
auto const& [tx, meta] : txns)
3600 <<
"AccountHistory job for account "
3601 <<
toBase58(accountId) <<
" empty tx or meta.";
3611 <<
"AccountHistory job for account "
3612 <<
toBase58(accountId) <<
" no ledger.";
3617 tx->getSTransaction();
3621 <<
"AccountHistory job for account "
3623 <<
" getSTransaction failed.";
3628 *stTxn, meta->getResultTER(),
true, curTxLedger);
3630 jvTx[jss::account_history_tx_index] = txHistoryIndex--;
3632 jvTx[jss::meta], *curTxLedger, stTxn, *meta);
3633 if (isFirstTx(tx, meta))
3635 jvTx[jss::account_history_tx_first] =
true;
3639 <<
"AccountHistory job for account "
3641 <<
" done, found last tx.";
3653 <<
"AccountHistory job for account "
3655 <<
" paging, marker=" << marker->ledgerSeq <<
":"
3664 if (!subInfo.
index_->stopHistorical_)
3666 lastLedgerSeq = startLedgerSeq - 1;
3667 if (lastLedgerSeq <= 1)
3670 <<
"AccountHistory job for account "
3672 <<
" done, reached genesis ledger.";
3685 subInfo.
index_->separationLedgerSeq_ = ledger->seq();
3686 auto const& accountId = subInfo.
index_->accountId_;
3688 if (!ledger->exists(accountKeylet))
3691 <<
"subAccountHistoryStart, no account " <<
toBase58(accountId)
3692 <<
", no need to add AccountHistory job.";
3697 if (
auto const sleAcct = ledger->read(accountKeylet); sleAcct)
3702 <<
"subAccountHistoryStart, genesis account "
3704 <<
" does not have tx, no need to add AccountHistory job.";
3714 subInfo.
index_->historyLastLedgerSeq_ = ledger->seq();
3715 subInfo.
index_->haveHistorical_ =
true;
3718 <<
"subAccountHistoryStart, add AccountHistory job: accountId="
3719 <<
toBase58(accountId) <<
", currentLedgerSeq=" << ledger->seq();
3729 if (!isrListener->insertSubAccountHistory(accountId))
3732 <<
"subAccountHistory, already subscribed to account "
3739 isrListener, std::make_shared<SubAccountHistoryIndex>(accountId)};
3744 inner.
emplace(isrListener->getSeq(), ahi);
3750 simIterator->second.emplace(isrListener->getSeq(), ahi);
3764 <<
"subAccountHistory, no validated ledger yet, delay start";
3777 isrListener->deleteSubAccountHistory(account);
3791 auto& subInfoMap = simIterator->second;
3792 auto subInfoIter = subInfoMap.find(seq);
3793 if (subInfoIter != subInfoMap.end())
3795 subInfoIter->second.index_->stopHistorical_ =
true;
3800 simIterator->second.erase(seq);
3801 if (simIterator->second.empty())
3807 <<
"unsubAccountHistory, account " <<
toBase58(account)
3808 <<
", historyOnly = " << (historyOnly ?
"true" :
"false");
3816 listeners->addSubscriber(isrListener);
3826 listeners->removeSubscriber(uSeq);
3840 Throw<std::runtime_error>(
3841 "Operation only possible in STANDALONE mode.");
3856 jvResult[jss::ledger_index] = lpClosed->info().seq;
3857 jvResult[jss::ledger_hash] =
to_string(lpClosed->info().hash);
3859 lpClosed->info().closeTime.time_since_epoch().count());
3860 jvResult[jss::fee_ref] = lpClosed->fees().units.jsonClipped();
3861 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
3862 jvResult[jss::reserve_base] =
3863 lpClosed->fees().accountReserve(0).jsonClipped();
3864 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3869 jvResult[jss::validated_ledgers] =
3875 .emplace(isrListener->getSeq(), isrListener)
3893 .emplace(isrListener->getSeq(), isrListener)
3921 jvResult[jss::random] =
to_string(uRandom);
3923 jvResult[jss::load_base] = feeTrack.getLoadBase();
3924 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
3925 jvResult[jss::hostid] =
getHostId(admin);
3926 jvResult[jss::pubkey_node] =
3931 .emplace(isrListener->getSeq(), isrListener)
3949 .emplace(isrListener->getSeq(), isrListener)
3967 .emplace(isrListener->getSeq(), isrListener)
3985 .emplace(isrListener->getSeq(), isrListener)
4009 .emplace(isrListener->getSeq(), isrListener)
4027 .emplace(isrListener->getSeq(), isrListener)
4075 if (map.find(pInfo->getSeq()) != map.end())
4082 #ifndef USE_NEW_BOOK_PAGE
4093 unsigned int iLimit,
4103 uint256 uTipIndex = uBookBase;
4107 stream <<
"getBookPage:" << book;
4108 stream <<
"getBookPage: uBookBase=" << uBookBase;
4109 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
4110 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
4119 bool bDirectAdvance =
true;
4123 unsigned int uBookEntry;
4129 while (!bDone && iLimit-- > 0)
4133 bDirectAdvance =
false;
4137 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
4141 sleOfferDir.
reset();
4150 uTipIndex = sleOfferDir->key();
4153 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
4156 <<
"getBookPage: uTipIndex=" << uTipIndex;
4158 <<
"getBookPage: offerIndex=" << offerIndex;
4168 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4169 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4170 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4172 bool firstOwnerOffer(
true);
4178 saOwnerFunds = saTakerGets;
4180 else if (bGlobalFreeze)
4188 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4189 if (umBalanceEntry != umBalance.
end())
4193 saOwnerFunds = umBalanceEntry->second;
4194 firstOwnerOffer =
false;
4208 if (saOwnerFunds < beast::zero)
4212 saOwnerFunds.
clear();
4220 STAmount saOwnerFundsLimit = saOwnerFunds;
4232 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4235 if (saOwnerFundsLimit >= saTakerGets)
4238 saTakerGetsFunded = saTakerGets;
4244 saTakerGetsFunded = saOwnerFundsLimit;
4246 saTakerGetsFunded.
setJson(jvOffer[jss::taker_gets_funded]);
4250 saTakerGetsFunded, saDirRate, saTakerPays.
issue()))
4251 .setJson(jvOffer[jss::taker_pays_funded]);
4257 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4259 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4263 jvOf[jss::quality] = saDirRate.
getText();
4265 if (firstOwnerOffer)
4266 jvOf[jss::owner_funds] = saOwnerFunds.
getText();
4273 if (!
cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
4275 bDirectAdvance =
true;
4280 <<
"getBookPage: offerIndex=" << offerIndex;
4300 unsigned int iLimit,
4308 MetaView lesActive(lpLedger,
tapNONE,
true);
4309 OrderBookIterator obIterator(lesActive, book);
4313 const bool bGlobalFreeze = lesActive.isGlobalFrozen(book.
out.
account) ||
4314 lesActive.isGlobalFrozen(book.
in.
account);
4316 while (iLimit-- > 0 && obIterator.nextOffer())
4321 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4322 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4323 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4324 STAmount saDirRate = obIterator.getCurrentRate();
4330 saOwnerFunds = saTakerGets;
4332 else if (bGlobalFreeze)
4340 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4342 if (umBalanceEntry != umBalance.
end())
4346 saOwnerFunds = umBalanceEntry->second;
4352 saOwnerFunds = lesActive.accountHolds(
4358 if (saOwnerFunds.isNegative())
4362 saOwnerFunds.zero();
4369 STAmount saTakerGetsFunded;
4370 STAmount saOwnerFundsLimit = saOwnerFunds;
4382 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4385 if (saOwnerFundsLimit >= saTakerGets)
4388 saTakerGetsFunded = saTakerGets;
4393 saTakerGetsFunded = saOwnerFundsLimit;
4395 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
4401 multiply(saTakerGetsFunded, saDirRate, saTakerPays.issue()))
4402 .setJson(jvOffer[jss::taker_pays_funded]);
4405 STAmount saOwnerPays = (
parityRate == offerRate)
4408 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4410 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4412 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
4416 jvOf[jss::quality] = saDirRate.
getText();
4431 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4471 ++counters_[
static_cast<std::size_t>(om)].transitions;
4473 counters_[
static_cast<std::size_t>(om)].transitions == 1)
4475 initialSyncUs_ = std::chrono::duration_cast<std::chrono::microseconds>(
4476 now - processStart_)
4480 std::chrono::duration_cast<std::chrono::microseconds>(now - start_);
4489 auto [counters, mode, start, initialSync] = getCounterData();
4490 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4500 auto& state = obj[jss::state_accounting][
states_[i]];
4501 state[jss::transitions] =
std::to_string(counters[i].transitions);
4502 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
4506 obj[jss::initial_sync_duration_us] =
std::to_string(initialSync);
4521 boost::asio::io_service& io_svc,
4525 return std::make_unique<NetworkOPsImp>(