20 #include <ripple/app/misc/NetworkOPs.h>
21 #include <ripple/consensus/Consensus.h>
22 #include <ripple/app/consensus/RCLConsensus.h>
23 #include <ripple/app/consensus/RCLValidations.h>
24 #include <ripple/app/ledger/AcceptedLedger.h>
25 #include <ripple/app/ledger/InboundLedgers.h>
26 #include <ripple/app/ledger/LedgerMaster.h>
27 #include <ripple/consensus/ConsensusParms.h>
28 #include <ripple/app/ledger/LedgerToJson.h>
29 #include <ripple/app/ledger/LocalTxs.h>
30 #include <ripple/app/ledger/OpenLedger.h>
31 #include <ripple/app/ledger/OrderBookDB.h>
32 #include <ripple/app/ledger/TransactionMaster.h>
33 #include <ripple/app/main/LoadManager.h>
34 #include <ripple/app/misc/AmendmentTable.h>
35 #include <ripple/app/misc/HashRouter.h>
36 #include <ripple/app/misc/LoadFeeTrack.h>
37 #include <ripple/app/misc/Transaction.h>
38 #include <ripple/app/misc/TxQ.h>
39 #include <ripple/app/misc/ValidatorKeys.h>
40 #include <ripple/app/misc/ValidatorList.h>
41 #include <ripple/app/misc/impl/AccountTxPaging.h>
42 #include <ripple/app/tx/apply.h>
43 #include <ripple/basics/base64.h>
44 #include <ripple/basics/mulDiv.h>
45 #include <ripple/basics/PerfLog.h>
46 #include <ripple/basics/safe_cast.h>
47 #include <ripple/basics/UptimeClock.h>
48 #include <ripple/core/ConfigSections.h>
49 #include <ripple/crypto/csprng.h>
50 #include <ripple/crypto/RFC1751.h>
51 #include <ripple/json/to_string.h>
52 #include <ripple/overlay/Cluster.h>
53 #include <ripple/overlay/Overlay.h>
54 #include <ripple/overlay/predicates.h>
55 #include <ripple/protocol/BuildInfo.h>
56 #include <ripple/resource/ResourceManager.h>
57 #include <ripple/rpc/DeliveredAmount.h>
58 #include <ripple/beast/rfc2616.h>
59 #include <ripple/beast/core/LexicalCast.h>
60 #include <ripple/beast/utility/rngfill.h>
61 #include <boost/asio/steady_timer.hpp>
62 #include <boost/asio/ip/host_name.hpp>
141 std::chrono::system_clock::time_point
start_ =
202 return !(*
this != b);
208 boost::optional<TxQ::Metrics>
em = boost::none;
214 bool standalone,
std::size_t minPeerCount,
bool start_valid,
216 ValidatorKeys const & validatorKeys, boost::asio::io_service& io_svc,
229 app_.logs().journal(
"FeeVote")),
232 app.getInboundTransactions(),
233 beast::get_abstract_clock<
std::chrono::steady_clock>(),
235 app_.logs().journal(
"LedgerConsensus"))
275 bool bUnlimited,
bool bLocal,
FailHard failType)
override;
286 bool bUnlimited,
FailHard failType);
298 bool bUnlimited,
FailHard failtype);
341 protocol::TxSetStatus status);
345 bool fromAcquire)
override;
415 boost::optional<std::chrono::milliseconds> consensusDelay)
override;
434 bool binary,
bool count,
bool bUnlimited);
452 bool bUnlimited)
override;
461 int limit,
bool bUnlimited)
override;
472 bool bUnlimited)
override;
547 boost::system::error_code ec;
552 <<
"NetworkOPs: heartbeatTimer cancel error: "
561 <<
"NetworkOPs: clusterTimer cancel error: "
567 using namespace std::chrono_literals;
579 const STTx& stTxn,
TER terResult,
bool bValidated,
668 template <
class Handler>
670 :
hook (collector->make_hook (handler))
673 ,
syncing_duration(collector->make_gauge(
"State_Accounting",
"Syncing_duration"))
674 ,
tracking_duration (collector->make_gauge(
"State_Accounting",
"Tracking_duration"))
675 ,
full_duration (collector-> make_gauge(
"State_Accounting",
"Full_duration"))
680 ,
full_transitions (collector-> make_gauge(
"State_Accounting",
"Full_transitions"))
745 static std::string const hostname = boost::asio::ip::host_name();
762 return shroudedHostId;
775 [
this] (boost::system::error_code
const& e)
777 if ((e.value() == boost::system::errc::success) &&
778 (! m_job_queue.isStopped()))
780 m_job_queue.addJob (jtNETOP_TIMER,
"NetOPs.heartbeat",
781 [this] (Job&) { processHeartbeatTimer(); });
784 if (e.value() != boost::system::errc::success &&
785 e.value() != boost::asio::error::operation_aborted)
788 JLOG (m_journal.error())
789 <<
"Heartbeat timer got error '" << e.message()
790 <<
"'. Restarting timer.";
805 [
this] (boost::system::error_code
const& e)
807 if ((e.value() == boost::system::errc::success) &&
808 (! m_job_queue.isStopped()))
810 m_job_queue.addJob (jtNETOP_CLUSTER,
"NetOPs.cluster",
811 [this] (Job&) { processClusterTimer(); });
814 if (e.value() != boost::system::errc::success &&
815 e.value() != boost::asio::error::operation_aborted)
818 JLOG (m_journal.error())
819 <<
"Cluster timer got error '" << e.message()
820 <<
"'. Restarting timer.";
825 using namespace std::chrono_literals;
826 clusterTimer_.expires_from_now (10s);
827 clusterTimer_.async_wait (std::move (*optionalCountedHandler));
849 <<
"Node count (" << numPeers <<
") has fallen "
865 <<
"Node count (" << numPeers <<
") is sufficient.";
890 using namespace std::chrono_literals;
906 protocol::TMCluster cluster;
910 protocol::TMClusterNode& n = *cluster.add_clusternodes();
918 n.set_nodename(node.
name());
922 for (
auto& item: gossip.
items)
924 protocol::TMLoadSource& node = *cluster.add_loadsources();
925 node.set_name (
to_string (item.address));
926 node.set_cost (item.balance);
929 std::make_shared<Message>(cluster, protocol::mtCLUSTER),
937 bool const admin)
const
966 auto const txid = trans->getTransactionID ();
969 if ((flags & SF_BAD) != 0)
971 JLOG(
m_journal.
warn()) <<
"Submitted transaction cached bad";
985 "Submitted transaction invalid: " <<
992 JLOG(
m_journal.
warn()) <<
"Exception checking transaction" << txid;
999 auto tx = std::make_shared<Transaction> (
1000 trans, reason,
app_);
1011 bool bUnlimited,
bool bLocal,
FailHard failType)
1016 if ((newFlags & SF_BAD) != 0)
1019 transaction->setStatus (
INVALID);
1030 *transaction->getSTransaction(),
1037 JLOG(
m_journal.
info()) <<
"Transaction has bad signature: " <<
1039 transaction->setStatus(
INVALID);
1056 bool bUnlimited,
FailHard failType)
1060 if (transaction->getApplying())
1065 transaction->setApplying();
1071 [
this] (
Job&) { transactionBatch(); }))
1079 bool bUnlimited,
FailHard failType)
1083 if (! transaction->getApplying())
1087 transaction->setApplying();
1106 [
this] (
Job&) { transactionBatch(); }))
1113 while (transaction->getApplying());
1134 assert (! transactions.
empty());
1143 bool changed =
false;
1162 app_, view, e.transaction->getSTransaction(),
1164 e.result = result.first;
1165 e.applied = result.second;
1166 changed = changed || result.second;
1174 boost::optional<LedgerIndex> validatedLedgerIndex;
1176 validatedLedgerIndex = l->info().seq;
1181 e.transaction->clearSubmitResult();
1186 e.transaction->getSTransaction(), e.result);
1187 e.transaction->setApplied();
1190 e.transaction->setResult (e.result);
1203 << token <<
": " << human;
1208 bool addLocal = e.local;
1213 <<
"Transaction is now included in open ledger";
1214 e.transaction->setStatus (
INCLUDED);
1216 auto txCur = e.transaction->getSTransaction();
1218 txCur->getAccountID(
sfAccount), txCur->getSequence() + 1))
1222 auto t = std::make_shared<Transaction>(
1223 trans, reason,
app_);
1233 e.transaction->setStatus (
OBSOLETE);
1238 <<
" fee, but is queued until fee drops";
1240 e.transaction->setStatus(
HELD);
1245 e.transaction->setQueued();
1246 e.transaction->setKept();
1254 <<
"Transaction should be held: " << e.result;
1255 e.transaction->setStatus (
HELD);
1257 e.transaction->setKept();
1263 <<
"Status other than success " << e.result;
1264 e.transaction->setStatus (
INVALID);
1270 if (addLocal && !enforceFailHard)
1274 e.transaction->getSTransaction());
1275 e.transaction->setKept();
1280 (e.result ==
terQUEUED)) && !enforceFailHard)
1283 e.transaction->getID());
1287 protocol::TMTransaction tx;
1290 e.transaction->getSTransaction()->add (s);
1291 tx.set_rawtransaction (s.
data(), s.
size());
1292 tx.set_status (protocol::tsCURRENT);
1297 std::make_shared<Message> (tx, protocol::mtTRANSACTION),
1299 e.transaction->setBroadcast();
1303 if (validatedLedgerIndex)
1305 auto [fee, accountSeq, availableSeq] =
1307 *newOL, e.transaction->getSTransaction());
1308 e.transaction->setCurrentLedgerState(
1309 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1317 e.transaction->clearApplying();
1319 if (! submit_held.
empty())
1324 for (
auto& e : submit_held)
1342 auto sleNode = lpLedger->read (
keylet::page (uRootIndex));
1349 for (
auto const& uDirEntry : sleNode->getFieldV256 (
sfIndexes))
1354 switch (sleCur->getType ())
1357 if (!jvObjects.
isMember (jss::offers))
1360 jvObjects[jss::offers].
append (
1365 if (!jvObjects.
isMember (jss::ripple_lines))
1367 jvObjects[jss::ripple_lines] =
1371 jvObjects[jss::ripple_lines].
append (
1387 sleNode = lpLedger->read (
keylet::page (uRootIndex, uNodeDir));
1415 JLOG(
m_journal.
trace()) <<
"NetworkOPsImp::checkLastClosedLedger";
1422 uint256 closedLedger = ourClosed->info().hash;
1423 uint256 prevClosedLedger = ourClosed->info().parentHash;
1432 <<
"ValidationTrie " <<
Json::Compact(validations.getJsonTrie());
1436 peerCounts[closedLedger] = 0;
1438 peerCounts[closedLedger]++;
1440 for (
auto& peer : peerList)
1442 uint256 peerLedger = peer->getClosedLedgerHash();
1445 ++peerCounts[peerLedger];
1448 for(
auto const & it: peerCounts)
1449 JLOG(
m_journal.
debug()) <<
"L: " << it.first <<
" n=" << it.second;
1451 uint256 preferredLCL = validations.getPreferredLCL(
1456 bool switchLedgers = preferredLCL != closedLedger;
1458 closedLedger = preferredLCL;
1460 if (switchLedgers && (closedLedger == prevClosedLedger))
1463 JLOG(
m_journal.
info()) <<
"We won't switch to our own previous ledger";
1464 networkClosed = ourClosed->info().hash;
1465 switchLedgers =
false;
1468 networkClosed = closedLedger;
1486 networkClosed = ourClosed->info().hash;
1490 JLOG(
m_journal.
warn()) <<
"We are not running on the consensus ledger";
1516 "JUMP last closed ledger to " << newLCL->info().hash;
1529 auto const lastVal =
1531 boost::optional<Rules> rules;
1548 protocol::TMStatusChange s;
1549 s.set_newevent (protocol::neSWITCHED_LEDGER);
1550 s.set_ledgerseq (newLCL->info().seq);
1552 s.set_ledgerhashprevious (
1553 newLCL->info().parentHash.begin (),
1554 newLCL->info().parentHash.size ());
1556 newLCL->info().hash.begin (),
1557 newLCL->info().hash.size ());
1560 std::make_shared<Message> (s, protocol::mtSTATUS_CHANGE)));
1570 "Consensus time for #" << closingInfo.seq <<
1571 " with LCL " << closingInfo.parentHash;
1574 closingInfo.parentHash);
1581 JLOG(
m_journal.
warn()) <<
"Don't have LCL, going to tracking";
1588 assert (prevLedger->info().hash == closingInfo.parentHash);
1589 assert (closingInfo.parentHash ==
1595 if (!changes.
added.empty() || !changes.
removed.empty())
1642 protocol::TMHaveTransactionSet msg;
1643 msg.set_hash (map->getHash().as_uint256().begin(), 256 / 8);
1644 msg.set_status (protocol::tsHAVE);
1646 std::make_shared<Message> (
1647 msg, protocol::mtHAVE_SET)));
1662 if (it && (it->getClosedLedgerHash () == deadLedger))
1673 if (networkClosed.
isZero ())
1700 (
current->info().parentCloseTime + 2*
current->info().closeTimeResolution))
1727 jvObj [jss::type] =
"manifestReceived";
1728 jvObj [jss::master_key] =
toBase58(
1731 jvObj[jss::signing_key] =
1735 jvObj [jss::signature] =
strHex (*sig);
1741 if (
auto p = i->second.lock())
1743 p->send (jvObj,
true);
1759 , loadBaseServer{loadFeeTrack.getLoadBase()}
1761 , em{std::move(escalationMetrics)}
1773 em.is_initialized() != b.
em.is_initialized())
1778 return (em->minProcessingFeeLevel != b.
em->minProcessingFeeLevel ||
1779 em->openLedgerFeeLevel != b.
em->openLedgerFeeLevel ||
1780 em->referenceFeeLevel != b.
em->referenceFeeLevel);
1811 jvObj [jss::type] =
"serverStatus";
1813 jvObj [jss::load_base] = f.loadBaseServer;
1814 jvObj [jss::load_factor_server] = f.loadFactorServer;
1815 jvObj [jss::base_fee] = f.baseFee.jsonClipped();
1819 auto const loadFactor =
1820 std::max(safe_cast<std::uint64_t>(f.loadFactorServer),
1821 mulDiv(f.em->openLedgerFeeLevel, f.loadBaseServer,
1822 f.em->referenceFeeLevel).second);
1824 jvObj [jss::load_factor] =
trunc32(loadFactor);
1825 jvObj [jss::load_factor_fee_escalation] =
1826 f.em->openLedgerFeeLevel.jsonClipped();
1827 jvObj [jss::load_factor_fee_queue] =
1828 f.em->minProcessingFeeLevel.jsonClipped();
1829 jvObj [jss::load_factor_fee_reference] =
1830 f.em->referenceFeeLevel.jsonClipped();
1834 jvObj [jss::load_factor] = f.loadFactorServer;
1848 p->send (jvObj,
true);
1864 if (!streamMap.empty ())
1867 jvObj [jss::type] =
"consensusPhase";
1868 jvObj [jss::consensus] =
to_string(phase);
1870 for (
auto i = streamMap.begin ();
1871 i != streamMap.end (); )
1873 if (
auto p = i->second.lock())
1875 p->send (jvObj,
true);
1880 i = streamMap.erase (i);
1896 auto const signerPublic = val->getSignerPublic();
1898 jvObj [jss::type] =
"validationReceived";
1899 jvObj [jss::validation_public_key] =
toBase58(
1902 jvObj [jss::ledger_hash] =
to_string (val->getLedgerHash ());
1903 jvObj [jss::signature] =
strHex (val->getSignature ());
1904 jvObj [jss::full] = val->isFull();
1905 jvObj [jss::flags] = val->getFlags();
1910 if(masterKey != signerPublic)
1914 jvObj [jss::ledger_index] =
to_string (*seq);
1919 for (
auto const& amendment : val->getFieldV256(
sfAmendments))
1924 jvObj [jss::close_time] = *closeTime;
1926 if (
auto const loadFee = (*val)[~
sfLoadFee])
1927 jvObj [jss::load_fee] = *loadFee;
1929 if (
auto const baseFee = (*val)[~
sfBaseFee])
1930 jvObj [jss::base_fee] =
static_cast<double> (*baseFee);
1933 jvObj [jss::reserve_base] = *reserveBase;
1936 jvObj [jss::reserve_inc] = *reserveInc;
1941 if (
auto p = i->second.lock())
1943 p->send (jvObj,
true);
1963 jvObj [jss::type] =
"peerStatusChange";
1972 p->send (jvObj,
true);
1985 using namespace std::chrono_literals;
2017 bool binary,
bool count,
bool bUnlimited)
2026 numberOfResults = 1000000000;
2030 numberOfResults = binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH;
2032 else if (!bUnlimited)
2035 binary ? BINARY_PAGE_LENGTH : NONBINARY_PAGE_LENGTH,
2040 numberOfResults = limit;
2046 if (maxLedger != -1)
2048 maxClause = boost::str (boost::format (
2049 "AND AccountTransactions.LedgerSeq <= '%u'") % maxLedger);
2052 if (minLedger != -1)
2054 minClause = boost::str (boost::format (
2055 "AND AccountTransactions.LedgerSeq >= '%u'") % minLedger);
2062 boost::str (boost::format (
2063 "SELECT %s FROM AccountTransactions "
2064 "WHERE Account = '%s' %s %s LIMIT %u, %u;")
2069 % beast::lexicalCastThrow <std::string> (offset)
2070 % beast::lexicalCastThrow <std::string> (numberOfResults)
2074 boost::str (boost::format (
2076 "AccountTransactions INNER JOIN Transactions "
2077 "ON Transactions.TransID = AccountTransactions.TransID "
2078 "WHERE Account = '%s' %s %s "
2079 "ORDER BY AccountTransactions.LedgerSeq %s, "
2080 "AccountTransactions.TxnSeq %s, AccountTransactions.TransID %s "
2086 % (descending ?
"DESC" :
"ASC")
2087 % (descending ?
"DESC" :
"ASC")
2088 % (descending ?
"DESC" :
"ASC")
2089 % beast::lexicalCastThrow <std::string> (offset)
2090 % beast::lexicalCastThrow <std::string> (numberOfResults)
2105 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta", account,
2106 minLedger, maxLedger, descending, offset, limit,
false,
false,
2112 boost::optional<std::uint64_t> ledgerSeq;
2113 boost::optional<std::string> status;
2114 soci::blob sociTxnBlob (*db), sociTxnMetaBlob (*db);
2115 soci::indicator rti, tmi;
2116 Blob rawTxn, txnMeta;
2118 soci::statement st =
2119 (db->prepare << sql,
2120 soci::into(ledgerSeq),
2122 soci::into(sociTxnBlob, rti),
2123 soci::into(sociTxnMetaBlob, tmi));
2128 if (soci::i_ok == rti)
2133 if (soci::i_ok == tmi)
2134 convert (sociTxnMetaBlob, txnMeta);
2139 ledgerSeq, status, rawTxn,
app_);
2141 if (txnMeta.
empty ())
2143 auto const seq = rangeCheckedCast<std::uint32_t>(
2144 ledgerSeq.value_or (0));
2147 "Recovering ledger " << seq <<
2148 ", txn " << txn->getID();
2157 std::make_shared<TxMeta>(
2158 txn->getID(), txn->getLedger(), txnMeta));
2174 "AccountTransactions.LedgerSeq,Status,RawTxn,TxnMeta", account,
2175 minLedger, maxLedger, descending, offset, limit,
true,
false,
2181 boost::optional<std::uint64_t> ledgerSeq;
2182 boost::optional<std::string> status;
2183 soci::blob sociTxnBlob (*db), sociTxnMetaBlob (*db);
2184 soci::indicator rti, tmi;
2186 soci::statement st =
2187 (db->prepare << sql,
2188 soci::into(ledgerSeq),
2190 soci::into(sociTxnBlob, rti),
2191 soci::into(sociTxnMetaBlob, tmi));
2197 if (soci::i_ok == rti)
2198 convert (sociTxnBlob, rawTxn);
2200 if (soci::i_ok == tmi)
2201 convert (sociTxnMetaBlob, txnMeta);
2204 rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or (0));
2207 std::move(rawTxn), std::move(txnMeta), seq);
2229 auto bound = [&ret, &app](
2233 Blob const& rawMeta) {
2268 auto bound = [&ret](
2272 Blob const& rawMeta) {
2273 ret.
emplace_back(std::move(rawTxn), std::move(rawMeta), ledgerIndex);
2295 JLOG(
m_journal.
debug()) <<
"recvValidation " << val->getLedgerHash ()
2296 <<
" from " << source;
2318 "This server is amendment blocked, and must be updated to be "
2319 "able to stay in sync with the network.";
2326 "One or more unsupported amendments have reached majority. "
2327 "Upgrade to the latest version before they are activated "
2328 "to avoid being amendment blocked.";
2329 if (
auto const expected =
2333 d[jss::expected_date] = expected->time_since_epoch().count();
2334 d[jss::expected_date_UTC] =
to_string(*expected);
2338 if (warnings.size())
2339 info[jss::warnings] = std::move(warnings);
2347 info [jss::network_id] =
static_cast<Json::UInt>(*netid);
2353 info [jss::time] =
to_string(date::floor<std::chrono::microseconds>(
2357 info[jss::network_ledger] =
"waiting";
2359 info[jss::validation_quorum] =
static_cast<Json::UInt>(
2369 info[jss::validator_list_expires] =
2370 safe_cast<Json::UInt>(when->time_since_epoch().count());
2372 info[jss::validator_list_expires] = 0;
2382 if (*when == TimeKeeper::time_point::max())
2384 x[jss::expiration] =
"never";
2385 x[jss::status] =
"active";
2392 x[jss::status] =
"active";
2394 x[jss::status] =
"expired";
2399 x[jss::status] =
"unknown";
2400 x[jss::expiration] =
"unknown";
2404 info[jss::io_latency_ms] =
static_cast<Json::UInt> (
2411 info[jss::pubkey_validator] =
toBase58 (
2417 info[jss::pubkey_validator] =
"none";
2427 info[jss::pubkey_node] =
toBase58 (
2431 info[jss::complete_ledgers] =
2435 info[jss::amendment_blocked] =
true;
2449 lastClose[jss::converge_time_s] =
2455 lastClose[jss::converge_time] =
2459 info[jss::last_close] = lastClose;
2474 auto const loadFactorFeeEscalation =
mulDiv(
2475 escalationMetrics.openLedgerFeeLevel, loadBaseServer,
2476 escalationMetrics.referenceFeeLevel).second;
2478 auto const loadFactor =
std::max(safe_cast<std::uint64_t>(loadFactorServer),
2479 loadFactorFeeEscalation);
2483 info[jss::load_base] = loadBaseServer;
2484 info[jss::load_factor] =
trunc32(loadFactor);
2485 info[jss::load_factor_server] = loadFactorServer;
2492 info[jss::load_factor_fee_escalation] =
2493 escalationMetrics.openLedgerFeeLevel.jsonClipped();
2494 info[jss::load_factor_fee_queue] =
2495 escalationMetrics.minProcessingFeeLevel.jsonClipped();
2496 info[jss::load_factor_fee_reference] =
2497 escalationMetrics.referenceFeeLevel.jsonClipped();
2501 info[jss::load_factor] =
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 &&
2525 loadFactorFeeEscalation != loadFactor))
2526 info[jss::load_factor_fee_escalation] =
2527 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
2528 escalationMetrics.referenceFeeLevel);
2529 if (escalationMetrics.minProcessingFeeLevel !=
2530 escalationMetrics.referenceFeeLevel)
2531 info[jss::load_factor_fee_queue] =
2532 escalationMetrics.minProcessingFeeLevel.decimalFromReference(
2533 escalationMetrics.referenceFeeLevel);
2546 XRPAmount const baseFee = lpClosed->fees().base;
2548 l[jss::seq] =
Json::UInt (lpClosed->info().seq);
2549 l[jss::hash] =
to_string (lpClosed->info().hash);
2554 l[jss::reserve_base] = lpClosed->fees().accountReserve(0).jsonClipped();
2555 l[jss::reserve_inc] =
2556 lpClosed->fees().increment.jsonClipped();
2558 lpClosed->info().closeTime.time_since_epoch().count());
2562 l[jss::base_fee_xrp] =
2564 l[jss::reserve_base_xrp] =
2565 lpClosed->fees().accountReserve(0).decimalXRP();
2566 l[jss::reserve_inc_xrp] =
2567 lpClosed->fees().increment.decimalXRP();
2570 if (std::abs (nowOffset.count()) >= 60)
2571 l[jss::system_time_offset] = nowOffset.count();
2574 if (std::abs (closeOffset.count()) >= 60)
2575 l[jss::close_time_offset] = closeOffset.count();
2577 auto lCloseTime = lpClosed->info().closeTime;
2579 if (lCloseTime <= closeTime)
2581 using namespace std::chrono_literals;
2582 auto age = closeTime - lCloseTime;
2591 info[jss::validated_ledger] = l;
2593 info[jss::closed_ledger] = l;
2597 info[jss::published_ledger] =
"none";
2598 else if (lpPublished->info().seq != lpClosed->info().seq)
2599 info[jss::published_ledger] = lpPublished->info().seq;
2602 std::tie(info[jss::state_accounting],
2641 p->send (jvObj,
true);
2666 alpAccepted = std::make_shared<AcceptedLedger> (
2669 lpAccepted->info().hash, alpAccepted);
2679 jvObj[jss::type] =
"ledgerClosed";
2680 jvObj[jss::ledger_index] = lpAccepted->info().seq;
2681 jvObj[jss::ledger_hash] =
to_string (lpAccepted->info().hash);
2682 jvObj[jss::ledger_time]
2685 jvObj[jss::fee_ref] = lpAccepted->fees().units.jsonClipped();
2686 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
2687 jvObj[jss::reserve_base] =
2688 lpAccepted->fees().accountReserve(0).jsonClipped();
2689 jvObj[jss::reserve_inc] = lpAccepted->fees().increment.jsonClipped();
2691 jvObj[jss::txn_count] =
Json::UInt (alpAccepted->getTxnCount ());
2695 jvObj[jss::validated_ledgers]
2705 p->send (jvObj,
true);
2715 for (
auto const& [_, accTx] : alpAccepted->getMap ())
2733 jtCLIENT,
"reportFeeChange->pubServer",
2741 jtCLIENT,
"reportConsensusStateChange->pubConsensus",
2748 const STTx& stTxn,
TER terResult,
bool bValidated,
2757 jvObj[jss::type] =
"transaction";
2762 jvObj[jss::ledger_index] = lpCurrent->info().seq;
2763 jvObj[jss::ledger_hash] =
to_string (lpCurrent->info().hash);
2764 jvObj[jss::transaction][jss::date] =
2765 lpCurrent->info().closeTime.time_since_epoch().count();
2766 jvObj[jss::validated] =
true;
2773 jvObj[jss::validated] =
false;
2774 jvObj[jss::ledger_current_index] = lpCurrent->info().seq;
2777 jvObj[jss::status] = bValidated ?
"closed" :
"proposed";
2778 jvObj[jss::engine_result] = sToken;
2779 jvObj[jss::engine_result_code] = terResult;
2780 jvObj[jss::engine_result_message] = sHuman;
2788 if (account != amount.issue ().account)
2792 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText ();
2805 *stTxn, alTx.
getResult (),
true, alAccepted);
2807 if (
auto const txMeta = alTx.
getMeta())
2811 jvObj[jss::meta], *alAccepted, stTxn, *txMeta);
2824 p->send (jvObj,
true);
2839 p->send (jvObj,
true);
2866 for (
auto const& affectedAccount: alTx.
getAffected ())
2872 auto it = simiIt->second.begin ();
2874 while (it != simiIt->second.end ())
2885 it = simiIt->second.erase (it);
2895 auto it = simiIt->second.begin ();
2896 while (it != simiIt->second.end ())
2907 it = simiIt->second.erase (it);
2915 " iProposed=" << iProposed <<
2916 " iAccepted=" << iAccepted;
2918 if (!notify.
empty ())
2922 *stTxn, alTx.
getResult (), bAccepted, lpCurrent);
2926 if (
auto const txMeta = alTx.
getMeta())
2930 jvObj[jss::meta], *lpCurrent, stTxn, *txMeta);
2935 isrListener->send (jvObj,
true);
2949 for (
auto const& naAccountID : vnaAccountIDs)
2952 "subAccount: account: " <<
toBase58(naAccountID);
2954 isrListener->insertSubAccountInfo (naAccountID, rt);
2959 for (
auto const& naAccountID : vnaAccountIDs)
2961 auto simIterator = subMap.
find (naAccountID);
2962 if (simIterator == subMap.
end ())
2966 usisElement[isrListener->getSeq ()] = isrListener;
2968 subMap.
insert (simIterator,
2969 make_pair(naAccountID, usisElement));
2974 simIterator->second[isrListener->getSeq ()] = isrListener;
2984 for (
auto const& naAccountID : vnaAccountIDs)
2987 isrListener->deleteSubAccountInfo(naAccountID, rt);
3003 for (
auto const& naAccountID : vnaAccountIDs)
3005 auto simIterator = subMap.
find (naAccountID);
3007 if (simIterator != subMap.
end ())
3010 simIterator->second.erase (uSeq);
3012 if (simIterator->second.empty ())
3015 subMap.
erase (simIterator);
3024 listeners->addSubscriber (isrListener);
3033 listeners->removeSubscriber (uSeq);
3039 boost::optional<std::chrono::milliseconds> consensusDelay)
3046 Throw<std::runtime_error> (
"Operation only possible in STANDALONE mode.");
3060 jvResult[jss::ledger_index] = lpClosed->info().seq;
3061 jvResult[jss::ledger_hash] =
to_string (lpClosed->info().hash);
3063 lpClosed->info().closeTime.time_since_epoch().count());
3064 jvResult[jss::fee_ref] = lpClosed->fees().units.jsonClipped();
3065 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
3066 jvResult[jss::reserve_base] =
3067 lpClosed->fees().accountReserve(0).jsonClipped();
3068 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3073 jvResult[jss::validated_ledgers]
3079 isrListener->getSeq (), isrListener).second;
3094 isrListener->getSeq (), isrListener).second;
3120 jvResult[jss::random] =
to_string (uRandom);
3122 jvResult[jss::load_base] = feeTrack.getLoadBase ();
3123 jvResult[jss::load_factor] = feeTrack.getLoadFactor ();
3124 jvResult [jss::hostid] =
getHostId (admin);
3125 jvResult[jss::pubkey_node] =
toBase58 (
3131 isrListener->getSeq (), isrListener).second;
3146 isrListener->getSeq (), isrListener).second;
3161 isrListener->getSeq (), isrListener).second;
3176 isrListener->getSeq (), isrListener).second;
3191 isrListener->getSeq (), isrListener).second;
3206 isrListener->getSeq (), isrListener).second;
3250 if (map.find(pInfo->getSeq()) != map.end())
3257 #ifndef USE_NEW_BOOK_PAGE
3267 unsigned int iLimit,
3277 uint256 uTipIndex = uBookBase;
3281 stream <<
"getBookPage:" << book;
3282 stream <<
"getBookPage: uBookBase=" << uBookBase;
3283 stream <<
"getBookPage: uBookEnd=" << uBookEnd;
3284 stream <<
"getBookPage: uTipIndex=" << uTipIndex;
3289 bool const bGlobalFreeze =
3294 bool bDirectAdvance =
true;
3298 unsigned int uBookEntry;
3304 while (! bDone && iLimit-- > 0)
3308 bDirectAdvance =
false;
3312 auto const ledgerIndex = view.
succ(uTipIndex, uBookEnd);
3316 sleOfferDir.
reset();
3325 uTipIndex = sleOfferDir->key();
3329 uTipIndex, sleOfferDir, uBookEntry, offerIndex, viewJ);
3332 <<
"getBookPage: uTipIndex=" << uTipIndex;
3334 <<
"getBookPage: offerIndex=" << offerIndex;
3344 auto const uOfferOwnerID =
3346 auto const& saTakerGets =
3348 auto const& saTakerPays =
3351 bool firstOwnerOffer (
true);
3357 saOwnerFunds = saTakerGets;
3359 else if (bGlobalFreeze)
3367 auto umBalanceEntry = umBalance.
find (uOfferOwnerID);
3368 if (umBalanceEntry != umBalance.
end ())
3372 saOwnerFunds = umBalanceEntry->second;
3373 firstOwnerOffer =
false;
3383 if (saOwnerFunds < beast::zero)
3387 saOwnerFunds.
clear ();
3395 STAmount saOwnerFundsLimit = saOwnerFunds;
3407 saOwnerFundsLimit =
divide (
3408 saOwnerFunds, offerRate);
3411 if (saOwnerFundsLimit >= saTakerGets)
3414 saTakerGetsFunded = saTakerGets;
3420 saTakerGetsFunded = saOwnerFundsLimit;
3422 saTakerGetsFunded.
setJson (jvOffer[jss::taker_gets_funded]);
3425 saTakerGetsFunded, saDirRate, saTakerPays.
issue ())).setJson
3426 (jvOffer[jss::taker_pays_funded]);
3433 multiply (saTakerGetsFunded, offerRate));
3435 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
3439 jvOf[jss::quality] = saDirRate.
getText ();
3441 if (firstOwnerOffer)
3442 jvOf[jss::owner_funds] = saOwnerFunds.
getText ();
3450 uTipIndex, sleOfferDir, uBookEntry, offerIndex, viewJ))
3452 bDirectAdvance =
true;
3457 <<
"getBookPage: offerIndex=" << offerIndex;
3477 unsigned int iLimit,
3485 MetaView lesActive (lpLedger,
tapNONE,
true);
3486 OrderBookIterator obIterator (lesActive, book);
3490 const bool bGlobalFreeze = lesActive.isGlobalFrozen (book.
out.
account) ||
3491 lesActive.isGlobalFrozen (book.
in.
account);
3493 while (iLimit-- > 0 && obIterator.nextOffer ())
3499 auto const uOfferOwnerID = sleOffer->getAccountID (
sfAccount);
3500 auto const& saTakerGets = sleOffer->getFieldAmount (
sfTakerGets);
3501 auto const& saTakerPays = sleOffer->getFieldAmount (
sfTakerPays);
3502 STAmount saDirRate = obIterator.getCurrentRate ();
3508 saOwnerFunds = saTakerGets;
3510 else if (bGlobalFreeze)
3518 auto umBalanceEntry = umBalance.
find (uOfferOwnerID);
3520 if (umBalanceEntry != umBalance.
end ())
3524 saOwnerFunds = umBalanceEntry->second;
3530 saOwnerFunds = lesActive.accountHolds (
3533 if (saOwnerFunds.isNegative ())
3537 saOwnerFunds.zero ();
3544 STAmount saTakerGetsFunded;
3545 STAmount saOwnerFundsLimit = saOwnerFunds;
3557 saOwnerFundsLimit =
divide (saOwnerFunds, offerRate);
3560 if (saOwnerFundsLimit >= saTakerGets)
3563 saTakerGetsFunded = saTakerGets;
3568 saTakerGetsFunded = saOwnerFundsLimit;
3570 saTakerGetsFunded.setJson (jvOffer[jss::taker_gets_funded]);
3575 saTakerGetsFunded, saDirRate, saTakerPays.issue ())).setJson (
3576 jvOffer[jss::taker_pays_funded]);
3579 STAmount saOwnerPays = (
parityRate == offerRate)
3583 multiply (saTakerGetsFunded, offerRate));
3585 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
3587 if (!saOwnerFunds.isZero () || uOfferOwnerID == uTakerID)
3591 jvOf[jss::quality] = saDirRate.
getText ();
3620 std::chrono::duration_cast<std::chrono::microseconds>(now -
start_);
3629 auto [counters, mode, start] = getCounterData();
3641 auto& state = ret[
states_[i]];
3642 state[jss::transitions] = counters[i].transitions;
3643 state[jss::duration_us] =
std::to_string(counters[i].dur.count());
3653 bool standalone,
std::size_t minPeerCount,
bool startvalid,
3655 ValidatorKeys const & validatorKeys, boost::asio::io_service& io_svc,
3658 return std::make_unique<NetworkOPsImp> (app, clock, standalone,
3659 minPeerCount, startvalid, job_queue,
ledgerMaster, parent,
3660 validatorKeys, io_svc, journal, collector);
bool unsubValidations(std::uint64_t uListener) override
beast::insight::Hook hook
TxType getTxnType() const
FeeVote::Setup setup_FeeVote(Section const §ion)
Build FeeVote::Setup from a config section.
RCLCxLedger::ID prevLedgerID() const
bool subValidations(InfoSub::ref ispListener) override
void processHeartbeatTimer()
Provides server functionality for clients.
ConsensusPhase phase() const
void mapComplete(std::shared_ptr< SHAMap > const &map, bool fromAcquire) override
Rate transferRate(ReadView const &view, AccountID const &issuer)
virtual std::chrono::duration< std::int32_t > nowOffset() const =0
bool unsubConsensus(std::uint64_t uListener) override
static Transaction::pointer transactionFromSQL(boost::optional< std::uint64_t > const &ledgerSeq, boost::optional< std::string > const &status, Blob const &rawTxn, Application &app)
virtual OrderBookDB & getOrderBookDB()=0
uint256 getConsensusLCL() override
A peer's signed, proposed position for use in RCLConsensus.
@ ledgerMaster
ledger master data for signing
virtual Json::Value getInfo()=0
const SF_U32 sfLoadFee(access, STI_UINT32, 24, "LoadFee")
boost::optional< TxQ::Metrics > em
virtual Cluster & cluster()=0
std::string transactionsSQL(std::string selection, AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool descending, std::uint32_t offset, int limit, bool binary, bool count, bool bUnlimited)
const SF_U64 sfIndexNext(access, STI_UINT64, 1, "IndexNext")
std::shared_ptr< ReadView const > getPublishedLedger()
void pubProposedTransaction(std::shared_ptr< ReadView const > const &lpCurrent, std::shared_ptr< STTx const > const &stTxn, TER terResult) override
virtual TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache()=0
std::vector< AccountTx > AccountTxs
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
ServerFeeSummary mLastFeeSummary
PublicKey localPublicKey() const
Returns local validator public key.
@ proposing
We are normal participant in consensus and propose our position.
boost::asio::steady_timer heartbeatTimer_
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
Json::Value getJson(bool full) const
const std::size_t minPeerCount_
Represents a transfer rate.
void setStateTimer() override
Called to initially start our timers.
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
Stream trace() const
Severity stream access functions.
void pubValidation(STValidation::ref val) override
std::shared_ptr< STTx const > const & getTxn() const
int getFlags(uint256 const &key)
std::unique_ptr< FeeVote > make_FeeVote(FeeVote::Setup const &setup, beast::Journal journal)
Create an instance of the FeeVote logic.
std::vector< std::shared_ptr< STTx const > > pruneHeldTransactions(AccountID const &account, std::uint32_t const seq)
Get all the transactions held for a particular account.
std::tuple< Blob, Blob, std::uint32_t > txnMetaLedgerType
MetaTxsList getTxsAccountB(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool forward, std::optional< AccountTxMarker > &marker, int limit, bool bUnlimited) override
Changes in trusted nodes after updating validator list.
Data format for exchanging consumption information across peers.
void setAmendmentWarned() override
void pubManifest(Manifest const &) override
bool subPeerStatus(InfoSub::ref ispListener) override
DispatchState mDispatchState
@ arrayValue
array value (ordered list)
std::pair< TER, bool > apply(Application &app, OpenView &view, std::shared_ptr< STTx const > const &tx, ApplyFlags flags, beast::Journal j)
Add a new transaction to the open ledger, hold it in the queue, or reject it.
virtual std::uint64_t getJqTransOverflow() const =0
SubInfoMapType mSubRTAccount
std::atomic< bool > amendmentWarned_
static const std::array< char const *, 5 > states_
@ wrongLedger
We have the wrong ledger and are attempting to acquire it.
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
LedgerIndex getValidLedgerIndex()
virtual AmendmentTable & getAmendmentTable()=0
void setMode(OperatingMode om) override
std::string const & name() const
Writable ledger view that accumulates state and tx changes.
bool cdirNext(ReadView const &view, uint256 const &uRootIndex, std::shared_ptr< SLE const > &sleNode, unsigned int &uDirEntry, uint256 &uEntryIndex, beast::Journal j)
std::string strOperatingMode(bool const admin=false) const override
Decorator for streaming out compact json.
uint256 getBookBase(Book const &book)
std::chrono::microseconds dur
PublicKey signingKey
The ephemeral key associated with this manifest.
Manages a client's subscription to data feeds.
void trustChanged(hash_set< NodeID > const &added, hash_set< NodeID > const &removed)
Update trust status of validations.
std::uint32_t acceptLedger(boost::optional< std::chrono::milliseconds > consensusDelay) override
Accepts the current transaction tree, return the new ledger's sequence.
void setNeedNetworkLedger() override
bool tryRemoveRpcSub(std::string const &strUrl) override
PublicKey masterKey
The master key associated with this manifest.
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j)
bool empty() const noexcept
std::string getText() const override
void accountTxPage(DatabaseCon &connection, AccountIDCache const &idCache, std::function< void(std::uint32_t)> const &onUnsavedLedger, std::function< void(std::uint32_t, std::string const &, Blob const &, Blob const &)> const &onTransaction, AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool forward, std::optional< NetworkOPs::AccountTxMarker > &marker, int limit, bool bAdmin, std::uint32_t page_length)
virtual PeerSequence getActivePeers()=0
Returns a sequence representing the current list of peers.
std::enable_if_t<! std::is_void< typename UnaryFunc::return_type >::value, typename UnaryFunc::return_type > foreach(UnaryFunc f)
Visit every active peer and return a value The functor must:
std::string getHostId(bool forAdmin)
void gotTxSet(NetClock::time_point const &now, RCLTxSet const &txSet)
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
csprng_engine & crypto_prng()
The default cryptographically secure PRNG.
Rules getValidatedRules()
Json::Value getJson(int c=0)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
TrustChanges updateTrusted(hash_set< NodeID > const &seenValidators)
Update trusted nodes.
beast::insight::Gauge disconnected_duration
const SF_Amount sfTakerPays(access, STI_AMOUNT, 4, "TakerPays")
void switchLCL(std::shared_ptr< Ledger const > const &lastClosed)
Keylet child(uint256 const &key)
Any item that can be in an owner dir.
void consensusViewChange() override
StateAccounting accounting_
std::chrono::milliseconds ledgerGRANULARITY
How often we check state or change positions.
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
void timerEntry(NetClock::time_point const &now)
void apply(std::unique_lock< std::mutex > &batchLock)
Attempt to apply transactions and post-process based on the results.
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
beast::insight::Gauge syncing_transitions
std::uint32_t getLoadBase() const
std::string to_string(ListDisposition disposition)
uint256 getQualityNext(uint256 const &uBase)
virtual TimeKeeper & timeKeeper()=0
virtual MutexType & getMasterMutex()=0
virtual OpenLedger & openLedger()=0
void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted) override
bool update(PublicKey const &identity, std::string name, std::uint32_t loadFee=0, NetClock::time_point reportTime=NetClock::time_point{})
Store information about the state of a cluster node.
void switchLastClosedLedger(std::shared_ptr< Ledger const > const &newLCL)
void convertBlobsToTxResult(NetworkOPs::AccountTxs &to, std::uint32_t ledger_index, std::string const &status, Blob const &rawTxn, Blob const &rawMeta, Application &app)
void doTransactionAsync(std::shared_ptr< Transaction > transaction, bool bUnlimited, FailHard failtype)
For transactions not submitted by a locally connected client, fire and forget.
Structure returned by TxQ::getMetrics, expressed in reference fee level units.
Select all peers that are in the specified set.
Wraps a ledger instance for use in generic Validations LedgerTrie.
const SF_U32 sfReserveBase(access, STI_UINT32, 31, "ReserveBase")
void accept(Application &app, Rules const &rules, std::shared_ptr< Ledger const > const &ledger, OrderedTxs const &locals, bool retriesFirst, OrderedTxs &retries, ApplyFlags flags, std::string const &suffix="", modify_type const &f={})
Accept a new ledger.
const Rate parityRate(QUALITY_ONE)
A transfer rate signifying a 1:1 exchange.
bool handleNewValidation(Application &app, STValidation::ref val, std::string const &source)
Handle a new validation.
AccountTxs getAccountTxs(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool descending, std::uint32_t offset, int limit, bool bUnlimited) override
Validator keys and manifest as set in configuration file.
virtual AccountIDCache const & accountIDCache() const =0
std::shared_ptr< InboundLedger > mAcquiringLedger
virtual InboundLedgers & getInboundLedgers()=0
virtual LoadFeeTrack & getFeeTrack()=0
constexpr static std::size_t size()
std::string getCompleteLedgers()
Sends a message to all peers.
static const Json::StaticString transitions_
@ SYNCING
fallen slightly behind
void processClusterTimer()
bool unsubTransactions(std::uint64_t uListener) override
void const * data() const noexcept
virtual Gossip exportConsumers()=0
Extract packaged consumer information for export.
std::recursive_mutex & peekMutex()
std::uint32_t loadFactorServer
STAmount divide(STAmount const &amount, Rate const &rate)
~NetworkOPsImp() override
std::uint32_t getRemoteFee() const
std::unique_ptr< NetworkOPs > make_NetworkOPs(Application &app, NetworkOPs::clock_type &clock, bool standalone, std::size_t minPeerCount, bool startvalid, JobQueue &job_queue, LedgerMaster &ledgerMaster, Stoppable &parent, ValidatorKeys const &validatorKeys, boost::asio::io_service &io_svc, beast::Journal journal, beast::insight::Collector::ptr const &collector)
boost::optional< Blob > getSignature() const
Returns manifest signature.
Manages the generic consensus algorithm for use by the RCL.
@ warnRPC_AMENDMENT_BLOCKED
const ConsensusParms & parms() const
T time_since_epoch(T... args)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
beast::insight::Gauge syncing_duration
bool isAmendmentBlocked() override
InfoSub::pointer addRpcSub(std::string const &strUrl, InfoSub::ref) override
Value & append(const Value &value)
Append value to array at the end.
StateCountersJson json() const
Output state counters in JSON format.
@ DISCONNECTED
not ready to process requests
Provides an interface for starting and stopping.
void clearAmendmentWarned() override
void setJson(Json::Value &) const
void processTxn(std::shared_ptr< ReadView const > const &ledger, const AcceptedLedgerTx &alTx, Json::Value const &jvObj)
std::shared_ptr< TxMeta > const & getMeta() const
virtual std::chrono::milliseconds getIOLatency()=0
virtual const PublicKey & getValidationPublicKey() const =0
Json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account) override
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules, Config const &config)
Checks transaction signature and local checks.
LockedSociSession checkoutDb()
std::vector< txnMetaLedgerType > MetaTxsList
void reportFeeChange() override
std::uint32_t getLocalFee() const
@ CONNECTED
convinced we are talking to the network
virtual LoadManager & getLoadManager()=0
std::shared_ptr< InfoSub > pointer
@ objectValue
object value (collection of name/value pairs).
constexpr double decimalXRP() const
bool hasTXSet(const std::shared_ptr< Peer > &peer, uint256 const &set, protocol::TxSetStatus status)
virtual LedgerMaster & getLedgerMaster()=0
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
bool peerProposal(NetClock::time_point const &now, RCLCxPeerPos const &newProposal)
@ TRACKING
convinced we agree with the network
void pubValidatedTransaction(std::shared_ptr< ReadView const > const &alAccepted, const AcceptedLedgerTx &alTransaction)
AccountID getAccountID(SField const &field) const
void saveLedgerAsync(Application &app, std::uint32_t seq)
DispatchState
Synchronization states for transaction batches.
virtual Config & config()=0
Select all peers (except optional excluded) that are in our cluster.
hash_set< NodeID > removed
Represents a set of transactions in RCLConsensus.
const SF_U32 sfSigningTime(access, STI_UINT32, 9, "SigningTime")
void endConsensus() override
virtual void relay(protocol::TMProposeSet &m, uint256 const &uid)=0
Relay a proposal.
void unsubAccount(InfoSub::ref ispListener, hash_set< AccountID > const &vnaAccountIDs, bool rt) override
virtual std::pair< PublicKey, SecretKey > const & nodeIdentity()=0
bool canBeCurrent(std::shared_ptr< Ledger const > const &ledger)
Check the sequence number and parent close time of a ledger against our clock and last validated ledg...
bool unsubRTTransactions(std::uint64_t uListener) override
Manages the current fee schedule.
AccountTxs getTxsAccount(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool forward, std::optional< AccountTxMarker > &marker, int limit, bool bUnlimited) override
bool subManifests(InfoSub::ref ispListener) override
A transaction that is in a closed ledger.
std::vector< Item > items
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
const std::shared_ptr< Transaction > transaction
std::shared_ptr< Ledger const > getValidatedLedger()
FeeAndSeq getTxRequiredFeeAndSeq(OpenView const &view, std::shared_ptr< STTx const > const &tx) const
Returns minimum required fee for tx and two sequences: first vaild sequence for this account in curre...
Server fees published on server subscription.
Json::Value transJson(const STTx &stTxn, TER terResult, bool bValidated, std::shared_ptr< ReadView const > const &lpCurrent)
std::unique_ptr< LocalTxs > m_localTX
uint256 getOwnerDirIndex(AccountID const &account)
ConsensusPhase
Phases of consensus for a single ledger round.
const SF_U32 sfLedgerSequence(access, STI_UINT32, 6, "LedgerSequence")
bool isCompatible(ReadView const &, beast::Journal::Stream, char const *reason)
std::string const & getVersionString()
Server version.
void pubAccountTransaction(std::shared_ptr< ReadView const > const &lpCurrent, const AcceptedLedgerTx &alTransaction, bool isAccepted)
std::shared_ptr< Ledger const > getLedgerBySeq(std::uint32_t index)
ConsensusMode mode() const
boost::container::flat_set< AccountID > const & getAffected() const
decltype(counters_) counters
beast::insight::Gauge tracking_duration
bool recvValidation(STValidation::ref val, std::string const &source) override
@ warnRPC_UNSUPPORTED_MAJORITY
bool subTransactions(InfoSub::ref ispListener) override
virtual time_point closeTime() const =0
Returns the close time, in network time.
@ current
This was a new validation and was added.
std::array< Counters, 5 > counters_
bool isMember(const char *key) const
Return true if the object has a member named key.
bool unsubLedger(std::uint64_t uListener) override
A generic endpoint for log messages.
bool isAmendmentWarned() override
virtual RCLValidations & getValidations()=0
std::atomic< bool > needNetworkLedger_
boost::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
void addHeldTransaction(std::shared_ptr< Transaction > const &trans)
Blob getMasterSignature() const
Returns manifest master key signature.
ServerFeeSummary()=default
boost::optional< Wrapper< Closure > > wrap(Closure &&closure)
Wrap the passed closure with a reference counter.
NetworkOPsImp(Application &app, NetworkOPs::clock_type &clock, bool standalone, std::size_t minPeerCount, bool start_valid, JobQueue &job_queue, LedgerMaster &ledgerMaster, Stoppable &parent, ValidatorKeys const &validatorKeys, boost::asio::io_service &io_svc, beast::Journal journal, beast::insight::Collector::ptr const &collector)
const SF_Vec256 sfIndexes(access, STI_VECTOR256, 1, "Indexes", SField::sMD_Never)
std::uint32_t getClusterFee() const
NetworkOPs(Stoppable &parent)
STAmount amountFromQuality(std::uint64_t rate)
MetaTxsList getAccountTxsB(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool descending, std::uint32_t offset, int limit, bool bUnlimited) override
BookListeners::pointer makeBookListeners(Book const &)
void processClosedLedger(Application &app, ReadView const &view, bool timeLeap)
Update fee metrics and clean up the queue in preparation for the next ledger.
void subAccount(InfoSub::ref ispListener, hash_set< AccountID > const &vnaAccountIDs, bool rt) override
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< ReadView const > getCurrentLedger()
Json::Value getJson(JsonOptions options) const override
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
std::array< SubMapType, SubTypes::sLastEntry+1 > mStreamMaps
Transaction with input flags and results to be applied in batches.
virtual ValidatorList & validators()=0
A metric for measuring an integral value.
void transactionBatch()
Apply transactions in batches.
bool isNeedNetworkLedger() override
void resetDeadlockDetector()
Reset the deadlock detection timer.
bool operator!=(ServerFeeSummary const &b) const
TransactionStatus(std::shared_ptr< Transaction > t, bool a, bool l, FailHard f)
void setStandAlone() override
A pool of threads to perform work.
std::recursive_mutex mSubLock
void onStop() override
Override called when the stop notification is issued.
bool operator==(ServerFeeSummary const &b) const
std::chrono::system_clock::time_point start_
STAmount multiply(STAmount const &amount, Rate const &rate)
BookListeners::pointer getBookListeners(Book const &)
virtual std::size_t size()=0
Returns the number of active peers.
std::uint32_t sequence
The sequence number of this manifest.
virtual Resource::Manager & getResourceManager()=0
std::size_t getFetchPackCacheSize() const
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
beast::insight::Gauge tracking_transitions
std::chrono::seconds getValidatedLedgerAge()
std::shared_ptr< Ledger const > getClosedLedger()
beast::insight::Gauge connected_transitions
boost::asio::steady_timer clusterTimer_
virtual Json::Value countersJson() const =0
Render performance counters in Json.
std::vector< TransactionStatus > mTransactions
void reportConsensusStateChange(ConsensusPhase phase)
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool transResultInfo(TER code, std::string &token, std::string &text)
bool unsubServer(std::uint64_t uListener) override
std::chrono::milliseconds prevRoundTime() const
Get duration of the previous round.
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
std::unordered_set< uint256, beast::uhash<> > features
Stats(Handler const &handler, beast::insight::Collector::ptr const &collector)
virtual beast::Journal journal(std::string const &name)=0
virtual ManifestCache & validatorManifests()=0
std::size_t getLocalTxCount() override
std::size_t size() const noexcept
std::uint32_t getLoadFactor() const
std::shared_ptr< SHAMap > getTXMap(uint256 const &hash)
Json::Value getLedgerFetchInfo() override
send_if_not_pred< Predicate > send_if_not(std::shared_ptr< Message > const &m, Predicate const &f)
Helper function to aid in type deduction.
@ Valid
Signature and local checks are good / passed.
bool unsubBook(std::uint64_t uListener, Book const &) override
void canonicalize(std::shared_ptr< Transaction > *pTransaction)
T duration_cast(T... args)
SubInfoMapType mSubAccount
void clearNeedNetworkLedger() override
const SF_U32 sfReserveIncrement(access, STI_UINT32, 32, "ReserveIncrement")
void rngfill(void *buffer, std::size_t bytes, Generator &g)
Issue const & issue() const
Lightweight wrapper to tag static string.
bool checkLastClosedLedger(const Overlay::PeerSequence &, uint256 &networkClosed)
std::string strOperatingMode(OperatingMode const mode, bool const admin) const override
void getBookPage(std::shared_ptr< ReadView const > &lpLedger, Book const &, AccountID const &uTakerID, const bool bProof, unsigned int iLimit, Json::Value const &jvMarker, Json::Value &jvResult) override
void insertDeliveredAmount(Json::Value &meta, ReadView const &, std::shared_ptr< STTx const > const &serializedTx, TxMeta const &)
Add a delivered_amount field to the meta input/output parameter.
void pubPeerStatus(std::function< Json::Value(void)> const &) override
std::condition_variable mCond
LedgerIndex getCurrentLedgerIndex()
bool subLedger(InfoSub::ref ispListener, Json::Value &jvResult) override
beast::insight::Gauge full_transitions
static const std::array< char const *, 5 > stateNames
virtual time_point now() const override=0
Returns the estimate of wall time, in network time.
const SF_U32 sfCloseTime(access, STI_UINT32, 7, "CloseTime")
std::size_t prevProposers() const
Get the number of proposing peers that participated in the previous round.
virtual Overlay & overlay()=0
Source(char const *name, Stoppable &parent)
std::atomic< OperatingMode > mMode
bool unsubManifests(std::uint64_t uListener) override
const SF_Amount sfTakerGets(access, STI_AMOUNT, 5, "TakerGets")
std::atomic< bool > amendmentBlocked_
void submitTransaction(std::shared_ptr< STTx const > const &) override
OperatingMode
Specifies the mode under which the server believes it's operating.
virtual void clearFailures()=0
uint256 const & suppressionID() const
Unique id used by hash router to suppress duplicates.
void join(char const *name, std::chrono::milliseconds wait, beast::Journal j)
Returns once all counted in-flight closures are destroyed.
ConsensusPhase mLastConsensusPhase
void updateLocalTx(ReadView const &view) override
Json::Value getJson() const
void pubConsensus(ConsensusPhase phase)
void for_each(std::function< void(ClusterNode const &)> func) const
Invokes the callback once for every cluster node.
bool subRTTransactions(InfoSub::ref ispListener) override
NetClock::time_point getReportTime() const
beast::insight::Gauge disconnected_transitions
static const Json::StaticString dur_
virtual boost::optional< NetClock::time_point > firstUnsupportedExpected()=0
std::string strHex(FwdIt begin, FwdIt end)
std::pair< bool, Dest > mulDiv(Source1 value, Dest mul, Source2 div)
Json::Value getServerInfo(bool human, bool admin, bool counters) override
virtual Json::Value currentJson() const =0
Render currently executing jobs and RPC calls and durations in Json.
LedgerMaster & m_ledgerMaster
bool subServer(InfoSub::ref ispListener, Json::Value &jvResult, bool admin) override
auto getCurrentNodeIDs() -> hash_set< NodeID >
Get the set of node ids associated with current validations.
@ ltDIR_NODE
Directory node.
const SF_Vec256 sfAmendments(access, STI_VECTOR256, 3, "Amendments")
@ SigBad
Signature is bad. Didn't do local checks.
boost::optional< TimeKeeper::time_point > expires() const
Return the time when the validator list will expire.
bool validating() const
Whether we are validating consensus ledgers.
std::unique_ptr< LocalTxs > make_LocalTxs()
Metrics getMetrics(OpenView const &view) const
Returns fee metrics in reference fee level units.
void doTransactionSync(std::shared_ptr< Transaction > transaction, bool bUnlimited, FailHard failType)
For transactions submitted directly by a client, apply batch of transactions and wait for this transa...
CounterData getCounterData() const
const SF_U64 sfBaseFee(access, STI_UINT64, 5, "BaseFee")
std::unique_ptr< LoadEvent > makeLoadEvent(JobType t, std::string const &name)
Return a scoped LoadEvent.
beast::insight::Gauge full_duration
virtual perf::PerfLog & getPerfLog()=0
send_if_pred< Predicate > send_if(std::shared_ptr< Message > const &m, Predicate const &f)
Helper function to aid in type deduction.
virtual std::uint64_t getPeerDisconnect() const =0
CanonicalTXSet OrderedTxs
bool subBook(InfoSub::ref ispListener, Book const &) override
bool subConsensus(InfoSub::ref ispListener) override
bool pendSaveValidated(Application &app, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger Returns false on error.
Json::Value getConsensusInfo() override
static const offer_t offer
beast::insight::Gauge connected_duration
std::size_t count() const
Return the number of configured validator list sites.
ClosureCounter< void, boost::system::error_code const & > waitHandlerCounter_
void mode(OperatingMode om)
Record state transition.
static const std::array< Json::StaticString const, 5 > states_
virtual boost::optional< std::uint32_t > networkID() const =0
Returns the ID of the network this server is configured for, if any.
static std::string getWordFromBlob(void const *blob, size_t bytes)
Chooses a single dictionary word from the data.
void unsubAccountInternal(std::uint64_t seq, hash_set< AccountID > const &vnaAccountIDs, bool rt) override
virtual boost::optional< key_type > succ(key_type const &key, boost::optional< key_type > const &last=boost::none) const =0
Return the key of the next state item.
State accounting records two attributes for each possible server state: 1) Amount of time spent in ea...
A reference to a handler for performing polled collection.
std::uint64_t getQuality(uint256 const &uBase)
virtual std::uint64_t getPeerDisconnectCharges() const =0
virtual HashRouter & getHashRouter()=0
bool modify(modify_type const &f)
Modify the open ledger.
std::uint32_t transitions
STAmount const & getFieldAmount(SField const &field) const
bool unsubPeerStatus(std::uint64_t uListener) override
bool setFlags(uint256 const &key, int flags)
Set the flags on a hash.
bool isTemMalformed(TER x)
static std::uint32_t trunc32(std::uint64_t v)
Json::Value jsonClipped() const
OperatingMode getOperatingMode() const override
PublicKey const & identity() const
std::size_t quorum() const
Get quorum value for current trusted key set.
Keylet page(uint256 const &key, std::uint64_t index)
A page in a directory.
virtual std::chrono::duration< std::int32_t > closeOffset() const =0
InfoSub::pointer findRpcSub(std::string const &strUrl) override
void set(value_type value) const
Set the value on the gauge.
std::uint32_t loadBaseServer
void processTrustedProposal(RCLCxPeerPos proposal, std::shared_ptr< protocol::TMProposeSet > set) override
virtual DatabaseCon & getTxnDB()=0
void clearLedgerFetch() override
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
void simulate(NetClock::time_point const &now, boost::optional< std::chrono::milliseconds > consensusDelay)
std::uint32_t getLoadFee() const
void startRound(NetClock::time_point const &now, RCLCxLedger::ID const &prevLgrId, RCLCxLedger const &prevLgr, hash_set< NodeID > const &nowUntrusted)
Json::Value rate(Account const &account, double multiplier)
Set a transfer rate.
bool cdirFirst(ReadView const &view, uint256 const &uRootIndex, std::shared_ptr< SLE const > &sleNode, unsigned int &uDirEntry, uint256 &uEntryIndex, beast::Journal j)
virtual TransactionMaster & getMasterTransaction()=0
bool beginConsensus(uint256 const &networkClosed) override
void setAmendmentBlocked() override
void processTransaction(std::shared_ptr< Transaction > &transaction, bool bUnlimited, bool bLocal, FailHard failType) override
Process transactions as they arrive from the network or which are submitted by clients.
@ FULL
we have the ledger and can even validate