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/RelationalDBInterface.h>
41 #include <ripple/app/rdb/backend/RelationalDBInterfacePostgres.h>
42 #include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.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/to_string.h>
56 #include <ripple/net/RPCErr.h>
57 #include <ripple/nodestore/DatabaseShard.h>
58 #include <ripple/overlay/Cluster.h>
59 #include <ripple/overlay/Overlay.h>
60 #include <ripple/overlay/predicates.h>
61 #include <ripple/protocol/BuildInfo.h>
62 #include <ripple/protocol/Feature.h>
63 #include <ripple/protocol/STParsedJSON.h>
64 #include <ripple/resource/Fees.h>
65 #include <ripple/resource/ResourceManager.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 terResult)
override;
493 bool historyOnly)
override;
499 bool historyOnly)
override;
562 boost::system::error_code ec;
567 <<
"NetworkOPs: heartbeatTimer cancel error: "
576 <<
"NetworkOPs: clusterTimer cancel error: "
585 <<
"NetworkOPs: accountHistoryTxTimer cancel error: "
590 using namespace std::chrono_literals;
600 boost::asio::steady_timer& timer,
768 template <
class Handler>
770 Handler
const& handler,
772 :
hook(collector->make_hook(handler))
775 "Disconnected_duration"))
778 "Connected_duration"))
780 collector->make_gauge(
"State_Accounting",
"Syncing_duration"))
783 "Tracking_duration"))
785 collector->make_gauge(
"State_Accounting",
"Full_duration"))
788 "Disconnected_transitions"))
791 "Connected_transitions"))
794 "Syncing_transitions"))
797 "Tracking_transitions"))
799 collector->make_gauge(
"State_Accounting",
"Full_transitions"))
828 {
"disconnected",
"connected",
"syncing",
"tracking",
"full"}};
890 static std::string const hostname = boost::asio::ip::host_name();
897 static std::string const shroudedHostId = [
this]() {
903 return shroudedHostId;
915 boost::asio::steady_timer& timer,
922 [
this, onExpire, onError](boost::system::error_code
const& e) {
923 if ((e.value() == boost::system::errc::success) &&
924 (!m_job_queue.isStopped()))
929 if (e.value() != boost::system::errc::success &&
930 e.value() != boost::asio::error::operation_aborted)
933 JLOG(m_journal.error())
934 <<
"Timer got error '" << e.message()
935 <<
"'. Restarting timer.";
940 timer.expires_from_now(expiry_time);
941 timer.async_wait(std::move(*optionalCountedHandler));
952 m_job_queue.addJob(jtNETOP_TIMER,
"NetOPs.heartbeat", [this](Job&) {
953 processHeartbeatTimer();
956 [
this]() { setHeartbeatTimer(); });
960 NetworkOPsImp::setClusterTimer()
962 using namespace std::chrono_literals;
968 processClusterTimer();
971 [
this]() { setClusterTimer(); });
977 JLOG(m_journal.debug()) <<
"Scheduling AccountHistory job for account "
979 using namespace std::chrono_literals;
981 accountHistoryTxTimer_,
983 [
this, subInfo]() { addAccountHistoryJob(subInfo); },
984 [
this, subInfo]() { setAccountHistoryJobTimer(subInfo); });
988 NetworkOPsImp::processHeartbeatTimer()
997 std::size_t const numPeers = app_.overlay().size();
1000 if (numPeers < minPeerCount_)
1002 if (mMode != OperatingMode::DISCONNECTED)
1004 setMode(OperatingMode::DISCONNECTED);
1005 JLOG(m_journal.warn())
1006 <<
"Node count (" << numPeers <<
") has fallen "
1007 <<
"below required minimum (" << minPeerCount_ <<
").";
1014 setHeartbeatTimer();
1018 if (mMode == OperatingMode::DISCONNECTED)
1020 setMode(OperatingMode::CONNECTED);
1021 JLOG(m_journal.info())
1022 <<
"Node count (" << numPeers <<
") is sufficient.";
1027 if (mMode == OperatingMode::SYNCING)
1028 setMode(OperatingMode::SYNCING);
1029 else if (mMode == OperatingMode::CONNECTED)
1030 setMode(OperatingMode::CONNECTED);
1033 mConsensus.timerEntry(app_.timeKeeper().closeTime());
1036 if (mLastConsensusPhase != currPhase)
1038 reportConsensusStateChange(currPhase);
1039 mLastConsensusPhase = currPhase;
1042 setHeartbeatTimer();
1046 NetworkOPsImp::processClusterTimer()
1048 using namespace std::chrono_literals;
1049 bool const update = app_.cluster().update(
1050 app_.nodeIdentity().first,
1052 (m_ledgerMaster.getValidatedLedgerAge() <= 4
min)
1053 ? app_.getFeeTrack().getLocalFee()
1055 app_.timeKeeper().now());
1059 JLOG(m_journal.debug()) <<
"Too soon to send cluster update";
1064 protocol::TMCluster cluster;
1065 app_.cluster().for_each([&cluster](
ClusterNode const& node) {
1066 protocol::TMClusterNode& n = *cluster.add_clusternodes();
1071 n.set_nodename(node.
name());
1075 for (
auto& item : gossip.
items)
1077 protocol::TMLoadSource& node = *cluster.add_loadsources();
1079 node.set_cost(item.balance);
1081 app_.overlay().foreach(
send_if(
1082 std::make_shared<Message>(cluster, protocol::mtCLUSTER),
1093 if (mode == OperatingMode::FULL && admin)
1095 auto const consensusMode = mConsensus.mode();
1096 if (consensusMode != ConsensusMode::wrongLedger)
1098 if (consensusMode == ConsensusMode::proposing)
1101 if (mConsensus.validating())
1102 return "validating";
1112 if (isNeedNetworkLedger())
1121 auto const txid = trans->getTransactionID();
1122 auto const flags = app_.getHashRouter().getFlags(txid);
1124 if ((flags & SF_BAD) != 0)
1126 JLOG(m_journal.warn()) <<
"Submitted transaction cached bad";
1133 app_.getHashRouter(),
1135 m_ledgerMaster.getValidatedRules(),
1138 if (validity != Validity::Valid)
1140 JLOG(m_journal.warn())
1141 <<
"Submitted transaction invalid: " << reason;
1147 JLOG(m_journal.warn()) <<
"Exception checking transaction" << txid;
1154 auto tx = std::make_shared<Transaction>(trans, reason, app_);
1158 processTransaction(t,
false,
false, FailHard::no);
1163 NetworkOPsImp::processTransaction(
1169 auto ev = m_job_queue.makeLoadEvent(
jtTXN_PROC,
"ProcessTXN");
1170 auto const newFlags = app_.getHashRouter().getFlags(transaction->getID());
1172 if ((newFlags & SF_BAD) != 0)
1175 transaction->setStatus(
INVALID);
1183 auto const view = m_ledgerMaster.getCurrentLedger();
1185 app_.getHashRouter(),
1186 *transaction->getSTransaction(),
1189 assert(validity == Validity::Valid);
1192 if (validity == Validity::SigBad)
1194 JLOG(m_journal.info()) <<
"Transaction has bad signature: " << reason;
1195 transaction->setStatus(
INVALID);
1197 app_.getHashRouter().setFlags(transaction->getID(), SF_BAD);
1202 app_.getMasterTransaction().canonicalize(&transaction);
1205 doTransactionSync(transaction, bUnlimited, failType);
1207 doTransactionAsync(transaction, bUnlimited, failType);
1211 NetworkOPsImp::doTransactionAsync(
1218 if (transaction->getApplying())
1221 mTransactions.push_back(
1223 transaction->setApplying();
1225 if (mDispatchState == DispatchState::none)
1227 if (m_job_queue.addJob(
jtBATCH,
"transactionBatch", [
this](
Job&) {
1231 mDispatchState = DispatchState::scheduled;
1237 NetworkOPsImp::doTransactionSync(
1244 if (!transaction->getApplying())
1246 mTransactions.push_back(
1248 transaction->setApplying();
1253 if (mDispatchState == DispatchState::running)
1262 if (mTransactions.size())
1265 if (m_job_queue.addJob(
1270 mDispatchState = DispatchState::scheduled;
1274 }
while (transaction->getApplying());
1278 NetworkOPsImp::transactionBatch()
1282 if (mDispatchState == DispatchState::running)
1285 while (mTransactions.size())
1296 mTransactions.
swap(transactions);
1297 assert(!transactions.
empty());
1299 assert(mDispatchState != DispatchState::running);
1300 mDispatchState = DispatchState::running;
1306 bool changed =
false;
1309 m_ledgerMaster.peekMutex(), std::defer_lock};
1320 if (e.failType == FailHard::yes)
1323 auto const result = app_.getTxQ().apply(
1324 app_, view, e.transaction->getSTransaction(), flags, j);
1325 e.result = result.first;
1326 e.applied = result.second;
1327 changed = changed || result.second;
1336 if (
auto const l = m_ledgerMaster.getValidatedLedger())
1337 validatedLedgerIndex = l->info().seq;
1339 auto newOL = app_.openLedger().current();
1342 e.transaction->clearSubmitResult();
1346 pubProposedTransaction(
1347 newOL, e.transaction->getSTransaction(), e.result);
1348 e.transaction->setApplied();
1351 e.transaction->setResult(e.result);
1354 app_.getHashRouter().setFlags(e.transaction->getID(), SF_BAD);
1363 JLOG(m_journal.info())
1364 <<
"TransactionResult: " << token <<
": " << human;
1369 bool addLocal = e.local;
1373 JLOG(m_journal.debug())
1374 <<
"Transaction is now included in open ledger";
1375 e.transaction->setStatus(
INCLUDED);
1377 auto const& txCur = e.transaction->getSTransaction();
1378 auto const txNext = m_ledgerMaster.popAcctTransaction(txCur);
1383 auto t = std::make_shared<Transaction>(trans, reason, app_);
1384 submit_held.
emplace_back(t,
false,
false, FailHard::no);
1391 JLOG(m_journal.info()) <<
"Transaction is obsolete";
1392 e.transaction->setStatus(
OBSOLETE);
1396 JLOG(m_journal.debug())
1397 <<
"Transaction is likely to claim a"
1398 <<
" fee, but is queued until fee drops";
1400 e.transaction->setStatus(
HELD);
1404 m_ledgerMaster.addHeldTransaction(e.transaction);
1405 e.transaction->setQueued();
1406 e.transaction->setKept();
1410 if (e.failType != FailHard::yes)
1413 JLOG(m_journal.debug())
1414 <<
"Transaction should be held: " << e.result;
1415 e.transaction->setStatus(
HELD);
1416 m_ledgerMaster.addHeldTransaction(e.transaction);
1417 e.transaction->setKept();
1422 JLOG(m_journal.debug())
1423 <<
"Status other than success " << e.result;
1424 e.transaction->setStatus(
INVALID);
1427 auto const enforceFailHard =
1428 e.failType == FailHard::yes && !
isTesSuccess(e.result);
1430 if (addLocal && !enforceFailHard)
1432 m_localTX->push_back(
1433 m_ledgerMaster.getCurrentLedgerIndex(),
1434 e.transaction->getSTransaction());
1435 e.transaction->setKept();
1439 ((mMode != OperatingMode::FULL) &&
1440 (e.failType != FailHard::yes) && e.local) ||
1445 app_.getHashRouter().shouldRelay(e.transaction->getID());
1449 protocol::TMTransaction tx;
1452 e.transaction->getSTransaction()->add(s);
1453 tx.set_rawtransaction(s.
data(), s.
size());
1454 tx.set_status(protocol::tsCURRENT);
1455 tx.set_receivetimestamp(
1456 app_.timeKeeper().now().time_since_epoch().count());
1459 app_.overlay().relay(e.transaction->getID(), tx, *toSkip);
1460 e.transaction->setBroadcast();
1464 if (validatedLedgerIndex)
1466 auto [fee, accountSeq, availableSeq] =
1467 app_.getTxQ().getTxRequiredFeeAndSeq(
1468 *newOL, e.transaction->getSTransaction());
1469 e.transaction->setCurrentLedgerState(
1470 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1478 e.transaction->clearApplying();
1480 if (!submit_held.
empty())
1482 if (mTransactions.empty())
1483 mTransactions.swap(submit_held);
1485 for (
auto& e : submit_held)
1486 mTransactions.push_back(std::move(e));
1491 mDispatchState = DispatchState::none;
1499 NetworkOPsImp::getOwnerInfo(
1504 auto root = keylet::ownerDir(account);
1505 auto sleNode = lpLedger->read(keylet::page(root));
1512 for (
auto const& uDirEntry : sleNode->getFieldV256(
sfIndexes))
1514 auto sleCur = lpLedger->read(keylet::child(uDirEntry));
1517 switch (sleCur->getType())
1520 if (!jvObjects.
isMember(jss::offers))
1521 jvObjects[jss::offers] =
1524 jvObjects[jss::offers].
append(
1525 sleCur->getJson(JsonOptions::none));
1529 if (!jvObjects.
isMember(jss::ripple_lines))
1531 jvObjects[jss::ripple_lines] =
1535 jvObjects[jss::ripple_lines].
append(
1536 sleCur->getJson(JsonOptions::none));
1551 sleNode = lpLedger->read(keylet::page(root, uNodeDir));
1565 NetworkOPsImp::isBlocked()
1567 return isAmendmentBlocked() || isUNLBlocked();
1571 NetworkOPsImp::isAmendmentBlocked()
1573 return amendmentBlocked_;
1577 NetworkOPsImp::setAmendmentBlocked()
1579 amendmentBlocked_ =
true;
1580 setMode(OperatingMode::CONNECTED);
1584 NetworkOPsImp::isAmendmentWarned()
1586 return !amendmentBlocked_ && amendmentWarned_;
1590 NetworkOPsImp::setAmendmentWarned()
1592 amendmentWarned_ =
true;
1596 NetworkOPsImp::clearAmendmentWarned()
1598 amendmentWarned_ =
false;
1602 NetworkOPsImp::isUNLBlocked()
1608 NetworkOPsImp::setUNLBlocked()
1611 setMode(OperatingMode::CONNECTED);
1615 NetworkOPsImp::clearUNLBlocked()
1617 unlBlocked_ =
false;
1621 NetworkOPsImp::checkLastClosedLedger(
1630 JLOG(m_journal.trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
1632 auto const ourClosed = m_ledgerMaster.getClosedLedger();
1637 uint256 closedLedger = ourClosed->info().hash;
1638 uint256 prevClosedLedger = ourClosed->info().parentHash;
1639 JLOG(m_journal.trace()) <<
"OurClosed: " << closedLedger;
1640 JLOG(m_journal.trace()) <<
"PrevClosed: " << prevClosedLedger;
1645 auto& validations = app_.getValidations();
1646 JLOG(m_journal.debug())
1647 <<
"ValidationTrie " <<
Json::Compact(validations.getJsonTrie());
1651 peerCounts[closedLedger] = 0;
1652 if (mMode >= OperatingMode::TRACKING)
1653 peerCounts[closedLedger]++;
1655 for (
auto& peer : peerList)
1657 uint256 peerLedger = peer->getClosedLedgerHash();
1660 ++peerCounts[peerLedger];
1663 for (
auto const& it : peerCounts)
1664 JLOG(m_journal.debug()) <<
"L: " << it.first <<
" n=" << it.second;
1666 uint256 preferredLCL = validations.getPreferredLCL(
1668 m_ledgerMaster.getValidLedgerIndex(),
1671 bool switchLedgers = preferredLCL != closedLedger;
1673 closedLedger = preferredLCL;
1675 if (switchLedgers && (closedLedger == prevClosedLedger))
1678 JLOG(m_journal.info()) <<
"We won't switch to our own previous ledger";
1679 networkClosed = ourClosed->info().hash;
1680 switchLedgers =
false;
1683 networkClosed = closedLedger;
1688 auto consensus = m_ledgerMaster.getLedgerByHash(closedLedger);
1691 consensus = app_.getInboundLedgers().acquire(
1692 closedLedger, 0, InboundLedger::Reason::CONSENSUS);
1695 (!m_ledgerMaster.canBeCurrent(consensus) ||
1696 !m_ledgerMaster.isCompatible(
1697 *consensus, m_journal.debug(),
"Not switching")))
1701 networkClosed = ourClosed->info().hash;
1705 JLOG(m_journal.warn()) <<
"We are not running on the consensus ledger";
1706 JLOG(m_journal.info()) <<
"Our LCL: " <<
getJson({*ourClosed, {}});
1707 JLOG(m_journal.info()) <<
"Net LCL " << closedLedger;
1709 if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
1711 setMode(OperatingMode::CONNECTED);
1719 switchLastClosedLedger(consensus);
1726 NetworkOPsImp::switchLastClosedLedger(
1730 JLOG(m_journal.error())
1731 <<
"JUMP last closed ledger to " << newLCL->info().hash;
1733 clearNeedNetworkLedger();
1736 app_.getTxQ().processClosedLedger(app_, *newLCL,
true);
1743 auto retries = m_localTX->getTxSet();
1744 auto const lastVal = app_.getLedgerMaster().getValidatedLedger();
1747 rules.
emplace(*lastVal, app_.config().features);
1749 rules.
emplace(app_.config().features);
1750 app_.openLedger().accept(
1761 return app_.getTxQ().accept(app_, view);
1765 m_ledgerMaster.switchLCL(newLCL);
1767 protocol::TMStatusChange s;
1768 s.set_newevent(protocol::neSWITCHED_LEDGER);
1769 s.set_ledgerseq(newLCL->info().seq);
1770 s.set_networktime(app_.timeKeeper().now().time_since_epoch().count());
1771 s.set_ledgerhashprevious(
1772 newLCL->info().parentHash.begin(), newLCL->info().parentHash.size());
1773 s.set_ledgerhash(newLCL->info().hash.begin(), newLCL->info().hash.size());
1775 app_.overlay().foreach(
1776 send_always(std::make_shared<Message>(s, protocol::mtSTATUS_CHANGE)));
1780 NetworkOPsImp::beginConsensus(
uint256 const& networkClosed)
1784 auto closingInfo = m_ledgerMaster.getCurrentLedger()->info();
1786 JLOG(m_journal.info()) <<
"Consensus time for #" << closingInfo.seq
1787 <<
" with LCL " << closingInfo.parentHash;
1789 auto prevLedger = m_ledgerMaster.getLedgerByHash(closingInfo.parentHash);
1794 if (mMode == OperatingMode::FULL)
1796 JLOG(m_journal.warn()) <<
"Don't have LCL, going to tracking";
1797 setMode(OperatingMode::TRACKING);
1803 assert(prevLedger->info().hash == closingInfo.parentHash);
1805 closingInfo.parentHash ==
1806 m_ledgerMaster.getClosedLedger()->info().hash);
1809 app_.validators().setNegativeUNL(prevLedger->negativeUNL());
1810 TrustChanges const changes = app_.validators().updateTrusted(
1811 app_.getValidations().getCurrentNodeIDs(),
1812 closingInfo.parentCloseTime,
1815 app_.getHashRouter());
1817 if (!changes.
added.empty() || !changes.
removed.empty())
1818 app_.getValidations().trustChanged(changes.
added, changes.
removed);
1820 mConsensus.startRound(
1821 app_.timeKeeper().closeTime(),
1828 if (mLastConsensusPhase != currPhase)
1830 reportConsensusStateChange(currPhase);
1831 mLastConsensusPhase = currPhase;
1834 JLOG(m_journal.debug()) <<
"Initiating consensus engine";
1841 return mConsensus.peerProposal(app_.timeKeeper().closeTime(), peerPos);
1852 protocol::TMHaveTransactionSet msg;
1853 msg.set_hash(map->getHash().as_uint256().begin(), 256 / 8);
1854 msg.set_status(protocol::tsHAVE);
1855 app_.overlay().foreach(
1856 send_always(std::make_shared<Message>(msg, protocol::mtHAVE_SET)));
1860 mConsensus.gotTxSet(app_.timeKeeper().closeTime(),
RCLTxSet{map});
1864 NetworkOPsImp::endConsensus()
1866 uint256 deadLedger = m_ledgerMaster.getClosedLedger()->info().parentHash;
1868 for (
auto const& it : app_.overlay().getActivePeers())
1870 if (it && (it->getClosedLedgerHash() == deadLedger))
1872 JLOG(m_journal.trace()) <<
"Killing obsolete peer status";
1879 checkLastClosedLedger(app_.overlay().getActivePeers(), networkClosed);
1881 if (networkClosed.
isZero())
1890 if (((mMode == OperatingMode::CONNECTED) ||
1891 (mMode == OperatingMode::SYNCING)) &&
1897 if (!needNetworkLedger_)
1898 setMode(OperatingMode::TRACKING);
1901 if (((mMode == OperatingMode::CONNECTED) ||
1902 (mMode == OperatingMode::TRACKING)) &&
1908 auto current = m_ledgerMaster.getCurrentLedger();
1909 if (app_.timeKeeper().now() < (
current->info().parentCloseTime +
1910 2 *
current->info().closeTimeResolution))
1912 setMode(OperatingMode::FULL);
1916 beginConsensus(networkClosed);
1920 NetworkOPsImp::consensusViewChange()
1922 if ((mMode == OperatingMode::FULL) || (mMode == OperatingMode::TRACKING))
1924 setMode(OperatingMode::CONNECTED);
1934 if (!mStreamMaps[sManifests].empty())
1938 jvObj[jss::type] =
"manifestReceived";
1941 jvObj[jss::signing_key] =
1945 jvObj[jss::signature] =
strHex(*sig);
1948 jvObj[jss::domain] = mo.
domain;
1951 for (
auto i = mStreamMaps[sManifests].begin();
1952 i != mStreamMaps[sManifests].end();)
1954 if (
auto p = i->second.lock())
1956 p->send(jvObj,
true);
1961 i = mStreamMaps[sManifests].erase(i);
1967 NetworkOPsImp::ServerFeeSummary::ServerFeeSummary(
1972 , loadBaseServer{loadFeeTrack.getLoadBase()}
1974 , em{std::move(escalationMetrics)}
1984 em.has_value() != b.
em.has_value())
1990 em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
1991 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
1992 em->referenceFeeLevel != b.
em->referenceFeeLevel);
2025 jvObj[jss::type] =
"serverStatus";
2027 jvObj[jss::load_base] = f.loadBaseServer;
2028 jvObj[jss::load_factor_server] = f.loadFactorServer;
2029 jvObj[jss::base_fee] = f.baseFee.jsonClipped();
2034 safe_cast<std::uint64_t>(f.loadFactorServer),
2036 f.em->openLedgerFeeLevel,
2038 f.em->referenceFeeLevel)
2041 jvObj[jss::load_factor] =
trunc32(loadFactor);
2042 jvObj[jss::load_factor_fee_escalation] =
2043 f.em->openLedgerFeeLevel.jsonClipped();
2044 jvObj[jss::load_factor_fee_queue] =
2045 f.em->minProcessingFeeLevel.jsonClipped();
2046 jvObj[jss::load_factor_fee_reference] =
2047 f.em->referenceFeeLevel.jsonClipped();
2050 jvObj[jss::load_factor] = f.loadFactorServer;
2064 p->send(jvObj,
true);
2081 if (!streamMap.empty())
2084 jvObj[jss::type] =
"consensusPhase";
2085 jvObj[jss::consensus] =
to_string(phase);
2087 for (
auto i = streamMap.begin(); i != streamMap.end();)
2089 if (
auto p = i->second.lock())
2091 p->send(jvObj,
true);
2096 i = streamMap.erase(i);
2112 auto const signerPublic = val->getSignerPublic();
2114 jvObj[jss::type] =
"validationReceived";
2115 jvObj[jss::validation_public_key] =
2117 jvObj[jss::ledger_hash] =
to_string(val->getLedgerHash());
2118 jvObj[jss::signature] =
strHex(val->getSignature());
2119 jvObj[jss::full] = val->isFull();
2120 jvObj[jss::flags] = val->getFlags();
2122 jvObj[jss::data] =
strHex(val->getSerializer().slice());
2127 if (
auto cookie = (*val)[~
sfCookie])
2131 jvObj[jss::validated_hash] =
strHex(*hash);
2133 auto const masterKey =
2136 if (masterKey != signerPublic)
2140 jvObj[jss::ledger_index] =
to_string(*seq);
2145 for (
auto const& amendment : val->getFieldV256(
sfAmendments))
2150 jvObj[jss::close_time] = *closeTime;
2152 if (
auto const loadFee = (*val)[~
sfLoadFee])
2153 jvObj[jss::load_fee] = *loadFee;
2155 if (
auto const baseFee = (*val)[~
sfBaseFee])
2156 jvObj[jss::base_fee] =
static_cast<double>(*baseFee);
2159 jvObj[jss::reserve_base] = *reserveBase;
2162 jvObj[jss::reserve_inc] = *reserveInc;
2167 if (
auto p = i->second.lock())
2169 p->send(jvObj,
true);
2189 jvObj[jss::type] =
"peerStatusChange";
2198 p->send(jvObj,
true);
2212 using namespace std::chrono_literals;
2244 <<
"recvValidation " << val->getLedgerHash() <<
" from " << source;
2274 "This server is amendment blocked, and must be updated to be "
2275 "able to stay in sync with the network.";
2282 "This server has an expired validator list. validators.txt "
2283 "may be incorrectly configured or some [validator_list_sites] "
2284 "may be unreachable.";
2291 "One or more unsupported amendments have reached majority. "
2292 "Upgrade to the latest version before they are activated "
2293 "to avoid being amendment blocked.";
2294 if (
auto const expected =
2298 d[jss::expected_date] = expected->time_since_epoch().count();
2299 d[jss::expected_date_UTC] =
to_string(*expected);
2303 if (warnings.size())
2304 info[jss::warnings] = std::move(warnings);
2317 info[jss::network_id] =
static_cast<Json::UInt>(*netid);
2323 info[jss::time] =
to_string(std::chrono::floor<std::chrono::microseconds>(
2327 info[jss::network_ledger] =
"waiting";
2329 info[jss::validation_quorum] =
2337 info[jss::node_size] =
"tiny";
2340 info[jss::node_size] =
"small";
2343 info[jss::node_size] =
"medium";
2346 info[jss::node_size] =
"large";
2349 info[jss::node_size] =
"huge";
2358 info[jss::validator_list_expires] =
2359 safe_cast<Json::UInt>(when->time_since_epoch().count());
2361 info[jss::validator_list_expires] = 0;
2371 if (*when == TimeKeeper::time_point::max())
2373 x[jss::expiration] =
"never";
2374 x[jss::status] =
"active";
2381 x[jss::status] =
"active";
2383 x[jss::status] =
"expired";
2388 x[jss::status] =
"unknown";
2389 x[jss::expiration] =
"unknown";
2393 info[jss::io_latency_ms] =
2400 info[jss::pubkey_validator] =
toBase58(
2405 info[jss::pubkey_validator] =
"none";
2418 info[jss::counters][jss::nodestore] = nodestore;
2422 info[jss::pubkey_node] =
2428 info[jss::amendment_blocked] =
true;
2443 lastClose[jss::converge_time_s] =
2448 lastClose[jss::converge_time] =
2452 info[jss::last_close] = lastClose;
2461 auto const escalationMetrics =
2469 auto const loadFactorFeeEscalation =
2471 escalationMetrics.openLedgerFeeLevel,
2473 escalationMetrics.referenceFeeLevel)
2477 safe_cast<std::uint64_t>(loadFactorServer),
2478 loadFactorFeeEscalation);
2482 info[jss::load_base] = loadBaseServer;
2483 info[jss::load_factor] =
trunc32(loadFactor);
2484 info[jss::load_factor_server] = loadFactorServer;
2491 info[jss::load_factor_fee_escalation] =
2492 escalationMetrics.openLedgerFeeLevel.jsonClipped();
2493 info[jss::load_factor_fee_queue] =
2494 escalationMetrics.minProcessingFeeLevel.jsonClipped();
2495 info[jss::load_factor_fee_reference] =
2496 escalationMetrics.referenceFeeLevel.jsonClipped();
2500 info[jss::load_factor] =
2501 static_cast<double>(loadFactor) / loadBaseServer;
2503 if (loadFactorServer != loadFactor)
2504 info[jss::load_factor_server] =
2505 static_cast<double>(loadFactorServer) / loadBaseServer;
2510 if (fee != loadBaseServer)
2511 info[jss::load_factor_local] =
2512 static_cast<double>(fee) / loadBaseServer;
2514 if (fee != loadBaseServer)
2515 info[jss::load_factor_net] =
2516 static_cast<double>(fee) / loadBaseServer;
2518 if (fee != loadBaseServer)
2519 info[jss::load_factor_cluster] =
2520 static_cast<double>(fee) / loadBaseServer;
2522 if (escalationMetrics.openLedgerFeeLevel !=
2523 escalationMetrics.referenceFeeLevel &&
2524 (admin || loadFactorFeeEscalation != loadFactor))
2525 info[jss::load_factor_fee_escalation] =
2526 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
2527 escalationMetrics.referenceFeeLevel);
2528 if (escalationMetrics.minProcessingFeeLevel !=
2529 escalationMetrics.referenceFeeLevel)
2530 info[jss::load_factor_fee_queue] =
2531 escalationMetrics.minProcessingFeeLevel
2532 .decimalFromReference(
2533 escalationMetrics.referenceFeeLevel);
2547 XRPAmount const baseFee = lpClosed->fees().base;
2549 l[jss::seq] =
Json::UInt(lpClosed->info().seq);
2550 l[jss::hash] =
to_string(lpClosed->info().hash);
2555 l[jss::reserve_base] =
2556 lpClosed->fees().accountReserve(0).jsonClipped();
2557 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
2559 lpClosed->info().closeTime.time_since_epoch().count());
2564 l[jss::reserve_base_xrp] =
2565 lpClosed->fees().accountReserve(0).decimalXRP();
2566 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
2569 if (std::abs(nowOffset.count()) >= 60)
2570 l[jss::system_time_offset] = nowOffset.count();
2573 if (std::abs(closeOffset.count()) >= 60)
2574 l[jss::close_time_offset] = closeOffset.count();
2576 #if RIPPLED_REPORTING
2586 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2590 auto lCloseTime = lpClosed->info().closeTime;
2592 if (lCloseTime <= closeTime)
2594 using namespace std::chrono_literals;
2595 auto age = closeTime - lCloseTime;
2597 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2604 info[jss::validated_ledger] = l;
2606 info[jss::closed_ledger] = l;
2610 info[jss::published_ledger] =
"none";
2611 else if (lpPublished->info().seq != lpClosed->info().seq)
2612 info[jss::published_ledger] = lpPublished->info().seq;
2619 info[jss::jq_trans_overflow] =
2621 info[jss::peer_disconnects] =
2623 info[jss::peer_disconnects_resources] =
2664 p->send(jvObj,
true);
2685 if (jvObj[jss::validated].asBool())
2697 p->send(jvObj,
true);
2718 if (
auto p = i->second.lock())
2720 p->send(jvObj,
true);
2738 if (
auto p = i->second.lock())
2740 p->send(jvObj,
true);
2753 for (
auto& jv : jvObj)
2759 else if (jv.isString())
2783 if (jvObj.
isMember(jss::transaction))
2792 << __func__ <<
" : "
2793 <<
"error parsing json for accounts affected";
2802 for (
auto const& affectedAccount : accounts)
2807 auto it = simiIt->second.begin();
2809 while (it != simiIt->second.end())
2820 it = simiIt->second.erase(it);
2827 <<
" iProposed=" << iProposed;
2829 if (!notify.
empty())
2832 isrListener->send(jvObj,
true);
2846 alpAccepted = std::make_shared<AcceptedLedger>(lpAccepted,
app_);
2848 lpAccepted->info().hash, alpAccepted);
2853 <<
"Publishing ledger = " << lpAccepted->info().seq;
2860 jvObj[jss::type] =
"ledgerClosed";
2861 jvObj[jss::ledger_index] = lpAccepted->info().seq;
2862 jvObj[jss::ledger_hash] =
to_string(lpAccepted->info().hash);
2864 lpAccepted->info().closeTime.time_since_epoch().count());
2866 jvObj[jss::fee_ref] = lpAccepted->fees().units.jsonClipped();
2867 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
2868 jvObj[jss::reserve_base] =
2869 lpAccepted->fees().accountReserve(0).jsonClipped();
2870 jvObj[jss::reserve_inc] =
2871 lpAccepted->fees().increment.jsonClipped();
2873 jvObj[jss::txn_count] =
Json::UInt(alpAccepted->getTxnCount());
2877 jvObj[jss::validated_ledgers] =
2888 <<
"Publishing ledger = " << lpAccepted->info().seq
2889 <<
" : consumer = " << p->getConsumer()
2890 <<
" : obj = " << jvObj;
2891 p->send(jvObj,
true);
2900 static bool firstTime =
true;
2907 for (
auto& inner : outer.second)
2909 auto& subInfo = inner.second;
2910 if (subInfo.index_->separationLedgerSeq_ == 0)
2913 alpAccepted->getLedger(), subInfo);
2922 for (
auto const& [_, accTx] : alpAccepted->getMap())
2955 "reportConsensusStateChange->pubConsensus",
2985 jvObj[jss::type] =
"transaction";
2990 jvObj[jss::ledger_index] = lpCurrent->info().seq;
2991 jvObj[jss::ledger_hash] =
to_string(lpCurrent->info().hash);
2992 jvObj[jss::transaction][jss::date] =
2993 lpCurrent->info().closeTime.time_since_epoch().count();
2994 jvObj[jss::validated] =
true;
3000 jvObj[jss::validated] =
false;
3001 jvObj[jss::ledger_current_index] = lpCurrent->info().seq;
3004 jvObj[jss::status] = bValidated ?
"closed" :
"proposed";
3005 jvObj[jss::engine_result] = sToken;
3006 jvObj[jss::engine_result_code] = terResult;
3007 jvObj[jss::engine_result_message] = sHuman;
3015 if (account != amount.issue().account)
3023 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3038 if (
auto const txMeta = alTx.
getMeta())
3042 jvObj[jss::meta], *alAccepted, stTxn, *txMeta);
3055 p->send(jvObj,
true);
3070 p->send(jvObj,
true);
3092 auto const currLedgerSeq = lpCurrent->seq();
3102 for (
auto const& affectedAccount : alTx.
getAffected())
3107 auto it = simiIt->second.begin();
3109 while (it != simiIt->second.end())
3120 it = simiIt->second.erase(it);
3129 auto it = simiIt->second.begin();
3130 while (it != simiIt->second.end())
3141 it = simiIt->second.erase(it);
3148 auto& subs = histoIt->second;
3149 auto it = subs.begin();
3150 while (it != subs.end())
3153 if (currLedgerSeq <=
3154 info.
index_->separationLedgerSeq_)
3168 it = subs.erase(it);
3180 <<
"pubAccountTransaction:"
3181 <<
" iProposed=" << iProposed <<
" iAccepted=" << iAccepted;
3183 if (!notify.
empty() || !accountHistoryNotify.
empty())
3191 if (
auto const txMeta = alTx.
getMeta())
3195 jvObj[jss::meta], *lpCurrent, stTxn, *txMeta);
3200 isrListener->send(jvObj,
true);
3202 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3203 for (
auto& info : accountHistoryNotify)
3205 auto& index = info.index_;
3206 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3207 jvObj[jss::account_history_tx_first] =
true;
3208 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3209 info.sink_->send(jvObj,
true);
3226 for (
auto const& naAccountID : vnaAccountIDs)
3229 <<
"subAccount: account: " <<
toBase58(naAccountID);
3231 isrListener->insertSubAccountInfo(naAccountID, rt);
3236 for (
auto const& naAccountID : vnaAccountIDs)
3238 auto simIterator = subMap.
find(naAccountID);
3239 if (simIterator == subMap.
end())
3243 usisElement[isrListener->getSeq()] = isrListener;
3245 subMap.
insert(simIterator, make_pair(naAccountID, usisElement));
3250 simIterator->second[isrListener->getSeq()] = isrListener;
3261 for (
auto const& naAccountID : vnaAccountIDs)
3264 isrListener->deleteSubAccountInfo(naAccountID, rt);
3281 for (
auto const& naAccountID : vnaAccountIDs)
3283 auto simIterator = subMap.
find(naAccountID);
3285 if (simIterator != subMap.
end())
3288 simIterator->second.erase(uSeq);
3290 if (simIterator->second.empty())
3293 subMap.
erase(simIterator);
3302 enum DatabaseType { Postgres, Sqlite, None };
3303 static const auto databaseType = [&]() -> DatabaseType {
3304 #ifdef RIPPLED_REPORTING
3310 return DatabaseType::Postgres;
3312 return DatabaseType::None;
3319 return DatabaseType::Sqlite;
3321 return DatabaseType::None;
3327 return DatabaseType::Sqlite;
3329 return DatabaseType::None;
3333 if (databaseType == DatabaseType::None)
3336 <<
"AccountHistory job for account "
3348 "AccountHistoryTxStream",
3349 [
this, dbType = databaseType, subInfo](
Job&) {
3350 auto const& accountId = subInfo.
index_->accountId_;
3351 auto& lastLedgerSeq = subInfo.
index_->historyLastLedgerSeq_;
3352 auto& txHistoryIndex = subInfo.
index_->historyTxIndex_;
3355 <<
"AccountHistory job for account " <<
toBase58(accountId)
3356 <<
" started. lastLedgerSeq=" << lastLedgerSeq;
3366 auto stx = tx->getSTransaction();
3367 if (stx->getAccountID(
sfAccount) == accountId &&
3368 stx->getSeqProxy().value() == 1)
3372 for (
auto& node : meta->getNodes())
3379 if (
auto inner =
dynamic_cast<const STObject*
>(
3384 inner->getAccountID(
sfAccount) == accountId)
3396 bool unsubscribe) ->
bool {
3399 sptr->send(jvObj,
true);
3426 auto [txResult, status] = db->getAccountTx(args);
3430 <<
"AccountHistory job for account "
3432 <<
" getAccountTx failed";
3437 std::get_if<RelationalDBInterface::AccountTxs>(
3438 &txResult.transactions);
3446 <<
"AccountHistory job for account "
3448 <<
" getAccountTx wrong data";
3456 accountId, minLedger, maxLedger, marker, 0,
true};
3457 return db->newestAccountTxPage(options);
3469 while (lastLedgerSeq >= 2 && !subInfo.
index_->stopHistorical_)
3471 int feeChargeCount = 0;
3480 <<
"AccountHistory job for account "
3481 <<
toBase58(accountId) <<
" no InfoSub. Fee charged "
3482 << feeChargeCount <<
" times.";
3487 auto startLedgerSeq =
3488 (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
3490 <<
"AccountHistory job for account " <<
toBase58(accountId)
3491 <<
", working on ledger range [" << startLedgerSeq <<
","
3492 << lastLedgerSeq <<
"]";
3494 auto haveRange = [&]() ->
bool {
3497 auto haveSomeValidatedLedgers =
3499 validatedMin, validatedMax);
3501 return haveSomeValidatedLedgers &&
3502 validatedMin <= startLedgerSeq &&
3503 lastLedgerSeq <= validatedMax;
3509 <<
"AccountHistory reschedule job for account "
3510 <<
toBase58(accountId) <<
", incomplete ledger range ["
3511 << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
3517 while (!subInfo.
index_->stopHistorical_)
3520 getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
3524 <<
"AccountHistory job for account "
3525 <<
toBase58(accountId) <<
" getMoreTxns failed.";
3530 auto const& txns = dbResult->first;
3531 marker = dbResult->second;
3532 for (
auto const& [tx, meta] : txns)
3537 <<
"AccountHistory job for account "
3538 <<
toBase58(accountId) <<
" empty tx or meta.";
3548 <<
"AccountHistory job for account "
3549 <<
toBase58(accountId) <<
" no ledger.";
3554 tx->getSTransaction();
3558 <<
"AccountHistory job for account "
3560 <<
" getSTransaction failed.";
3565 *stTxn, meta->getResultTER(),
true, curTxLedger);
3567 jvTx[jss::account_history_tx_index] = txHistoryIndex--;
3569 jvTx[jss::meta], *curTxLedger, stTxn, *meta);
3570 if (isFirstTx(tx, meta))
3572 jvTx[jss::account_history_tx_first] =
true;
3576 <<
"AccountHistory job for account "
3578 <<
" done, found last tx.";
3590 <<
"AccountHistory job for account "
3592 <<
" paging, marker=" << marker->ledgerSeq <<
":"
3601 if (!subInfo.
index_->stopHistorical_)
3603 lastLedgerSeq = startLedgerSeq - 1;
3604 if (lastLedgerSeq <= 1)
3607 <<
"AccountHistory job for account "
3609 <<
" done, reached genesis ledger.";
3622 subInfo.
index_->separationLedgerSeq_ = ledger->seq();
3623 auto const& accountId = subInfo.
index_->accountId_;
3625 if (!ledger->exists(accountKeylet))
3628 <<
"subAccountHistoryStart, no account " <<
toBase58(accountId)
3629 <<
", no need to add AccountHistory job.";
3634 if (
auto const sleAcct = ledger->read(accountKeylet); sleAcct)
3639 <<
"subAccountHistoryStart, genesis account "
3641 <<
" does not have tx, no need to add AccountHistory job.";
3651 subInfo.
index_->historyLastLedgerSeq_ = ledger->seq();
3652 subInfo.
index_->haveHistorical_ =
true;
3655 <<
"subAccountHistoryStart, add AccountHistory job: accountId="
3656 <<
toBase58(accountId) <<
", currentLedgerSeq=" << ledger->seq();
3666 if (!isrListener->insertSubAccountHistory(accountId))
3669 <<
"subAccountHistory, already subscribed to account "
3676 isrListener, std::make_shared<SubAccountHistoryIndex>(accountId)};
3681 inner.
emplace(isrListener->getSeq(), ahi);
3687 simIterator->second.emplace(isrListener->getSeq(), ahi);
3701 <<
"subAccountHistory, no validated ledger yet, delay start";
3714 isrListener->deleteSubAccountHistory(account);
3728 auto& subInfoMap = simIterator->second;
3729 auto subInfoIter = subInfoMap.find(seq);
3730 if (subInfoIter != subInfoMap.end())
3732 subInfoIter->second.index_->stopHistorical_ =
true;
3737 simIterator->second.erase(seq);
3738 if (simIterator->second.empty())
3744 <<
"unsubAccountHistory, account " <<
toBase58(account)
3745 <<
", historyOnly = " << (historyOnly ?
"true" :
"false");
3753 listeners->addSubscriber(isrListener);
3763 listeners->removeSubscriber(uSeq);
3777 Throw<std::runtime_error>(
3778 "Operation only possible in STANDALONE mode.");
3793 jvResult[jss::ledger_index] = lpClosed->info().seq;
3794 jvResult[jss::ledger_hash] =
to_string(lpClosed->info().hash);
3796 lpClosed->info().closeTime.time_since_epoch().count());
3797 jvResult[jss::fee_ref] = lpClosed->fees().units.jsonClipped();
3798 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
3799 jvResult[jss::reserve_base] =
3800 lpClosed->fees().accountReserve(0).jsonClipped();
3801 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3806 jvResult[jss::validated_ledgers] =
3812 .emplace(isrListener->getSeq(), isrListener)
3830 .emplace(isrListener->getSeq(), isrListener)
3858 jvResult[jss::random] =
to_string(uRandom);
3860 jvResult[jss::load_base] = feeTrack.getLoadBase();
3861 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
3862 jvResult[jss::hostid] =
getHostId(admin);
3863 jvResult[jss::pubkey_node] =
3868 .emplace(isrListener->getSeq(), isrListener)
3886 .emplace(isrListener->getSeq(), isrListener)
3904 .emplace(isrListener->getSeq(), isrListener)
3922 .emplace(isrListener->getSeq(), isrListener)
3946 .emplace(isrListener->getSeq(), isrListener)
3964 .emplace(isrListener->getSeq(), isrListener)
4012 if (map.find(pInfo->getSeq()) != map.end())
4019 #ifndef USE_NEW_BOOK_PAGE
4030 unsigned int iLimit,
4040 uint256 uTipIndex = uBookBase;
4044 stream <<
"getBookPage:" << book;
4045 stream <<
"getBookPage: uBookBase=" << uBookBase;
4046 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
4047 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
4056 bool bDirectAdvance =
true;
4060 unsigned int uBookEntry;
4066 while (!bDone && iLimit-- > 0)
4070 bDirectAdvance =
false;
4074 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
4078 sleOfferDir.
reset();
4087 uTipIndex = sleOfferDir->key();
4090 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
4093 <<
"getBookPage: uTipIndex=" << uTipIndex;
4095 <<
"getBookPage: offerIndex=" << offerIndex;
4105 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4106 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4107 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4109 bool firstOwnerOffer(
true);
4115 saOwnerFunds = saTakerGets;
4117 else if (bGlobalFreeze)
4125 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4126 if (umBalanceEntry != umBalance.
end())
4130 saOwnerFunds = umBalanceEntry->second;
4131 firstOwnerOffer =
false;
4145 if (saOwnerFunds < beast::zero)
4149 saOwnerFunds.
clear();
4157 STAmount saOwnerFundsLimit = saOwnerFunds;
4169 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4172 if (saOwnerFundsLimit >= saTakerGets)
4175 saTakerGetsFunded = saTakerGets;
4181 saTakerGetsFunded = saOwnerFundsLimit;
4183 saTakerGetsFunded.
setJson(jvOffer[jss::taker_gets_funded]);
4187 saTakerGetsFunded, saDirRate, saTakerPays.
issue()))
4188 .setJson(jvOffer[jss::taker_pays_funded]);
4194 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4196 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4200 jvOf[jss::quality] = saDirRate.
getText();
4202 if (firstOwnerOffer)
4203 jvOf[jss::owner_funds] = saOwnerFunds.
getText();
4210 if (!
cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
4212 bDirectAdvance =
true;
4217 <<
"getBookPage: offerIndex=" << offerIndex;
4237 unsigned int iLimit,
4245 MetaView lesActive(lpLedger,
tapNONE,
true);
4246 OrderBookIterator obIterator(lesActive, book);
4250 const bool bGlobalFreeze = lesActive.isGlobalFrozen(book.
out.
account) ||
4251 lesActive.isGlobalFrozen(book.
in.
account);
4253 while (iLimit-- > 0 && obIterator.nextOffer())
4258 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4259 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4260 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4261 STAmount saDirRate = obIterator.getCurrentRate();
4267 saOwnerFunds = saTakerGets;
4269 else if (bGlobalFreeze)
4277 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4279 if (umBalanceEntry != umBalance.
end())
4283 saOwnerFunds = umBalanceEntry->second;
4289 saOwnerFunds = lesActive.accountHolds(
4295 if (saOwnerFunds.isNegative())
4299 saOwnerFunds.zero();
4306 STAmount saTakerGetsFunded;
4307 STAmount saOwnerFundsLimit = saOwnerFunds;
4319 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4322 if (saOwnerFundsLimit >= saTakerGets)
4325 saTakerGetsFunded = saTakerGets;
4330 saTakerGetsFunded = saOwnerFundsLimit;
4332 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
4338 multiply(saTakerGetsFunded, saDirRate, saTakerPays.issue()))
4339 .setJson(jvOffer[jss::taker_pays_funded]);
4342 STAmount saOwnerPays = (
parityRate == offerRate)
4345 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4347 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4349 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
4353 jvOf[jss::quality] = saDirRate.
getText();
4368 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4408 ++counters_[
static_cast<std::size_t>(om)].transitions;
4410 counters_[
static_cast<std::size_t>(om)].transitions == 1)
4412 initialSyncUs_ = std::chrono::duration_cast<std::chrono::microseconds>(
4413 now - processStart_)
4417 std::chrono::duration_cast<std::chrono::microseconds>(now - start_);
4426 auto [counters, mode, start, initialSync] = getCounterData();
4427 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4437 auto& state = obj[jss::state_accounting][
states_[i]];
4438 state[jss::transitions] =
std::to_string(counters[i].transitions);
4439 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
4443 obj[jss::initial_sync_duration_us] =
std::to_string(initialSync);
4458 boost::asio::io_service& io_svc,
4462 return std::make_unique<NetworkOPsImp>(