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()) <<
"Exception checking transaction" << txid;
1174 auto tx = std::make_shared<Transaction>(trans, reason, app_);
1176 m_job_queue.addJob(
jtTRANSACTION,
"submitTxn", [
this, tx]() {
1178 processTransaction(t,
false,
false, FailHard::no);
1183 NetworkOPsImp::processTransaction(
1189 auto ev = m_job_queue.makeLoadEvent(
jtTXN_PROC,
"ProcessTXN");
1190 auto const newFlags = app_.getHashRouter().getFlags(transaction->getID());
1192 if ((newFlags & SF_BAD) != 0)
1195 JLOG(m_journal.warn()) << transaction->getID() <<
": cached bad!\n";
1196 transaction->setStatus(
INVALID);
1204 auto const view = m_ledgerMaster.getCurrentLedger();
1206 app_.getHashRouter(),
1207 *transaction->getSTransaction(),
1210 assert(validity == Validity::Valid);
1213 if (validity == Validity::SigBad)
1215 JLOG(m_journal.info()) <<
"Transaction has bad signature: " << reason;
1216 transaction->setStatus(
INVALID);
1218 app_.getHashRouter().setFlags(transaction->getID(), SF_BAD);
1223 app_.getMasterTransaction().canonicalize(&transaction);
1226 doTransactionSync(transaction, bUnlimited, failType);
1228 doTransactionAsync(transaction, bUnlimited, failType);
1232 NetworkOPsImp::doTransactionAsync(
1239 if (transaction->getApplying())
1242 mTransactions.push_back(
1244 transaction->setApplying();
1246 if (mDispatchState == DispatchState::none)
1248 if (m_job_queue.addJob(
1249 jtBATCH,
"transactionBatch", [
this]() { transactionBatch(); }))
1251 mDispatchState = DispatchState::scheduled;
1257 NetworkOPsImp::doTransactionSync(
1264 if (!transaction->getApplying())
1266 mTransactions.push_back(
1268 transaction->setApplying();
1273 if (mDispatchState == DispatchState::running)
1282 if (mTransactions.size())
1285 if (m_job_queue.addJob(
jtBATCH,
"transactionBatch", [
this]() {
1289 mDispatchState = DispatchState::scheduled;
1293 }
while (transaction->getApplying());
1297 NetworkOPsImp::transactionBatch()
1301 if (mDispatchState == DispatchState::running)
1304 while (mTransactions.size())
1315 mTransactions.
swap(transactions);
1316 assert(!transactions.
empty());
1318 assert(mDispatchState != DispatchState::running);
1319 mDispatchState = DispatchState::running;
1325 bool changed =
false;
1328 m_ledgerMaster.peekMutex(), std::defer_lock};
1339 if (e.failType == FailHard::yes)
1342 auto const result = app_.getTxQ().apply(
1343 app_, view, e.transaction->getSTransaction(), flags, j);
1344 e.result = result.first;
1345 e.applied = result.second;
1346 changed = changed || result.second;
1355 if (
auto const l = m_ledgerMaster.getValidatedLedger())
1356 validatedLedgerIndex = l->info().seq;
1358 auto newOL = app_.openLedger().current();
1361 e.transaction->clearSubmitResult();
1365 pubProposedTransaction(
1366 newOL, e.transaction->getSTransaction(), e.result);
1367 e.transaction->setApplied();
1370 e.transaction->setResult(e.result);
1373 app_.getHashRouter().setFlags(e.transaction->getID(), SF_BAD);
1382 JLOG(m_journal.info())
1383 <<
"TransactionResult: " << token <<
": " << human;
1388 bool addLocal = e.local;
1392 JLOG(m_journal.debug())
1393 <<
"Transaction is now included in open ledger";
1394 e.transaction->setStatus(
INCLUDED);
1396 auto const& txCur = e.transaction->getSTransaction();
1397 auto const txNext = m_ledgerMaster.popAcctTransaction(txCur);
1402 auto t = std::make_shared<Transaction>(trans, reason, app_);
1403 submit_held.
emplace_back(t,
false,
false, FailHard::no);
1410 JLOG(m_journal.info()) <<
"Transaction is obsolete";
1411 e.transaction->setStatus(
OBSOLETE);
1415 JLOG(m_journal.debug())
1416 <<
"Transaction is likely to claim a"
1417 <<
" fee, but is queued until fee drops";
1419 e.transaction->setStatus(
HELD);
1423 m_ledgerMaster.addHeldTransaction(e.transaction);
1424 e.transaction->setQueued();
1425 e.transaction->setKept();
1429 if (e.failType != FailHard::yes)
1432 JLOG(m_journal.debug())
1433 <<
"Transaction should be held: " << e.result;
1434 e.transaction->setStatus(
HELD);
1435 m_ledgerMaster.addHeldTransaction(e.transaction);
1436 e.transaction->setKept();
1441 JLOG(m_journal.debug())
1442 <<
"Status other than success " << e.result;
1443 e.transaction->setStatus(
INVALID);
1446 auto const enforceFailHard =
1447 e.failType == FailHard::yes && !
isTesSuccess(e.result);
1449 if (addLocal && !enforceFailHard)
1451 m_localTX->push_back(
1452 m_ledgerMaster.getCurrentLedgerIndex(),
1453 e.transaction->getSTransaction());
1454 e.transaction->setKept();
1458 ((mMode != OperatingMode::FULL) &&
1459 (e.failType != FailHard::yes) && e.local) ||
1464 app_.getHashRouter().shouldRelay(e.transaction->getID());
1468 protocol::TMTransaction tx;
1471 e.transaction->getSTransaction()->add(s);
1472 tx.set_rawtransaction(s.
data(), s.
size());
1473 tx.set_status(protocol::tsCURRENT);
1474 tx.set_receivetimestamp(
1475 app_.timeKeeper().now().time_since_epoch().count());
1478 app_.overlay().relay(e.transaction->getID(), tx, *toSkip);
1479 e.transaction->setBroadcast();
1483 if (validatedLedgerIndex)
1485 auto [fee, accountSeq, availableSeq] =
1486 app_.getTxQ().getTxRequiredFeeAndSeq(
1487 *newOL, e.transaction->getSTransaction());
1488 e.transaction->setCurrentLedgerState(
1489 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1497 e.transaction->clearApplying();
1499 if (!submit_held.
empty())
1501 if (mTransactions.empty())
1502 mTransactions.swap(submit_held);
1504 for (
auto& e : submit_held)
1505 mTransactions.push_back(std::move(e));
1510 mDispatchState = DispatchState::none;
1518 NetworkOPsImp::getOwnerInfo(
1523 auto root = keylet::ownerDir(account);
1524 auto sleNode = lpLedger->read(keylet::page(root));
1531 for (
auto const& uDirEntry : sleNode->getFieldV256(
sfIndexes))
1533 auto sleCur = lpLedger->read(keylet::child(uDirEntry));
1536 switch (sleCur->getType())
1539 if (!jvObjects.
isMember(jss::offers))
1540 jvObjects[jss::offers] =
1543 jvObjects[jss::offers].
append(
1544 sleCur->getJson(JsonOptions::none));
1548 if (!jvObjects.
isMember(jss::ripple_lines))
1550 jvObjects[jss::ripple_lines] =
1554 jvObjects[jss::ripple_lines].
append(
1555 sleCur->getJson(JsonOptions::none));
1570 sleNode = lpLedger->read(keylet::page(root, uNodeDir));
1584 NetworkOPsImp::isBlocked()
1586 return isAmendmentBlocked() || isUNLBlocked();
1590 NetworkOPsImp::isAmendmentBlocked()
1592 return amendmentBlocked_;
1596 NetworkOPsImp::setAmendmentBlocked()
1598 amendmentBlocked_ =
true;
1599 setMode(OperatingMode::CONNECTED);
1603 NetworkOPsImp::isAmendmentWarned()
1605 return !amendmentBlocked_ && amendmentWarned_;
1609 NetworkOPsImp::setAmendmentWarned()
1611 amendmentWarned_ =
true;
1615 NetworkOPsImp::clearAmendmentWarned()
1617 amendmentWarned_ =
false;
1621 NetworkOPsImp::isUNLBlocked()
1627 NetworkOPsImp::setUNLBlocked()
1630 setMode(OperatingMode::CONNECTED);
1634 NetworkOPsImp::clearUNLBlocked()
1636 unlBlocked_ =
false;
1640 NetworkOPsImp::checkLastClosedLedger(
1649 JLOG(m_journal.trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
1651 auto const ourClosed = m_ledgerMaster.getClosedLedger();
1656 uint256 closedLedger = ourClosed->info().hash;
1657 uint256 prevClosedLedger = ourClosed->info().parentHash;
1658 JLOG(m_journal.trace()) <<
"OurClosed: " << closedLedger;
1659 JLOG(m_journal.trace()) <<
"PrevClosed: " << prevClosedLedger;
1664 auto& validations = app_.getValidations();
1665 JLOG(m_journal.debug())
1666 <<
"ValidationTrie " <<
Json::Compact(validations.getJsonTrie());
1670 peerCounts[closedLedger] = 0;
1671 if (mMode >= OperatingMode::TRACKING)
1672 peerCounts[closedLedger]++;
1674 for (
auto& peer : peerList)
1676 uint256 peerLedger = peer->getClosedLedgerHash();
1679 ++peerCounts[peerLedger];
1682 for (
auto const& it : peerCounts)
1683 JLOG(m_journal.debug()) <<
"L: " << it.first <<
" n=" << it.second;
1685 uint256 preferredLCL = validations.getPreferredLCL(
1687 m_ledgerMaster.getValidLedgerIndex(),
1690 bool switchLedgers = preferredLCL != closedLedger;
1692 closedLedger = preferredLCL;
1694 if (switchLedgers && (closedLedger == prevClosedLedger))
1697 JLOG(m_journal.info()) <<
"We won't switch to our own previous ledger";
1698 networkClosed = ourClosed->info().hash;
1699 switchLedgers =
false;
1702 networkClosed = closedLedger;
1707 auto consensus = m_ledgerMaster.getLedgerByHash(closedLedger);
1710 consensus = app_.getInboundLedgers().acquire(
1711 closedLedger, 0, InboundLedger::Reason::CONSENSUS);
1714 (!m_ledgerMaster.canBeCurrent(consensus) ||
1715 !m_ledgerMaster.isCompatible(
1716 *consensus, m_journal.debug(),
"Not switching")))
1720 networkClosed = ourClosed->info().hash;
1724 JLOG(m_journal.warn()) <<
"We are not running on the consensus ledger";
1725 JLOG(m_journal.info()) <<
"Our LCL: " <<
getJson({*ourClosed, {}});
1726 JLOG(m_journal.info()) <<
"Net LCL " << closedLedger;
1728 if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
1730 setMode(OperatingMode::CONNECTED);
1738 switchLastClosedLedger(consensus);
1745 NetworkOPsImp::switchLastClosedLedger(
1749 JLOG(m_journal.error())
1750 <<
"JUMP last closed ledger to " << newLCL->info().hash;
1752 clearNeedNetworkLedger();
1755 app_.getTxQ().processClosedLedger(app_, *newLCL,
true);
1762 auto retries = m_localTX->getTxSet();
1763 auto const lastVal = app_.getLedgerMaster().getValidatedLedger();
1768 rules.
emplace(app_.config().features);
1769 app_.openLedger().accept(
1780 return app_.getTxQ().accept(app_, view);
1784 m_ledgerMaster.switchLCL(newLCL);
1786 protocol::TMStatusChange s;
1787 s.set_newevent(protocol::neSWITCHED_LEDGER);
1788 s.set_ledgerseq(newLCL->info().seq);
1789 s.set_networktime(app_.timeKeeper().now().time_since_epoch().count());
1790 s.set_ledgerhashprevious(
1791 newLCL->info().parentHash.begin(), newLCL->info().parentHash.size());
1792 s.set_ledgerhash(newLCL->info().hash.begin(), newLCL->info().hash.size());
1794 app_.overlay().foreach(
1795 send_always(std::make_shared<Message>(s, protocol::mtSTATUS_CHANGE)));
1799 NetworkOPsImp::beginConsensus(
uint256 const& networkClosed)
1803 auto closingInfo = m_ledgerMaster.getCurrentLedger()->info();
1805 JLOG(m_journal.info()) <<
"Consensus time for #" << closingInfo.seq
1806 <<
" with LCL " << closingInfo.parentHash;
1808 auto prevLedger = m_ledgerMaster.getLedgerByHash(closingInfo.parentHash);
1813 if (mMode == OperatingMode::FULL)
1815 JLOG(m_journal.warn()) <<
"Don't have LCL, going to tracking";
1816 setMode(OperatingMode::TRACKING);
1822 assert(prevLedger->info().hash == closingInfo.parentHash);
1824 closingInfo.parentHash ==
1825 m_ledgerMaster.getClosedLedger()->info().hash);
1828 app_.validators().setNegativeUNL(prevLedger->negativeUNL());
1829 TrustChanges const changes = app_.validators().updateTrusted(
1830 app_.getValidations().getCurrentNodeIDs(),
1831 closingInfo.parentCloseTime,
1834 app_.getHashRouter());
1836 if (!changes.
added.empty() || !changes.
removed.empty())
1837 app_.getValidations().trustChanged(changes.
added, changes.
removed);
1839 mConsensus.startRound(
1840 app_.timeKeeper().closeTime(),
1847 if (mLastConsensusPhase != currPhase)
1849 reportConsensusStateChange(currPhase);
1850 mLastConsensusPhase = currPhase;
1853 JLOG(m_journal.debug()) <<
"Initiating consensus engine";
1860 return mConsensus.peerProposal(app_.timeKeeper().closeTime(), peerPos);
1871 protocol::TMHaveTransactionSet msg;
1872 msg.set_hash(map->getHash().as_uint256().begin(), 256 / 8);
1873 msg.set_status(protocol::tsHAVE);
1874 app_.overlay().foreach(
1875 send_always(std::make_shared<Message>(msg, protocol::mtHAVE_SET)));
1879 mConsensus.gotTxSet(app_.timeKeeper().closeTime(),
RCLTxSet{map});
1883 NetworkOPsImp::endConsensus()
1885 uint256 deadLedger = m_ledgerMaster.getClosedLedger()->info().parentHash;
1887 for (
auto const& it : app_.overlay().getActivePeers())
1889 if (it && (it->getClosedLedgerHash() == deadLedger))
1891 JLOG(m_journal.trace()) <<
"Killing obsolete peer status";
1898 checkLastClosedLedger(app_.overlay().getActivePeers(), networkClosed);
1900 if (networkClosed.
isZero())
1909 if (((mMode == OperatingMode::CONNECTED) ||
1910 (mMode == OperatingMode::SYNCING)) &&
1916 if (!needNetworkLedger_)
1917 setMode(OperatingMode::TRACKING);
1920 if (((mMode == OperatingMode::CONNECTED) ||
1921 (mMode == OperatingMode::TRACKING)) &&
1927 auto current = m_ledgerMaster.getCurrentLedger();
1928 if (app_.timeKeeper().now() < (
current->info().parentCloseTime +
1929 2 *
current->info().closeTimeResolution))
1931 setMode(OperatingMode::FULL);
1935 beginConsensus(networkClosed);
1939 NetworkOPsImp::consensusViewChange()
1941 if ((mMode == OperatingMode::FULL) || (mMode == OperatingMode::TRACKING))
1943 setMode(OperatingMode::CONNECTED);
1953 if (!mStreamMaps[sManifests].empty())
1957 jvObj[jss::type] =
"manifestReceived";
1960 jvObj[jss::signing_key] =
1964 jvObj[jss::signature] =
strHex(*sig);
1967 jvObj[jss::domain] = mo.
domain;
1970 for (
auto i = mStreamMaps[sManifests].begin();
1971 i != mStreamMaps[sManifests].end();)
1973 if (
auto p = i->second.lock())
1975 p->send(jvObj,
true);
1980 i = mStreamMaps[sManifests].erase(i);
1986 NetworkOPsImp::ServerFeeSummary::ServerFeeSummary(
1991 , loadBaseServer{loadFeeTrack.getLoadBase()}
1993 , em{std::move(escalationMetrics)}
2003 em.has_value() != b.
em.has_value())
2009 em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
2010 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
2011 em->referenceFeeLevel != b.
em->referenceFeeLevel);
2044 jvObj[jss::type] =
"serverStatus";
2046 jvObj[jss::load_base] = f.loadBaseServer;
2047 jvObj[jss::load_factor_server] = f.loadFactorServer;
2048 jvObj[jss::base_fee] = f.baseFee.jsonClipped();
2053 safe_cast<std::uint64_t>(f.loadFactorServer),
2055 f.em->openLedgerFeeLevel,
2057 f.em->referenceFeeLevel)
2060 jvObj[jss::load_factor] =
trunc32(loadFactor);
2061 jvObj[jss::load_factor_fee_escalation] =
2062 f.em->openLedgerFeeLevel.jsonClipped();
2063 jvObj[jss::load_factor_fee_queue] =
2064 f.em->minProcessingFeeLevel.jsonClipped();
2065 jvObj[jss::load_factor_fee_reference] =
2066 f.em->referenceFeeLevel.jsonClipped();
2069 jvObj[jss::load_factor] = f.loadFactorServer;
2083 p->send(jvObj,
true);
2100 if (!streamMap.empty())
2103 jvObj[jss::type] =
"consensusPhase";
2104 jvObj[jss::consensus] =
to_string(phase);
2106 for (
auto i = streamMap.begin(); i != streamMap.end();)
2108 if (
auto p = i->second.lock())
2110 p->send(jvObj,
true);
2115 i = streamMap.erase(i);
2131 auto const signerPublic = val->getSignerPublic();
2133 jvObj[jss::type] =
"validationReceived";
2134 jvObj[jss::validation_public_key] =
2136 jvObj[jss::ledger_hash] =
to_string(val->getLedgerHash());
2137 jvObj[jss::signature] =
strHex(val->getSignature());
2138 jvObj[jss::full] = val->isFull();
2139 jvObj[jss::flags] = val->getFlags();
2141 jvObj[jss::data] =
strHex(val->getSerializer().slice());
2146 if (
auto cookie = (*val)[~
sfCookie])
2150 jvObj[jss::validated_hash] =
strHex(*hash);
2152 auto const masterKey =
2155 if (masterKey != signerPublic)
2159 jvObj[jss::ledger_index] =
to_string(*seq);
2164 for (
auto const& amendment : val->getFieldV256(
sfAmendments))
2169 jvObj[jss::close_time] = *closeTime;
2171 if (
auto const loadFee = (*val)[~
sfLoadFee])
2172 jvObj[jss::load_fee] = *loadFee;
2174 if (
auto const baseFee = (*val)[~
sfBaseFee])
2175 jvObj[jss::base_fee] =
static_cast<double>(*baseFee);
2178 jvObj[jss::reserve_base] = *reserveBase;
2181 jvObj[jss::reserve_inc] = *reserveInc;
2186 if (
auto p = i->second.lock())
2188 p->send(jvObj,
true);
2208 jvObj[jss::type] =
"peerStatusChange";
2217 p->send(jvObj,
true);
2231 using namespace std::chrono_literals;
2263 <<
"recvValidation " << val->getLedgerHash() <<
" from " << source;
2293 "This server is amendment blocked, and must be updated to be "
2294 "able to stay in sync with the network.";
2301 "This server has an expired validator list. validators.txt "
2302 "may be incorrectly configured or some [validator_list_sites] "
2303 "may be unreachable.";
2310 "One or more unsupported amendments have reached majority. "
2311 "Upgrade to the latest version before they are activated "
2312 "to avoid being amendment blocked.";
2313 if (
auto const expected =
2317 d[jss::expected_date] = expected->time_since_epoch().count();
2318 d[jss::expected_date_UTC] =
to_string(*expected);
2322 if (warnings.size())
2323 info[jss::warnings] = std::move(warnings);
2338 info[jss::time] =
to_string(std::chrono::floor<std::chrono::microseconds>(
2342 info[jss::network_ledger] =
"waiting";
2344 info[jss::validation_quorum] =
2352 info[jss::node_size] =
"tiny";
2355 info[jss::node_size] =
"small";
2358 info[jss::node_size] =
"medium";
2361 info[jss::node_size] =
"large";
2364 info[jss::node_size] =
"huge";
2373 info[jss::validator_list_expires] =
2374 safe_cast<Json::UInt>(when->time_since_epoch().count());
2376 info[jss::validator_list_expires] = 0;
2386 if (*when == TimeKeeper::time_point::max())
2388 x[jss::expiration] =
"never";
2389 x[jss::status] =
"active";
2396 x[jss::status] =
"active";
2398 x[jss::status] =
"expired";
2403 x[jss::status] =
"unknown";
2404 x[jss::expiration] =
"unknown";
2408 info[jss::io_latency_ms] =
2415 info[jss::pubkey_validator] =
toBase58(
2420 info[jss::pubkey_validator] =
"none";
2433 info[jss::counters][jss::nodestore] = nodestore;
2437 info[jss::pubkey_node] =
2443 info[jss::amendment_blocked] =
true;
2458 lastClose[jss::converge_time_s] =
2463 lastClose[jss::converge_time] =
2467 info[jss::last_close] = lastClose;
2477 info[jss::network_id] =
static_cast<Json::UInt>(*netid);
2479 auto const escalationMetrics =
2487 auto const loadFactorFeeEscalation =
2489 escalationMetrics.openLedgerFeeLevel,
2491 escalationMetrics.referenceFeeLevel)
2495 safe_cast<std::uint64_t>(loadFactorServer),
2496 loadFactorFeeEscalation);
2500 info[jss::load_base] = loadBaseServer;
2501 info[jss::load_factor] =
trunc32(loadFactor);
2502 info[jss::load_factor_server] = loadFactorServer;
2509 info[jss::load_factor_fee_escalation] =
2510 escalationMetrics.openLedgerFeeLevel.jsonClipped();
2511 info[jss::load_factor_fee_queue] =
2512 escalationMetrics.minProcessingFeeLevel.jsonClipped();
2513 info[jss::load_factor_fee_reference] =
2514 escalationMetrics.referenceFeeLevel.jsonClipped();
2518 info[jss::load_factor] =
2519 static_cast<double>(loadFactor) / loadBaseServer;
2521 if (loadFactorServer != loadFactor)
2522 info[jss::load_factor_server] =
2523 static_cast<double>(loadFactorServer) / loadBaseServer;
2528 if (fee != loadBaseServer)
2529 info[jss::load_factor_local] =
2530 static_cast<double>(fee) / loadBaseServer;
2532 if (fee != loadBaseServer)
2533 info[jss::load_factor_net] =
2534 static_cast<double>(fee) / loadBaseServer;
2536 if (fee != loadBaseServer)
2537 info[jss::load_factor_cluster] =
2538 static_cast<double>(fee) / loadBaseServer;
2540 if (escalationMetrics.openLedgerFeeLevel !=
2541 escalationMetrics.referenceFeeLevel &&
2542 (admin || loadFactorFeeEscalation != loadFactor))
2543 info[jss::load_factor_fee_escalation] =
2544 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
2545 escalationMetrics.referenceFeeLevel);
2546 if (escalationMetrics.minProcessingFeeLevel !=
2547 escalationMetrics.referenceFeeLevel)
2548 info[jss::load_factor_fee_queue] =
2549 escalationMetrics.minProcessingFeeLevel
2550 .decimalFromReference(
2551 escalationMetrics.referenceFeeLevel);
2565 XRPAmount const baseFee = lpClosed->fees().base;
2567 l[jss::seq] =
Json::UInt(lpClosed->info().seq);
2568 l[jss::hash] =
to_string(lpClosed->info().hash);
2573 l[jss::reserve_base] =
2574 lpClosed->fees().accountReserve(0).jsonClipped();
2575 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
2577 lpClosed->info().closeTime.time_since_epoch().count());
2582 l[jss::reserve_base_xrp] =
2583 lpClosed->fees().accountReserve(0).decimalXRP();
2584 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
2587 if (std::abs(nowOffset.count()) >= 60)
2588 l[jss::system_time_offset] = nowOffset.count();
2591 if (std::abs(closeOffset.count()) >= 60)
2592 l[jss::close_time_offset] = closeOffset.count();
2594 #if RIPPLED_REPORTING
2604 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2608 auto lCloseTime = lpClosed->info().closeTime;
2610 if (lCloseTime <= closeTime)
2612 using namespace std::chrono_literals;
2613 auto age = closeTime - lCloseTime;
2615 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2622 info[jss::validated_ledger] = l;
2624 info[jss::closed_ledger] = l;
2628 info[jss::published_ledger] =
"none";
2629 else if (lpPublished->info().seq != lpClosed->info().seq)
2630 info[jss::published_ledger] = lpPublished->info().seq;
2637 info[jss::jq_trans_overflow] =
2639 info[jss::peer_disconnects] =
2641 info[jss::peer_disconnects_resources] =
2682 p->send(jvObj,
true);
2701 if (jvObj[jss::validated].asBool())
2713 p->send(jvObj,
true);
2734 if (
auto p = i->second.lock())
2736 p->send(jvObj,
true);
2754 if (
auto p = i->second.lock())
2756 p->send(jvObj,
true);
2769 for (
auto& jv : jvObj)
2775 else if (jv.isString())
2799 if (jvObj.
isMember(jss::transaction))
2808 << __func__ <<
" : "
2809 <<
"error parsing json for accounts affected";
2818 for (
auto const& affectedAccount : accounts)
2823 auto it = simiIt->second.begin();
2825 while (it != simiIt->second.end())
2836 it = simiIt->second.erase(it);
2843 <<
" iProposed=" << iProposed;
2845 if (!notify.
empty())
2848 isrListener->send(jvObj,
true);
2862 alpAccepted = std::make_shared<AcceptedLedger>(lpAccepted,
app_);
2864 lpAccepted->info().hash, alpAccepted);
2867 assert(alpAccepted->getLedger().
get() == lpAccepted.
get());
2871 <<
"Publishing ledger " << lpAccepted->info().seq <<
" "
2872 << lpAccepted->info().hash;
2880 jvObj[jss::type] =
"ledgerClosed";
2881 jvObj[jss::ledger_index] = lpAccepted->info().seq;
2882 jvObj[jss::ledger_hash] =
to_string(lpAccepted->info().hash);
2884 lpAccepted->info().closeTime.time_since_epoch().count());
2886 jvObj[jss::fee_ref] = lpAccepted->fees().units.jsonClipped();
2887 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
2888 jvObj[jss::reserve_base] =
2889 lpAccepted->fees().accountReserve(0).jsonClipped();
2890 jvObj[jss::reserve_inc] =
2891 lpAccepted->fees().increment.jsonClipped();
2893 jvObj[jss::txn_count] =
Json::UInt(alpAccepted->size());
2897 jvObj[jss::validated_ledgers] =
2907 p->send(jvObj,
true);
2925 p->send(jvObj,
true);
2934 static bool firstTime =
true;
2941 for (
auto& inner : outer.second)
2943 auto& subInfo = inner.second;
2944 if (subInfo.index_->separationLedgerSeq_ == 0)
2947 alpAccepted->getLedger(), subInfo);
2956 for (
auto const& accTx : *alpAccepted)
2988 "reportConsensusStateChange->pubConsensus",
3007 const STTx& transaction,
3018 jvObj[jss::type] =
"transaction";
3023 jvObj[jss::ledger_index] = ledger->info().seq;
3024 jvObj[jss::ledger_hash] =
to_string(ledger->info().hash);
3025 jvObj[jss::transaction][jss::date] =
3026 ledger->info().closeTime.time_since_epoch().count();
3027 jvObj[jss::validated] =
true;
3033 jvObj[jss::validated] =
false;
3034 jvObj[jss::ledger_current_index] = ledger->info().seq;
3037 jvObj[jss::status] = validated ?
"closed" :
"proposed";
3038 jvObj[jss::engine_result] = sToken;
3039 jvObj[jss::engine_result_code] = result;
3040 jvObj[jss::engine_result_message] = sHuman;
3048 if (account != amount.issue().account)
3056 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3068 auto const& stTxn = transaction.
getTxn();
3074 auto const& meta = transaction.
getMeta();
3089 p->send(jvObj,
true);
3104 p->send(jvObj,
true);
3128 auto const currLedgerSeq = ledger->seq();
3135 for (
auto const& affectedAccount : transaction.
getAffected())
3140 auto it = simiIt->second.begin();
3142 while (it != simiIt->second.end())
3153 it = simiIt->second.erase(it);
3160 auto it = simiIt->second.begin();
3161 while (it != simiIt->second.end())
3172 it = simiIt->second.erase(it);
3179 auto& subs = histoIt->second;
3180 auto it = subs.begin();
3181 while (it != subs.end())
3184 if (currLedgerSeq <= info.index_->separationLedgerSeq_)
3198 it = subs.erase(it);
3209 <<
"pubAccountTransaction: "
3210 <<
"proposed=" << iProposed <<
", accepted=" << iAccepted;
3212 if (!notify.
empty() || !accountHistoryNotify.
empty())
3214 auto const& stTxn = transaction.
getTxn();
3220 auto const& meta = transaction.
getMeta();
3227 isrListener->send(jvObj,
true);
3229 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3230 for (
auto& info : accountHistoryNotify)
3232 auto& index = info.index_;
3233 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3234 jvObj[jss::account_history_tx_first] =
true;
3235 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3236 info.sink_->send(jvObj,
true);
3261 for (
auto const& affectedAccount : tx->getMentionedAccounts())
3266 auto it = simiIt->second.begin();
3268 while (it != simiIt->second.end())
3279 it = simiIt->second.erase(it);
3286 JLOG(
m_journal.
trace()) <<
"pubProposedAccountTransaction: " << iProposed;
3288 if (!notify.
empty() || !accountHistoryNotify.
empty())
3293 isrListener->send(jvObj,
true);
3295 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3296 for (
auto& info : accountHistoryNotify)
3298 auto& index = info.index_;
3299 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3300 jvObj[jss::account_history_tx_first] =
true;
3301 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3302 info.sink_->send(jvObj,
true);
3319 for (
auto const& naAccountID : vnaAccountIDs)
3322 <<
"subAccount: account: " <<
toBase58(naAccountID);
3324 isrListener->insertSubAccountInfo(naAccountID, rt);
3329 for (
auto const& naAccountID : vnaAccountIDs)
3331 auto simIterator = subMap.
find(naAccountID);
3332 if (simIterator == subMap.
end())
3336 usisElement[isrListener->getSeq()] = isrListener;
3338 subMap.
insert(simIterator, make_pair(naAccountID, usisElement));
3343 simIterator->second[isrListener->getSeq()] = isrListener;
3354 for (
auto const& naAccountID : vnaAccountIDs)
3357 isrListener->deleteSubAccountInfo(naAccountID, rt);
3374 for (
auto const& naAccountID : vnaAccountIDs)
3376 auto simIterator = subMap.
find(naAccountID);
3378 if (simIterator != subMap.
end())
3381 simIterator->second.erase(uSeq);
3383 if (simIterator->second.empty())
3386 subMap.
erase(simIterator);
3395 enum DatabaseType { Postgres, Sqlite, None };
3396 static const auto databaseType = [&]() -> DatabaseType {
3397 #ifdef RIPPLED_REPORTING
3404 return DatabaseType::Postgres;
3406 return DatabaseType::None;
3414 return DatabaseType::Sqlite;
3416 return DatabaseType::None;
3423 return DatabaseType::Sqlite;
3425 return DatabaseType::None;
3429 if (databaseType == DatabaseType::None)
3432 <<
"AccountHistory job for account "
3444 "AccountHistoryTxStream",
3445 [
this, dbType = databaseType, subInfo]() {
3446 auto const& accountId = subInfo.
index_->accountId_;
3447 auto& lastLedgerSeq = subInfo.
index_->historyLastLedgerSeq_;
3448 auto& txHistoryIndex = subInfo.
index_->historyTxIndex_;
3451 <<
"AccountHistory job for account " <<
toBase58(accountId)
3452 <<
" started. lastLedgerSeq=" << lastLedgerSeq;
3462 auto stx = tx->getSTransaction();
3463 if (stx->getAccountID(
sfAccount) == accountId &&
3464 stx->getSeqProxy().value() == 1)
3468 for (
auto& node : meta->getNodes())
3475 if (
auto inner =
dynamic_cast<const STObject*
>(
3480 inner->getAccountID(
sfAccount) == accountId)
3492 bool unsubscribe) ->
bool {
3495 sptr->send(jvObj,
true);
3521 auto [txResult, status] = db->getAccountTx(args);
3525 <<
"AccountHistory job for account "
3527 <<
" getAccountTx failed";
3532 std::get_if<RelationalDatabase::AccountTxs>(
3533 &txResult.transactions);
3541 <<
"AccountHistory job for account "
3543 <<
" getAccountTx wrong data";
3551 accountId, minLedger, maxLedger, marker, 0,
true};
3552 return db->newestAccountTxPage(options);
3564 while (lastLedgerSeq >= 2 && !subInfo.
index_->stopHistorical_)
3566 int feeChargeCount = 0;
3575 <<
"AccountHistory job for account "
3576 <<
toBase58(accountId) <<
" no InfoSub. Fee charged "
3577 << feeChargeCount <<
" times.";
3582 auto startLedgerSeq =
3583 (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
3585 <<
"AccountHistory job for account " <<
toBase58(accountId)
3586 <<
", working on ledger range [" << startLedgerSeq <<
","
3587 << lastLedgerSeq <<
"]";
3589 auto haveRange = [&]() ->
bool {
3592 auto haveSomeValidatedLedgers =
3594 validatedMin, validatedMax);
3596 return haveSomeValidatedLedgers &&
3597 validatedMin <= startLedgerSeq &&
3598 lastLedgerSeq <= validatedMax;
3604 <<
"AccountHistory reschedule job for account "
3605 <<
toBase58(accountId) <<
", incomplete ledger range ["
3606 << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
3612 while (!subInfo.
index_->stopHistorical_)
3615 getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
3619 <<
"AccountHistory job for account "
3620 <<
toBase58(accountId) <<
" getMoreTxns failed.";
3625 auto const& txns = dbResult->first;
3626 marker = dbResult->second;
3627 for (
auto const& [tx, meta] : txns)
3632 <<
"AccountHistory job for account "
3633 <<
toBase58(accountId) <<
" empty tx or meta.";
3643 <<
"AccountHistory job for account "
3644 <<
toBase58(accountId) <<
" no ledger.";
3649 tx->getSTransaction();
3653 <<
"AccountHistory job for account "
3655 <<
" getSTransaction failed.";
3660 *stTxn, meta->getResultTER(),
true, curTxLedger);
3662 jvTx[jss::account_history_tx_index] = txHistoryIndex--;
3664 jvTx[jss::meta], *curTxLedger, stTxn, *meta);
3665 if (isFirstTx(tx, meta))
3667 jvTx[jss::account_history_tx_first] =
true;
3671 <<
"AccountHistory job for account "
3673 <<
" done, found last tx.";
3685 <<
"AccountHistory job for account "
3687 <<
" paging, marker=" << marker->ledgerSeq <<
":"
3696 if (!subInfo.
index_->stopHistorical_)
3698 lastLedgerSeq = startLedgerSeq - 1;
3699 if (lastLedgerSeq <= 1)
3702 <<
"AccountHistory job for account "
3704 <<
" done, reached genesis ledger.";
3717 subInfo.
index_->separationLedgerSeq_ = ledger->seq();
3718 auto const& accountId = subInfo.
index_->accountId_;
3720 if (!ledger->exists(accountKeylet))
3723 <<
"subAccountHistoryStart, no account " <<
toBase58(accountId)
3724 <<
", no need to add AccountHistory job.";
3729 if (
auto const sleAcct = ledger->read(accountKeylet); sleAcct)
3734 <<
"subAccountHistoryStart, genesis account "
3736 <<
" does not have tx, no need to add AccountHistory job.";
3746 subInfo.
index_->historyLastLedgerSeq_ = ledger->seq();
3747 subInfo.
index_->haveHistorical_ =
true;
3750 <<
"subAccountHistoryStart, add AccountHistory job: accountId="
3751 <<
toBase58(accountId) <<
", currentLedgerSeq=" << ledger->seq();
3761 if (!isrListener->insertSubAccountHistory(accountId))
3764 <<
"subAccountHistory, already subscribed to account "
3771 isrListener, std::make_shared<SubAccountHistoryIndex>(accountId)};
3776 inner.
emplace(isrListener->getSeq(), ahi);
3782 simIterator->second.emplace(isrListener->getSeq(), ahi);
3796 <<
"subAccountHistory, no validated ledger yet, delay start";
3809 isrListener->deleteSubAccountHistory(account);
3823 auto& subInfoMap = simIterator->second;
3824 auto subInfoIter = subInfoMap.find(seq);
3825 if (subInfoIter != subInfoMap.end())
3827 subInfoIter->second.index_->stopHistorical_ =
true;
3832 simIterator->second.erase(seq);
3833 if (simIterator->second.empty())
3839 <<
"unsubAccountHistory, account " <<
toBase58(account)
3840 <<
", historyOnly = " << (historyOnly ?
"true" :
"false");
3848 listeners->addSubscriber(isrListener);
3858 listeners->removeSubscriber(uSeq);
3872 Throw<std::runtime_error>(
3873 "Operation only possible in STANDALONE mode.");
3888 jvResult[jss::ledger_index] = lpClosed->info().seq;
3889 jvResult[jss::ledger_hash] =
to_string(lpClosed->info().hash);
3891 lpClosed->info().closeTime.time_since_epoch().count());
3892 jvResult[jss::fee_ref] = lpClosed->fees().units.jsonClipped();
3893 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
3894 jvResult[jss::reserve_base] =
3895 lpClosed->fees().accountReserve(0).jsonClipped();
3896 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3901 jvResult[jss::validated_ledgers] =
3907 .emplace(isrListener->getSeq(), isrListener)
3917 .emplace(isrListener->getSeq(), isrListener)
3943 .emplace(isrListener->getSeq(), isrListener)
3971 jvResult[jss::random] =
to_string(uRandom);
3973 jvResult[jss::load_base] = feeTrack.getLoadBase();
3974 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
3975 jvResult[jss::hostid] =
getHostId(admin);
3976 jvResult[jss::pubkey_node] =
3981 .emplace(isrListener->getSeq(), isrListener)
3999 .emplace(isrListener->getSeq(), isrListener)
4017 .emplace(isrListener->getSeq(), isrListener)
4035 .emplace(isrListener->getSeq(), isrListener)
4059 .emplace(isrListener->getSeq(), isrListener)
4077 .emplace(isrListener->getSeq(), isrListener)
4125 if (map.find(pInfo->getSeq()) != map.end())
4132 #ifndef USE_NEW_BOOK_PAGE
4143 unsigned int iLimit,
4153 uint256 uTipIndex = uBookBase;
4157 stream <<
"getBookPage:" << book;
4158 stream <<
"getBookPage: uBookBase=" << uBookBase;
4159 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
4160 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
4169 bool bDirectAdvance =
true;
4173 unsigned int uBookEntry;
4179 while (!bDone && iLimit-- > 0)
4183 bDirectAdvance =
false;
4187 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
4191 sleOfferDir.
reset();
4200 uTipIndex = sleOfferDir->key();
4203 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
4206 <<
"getBookPage: uTipIndex=" << uTipIndex;
4208 <<
"getBookPage: offerIndex=" << offerIndex;
4218 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4219 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4220 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4222 bool firstOwnerOffer(
true);
4228 saOwnerFunds = saTakerGets;
4230 else if (bGlobalFreeze)
4238 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4239 if (umBalanceEntry != umBalance.
end())
4243 saOwnerFunds = umBalanceEntry->second;
4244 firstOwnerOffer =
false;
4258 if (saOwnerFunds < beast::zero)
4262 saOwnerFunds.
clear();
4270 STAmount saOwnerFundsLimit = saOwnerFunds;
4282 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4285 if (saOwnerFundsLimit >= saTakerGets)
4288 saTakerGetsFunded = saTakerGets;
4294 saTakerGetsFunded = saOwnerFundsLimit;
4296 saTakerGetsFunded.
setJson(jvOffer[jss::taker_gets_funded]);
4300 saTakerGetsFunded, saDirRate, saTakerPays.
issue()))
4301 .setJson(jvOffer[jss::taker_pays_funded]);
4307 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4309 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4313 jvOf[jss::quality] = saDirRate.
getText();
4315 if (firstOwnerOffer)
4316 jvOf[jss::owner_funds] = saOwnerFunds.
getText();
4323 if (!
cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
4325 bDirectAdvance =
true;
4330 <<
"getBookPage: offerIndex=" << offerIndex;
4350 unsigned int iLimit,
4358 MetaView lesActive(lpLedger,
tapNONE,
true);
4359 OrderBookIterator obIterator(lesActive, book);
4363 const bool bGlobalFreeze = lesActive.isGlobalFrozen(book.
out.
account) ||
4364 lesActive.isGlobalFrozen(book.
in.
account);
4366 while (iLimit-- > 0 && obIterator.nextOffer())
4371 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4372 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4373 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4374 STAmount saDirRate = obIterator.getCurrentRate();
4380 saOwnerFunds = saTakerGets;
4382 else if (bGlobalFreeze)
4390 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4392 if (umBalanceEntry != umBalance.
end())
4396 saOwnerFunds = umBalanceEntry->second;
4402 saOwnerFunds = lesActive.accountHolds(
4408 if (saOwnerFunds.isNegative())
4412 saOwnerFunds.zero();
4419 STAmount saTakerGetsFunded;
4420 STAmount saOwnerFundsLimit = saOwnerFunds;
4432 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4435 if (saOwnerFundsLimit >= saTakerGets)
4438 saTakerGetsFunded = saTakerGets;
4443 saTakerGetsFunded = saOwnerFundsLimit;
4445 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
4451 multiply(saTakerGetsFunded, saDirRate, saTakerPays.issue()))
4452 .setJson(jvOffer[jss::taker_pays_funded]);
4455 STAmount saOwnerPays = (
parityRate == offerRate)
4458 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4460 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4462 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
4466 jvOf[jss::quality] = saDirRate.
getText();
4481 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4521 ++counters_[
static_cast<std::size_t>(om)].transitions;
4523 counters_[
static_cast<std::size_t>(om)].transitions == 1)
4525 initialSyncUs_ = std::chrono::duration_cast<std::chrono::microseconds>(
4526 now - processStart_)
4530 std::chrono::duration_cast<std::chrono::microseconds>(now - start_);
4539 auto [counters, mode, start, initialSync] = getCounterData();
4540 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4550 auto& state = obj[jss::state_accounting][
states_[i]];
4551 state[jss::transitions] =
std::to_string(counters[i].transitions);
4552 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
4556 obj[jss::initial_sync_duration_us] =
std::to_string(initialSync);
4571 boost::asio::io_service& io_svc,
4575 return std::make_unique<NetworkOPsImp>(