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 result)
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,
615 const STTx& transaction,
774 template <
class Handler>
776 Handler
const& handler,
778 :
hook(collector->make_hook(handler))
781 "Disconnected_duration"))
784 "Connected_duration"))
786 collector->make_gauge(
"State_Accounting",
"Syncing_duration"))
789 "Tracking_duration"))
791 collector->make_gauge(
"State_Accounting",
"Full_duration"))
794 "Disconnected_transitions"))
797 "Connected_transitions"))
800 "Syncing_transitions"))
803 "Tracking_transitions"))
805 collector->make_gauge(
"State_Accounting",
"Full_transitions"))
834 {
"disconnected",
"connected",
"syncing",
"tracking",
"full"}};
896 static std::string const hostname = boost::asio::ip::host_name();
903 static std::string const shroudedHostId = [
this]() {
909 return shroudedHostId;
921 boost::asio::steady_timer& timer,
928 [
this, onExpire, onError](boost::system::error_code
const& e) {
929 if ((e.value() == boost::system::errc::success) &&
930 (!m_job_queue.isStopped()))
935 if (e.value() != boost::system::errc::success &&
936 e.value() != boost::asio::error::operation_aborted)
939 JLOG(m_journal.error())
940 <<
"Timer got error '" << e.message()
941 <<
"'. Restarting timer.";
946 timer.expires_from_now(expiry_time);
947 timer.async_wait(std::move(*optionalCountedHandler));
958 m_job_queue.addJob(jtNETOP_TIMER,
"NetOPs.heartbeat", [this]() {
959 processHeartbeatTimer();
962 [
this]() { setHeartbeatTimer(); });
966 NetworkOPsImp::setClusterTimer()
968 using namespace std::chrono_literals;
974 processClusterTimer();
977 [
this]() { setClusterTimer(); });
983 JLOG(m_journal.debug()) <<
"Scheduling AccountHistory job for account "
985 using namespace std::chrono_literals;
987 accountHistoryTxTimer_,
989 [
this, subInfo]() { addAccountHistoryJob(subInfo); },
990 [
this, subInfo]() { setAccountHistoryJobTimer(subInfo); });
994 NetworkOPsImp::processHeartbeatTimer()
1003 std::size_t const numPeers = app_.overlay().size();
1006 if (numPeers < minPeerCount_)
1008 if (mMode != OperatingMode::DISCONNECTED)
1010 setMode(OperatingMode::DISCONNECTED);
1011 JLOG(m_journal.warn())
1012 <<
"Node count (" << numPeers <<
") has fallen "
1013 <<
"below required minimum (" << minPeerCount_ <<
").";
1020 setHeartbeatTimer();
1024 if (mMode == OperatingMode::DISCONNECTED)
1026 setMode(OperatingMode::CONNECTED);
1027 JLOG(m_journal.info())
1028 <<
"Node count (" << numPeers <<
") is sufficient.";
1033 if (mMode == OperatingMode::SYNCING)
1034 setMode(OperatingMode::SYNCING);
1035 else if (mMode == OperatingMode::CONNECTED)
1036 setMode(OperatingMode::CONNECTED);
1039 mConsensus.timerEntry(app_.timeKeeper().closeTime());
1042 if (mLastConsensusPhase != currPhase)
1044 reportConsensusStateChange(currPhase);
1045 mLastConsensusPhase = currPhase;
1048 setHeartbeatTimer();
1052 NetworkOPsImp::processClusterTimer()
1054 using namespace std::chrono_literals;
1055 bool const update = app_.cluster().update(
1056 app_.nodeIdentity().first,
1058 (m_ledgerMaster.getValidatedLedgerAge() <= 4
min)
1059 ? app_.getFeeTrack().getLocalFee()
1061 app_.timeKeeper().now());
1065 JLOG(m_journal.debug()) <<
"Too soon to send cluster update";
1070 protocol::TMCluster cluster;
1071 app_.cluster().for_each([&cluster](
ClusterNode const& node) {
1072 protocol::TMClusterNode& n = *cluster.add_clusternodes();
1077 n.set_nodename(node.
name());
1081 for (
auto& item : gossip.
items)
1083 protocol::TMLoadSource& node = *cluster.add_loadsources();
1085 node.set_cost(item.balance);
1087 app_.overlay().foreach(
send_if(
1088 std::make_shared<Message>(cluster, protocol::mtCLUSTER),
1099 if (mode == OperatingMode::FULL && admin)
1101 auto const consensusMode = mConsensus.mode();
1102 if (consensusMode != ConsensusMode::wrongLedger)
1104 if (consensusMode == ConsensusMode::proposing)
1107 if (mConsensus.validating())
1108 return "validating";
1118 if (isNeedNetworkLedger())
1127 auto const txid = trans->getTransactionID();
1128 auto const flags = app_.getHashRouter().getFlags(txid);
1130 if ((flags & SF_BAD) != 0)
1132 JLOG(m_journal.warn()) <<
"Submitted transaction cached bad";
1139 app_.getHashRouter(),
1141 m_ledgerMaster.getValidatedRules(),
1144 if (validity != Validity::Valid)
1146 JLOG(m_journal.warn())
1147 <<
"Submitted transaction invalid: " << reason;
1153 JLOG(m_journal.warn()) <<
"Exception checking transaction" << txid;
1160 auto tx = std::make_shared<Transaction>(trans, reason, app_);
1162 m_job_queue.addJob(
jtTRANSACTION,
"submitTxn", [
this, tx]() {
1164 processTransaction(t,
false,
false, FailHard::no);
1169 NetworkOPsImp::processTransaction(
1175 auto ev = m_job_queue.makeLoadEvent(
jtTXN_PROC,
"ProcessTXN");
1176 auto const newFlags = app_.getHashRouter().getFlags(transaction->getID());
1178 if ((newFlags & SF_BAD) != 0)
1181 JLOG(m_journal.warn()) << transaction->getID() <<
": cached bad!\n";
1182 transaction->setStatus(
INVALID);
1190 auto const view = m_ledgerMaster.getCurrentLedger();
1192 app_.getHashRouter(),
1193 *transaction->getSTransaction(),
1196 assert(validity == Validity::Valid);
1199 if (validity == Validity::SigBad)
1201 JLOG(m_journal.info()) <<
"Transaction has bad signature: " << reason;
1202 transaction->setStatus(
INVALID);
1204 app_.getHashRouter().setFlags(transaction->getID(), SF_BAD);
1209 app_.getMasterTransaction().canonicalize(&transaction);
1212 doTransactionSync(transaction, bUnlimited, failType);
1214 doTransactionAsync(transaction, bUnlimited, failType);
1218 NetworkOPsImp::doTransactionAsync(
1225 if (transaction->getApplying())
1228 mTransactions.push_back(
1230 transaction->setApplying();
1232 if (mDispatchState == DispatchState::none)
1234 if (m_job_queue.addJob(
1235 jtBATCH,
"transactionBatch", [
this]() { transactionBatch(); }))
1237 mDispatchState = DispatchState::scheduled;
1243 NetworkOPsImp::doTransactionSync(
1250 if (!transaction->getApplying())
1252 mTransactions.push_back(
1254 transaction->setApplying();
1259 if (mDispatchState == DispatchState::running)
1268 if (mTransactions.size())
1271 if (m_job_queue.addJob(
jtBATCH,
"transactionBatch", [
this]() {
1275 mDispatchState = DispatchState::scheduled;
1279 }
while (transaction->getApplying());
1283 NetworkOPsImp::transactionBatch()
1287 if (mDispatchState == DispatchState::running)
1290 while (mTransactions.size())
1301 mTransactions.
swap(transactions);
1302 assert(!transactions.
empty());
1304 assert(mDispatchState != DispatchState::running);
1305 mDispatchState = DispatchState::running;
1311 bool changed =
false;
1314 m_ledgerMaster.peekMutex(), std::defer_lock};
1325 if (e.failType == FailHard::yes)
1328 auto const result = app_.getTxQ().apply(
1329 app_, view, e.transaction->getSTransaction(), flags, j);
1330 e.result = result.first;
1331 e.applied = result.second;
1332 changed = changed || result.second;
1341 if (
auto const l = m_ledgerMaster.getValidatedLedger())
1342 validatedLedgerIndex = l->info().seq;
1344 auto newOL = app_.openLedger().current();
1347 e.transaction->clearSubmitResult();
1351 pubProposedTransaction(
1352 newOL, e.transaction->getSTransaction(), e.result);
1353 e.transaction->setApplied();
1356 e.transaction->setResult(e.result);
1359 app_.getHashRouter().setFlags(e.transaction->getID(), SF_BAD);
1368 JLOG(m_journal.info())
1369 <<
"TransactionResult: " << token <<
": " << human;
1374 bool addLocal = e.local;
1378 JLOG(m_journal.debug())
1379 <<
"Transaction is now included in open ledger";
1380 e.transaction->setStatus(
INCLUDED);
1382 auto const& txCur = e.transaction->getSTransaction();
1383 auto const txNext = m_ledgerMaster.popAcctTransaction(txCur);
1388 auto t = std::make_shared<Transaction>(trans, reason, app_);
1389 submit_held.
emplace_back(t,
false,
false, FailHard::no);
1396 JLOG(m_journal.info()) <<
"Transaction is obsolete";
1397 e.transaction->setStatus(
OBSOLETE);
1401 JLOG(m_journal.debug())
1402 <<
"Transaction is likely to claim a"
1403 <<
" fee, but is queued until fee drops";
1405 e.transaction->setStatus(
HELD);
1409 m_ledgerMaster.addHeldTransaction(e.transaction);
1410 e.transaction->setQueued();
1411 e.transaction->setKept();
1415 if (e.failType != FailHard::yes)
1418 JLOG(m_journal.debug())
1419 <<
"Transaction should be held: " << e.result;
1420 e.transaction->setStatus(
HELD);
1421 m_ledgerMaster.addHeldTransaction(e.transaction);
1422 e.transaction->setKept();
1427 JLOG(m_journal.debug())
1428 <<
"Status other than success " << e.result;
1429 e.transaction->setStatus(
INVALID);
1432 auto const enforceFailHard =
1433 e.failType == FailHard::yes && !
isTesSuccess(e.result);
1435 if (addLocal && !enforceFailHard)
1437 m_localTX->push_back(
1438 m_ledgerMaster.getCurrentLedgerIndex(),
1439 e.transaction->getSTransaction());
1440 e.transaction->setKept();
1444 ((mMode != OperatingMode::FULL) &&
1445 (e.failType != FailHard::yes) && e.local) ||
1450 app_.getHashRouter().shouldRelay(e.transaction->getID());
1454 protocol::TMTransaction tx;
1457 e.transaction->getSTransaction()->add(s);
1458 tx.set_rawtransaction(s.
data(), s.
size());
1459 tx.set_status(protocol::tsCURRENT);
1460 tx.set_receivetimestamp(
1461 app_.timeKeeper().now().time_since_epoch().count());
1464 app_.overlay().relay(e.transaction->getID(), tx, *toSkip);
1465 e.transaction->setBroadcast();
1469 if (validatedLedgerIndex)
1471 auto [fee, accountSeq, availableSeq] =
1472 app_.getTxQ().getTxRequiredFeeAndSeq(
1473 *newOL, e.transaction->getSTransaction());
1474 e.transaction->setCurrentLedgerState(
1475 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1483 e.transaction->clearApplying();
1485 if (!submit_held.
empty())
1487 if (mTransactions.empty())
1488 mTransactions.swap(submit_held);
1490 for (
auto& e : submit_held)
1491 mTransactions.push_back(std::move(e));
1496 mDispatchState = DispatchState::none;
1504 NetworkOPsImp::getOwnerInfo(
1509 auto root = keylet::ownerDir(account);
1510 auto sleNode = lpLedger->read(keylet::page(root));
1517 for (
auto const& uDirEntry : sleNode->getFieldV256(
sfIndexes))
1519 auto sleCur = lpLedger->read(keylet::child(uDirEntry));
1522 switch (sleCur->getType())
1525 if (!jvObjects.
isMember(jss::offers))
1526 jvObjects[jss::offers] =
1529 jvObjects[jss::offers].
append(
1530 sleCur->getJson(JsonOptions::none));
1534 if (!jvObjects.
isMember(jss::ripple_lines))
1536 jvObjects[jss::ripple_lines] =
1540 jvObjects[jss::ripple_lines].
append(
1541 sleCur->getJson(JsonOptions::none));
1556 sleNode = lpLedger->read(keylet::page(root, uNodeDir));
1570 NetworkOPsImp::isBlocked()
1572 return isAmendmentBlocked() || isUNLBlocked();
1576 NetworkOPsImp::isAmendmentBlocked()
1578 return amendmentBlocked_;
1582 NetworkOPsImp::setAmendmentBlocked()
1584 amendmentBlocked_ =
true;
1585 setMode(OperatingMode::CONNECTED);
1589 NetworkOPsImp::isAmendmentWarned()
1591 return !amendmentBlocked_ && amendmentWarned_;
1595 NetworkOPsImp::setAmendmentWarned()
1597 amendmentWarned_ =
true;
1601 NetworkOPsImp::clearAmendmentWarned()
1603 amendmentWarned_ =
false;
1607 NetworkOPsImp::isUNLBlocked()
1613 NetworkOPsImp::setUNLBlocked()
1616 setMode(OperatingMode::CONNECTED);
1620 NetworkOPsImp::clearUNLBlocked()
1622 unlBlocked_ =
false;
1626 NetworkOPsImp::checkLastClosedLedger(
1635 JLOG(m_journal.trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
1637 auto const ourClosed = m_ledgerMaster.getClosedLedger();
1642 uint256 closedLedger = ourClosed->info().hash;
1643 uint256 prevClosedLedger = ourClosed->info().parentHash;
1644 JLOG(m_journal.trace()) <<
"OurClosed: " << closedLedger;
1645 JLOG(m_journal.trace()) <<
"PrevClosed: " << prevClosedLedger;
1650 auto& validations = app_.getValidations();
1651 JLOG(m_journal.debug())
1652 <<
"ValidationTrie " <<
Json::Compact(validations.getJsonTrie());
1656 peerCounts[closedLedger] = 0;
1657 if (mMode >= OperatingMode::TRACKING)
1658 peerCounts[closedLedger]++;
1660 for (
auto& peer : peerList)
1662 uint256 peerLedger = peer->getClosedLedgerHash();
1665 ++peerCounts[peerLedger];
1668 for (
auto const& it : peerCounts)
1669 JLOG(m_journal.debug()) <<
"L: " << it.first <<
" n=" << it.second;
1671 uint256 preferredLCL = validations.getPreferredLCL(
1673 m_ledgerMaster.getValidLedgerIndex(),
1676 bool switchLedgers = preferredLCL != closedLedger;
1678 closedLedger = preferredLCL;
1680 if (switchLedgers && (closedLedger == prevClosedLedger))
1683 JLOG(m_journal.info()) <<
"We won't switch to our own previous ledger";
1684 networkClosed = ourClosed->info().hash;
1685 switchLedgers =
false;
1688 networkClosed = closedLedger;
1693 auto consensus = m_ledgerMaster.getLedgerByHash(closedLedger);
1696 consensus = app_.getInboundLedgers().acquire(
1697 closedLedger, 0, InboundLedger::Reason::CONSENSUS);
1700 (!m_ledgerMaster.canBeCurrent(consensus) ||
1701 !m_ledgerMaster.isCompatible(
1702 *consensus, m_journal.debug(),
"Not switching")))
1706 networkClosed = ourClosed->info().hash;
1710 JLOG(m_journal.warn()) <<
"We are not running on the consensus ledger";
1711 JLOG(m_journal.info()) <<
"Our LCL: " <<
getJson({*ourClosed, {}});
1712 JLOG(m_journal.info()) <<
"Net LCL " << closedLedger;
1714 if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
1716 setMode(OperatingMode::CONNECTED);
1724 switchLastClosedLedger(consensus);
1731 NetworkOPsImp::switchLastClosedLedger(
1735 JLOG(m_journal.error())
1736 <<
"JUMP last closed ledger to " << newLCL->info().hash;
1738 clearNeedNetworkLedger();
1741 app_.getTxQ().processClosedLedger(app_, *newLCL,
true);
1748 auto retries = m_localTX->getTxSet();
1749 auto const lastVal = app_.getLedgerMaster().getValidatedLedger();
1752 rules.
emplace(*lastVal, app_.config().features);
1754 rules.
emplace(app_.config().features);
1755 app_.openLedger().accept(
1766 return app_.getTxQ().accept(app_, view);
1770 m_ledgerMaster.switchLCL(newLCL);
1772 protocol::TMStatusChange s;
1773 s.set_newevent(protocol::neSWITCHED_LEDGER);
1774 s.set_ledgerseq(newLCL->info().seq);
1775 s.set_networktime(app_.timeKeeper().now().time_since_epoch().count());
1776 s.set_ledgerhashprevious(
1777 newLCL->info().parentHash.begin(), newLCL->info().parentHash.size());
1778 s.set_ledgerhash(newLCL->info().hash.begin(), newLCL->info().hash.size());
1780 app_.overlay().foreach(
1781 send_always(std::make_shared<Message>(s, protocol::mtSTATUS_CHANGE)));
1785 NetworkOPsImp::beginConsensus(
uint256 const& networkClosed)
1789 auto closingInfo = m_ledgerMaster.getCurrentLedger()->info();
1791 JLOG(m_journal.info()) <<
"Consensus time for #" << closingInfo.seq
1792 <<
" with LCL " << closingInfo.parentHash;
1794 auto prevLedger = m_ledgerMaster.getLedgerByHash(closingInfo.parentHash);
1799 if (mMode == OperatingMode::FULL)
1801 JLOG(m_journal.warn()) <<
"Don't have LCL, going to tracking";
1802 setMode(OperatingMode::TRACKING);
1808 assert(prevLedger->info().hash == closingInfo.parentHash);
1810 closingInfo.parentHash ==
1811 m_ledgerMaster.getClosedLedger()->info().hash);
1814 app_.validators().setNegativeUNL(prevLedger->negativeUNL());
1815 TrustChanges const changes = app_.validators().updateTrusted(
1816 app_.getValidations().getCurrentNodeIDs(),
1817 closingInfo.parentCloseTime,
1820 app_.getHashRouter());
1822 if (!changes.
added.empty() || !changes.
removed.empty())
1823 app_.getValidations().trustChanged(changes.
added, changes.
removed);
1825 mConsensus.startRound(
1826 app_.timeKeeper().closeTime(),
1833 if (mLastConsensusPhase != currPhase)
1835 reportConsensusStateChange(currPhase);
1836 mLastConsensusPhase = currPhase;
1839 JLOG(m_journal.debug()) <<
"Initiating consensus engine";
1846 return mConsensus.peerProposal(app_.timeKeeper().closeTime(), peerPos);
1857 protocol::TMHaveTransactionSet msg;
1858 msg.set_hash(map->getHash().as_uint256().begin(), 256 / 8);
1859 msg.set_status(protocol::tsHAVE);
1860 app_.overlay().foreach(
1861 send_always(std::make_shared<Message>(msg, protocol::mtHAVE_SET)));
1865 mConsensus.gotTxSet(app_.timeKeeper().closeTime(),
RCLTxSet{map});
1869 NetworkOPsImp::endConsensus()
1871 uint256 deadLedger = m_ledgerMaster.getClosedLedger()->info().parentHash;
1873 for (
auto const& it : app_.overlay().getActivePeers())
1875 if (it && (it->getClosedLedgerHash() == deadLedger))
1877 JLOG(m_journal.trace()) <<
"Killing obsolete peer status";
1884 checkLastClosedLedger(app_.overlay().getActivePeers(), networkClosed);
1886 if (networkClosed.
isZero())
1895 if (((mMode == OperatingMode::CONNECTED) ||
1896 (mMode == OperatingMode::SYNCING)) &&
1902 if (!needNetworkLedger_)
1903 setMode(OperatingMode::TRACKING);
1906 if (((mMode == OperatingMode::CONNECTED) ||
1907 (mMode == OperatingMode::TRACKING)) &&
1913 auto current = m_ledgerMaster.getCurrentLedger();
1914 if (app_.timeKeeper().now() < (
current->info().parentCloseTime +
1915 2 *
current->info().closeTimeResolution))
1917 setMode(OperatingMode::FULL);
1921 beginConsensus(networkClosed);
1925 NetworkOPsImp::consensusViewChange()
1927 if ((mMode == OperatingMode::FULL) || (mMode == OperatingMode::TRACKING))
1929 setMode(OperatingMode::CONNECTED);
1939 if (!mStreamMaps[sManifests].empty())
1943 jvObj[jss::type] =
"manifestReceived";
1946 jvObj[jss::signing_key] =
1950 jvObj[jss::signature] =
strHex(*sig);
1953 jvObj[jss::domain] = mo.
domain;
1956 for (
auto i = mStreamMaps[sManifests].begin();
1957 i != mStreamMaps[sManifests].end();)
1959 if (
auto p = i->second.lock())
1961 p->send(jvObj,
true);
1966 i = mStreamMaps[sManifests].erase(i);
1972 NetworkOPsImp::ServerFeeSummary::ServerFeeSummary(
1977 , loadBaseServer{loadFeeTrack.getLoadBase()}
1979 , em{std::move(escalationMetrics)}
1989 em.has_value() != b.
em.has_value())
1995 em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
1996 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
1997 em->referenceFeeLevel != b.
em->referenceFeeLevel);
2030 jvObj[jss::type] =
"serverStatus";
2032 jvObj[jss::load_base] = f.loadBaseServer;
2033 jvObj[jss::load_factor_server] = f.loadFactorServer;
2034 jvObj[jss::base_fee] = f.baseFee.jsonClipped();
2039 safe_cast<std::uint64_t>(f.loadFactorServer),
2041 f.em->openLedgerFeeLevel,
2043 f.em->referenceFeeLevel)
2046 jvObj[jss::load_factor] =
trunc32(loadFactor);
2047 jvObj[jss::load_factor_fee_escalation] =
2048 f.em->openLedgerFeeLevel.jsonClipped();
2049 jvObj[jss::load_factor_fee_queue] =
2050 f.em->minProcessingFeeLevel.jsonClipped();
2051 jvObj[jss::load_factor_fee_reference] =
2052 f.em->referenceFeeLevel.jsonClipped();
2055 jvObj[jss::load_factor] = f.loadFactorServer;
2069 p->send(jvObj,
true);
2086 if (!streamMap.empty())
2089 jvObj[jss::type] =
"consensusPhase";
2090 jvObj[jss::consensus] =
to_string(phase);
2092 for (
auto i = streamMap.begin(); i != streamMap.end();)
2094 if (
auto p = i->second.lock())
2096 p->send(jvObj,
true);
2101 i = streamMap.erase(i);
2117 auto const signerPublic = val->getSignerPublic();
2119 jvObj[jss::type] =
"validationReceived";
2120 jvObj[jss::validation_public_key] =
2122 jvObj[jss::ledger_hash] =
to_string(val->getLedgerHash());
2123 jvObj[jss::signature] =
strHex(val->getSignature());
2124 jvObj[jss::full] = val->isFull();
2125 jvObj[jss::flags] = val->getFlags();
2127 jvObj[jss::data] =
strHex(val->getSerializer().slice());
2132 if (
auto cookie = (*val)[~
sfCookie])
2136 jvObj[jss::validated_hash] =
strHex(*hash);
2138 auto const masterKey =
2141 if (masterKey != signerPublic)
2145 jvObj[jss::ledger_index] =
to_string(*seq);
2150 for (
auto const& amendment : val->getFieldV256(
sfAmendments))
2155 jvObj[jss::close_time] = *closeTime;
2157 if (
auto const loadFee = (*val)[~
sfLoadFee])
2158 jvObj[jss::load_fee] = *loadFee;
2160 if (
auto const baseFee = (*val)[~
sfBaseFee])
2161 jvObj[jss::base_fee] =
static_cast<double>(*baseFee);
2164 jvObj[jss::reserve_base] = *reserveBase;
2167 jvObj[jss::reserve_inc] = *reserveInc;
2172 if (
auto p = i->second.lock())
2174 p->send(jvObj,
true);
2194 jvObj[jss::type] =
"peerStatusChange";
2203 p->send(jvObj,
true);
2217 using namespace std::chrono_literals;
2249 <<
"recvValidation " << val->getLedgerHash() <<
" from " << source;
2279 "This server is amendment blocked, and must be updated to be "
2280 "able to stay in sync with the network.";
2287 "This server has an expired validator list. validators.txt "
2288 "may be incorrectly configured or some [validator_list_sites] "
2289 "may be unreachable.";
2296 "One or more unsupported amendments have reached majority. "
2297 "Upgrade to the latest version before they are activated "
2298 "to avoid being amendment blocked.";
2299 if (
auto const expected =
2303 d[jss::expected_date] = expected->time_since_epoch().count();
2304 d[jss::expected_date_UTC] =
to_string(*expected);
2308 if (warnings.size())
2309 info[jss::warnings] = std::move(warnings);
2322 info[jss::network_id] =
static_cast<Json::UInt>(*netid);
2328 info[jss::time] =
to_string(std::chrono::floor<std::chrono::microseconds>(
2332 info[jss::network_ledger] =
"waiting";
2334 info[jss::validation_quorum] =
2342 info[jss::node_size] =
"tiny";
2345 info[jss::node_size] =
"small";
2348 info[jss::node_size] =
"medium";
2351 info[jss::node_size] =
"large";
2354 info[jss::node_size] =
"huge";
2363 info[jss::validator_list_expires] =
2364 safe_cast<Json::UInt>(when->time_since_epoch().count());
2366 info[jss::validator_list_expires] = 0;
2376 if (*when == TimeKeeper::time_point::max())
2378 x[jss::expiration] =
"never";
2379 x[jss::status] =
"active";
2386 x[jss::status] =
"active";
2388 x[jss::status] =
"expired";
2393 x[jss::status] =
"unknown";
2394 x[jss::expiration] =
"unknown";
2398 info[jss::io_latency_ms] =
2405 info[jss::pubkey_validator] =
toBase58(
2410 info[jss::pubkey_validator] =
"none";
2423 info[jss::counters][jss::nodestore] = nodestore;
2427 info[jss::pubkey_node] =
2433 info[jss::amendment_blocked] =
true;
2448 lastClose[jss::converge_time_s] =
2453 lastClose[jss::converge_time] =
2457 info[jss::last_close] = lastClose;
2466 auto const escalationMetrics =
2474 auto const loadFactorFeeEscalation =
2476 escalationMetrics.openLedgerFeeLevel,
2478 escalationMetrics.referenceFeeLevel)
2482 safe_cast<std::uint64_t>(loadFactorServer),
2483 loadFactorFeeEscalation);
2487 info[jss::load_base] = loadBaseServer;
2488 info[jss::load_factor] =
trunc32(loadFactor);
2489 info[jss::load_factor_server] = loadFactorServer;
2496 info[jss::load_factor_fee_escalation] =
2497 escalationMetrics.openLedgerFeeLevel.jsonClipped();
2498 info[jss::load_factor_fee_queue] =
2499 escalationMetrics.minProcessingFeeLevel.jsonClipped();
2500 info[jss::load_factor_fee_reference] =
2501 escalationMetrics.referenceFeeLevel.jsonClipped();
2505 info[jss::load_factor] =
2506 static_cast<double>(loadFactor) / loadBaseServer;
2508 if (loadFactorServer != loadFactor)
2509 info[jss::load_factor_server] =
2510 static_cast<double>(loadFactorServer) / loadBaseServer;
2515 if (fee != loadBaseServer)
2516 info[jss::load_factor_local] =
2517 static_cast<double>(fee) / loadBaseServer;
2519 if (fee != loadBaseServer)
2520 info[jss::load_factor_net] =
2521 static_cast<double>(fee) / loadBaseServer;
2523 if (fee != loadBaseServer)
2524 info[jss::load_factor_cluster] =
2525 static_cast<double>(fee) / loadBaseServer;
2527 if (escalationMetrics.openLedgerFeeLevel !=
2528 escalationMetrics.referenceFeeLevel &&
2529 (admin || loadFactorFeeEscalation != loadFactor))
2530 info[jss::load_factor_fee_escalation] =
2531 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
2532 escalationMetrics.referenceFeeLevel);
2533 if (escalationMetrics.minProcessingFeeLevel !=
2534 escalationMetrics.referenceFeeLevel)
2535 info[jss::load_factor_fee_queue] =
2536 escalationMetrics.minProcessingFeeLevel
2537 .decimalFromReference(
2538 escalationMetrics.referenceFeeLevel);
2552 XRPAmount const baseFee = lpClosed->fees().base;
2554 l[jss::seq] =
Json::UInt(lpClosed->info().seq);
2555 l[jss::hash] =
to_string(lpClosed->info().hash);
2560 l[jss::reserve_base] =
2561 lpClosed->fees().accountReserve(0).jsonClipped();
2562 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
2564 lpClosed->info().closeTime.time_since_epoch().count());
2569 l[jss::reserve_base_xrp] =
2570 lpClosed->fees().accountReserve(0).decimalXRP();
2571 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
2574 if (std::abs(nowOffset.count()) >= 60)
2575 l[jss::system_time_offset] = nowOffset.count();
2578 if (std::abs(closeOffset.count()) >= 60)
2579 l[jss::close_time_offset] = closeOffset.count();
2581 #if RIPPLED_REPORTING
2591 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2595 auto lCloseTime = lpClosed->info().closeTime;
2597 if (lCloseTime <= closeTime)
2599 using namespace std::chrono_literals;
2600 auto age = closeTime - lCloseTime;
2602 Json::UInt(age < highAgeThreshold ? age.count() : 0);
2609 info[jss::validated_ledger] = l;
2611 info[jss::closed_ledger] = l;
2615 info[jss::published_ledger] =
"none";
2616 else if (lpPublished->info().seq != lpClosed->info().seq)
2617 info[jss::published_ledger] = lpPublished->info().seq;
2624 info[jss::jq_trans_overflow] =
2626 info[jss::peer_disconnects] =
2628 info[jss::peer_disconnects_resources] =
2669 p->send(jvObj,
true);
2688 if (jvObj[jss::validated].asBool())
2700 p->send(jvObj,
true);
2721 if (
auto p = i->second.lock())
2723 p->send(jvObj,
true);
2741 if (
auto p = i->second.lock())
2743 p->send(jvObj,
true);
2756 for (
auto& jv : jvObj)
2762 else if (jv.isString())
2786 if (jvObj.
isMember(jss::transaction))
2795 << __func__ <<
" : "
2796 <<
"error parsing json for accounts affected";
2805 for (
auto const& affectedAccount : accounts)
2810 auto it = simiIt->second.begin();
2812 while (it != simiIt->second.end())
2823 it = simiIt->second.erase(it);
2830 <<
" iProposed=" << iProposed;
2832 if (!notify.
empty())
2835 isrListener->send(jvObj,
true);
2849 alpAccepted = std::make_shared<AcceptedLedger>(lpAccepted,
app_);
2851 lpAccepted->info().hash, alpAccepted);
2854 assert(alpAccepted->getLedger().
get() == lpAccepted.
get());
2858 <<
"Publishing ledger " << lpAccepted->info().seq <<
" "
2859 << lpAccepted->info().hash;
2867 jvObj[jss::type] =
"ledgerClosed";
2868 jvObj[jss::ledger_index] = lpAccepted->info().seq;
2869 jvObj[jss::ledger_hash] =
to_string(lpAccepted->info().hash);
2871 lpAccepted->info().closeTime.time_since_epoch().count());
2873 jvObj[jss::fee_ref] = lpAccepted->fees().units.jsonClipped();
2874 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
2875 jvObj[jss::reserve_base] =
2876 lpAccepted->fees().accountReserve(0).jsonClipped();
2877 jvObj[jss::reserve_inc] =
2878 lpAccepted->fees().increment.jsonClipped();
2880 jvObj[jss::txn_count] =
Json::UInt(alpAccepted->size());
2884 jvObj[jss::validated_ledgers] =
2894 p->send(jvObj,
true);
2903 static bool firstTime =
true;
2910 for (
auto& inner : outer.second)
2912 auto& subInfo = inner.second;
2913 if (subInfo.index_->separationLedgerSeq_ == 0)
2916 alpAccepted->getLedger(), subInfo);
2925 for (
auto const& accTx : *alpAccepted)
2957 "reportConsensusStateChange->pubConsensus",
2976 const STTx& transaction,
2987 jvObj[jss::type] =
"transaction";
2992 jvObj[jss::ledger_index] = ledger->info().seq;
2993 jvObj[jss::ledger_hash] =
to_string(ledger->info().hash);
2994 jvObj[jss::transaction][jss::date] =
2995 ledger->info().closeTime.time_since_epoch().count();
2996 jvObj[jss::validated] =
true;
3002 jvObj[jss::validated] =
false;
3003 jvObj[jss::ledger_current_index] = ledger->info().seq;
3006 jvObj[jss::status] = validated ?
"closed" :
"proposed";
3007 jvObj[jss::engine_result] = sToken;
3008 jvObj[jss::engine_result_code] = result;
3009 jvObj[jss::engine_result_message] = sHuman;
3017 if (account != amount.issue().account)
3025 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3037 auto const& stTxn = transaction.
getTxn();
3043 auto const& meta = transaction.
getMeta();
3058 p->send(jvObj,
true);
3073 p->send(jvObj,
true);
3097 auto const currLedgerSeq = ledger->seq();
3104 for (
auto const& affectedAccount : transaction.
getAffected())
3109 auto it = simiIt->second.begin();
3111 while (it != simiIt->second.end())
3122 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 <= info.index_->separationLedgerSeq_)
3167 it = subs.erase(it);
3178 <<
"pubAccountTransaction: "
3179 <<
"proposed=" << iProposed <<
", accepted=" << iAccepted;
3181 if (!notify.
empty() || !accountHistoryNotify.
empty())
3183 auto const& stTxn = transaction.
getTxn();
3189 auto const& meta = transaction.
getMeta();
3196 isrListener->send(jvObj,
true);
3198 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3199 for (
auto& info : accountHistoryNotify)
3201 auto& index = info.index_;
3202 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3203 jvObj[jss::account_history_tx_first] =
true;
3204 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3205 info.sink_->send(jvObj,
true);
3230 for (
auto const& affectedAccount : tx->getMentionedAccounts())
3235 auto it = simiIt->second.begin();
3237 while (it != simiIt->second.end())
3248 it = simiIt->second.erase(it);
3255 JLOG(
m_journal.
trace()) <<
"pubProposedAccountTransaction: " << iProposed;
3257 if (!notify.
empty() || !accountHistoryNotify.
empty())
3262 isrListener->send(jvObj,
true);
3264 assert(!jvObj.
isMember(jss::account_history_tx_stream));
3265 for (
auto& info : accountHistoryNotify)
3267 auto& index = info.index_;
3268 if (index->forwardTxIndex_ == 0 && !index->haveHistorical_)
3269 jvObj[jss::account_history_tx_first] =
true;
3270 jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++;
3271 info.sink_->send(jvObj,
true);
3288 for (
auto const& naAccountID : vnaAccountIDs)
3291 <<
"subAccount: account: " <<
toBase58(naAccountID);
3293 isrListener->insertSubAccountInfo(naAccountID, rt);
3298 for (
auto const& naAccountID : vnaAccountIDs)
3300 auto simIterator = subMap.
find(naAccountID);
3301 if (simIterator == subMap.
end())
3305 usisElement[isrListener->getSeq()] = isrListener;
3307 subMap.
insert(simIterator, make_pair(naAccountID, usisElement));
3312 simIterator->second[isrListener->getSeq()] = isrListener;
3323 for (
auto const& naAccountID : vnaAccountIDs)
3326 isrListener->deleteSubAccountInfo(naAccountID, rt);
3343 for (
auto const& naAccountID : vnaAccountIDs)
3345 auto simIterator = subMap.
find(naAccountID);
3347 if (simIterator != subMap.
end())
3350 simIterator->second.erase(uSeq);
3352 if (simIterator->second.empty())
3355 subMap.
erase(simIterator);
3364 enum DatabaseType { Postgres, Sqlite, None };
3365 static const auto databaseType = [&]() -> DatabaseType {
3366 #ifdef RIPPLED_REPORTING
3372 return DatabaseType::Postgres;
3374 return DatabaseType::None;
3381 return DatabaseType::Sqlite;
3383 return DatabaseType::None;
3389 return DatabaseType::Sqlite;
3391 return DatabaseType::None;
3395 if (databaseType == DatabaseType::None)
3398 <<
"AccountHistory job for account "
3410 "AccountHistoryTxStream",
3411 [
this, dbType = databaseType, subInfo]() {
3412 auto const& accountId = subInfo.
index_->accountId_;
3413 auto& lastLedgerSeq = subInfo.
index_->historyLastLedgerSeq_;
3414 auto& txHistoryIndex = subInfo.
index_->historyTxIndex_;
3417 <<
"AccountHistory job for account " <<
toBase58(accountId)
3418 <<
" started. lastLedgerSeq=" << lastLedgerSeq;
3428 auto stx = tx->getSTransaction();
3429 if (stx->getAccountID(
sfAccount) == accountId &&
3430 stx->getSeqProxy().value() == 1)
3434 for (
auto& node : meta->getNodes())
3441 if (
auto inner =
dynamic_cast<const STObject*
>(
3446 inner->getAccountID(
sfAccount) == accountId)
3458 bool unsubscribe) ->
bool {
3461 sptr->send(jvObj,
true);
3488 auto [txResult, status] = db->getAccountTx(args);
3492 <<
"AccountHistory job for account "
3494 <<
" getAccountTx failed";
3499 std::get_if<RelationalDBInterface::AccountTxs>(
3500 &txResult.transactions);
3508 <<
"AccountHistory job for account "
3510 <<
" getAccountTx wrong data";
3518 accountId, minLedger, maxLedger, marker, 0,
true};
3519 return db->newestAccountTxPage(options);
3531 while (lastLedgerSeq >= 2 && !subInfo.
index_->stopHistorical_)
3533 int feeChargeCount = 0;
3542 <<
"AccountHistory job for account "
3543 <<
toBase58(accountId) <<
" no InfoSub. Fee charged "
3544 << feeChargeCount <<
" times.";
3549 auto startLedgerSeq =
3550 (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
3552 <<
"AccountHistory job for account " <<
toBase58(accountId)
3553 <<
", working on ledger range [" << startLedgerSeq <<
","
3554 << lastLedgerSeq <<
"]";
3556 auto haveRange = [&]() ->
bool {
3559 auto haveSomeValidatedLedgers =
3561 validatedMin, validatedMax);
3563 return haveSomeValidatedLedgers &&
3564 validatedMin <= startLedgerSeq &&
3565 lastLedgerSeq <= validatedMax;
3571 <<
"AccountHistory reschedule job for account "
3572 <<
toBase58(accountId) <<
", incomplete ledger range ["
3573 << startLedgerSeq <<
"," << lastLedgerSeq <<
"]";
3579 while (!subInfo.
index_->stopHistorical_)
3582 getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
3586 <<
"AccountHistory job for account "
3587 <<
toBase58(accountId) <<
" getMoreTxns failed.";
3592 auto const& txns = dbResult->first;
3593 marker = dbResult->second;
3594 for (
auto const& [tx, meta] : txns)
3599 <<
"AccountHistory job for account "
3600 <<
toBase58(accountId) <<
" empty tx or meta.";
3610 <<
"AccountHistory job for account "
3611 <<
toBase58(accountId) <<
" no ledger.";
3616 tx->getSTransaction();
3620 <<
"AccountHistory job for account "
3622 <<
" getSTransaction failed.";
3627 *stTxn, meta->getResultTER(),
true, curTxLedger);
3629 jvTx[jss::account_history_tx_index] = txHistoryIndex--;
3631 jvTx[jss::meta], *curTxLedger, stTxn, *meta);
3632 if (isFirstTx(tx, meta))
3634 jvTx[jss::account_history_tx_first] =
true;
3638 <<
"AccountHistory job for account "
3640 <<
" done, found last tx.";
3652 <<
"AccountHistory job for account "
3654 <<
" paging, marker=" << marker->ledgerSeq <<
":"
3663 if (!subInfo.
index_->stopHistorical_)
3665 lastLedgerSeq = startLedgerSeq - 1;
3666 if (lastLedgerSeq <= 1)
3669 <<
"AccountHistory job for account "
3671 <<
" done, reached genesis ledger.";
3684 subInfo.
index_->separationLedgerSeq_ = ledger->seq();
3685 auto const& accountId = subInfo.
index_->accountId_;
3687 if (!ledger->exists(accountKeylet))
3690 <<
"subAccountHistoryStart, no account " <<
toBase58(accountId)
3691 <<
", no need to add AccountHistory job.";
3696 if (
auto const sleAcct = ledger->read(accountKeylet); sleAcct)
3701 <<
"subAccountHistoryStart, genesis account "
3703 <<
" does not have tx, no need to add AccountHistory job.";
3713 subInfo.
index_->historyLastLedgerSeq_ = ledger->seq();
3714 subInfo.
index_->haveHistorical_ =
true;
3717 <<
"subAccountHistoryStart, add AccountHistory job: accountId="
3718 <<
toBase58(accountId) <<
", currentLedgerSeq=" << ledger->seq();
3728 if (!isrListener->insertSubAccountHistory(accountId))
3731 <<
"subAccountHistory, already subscribed to account "
3738 isrListener, std::make_shared<SubAccountHistoryIndex>(accountId)};
3743 inner.
emplace(isrListener->getSeq(), ahi);
3749 simIterator->second.emplace(isrListener->getSeq(), ahi);
3763 <<
"subAccountHistory, no validated ledger yet, delay start";
3776 isrListener->deleteSubAccountHistory(account);
3790 auto& subInfoMap = simIterator->second;
3791 auto subInfoIter = subInfoMap.find(seq);
3792 if (subInfoIter != subInfoMap.end())
3794 subInfoIter->second.index_->stopHistorical_ =
true;
3799 simIterator->second.erase(seq);
3800 if (simIterator->second.empty())
3806 <<
"unsubAccountHistory, account " <<
toBase58(account)
3807 <<
", historyOnly = " << (historyOnly ?
"true" :
"false");
3815 listeners->addSubscriber(isrListener);
3825 listeners->removeSubscriber(uSeq);
3839 Throw<std::runtime_error>(
3840 "Operation only possible in STANDALONE mode.");
3855 jvResult[jss::ledger_index] = lpClosed->info().seq;
3856 jvResult[jss::ledger_hash] =
to_string(lpClosed->info().hash);
3858 lpClosed->info().closeTime.time_since_epoch().count());
3859 jvResult[jss::fee_ref] = lpClosed->fees().units.jsonClipped();
3860 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
3861 jvResult[jss::reserve_base] =
3862 lpClosed->fees().accountReserve(0).jsonClipped();
3863 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3868 jvResult[jss::validated_ledgers] =
3874 .emplace(isrListener->getSeq(), isrListener)
3892 .emplace(isrListener->getSeq(), isrListener)
3920 jvResult[jss::random] =
to_string(uRandom);
3922 jvResult[jss::load_base] = feeTrack.getLoadBase();
3923 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
3924 jvResult[jss::hostid] =
getHostId(admin);
3925 jvResult[jss::pubkey_node] =
3930 .emplace(isrListener->getSeq(), isrListener)
3948 .emplace(isrListener->getSeq(), isrListener)
3966 .emplace(isrListener->getSeq(), isrListener)
3984 .emplace(isrListener->getSeq(), isrListener)
4008 .emplace(isrListener->getSeq(), isrListener)
4026 .emplace(isrListener->getSeq(), isrListener)
4074 if (map.find(pInfo->getSeq()) != map.end())
4081 #ifndef USE_NEW_BOOK_PAGE
4092 unsigned int iLimit,
4102 uint256 uTipIndex = uBookBase;
4106 stream <<
"getBookPage:" << book;
4107 stream <<
"getBookPage: uBookBase=" << uBookBase;
4108 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
4109 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
4118 bool bDirectAdvance =
true;
4122 unsigned int uBookEntry;
4128 while (!bDone && iLimit-- > 0)
4132 bDirectAdvance =
false;
4136 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
4140 sleOfferDir.
reset();
4149 uTipIndex = sleOfferDir->key();
4152 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
4155 <<
"getBookPage: uTipIndex=" << uTipIndex;
4157 <<
"getBookPage: offerIndex=" << offerIndex;
4167 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4168 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4169 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4171 bool firstOwnerOffer(
true);
4177 saOwnerFunds = saTakerGets;
4179 else if (bGlobalFreeze)
4187 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4188 if (umBalanceEntry != umBalance.
end())
4192 saOwnerFunds = umBalanceEntry->second;
4193 firstOwnerOffer =
false;
4207 if (saOwnerFunds < beast::zero)
4211 saOwnerFunds.
clear();
4219 STAmount saOwnerFundsLimit = saOwnerFunds;
4231 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4234 if (saOwnerFundsLimit >= saTakerGets)
4237 saTakerGetsFunded = saTakerGets;
4243 saTakerGetsFunded = saOwnerFundsLimit;
4245 saTakerGetsFunded.
setJson(jvOffer[jss::taker_gets_funded]);
4249 saTakerGetsFunded, saDirRate, saTakerPays.
issue()))
4250 .setJson(jvOffer[jss::taker_pays_funded]);
4256 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4258 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4262 jvOf[jss::quality] = saDirRate.
getText();
4264 if (firstOwnerOffer)
4265 jvOf[jss::owner_funds] = saOwnerFunds.
getText();
4272 if (!
cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
4274 bDirectAdvance =
true;
4279 <<
"getBookPage: offerIndex=" << offerIndex;
4299 unsigned int iLimit,
4307 MetaView lesActive(lpLedger,
tapNONE,
true);
4308 OrderBookIterator obIterator(lesActive, book);
4312 const bool bGlobalFreeze = lesActive.isGlobalFrozen(book.
out.
account) ||
4313 lesActive.isGlobalFrozen(book.
in.
account);
4315 while (iLimit-- > 0 && obIterator.nextOffer())
4320 auto const uOfferOwnerID = sleOffer->getAccountID(
sfAccount);
4321 auto const& saTakerGets = sleOffer->getFieldAmount(
sfTakerGets);
4322 auto const& saTakerPays = sleOffer->getFieldAmount(
sfTakerPays);
4323 STAmount saDirRate = obIterator.getCurrentRate();
4329 saOwnerFunds = saTakerGets;
4331 else if (bGlobalFreeze)
4339 auto umBalanceEntry = umBalance.
find(uOfferOwnerID);
4341 if (umBalanceEntry != umBalance.
end())
4345 saOwnerFunds = umBalanceEntry->second;
4351 saOwnerFunds = lesActive.accountHolds(
4357 if (saOwnerFunds.isNegative())
4361 saOwnerFunds.zero();
4368 STAmount saTakerGetsFunded;
4369 STAmount saOwnerFundsLimit = saOwnerFunds;
4381 saOwnerFundsLimit =
divide(saOwnerFunds, offerRate);
4384 if (saOwnerFundsLimit >= saTakerGets)
4387 saTakerGetsFunded = saTakerGets;
4392 saTakerGetsFunded = saOwnerFundsLimit;
4394 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
4400 multiply(saTakerGetsFunded, saDirRate, saTakerPays.issue()))
4401 .setJson(jvOffer[jss::taker_pays_funded]);
4404 STAmount saOwnerPays = (
parityRate == offerRate)
4407 saOwnerFunds,
multiply(saTakerGetsFunded, offerRate));
4409 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
4411 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
4415 jvOf[jss::quality] = saDirRate.
getText();
4430 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4470 ++counters_[
static_cast<std::size_t>(om)].transitions;
4472 counters_[
static_cast<std::size_t>(om)].transitions == 1)
4474 initialSyncUs_ = std::chrono::duration_cast<std::chrono::microseconds>(
4475 now - processStart_)
4479 std::chrono::duration_cast<std::chrono::microseconds>(now - start_);
4488 auto [counters, mode, start, initialSync] = getCounterData();
4489 auto const current = std::chrono::duration_cast<std::chrono::microseconds>(
4499 auto& state = obj[jss::state_accounting][
states_[i]];
4500 state[jss::transitions] =
std::to_string(counters[i].transitions);
4501 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
4505 obj[jss::initial_sync_duration_us] =
std::to_string(initialSync);
4520 boost::asio::io_service& io_svc,
4524 return std::make_unique<NetworkOPsImp>(