xrpld
Loading...
Searching...
No Matches
NetworkOPs.cpp
1#include <xrpl/server/NetworkOPs.h>
2
3#include <xrpld/app/consensus/RCLConsensus.h>
4#include <xrpld/app/consensus/RCLCxPeerPos.h>
5#include <xrpld/app/consensus/RCLValidations.h>
6#include <xrpld/app/ledger/AcceptedLedger.h>
7#include <xrpld/app/ledger/InboundLedger.h>
8#include <xrpld/app/ledger/InboundLedgers.h>
9#include <xrpld/app/ledger/LedgerMaster.h>
10#include <xrpld/app/ledger/LedgerToJson.h>
11#include <xrpld/app/ledger/LocalTxs.h>
12#include <xrpld/app/ledger/OpenLedger.h>
13#include <xrpld/app/ledger/TransactionMaster.h>
14#include <xrpld/app/main/LoadManager.h>
15#include <xrpld/app/main/Tuning.h>
16#include <xrpld/app/misc/DeliverMax.h>
17#include <xrpld/app/misc/FeeVote.h>
18#include <xrpld/app/misc/Transaction.h>
19#include <xrpld/app/misc/TxQ.h>
20#include <xrpld/app/misc/ValidatorKeys.h>
21#include <xrpld/app/misc/ValidatorList.h>
22#include <xrpld/app/misc/make_NetworkOPs.h>
23#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
24#include <xrpld/core/Config.h>
25#include <xrpld/overlay/Cluster.h>
26#include <xrpld/overlay/ClusterNode.h>
27#include <xrpld/overlay/Overlay.h>
28#include <xrpld/overlay/predicates.h>
29#include <xrpld/rpc/BookChanges.h>
30#include <xrpld/rpc/CTID.h>
31#include <xrpld/rpc/ServerHandler.h>
32#include <xrpld/rpc/detail/SyntheticFields.h>
33
34#include <xrpl/basics/Log.h>
35#include <xrpl/basics/Number.h>
36#include <xrpl/basics/ToString.h>
37#include <xrpl/basics/UnorderedContainers.h>
38#include <xrpl/basics/UptimeClock.h>
39#include <xrpl/basics/base_uint.h>
40#include <xrpl/basics/chrono.h>
41#include <xrpl/basics/contract.h>
42#include <xrpl/basics/mulDiv.h>
43#include <xrpl/basics/safe_cast.h>
44#include <xrpl/basics/scope.h>
45#include <xrpl/basics/strHex.h>
46#include <xrpl/beast/clock/abstract_clock.h>
47#include <xrpl/beast/insight/Collector.h>
48#include <xrpl/beast/insight/Gauge.h>
49#include <xrpl/beast/insight/Hook.h>
50#include <xrpl/beast/net/IPEndpoint.h>
51#include <xrpl/beast/utility/Zero.h>
52#include <xrpl/beast/utility/instrumentation.h>
53#include <xrpl/beast/utility/rngfill.h>
54#include <xrpl/config/Constants.h>
55#include <xrpl/consensus/ConsensusParms.h>
56#include <xrpl/consensus/ConsensusTypes.h>
57#include <xrpl/core/ClosureCounter.h>
58#include <xrpl/core/HashRouter.h>
59#include <xrpl/core/Job.h>
60#include <xrpl/core/NetworkIDService.h>
61#include <xrpl/core/PerfLog.h>
62#include <xrpl/core/ServiceRegistry.h>
63#include <xrpl/crypto/RFC1751.h>
64#include <xrpl/crypto/csprng.h>
65#include <xrpl/git/Git.h>
66#include <xrpl/json/json_forwards.h>
67#include <xrpl/json/json_value.h>
68#include <xrpl/json/json_writer.h>
69#include <xrpl/ledger/AcceptedLedgerTx.h>
70#include <xrpl/ledger/AmendmentTable.h>
71#include <xrpl/ledger/ApplyView.h>
72#include <xrpl/ledger/CanonicalTXSet.h>
73#include <xrpl/ledger/Ledger.h>
74#include <xrpl/ledger/OpenView.h>
75#include <xrpl/ledger/OrderBookDB.h>
76#include <xrpl/ledger/ReadView.h>
77#include <xrpl/ledger/helpers/DirectoryHelpers.h>
78#include <xrpl/ledger/helpers/MPTokenHelpers.h>
79#include <xrpl/ledger/helpers/TokenHelpers.h>
80#include <xrpl/protocol/AccountID.h>
81#include <xrpl/protocol/AmountConversions.h>
82#include <xrpl/protocol/ApiVersion.h>
83#include <xrpl/protocol/Book.h>
84#include <xrpl/protocol/BuildInfo.h>
85#include <xrpl/protocol/ErrorCodes.h>
86#include <xrpl/protocol/Feature.h>
87#include <xrpl/protocol/Fees.h>
88#include <xrpl/protocol/Indexes.h>
89#include <xrpl/protocol/Issue.h>
90#include <xrpl/protocol/KeyType.h>
91#include <xrpl/protocol/LedgerFormats.h>
92#include <xrpl/protocol/MPTAmount.h>
93#include <xrpl/protocol/MPTIssue.h>
94#include <xrpl/protocol/MultiApiJson.h>
95#include <xrpl/protocol/Protocol.h>
96#include <xrpl/protocol/PublicKey.h>
97#include <xrpl/protocol/RPCErr.h>
98#include <xrpl/protocol/Rate.h>
99#include <xrpl/protocol/SField.h>
100#include <xrpl/protocol/STAmount.h>
101#include <xrpl/protocol/STTx.h>
102#include <xrpl/protocol/SecretKey.h>
103#include <xrpl/protocol/Seed.h>
104#include <xrpl/protocol/Serializer.h>
105#include <xrpl/protocol/TER.h>
106#include <xrpl/protocol/TxFlags.h>
107#include <xrpl/protocol/TxFormats.h>
108#include <xrpl/protocol/UintTypes.h>
109#include <xrpl/protocol/Units.h>
110#include <xrpl/protocol/XRPAmount.h>
111#include <xrpl/protocol/jss.h>
112#include <xrpl/protocol/tokens.h>
113#include <xrpl/rdb/RelationalDatabase.h>
114#include <xrpl/resource/Fees.h>
115#include <xrpl/resource/Gossip.h>
116#include <xrpl/resource/ResourceManager.h>
117#include <xrpl/server/InfoSub.h>
118#include <xrpl/server/LoadFeeTrack.h>
119#include <xrpl/server/Manifest.h>
120#include <xrpl/shamap/SHAMap.h>
121#include <xrpl/tx/apply.h>
122
123#include <boost/asio/error.hpp>
124#include <boost/asio/io_context.hpp>
125#include <boost/asio/ip/host_name.hpp>
126#include <boost/asio/steady_timer.hpp>
127#include <boost/system/detail/errc.hpp>
128#include <boost/system/detail/error_code.hpp>
129#include <boost/system/system_error.hpp>
130
131#include <xrpl.pb.h>
132
133#include <algorithm>
134#include <array>
135#include <atomic>
136#include <chrono>
137#include <climits>
138#include <condition_variable>
139#include <cstddef>
140#include <cstdint>
141#include <cstdlib>
142#include <exception>
143#include <functional>
144#include <iterator>
145#include <limits>
146#include <memory>
147#include <mutex>
148#include <optional>
149#include <set>
150#include <sstream>
151#include <stdexcept>
152#include <string>
153#include <string_view>
154#include <type_traits>
155#include <unordered_map>
156#include <utility>
157#include <vector>
158
159namespace xrpl {
160
168class NetworkOPsImp final : public NetworkOPs
169{
173
175 {
176 public:
178 bool const admin;
179 bool const local;
181 bool applied = false;
183
185 : transaction(std::move(t)), admin(a), local(l), failType(f)
186 {
187 XRPL_ASSERT(
189 "xrpl::NetworkOPsImp::TransactionStatus::TransactionStatus : "
190 "valid inputs");
191 }
192 };
193
197 enum class DispatchState : unsigned char {
201 };
202
204
220 {
228
232 std::chrono::steady_clock::time_point start_ = std::chrono::steady_clock::now();
233 std::chrono::steady_clock::time_point const processStart_ = start_;
236
237 public:
239 {
240 counters_[static_cast<std::size_t>(OperatingMode::DISCONNECTED)].transitions = 1;
241 }
242
249 void
251
257 void
258 json(json::Value& obj) const;
259
267
268 CounterData
270 {
271 std::scoped_lock const lock(mutex_);
272 return {
273 .counters = counters_,
274 .mode = mode_,
275 .start = start_,
276 .initialSyncUs = initialSyncUs_,
277 };
278 }
279 };
280
285 {
286 ServerFeeSummary() = default;
287
289 XRPAmount fee,
290 TxQ::Metrics escalationMetrics, // trivially copyable
291 LoadFeeTrack const& loadFeeTrack);
292 bool
293 operator!=(ServerFeeSummary const& b) const;
294
295 bool
297 {
298 return !(*this != b);
299 }
300
305 };
306
307public:
309 ServiceRegistry& registry,
311 bool standalone,
312 std::size_t minPeerCount,
313 bool startValid,
314 JobQueue& jobQueue,
315 LedgerMaster& ledgerMaster,
316 ValidatorKeys const& validatorKeys,
317 boost::asio::io_context& ioCtx,
319 beast::insight::Collector::Ptr const& collector)
320 : registry_(registry)
324 , heartbeatTimer_(ioCtx)
325 , clusterTimer_(ioCtx)
327 , consensus_(
328 registry_.get().getApp(),
330 setupFeeVote(registry_.get().getApp().config().section(Sections::kVoting)),
331 registry_.get().getJournal("FeeVote")),
332 ledgerMaster,
333 *localTX_,
334 registry.getInboundTransactions(),
335 beast::getAbstractClock<std::chrono::steady_clock>(),
336 validatorKeys,
337 registry_.get().getJournal("LedgerConsensus"))
338 , validatorPK_(
339 validatorKeys.keys ? validatorKeys.keys->publicKey : decltype(validatorPK_){})
341 validatorKeys.keys ? validatorKeys.keys->masterPublicKey
342 : decltype(validatorMasterPK_){})
343 , ledgerMaster_(ledgerMaster)
344 , jobQueue_(jobQueue)
345 , standalone_(standalone)
346 , minPeerCount_(startValid ? 0 : minPeerCount)
347 , stats_([this] { collectMetrics(); }, collector)
348 {
349 }
350
351 ~NetworkOPsImp() override
352 {
353 // This clear() is necessary to ensure the shared_ptrs in this map get
354 // destroyed NOW because the objects in this map invoke methods on this
355 // class when they are destroyed
356 rpcSubMap_.clear();
357 }
358
359public:
361 getOperatingMode() const override;
362
364 strOperatingMode(OperatingMode const mode, bool const admin) const override;
365
367 strOperatingMode(bool const admin = false) const override;
368
369 //
370 // Transaction operations.
371 //
372
373 // Must complete immediately.
374 void
376
377 void
379 std::shared_ptr<Transaction>& transaction,
380 bool bUnlimited,
381 bool bLocal,
382 FailHard failType) override;
383
384 void
386
395 void
396 doTransactionSync(std::shared_ptr<Transaction> transaction, bool bUnlimited, FailHard failType);
397
407 void
410 bool bUnlimited,
411 FailHard failtype);
412
413private:
414 bool
416
417 void
420 std::function<bool(std::unique_lock<std::mutex> const&)> retryCallback);
421
422public:
426 void
428
434 void
436
437 //
438 // Owner functions.
439 //
440
442 getOwnerInfo(std::shared_ptr<ReadView const> lpLedger, AccountID const& account) override;
443
444 //
445 // Book functions.
446 //
447
448 void
451 Book const&,
452 AccountID const& uTakerID,
453 bool const bProof,
454 unsigned int iLimit,
455 json::Value const& jvMarker,
456 json::Value& jvResult) override;
457
458 // Ledger proposal/close functions.
459 bool
461
462 bool
463 recvValidation(std::shared_ptr<STValidation> const& val, std::string const& source) override;
464
465 void
466 mapComplete(std::shared_ptr<SHAMap> const& map, bool fromAcquire) override;
467
468 // Network state machine.
469
470 // Used for the "jump" case.
471private:
472 void
474 bool
476
477public:
478 bool
479 beginConsensus(UInt256 const& networkClosed, std::unique_ptr<std::stringstream> const& clog)
480 override;
481 void
483 void
484 setStandAlone() override;
485
490 void
491 setStateTimer() override;
492
493 void
494 setNeedNetworkLedger() override;
495 void
496 clearNeedNetworkLedger() override;
497 bool
498 isNeedNetworkLedger() override;
499 bool
500 isFull() override;
501
502 void
503 setMode(OperatingMode om) override;
504
505 bool
506 isBlocked() override;
507 bool
508 isAmendmentBlocked() override;
509 void
510 setAmendmentBlocked() override;
511 bool
512 isAmendmentWarned() override;
513 void
514 setAmendmentWarned() override;
515 void
516 clearAmendmentWarned() override;
517 bool
518 isUNLBlocked() override;
519 void
520 setUNLBlocked() override;
521 void
522 clearUNLBlocked() override;
523 void
524 consensusViewChange() override;
525
527 getConsensusInfo() override;
529 getServerInfo(bool human, bool admin, bool counters) override;
530 void
531 clearLedgerFetch() override;
533 getLedgerFetchInfo() override;
536 void
537 reportFeeChange() override;
538 void
540
541 void
542 updateLocalTx(ReadView const& view) override;
544 getLocalTxCount() override;
546 getBookSubscribersCount() override;
547
548 //
549 // Monitoring: publisher side.
550 //
551 void
552 pubLedger(std::shared_ptr<ReadView const> const& lpAccepted) override;
553 void
556 std::shared_ptr<STTx const> const& transaction,
557 TER result) override;
558 void
559 pubValidation(std::shared_ptr<STValidation> const& val) override;
560
561 //--------------------------------------------------------------------------
562 //
563 // InfoSub::Source.
564 //
565 void
566 subAccount(InfoSub::Ref ispListener, HashSet<AccountID> const& vnaAccountIDs, bool rt) override;
567 void
568 unsubAccount(InfoSub::Ref ispListener, HashSet<AccountID> const& vnaAccountIDs, bool rt)
569 override;
570
571 // Just remove the subscription from the tracking
572 // not from the InfoSub. Needed for InfoSub destruction
573 void
574 unsubAccountInternal(std::uint64_t seq, HashSet<AccountID> const& vnaAccountIDs, bool rt)
575 override;
576
577 void
578 subMPT(InfoSub::Ref ispListener, HashSet<MPTID> const& mptIDs) override;
579 void
580 unsubMPT(InfoSub::Ref ispListener, HashSet<MPTID> const& mptIDs) override;
581 void
582 unsubMPTInternal(std::uint64_t seq, MPTID const& mptID) override;
583
585 subAccountHistory(InfoSub::Ref ispListener, AccountID const& account) override;
586 void
587 unsubAccountHistory(InfoSub::Ref ispListener, AccountID const& account, bool historyOnly)
588 override;
589
590 void
591 unsubAccountHistoryInternal(std::uint64_t seq, AccountID const& account, bool historyOnly)
592 override;
593
594 void
596 std::uint64_t seq,
597 HashSet<AccountID> rtAccounts,
598 HashSet<AccountID> normalAccounts,
599 HashSet<AccountID> historyAccounts) override;
600
601 bool
602 subLedger(InfoSub::Ref ispListener, json::Value& jvResult) override;
603 bool
604 unsubLedger(std::uint64_t uListener) override;
605
606 bool
607 subBookChanges(InfoSub::Ref ispListener) override;
608 bool
609 unsubBookChanges(std::uint64_t uListener) override;
610
611 bool
612 subServer(InfoSub::Ref ispListener, json::Value& jvResult, bool admin) override;
613 bool
614 unsubServer(std::uint64_t uListener) override;
615
616 bool
617 subBook(InfoSub::Ref ispListener, Book const&) override;
618 bool
619 unsubBook(InfoSub::Ref ispListener, Book const&) override;
620 bool
621 unsubBookInternal(std::uint64_t uListener, Book const&) override;
622
623 bool
624 subManifests(InfoSub::Ref ispListener) override;
625 bool
626 unsubManifests(std::uint64_t uListener) override;
627 void
628 pubManifest(Manifest const&) override;
629
630 bool
631 subTransactions(InfoSub::Ref ispListener) override;
632 bool
633 unsubTransactions(std::uint64_t uListener) override;
634
635 bool
636 subRTTransactions(InfoSub::Ref ispListener) override;
637 bool
638 unsubRTTransactions(std::uint64_t uListener) override;
639
640 bool
641 subValidations(InfoSub::Ref ispListener) override;
642 bool
643 unsubValidations(std::uint64_t uListener) override;
644
645 bool
646 subPeerStatus(InfoSub::Ref ispListener) override;
647 bool
648 unsubPeerStatus(std::uint64_t uListener) override;
649 void
650 pubPeerStatus(std::function<json::Value()> const&) override;
651
652 bool
653 subConsensus(InfoSub::Ref ispListener) override;
654 bool
655 unsubConsensus(std::uint64_t uListener) override;
656
658 findRpcSub(std::string const& strUrl) override;
660 addRpcSub(std::string const& strUrl, InfoSub::Ref) override;
661 bool
662 tryRemoveRpcSub(std::string const& strUrl) override;
663
676 findRpcSubLocked(std::string const& strUrl);
677
678 beast::Journal const&
679 journal() const override
680 {
681 return journal_;
682 }
683
684 void
685 stop() override
686 {
687 {
688 try
689 {
690 heartbeatTimer_.cancel();
691 }
692 catch (boost::system::system_error const& e)
693 {
694 JLOG(journal_.error()) << "NetworkOPs: heartbeatTimer cancel error: " << e.what();
695 }
696
697 try
698 {
699 clusterTimer_.cancel();
700 }
701 catch (boost::system::system_error const& e)
702 {
703 JLOG(journal_.error()) << "NetworkOPs: clusterTimer cancel error: " << e.what();
704 }
705
706 try
707 {
708 accountHistoryTxTimer_.cancel();
709 }
710 catch (boost::system::system_error const& e)
711 {
712 JLOG(journal_.error())
713 << "NetworkOPs: accountHistoryTxTimer cancel error: " << e.what();
714 }
715 }
716 // Make sure that any waitHandlers pending in our timers are done.
717 using namespace std::chrono_literals;
718 waitHandlerCounter_.join("NetworkOPs", 1s, journal_);
719 }
720
721 void
722 stateAccounting(json::Value& obj) override;
723
724private:
725 void
726 setTimer(
727 boost::asio::steady_timer& timer,
728 std::chrono::milliseconds const& expiryTime,
729 std::function<void()> onExpire,
730 std::function<void()> onError);
731 void
733 void
735 void
737 void
739
741 transJson(
742 std::shared_ptr<STTx const> const& transaction,
743 TER result,
744 bool validated,
747
748 void
751 AcceptedLedgerTx const& transaction,
752 bool last);
753
754 void
757 AcceptedLedgerTx const& transaction,
758 bool last);
759
783 void
784 pubBookTransaction(AcceptedLedgerTx const& transaction, MultiApiJson const& jvObj);
785
786 void
789 std::shared_ptr<STTx const> const& transaction,
790 TER result);
791
796 void
798 std::shared_ptr<ReadView const> const& lpAccepted,
799 std::shared_ptr<AcceptedLedger const> const& alpAccepted);
800
806 void
808
809 void
810 pubServer();
811 void
813 void
814 pubMPTTransaction(AcceptedLedgerTx const& transaction, MultiApiJson const& jvObj);
815
817 getHostId(bool forAdmin);
818
819private:
824
825 /*
826 * With a validated ledger to separate history and future, the node
827 * streams historical txns with negative indexes starting from -1,
828 * and streams future txns starting from index 0.
829 * The SubAccountHistoryIndex struct maintains these indexes.
830 * It also has a flag stopHistorical_ for stopping streaming
831 * the historical txns.
832 */
862
868 void
872 void
874 void
876
887 static constexpr std::size_t kAccountCleanupChunk = 4096;
888
910 template <typename OuterMap, typename BeforeErase>
911 void
913 std::uint64_t seq,
914 HashSet<AccountID> const& accounts,
915 OuterMap& outerMap,
916 BeforeErase&& beforeErase);
917
925 void
927 std::uint64_t seq,
928 HashSet<AccountID> const& accounts,
929 SubInfoMapType& subMap);
930
935 void
937
940
942
943 // Independent lock domains so a long cleanup/publish on one does not stall
944 // the others. Hold at most one at a time; if ever more, order: accountLock_,
945 // bookLock_, mptLock_, streamLock_.
946 //
947 // Deferred-destruction rule (non-recursive mutexes): under bookLock_,
948 // mptLock_, or streamLock_, never let the last InfoSub pointer die inside the
949 // lock - ~InfoSub re-acquires it via unsub* -> self-deadlock. Publishers
950 // collect the locked pointers in a container declared before the lock and
951 // destruct after release (see pubServer / pubBookTransaction /
952 // pubMPTTransaction). accountLock_ is exempt: ~InfoSub offloads account
953 // teardown to scheduleAccountCleanup.
958
960
965
967 boost::asio::steady_timer heartbeatTimer_;
968 boost::asio::steady_timer clusterTimer_;
969 boost::asio::steady_timer accountHistoryTxTimer_;
970
972
975
977
979
990
995
997
999
1000 // Used as array indices; converting to enum class would require casts at ~40 call sites.
1001 // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
1003 SLedger, // Accepted ledgers.
1004 SManifests, // Received validator manifests.
1005 SServer, // When server changes connectivity state.
1006 STransactions, // All accepted transactions.
1007 SRtTransactions, // All proposed and accepted transactions.
1008 SValidations, // Received validations.
1009 SPeerStatus, // Peer status changes.
1010 SConsensusPhase, // Consensus phase
1011 SBookChanges, // Per-ledger order book changes
1012 SLastEntry, // Any new entry must be ADDED ABOVE this one
1013 };
1014
1020
1022
1024
1025 // Whether we are in standalone mode.
1026 bool const standalone_;
1027
1028 // The number of nodes that we need to consider ourselves connected.
1030
1031 // Transaction batching.
1036
1038
1041
1042private:
1043 struct Stats
1044 {
1045 template <class Handler>
1046 Stats(Handler const& handler, beast::insight::Collector::Ptr const& collector)
1047 : hook(collector->makeHook(handler))
1049 collector->makeGauge("State_Accounting", "Disconnected_duration"))
1050 , connectedDuration(collector->makeGauge("State_Accounting", "Connected_duration"))
1051 , syncingDuration(collector->makeGauge("State_Accounting", "Syncing_duration"))
1052 , trackingDuration(collector->makeGauge("State_Accounting", "Tracking_duration"))
1053 , fullDuration(collector->makeGauge("State_Accounting", "Full_duration"))
1055 collector->makeGauge("State_Accounting", "Disconnected_transitions"))
1057 collector->makeGauge("State_Accounting", "Connected_transitions"))
1058 , syncingTransitions(collector->makeGauge("State_Accounting", "Syncing_transitions"))
1059 , trackingTransitions(collector->makeGauge("State_Accounting", "Tracking_transitions"))
1060 , fullTransitions(collector->makeGauge("State_Accounting", "Full_transitions"))
1061 {
1062 }
1063
1070
1076 };
1077
1078 std::mutex statsMutex_; // Mutex to lock stats_
1080
1081private:
1082 void
1084};
1085
1086//------------------------------------------------------------------------------
1087
1089 {"disconnected", "connected", "syncing", "tracking", "full"},
1090};
1091
1093
1095 {
1101 },
1102};
1103
1104static auto const kGenesisAccountId =
1105 calcAccountID(generateKeyPair(KeyType::Secp256k1, generateSeed("masterpassphrase")).first);
1106
1107//------------------------------------------------------------------------------
1108inline OperatingMode
1110{
1111 return mode_;
1112}
1113
1114inline std::string
1115NetworkOPsImp::strOperatingMode(bool const admin /* = false */) const
1116{
1117 return strOperatingMode(mode_, admin);
1118}
1119
1120inline void
1125
1126inline void
1131
1132inline void
1137
1138inline bool
1143
1144inline bool
1149
1152{
1153 static std::string const kHostname = boost::asio::ip::host_name();
1154
1155 if (forAdmin)
1156 return kHostname;
1157
1158 // For non-admin uses hash the node public key into a
1159 // single RFC1751 word:
1160 static std::string const kShroudedHostId = [this] {
1161 auto const& id = registry_.get().getApp().nodeIdentity();
1162
1163 return RFC1751::getWordFromBlob(id.first.data(), id.first.size());
1164 }();
1165
1166 return kShroudedHostId;
1167}
1168
1169void
1171{
1173
1174 // Only do this work if a cluster is configured
1175 if (registry_.get().getCluster().size() != 0)
1177}
1178
1179void
1181 boost::asio::steady_timer& timer,
1182 std::chrono::milliseconds const& expiryTime,
1183 std::function<void()> onExpire,
1184 std::function<void()> onError)
1185{
1186 // Only start the timer if waitHandlerCounter_ is not yet joined.
1187 if (auto optionalCountedHandler =
1188 waitHandlerCounter_.wrap([this, onExpire, onError](boost::system::error_code const& e) {
1189 if ((e.value() == boost::system::errc::success) && (!jobQueue_.isStopped()))
1190 {
1191 onExpire();
1192 }
1193 // Recover as best we can if an unexpected error occurs.
1194 if (e.value() != boost::system::errc::success &&
1195 e.value() != boost::asio::error::operation_aborted)
1196 {
1197 // Try again later and hope for the best.
1198 JLOG(journal_.error())
1199 << "Timer got error '" << e.message() << "'. Restarting timer.";
1200 onError();
1201 }
1202 }))
1203 {
1204 timer.expires_after(expiryTime);
1205 timer.async_wait(std::move(*optionalCountedHandler));
1206 }
1207}
1208
1209void
1211{
1212 setTimer(
1214 consensus_.parms().ledgerGRANULARITY,
1215 [this] { jobQueue_.addJob(JtNetopTimer, "NetHeart", [this] { processHeartbeatTimer(); }); },
1216 [this] { setHeartbeatTimer(); });
1217}
1218
1219void
1221{
1222 using namespace std::chrono_literals;
1223
1224 setTimer(
1226 10s,
1227 [this] {
1228 jobQueue_.addJob(JtNetopCluster, "NetCluster", [this] { processClusterTimer(); });
1229 },
1230 [this] { setClusterTimer(); });
1231}
1232
1233void
1235{
1236 JLOG(journal_.debug()) << "Scheduling AccountHistory job for account "
1237 << toBase58(subInfo.index->accountId);
1238 using namespace std::chrono_literals;
1239 setTimer(
1241 4s,
1242 [this, subInfo] { addAccountHistoryJob(subInfo); },
1243 [this, subInfo] { setAccountHistoryJobTimer(subInfo); });
1244}
1245
1246void
1248{
1249 RclConsensusLogger clog("Heartbeat Timer", consensus_.validating(), journal_);
1250 {
1251 std::unique_lock lock{registry_.get().getApp().getMasterMutex()};
1252
1253 // VFALCO NOTE This is for diagnosing a crash on exit
1254 LoadManager& mgr(registry_.get().getLoadManager());
1255 mgr.heartbeat();
1256
1257 std::size_t const numPeers = registry_.get().getOverlay().size();
1258
1259 // do we have sufficient peers? If not, we are disconnected.
1260 if (numPeers < minPeerCount_)
1261 {
1263 {
1266 ss << "Node count (" << numPeers << ") has fallen "
1267 << "below required minimum (" << minPeerCount_ << ").";
1268 JLOG(journal_.warn()) << ss.str();
1269 CLOG(clog.ss()) << "set mode to DISCONNECTED: " << ss.str();
1270 }
1271 else
1272 {
1273 CLOG(clog.ss()) << "already DISCONNECTED. too few peers (" << numPeers
1274 << "), need at least " << minPeerCount_;
1275 }
1276
1277 // MasterMutex lock need not be held to call setHeartbeatTimer()
1278 lock.unlock();
1279 // We do not call consensus_.timerEntry until there are enough
1280 // peers providing meaningful inputs to consensus
1282
1283 return;
1284 }
1285
1287 {
1289 JLOG(journal_.info()) << "Node count (" << numPeers << ") is sufficient.";
1290 CLOG(clog.ss()) << "setting mode to CONNECTED based on " << numPeers << " peers. ";
1291 }
1292
1293 // Check if the last validated ledger forces a change between these
1294 // states.
1295 auto const origMode = mode_.load();
1296 CLOG(clog.ss()) << "mode: " << strOperatingMode(origMode, true);
1298 {
1300 }
1301 else if (mode_ == OperatingMode::CONNECTED)
1302 {
1304 }
1305 auto const newMode = mode_.load();
1306 if (origMode != newMode)
1307 {
1308 CLOG(clog.ss()) << ", changing to " << strOperatingMode(newMode, true);
1309 }
1310 CLOG(clog.ss()) << ". ";
1311 }
1312
1313 consensus_.timerEntry(registry_.get().getTimeKeeper().closeTime(), clog.ss());
1314
1315 CLOG(clog.ss()) << "consensus phase " << to_string(lastConsensusPhase_);
1316 ConsensusPhase const currPhase = consensus_.phase();
1317 if (lastConsensusPhase_ != currPhase)
1318 {
1319 reportConsensusStateChange(currPhase);
1320 lastConsensusPhase_ = currPhase;
1321 CLOG(clog.ss()) << " changed to " << to_string(lastConsensusPhase_);
1322 }
1323 CLOG(clog.ss()) << ". ";
1324
1326}
1327
1328void
1330{
1331 if (registry_.get().getCluster().size() == 0)
1332 return;
1333
1334 using namespace std::chrono_literals;
1335
1336 bool const update = registry_.get().getCluster().update(
1337 registry_.get().getApp().nodeIdentity().first,
1338 "",
1339 (ledgerMaster_.getValidatedLedgerAge() <= 4min)
1340 ? registry_.get().getFeeTrack().getLocalFee()
1341 : 0,
1342 registry_.get().getTimeKeeper().now());
1343
1344 if (!update)
1345 {
1346 JLOG(journal_.debug()) << "Too soon to send cluster update";
1348 return;
1349 }
1350
1351 protocol::TMCluster cluster;
1352 registry_.get().getCluster().forEach([&cluster](ClusterNode const& node) {
1353 protocol::TMClusterNode& n = *cluster.add_clusternodes();
1354 n.set_publickey(toBase58(TokenType::NodePublic, node.identity()));
1355 n.set_reporttime(node.getReportTime().time_since_epoch().count());
1356 n.set_nodeload(node.getLoadFee());
1357 if (!node.name().empty())
1358 n.set_nodename(node.name());
1359 });
1360
1361 resource::Gossip const gossip = registry_.get().getResourceManager().exportConsumers();
1362 for (auto& item : gossip.items)
1363 {
1364 protocol::TMLoadSource& node = *cluster.add_loadsources();
1365 node.set_name(to_string(item.address));
1366 node.set_cost(item.balance);
1367 }
1368 registry_.get().getOverlay().foreach(
1369 sendIf(std::make_shared<Message>(cluster, protocol::mtCLUSTER), PeerInCluster()));
1371}
1372
1373//------------------------------------------------------------------------------
1374
1376NetworkOPsImp::strOperatingMode(OperatingMode const mode, bool const admin) const
1377{
1378 if (mode == OperatingMode::FULL && admin)
1379 {
1380 auto const consensusMode = consensus_.mode();
1381 if (consensusMode != ConsensusMode::WrongLedger)
1382 {
1383 if (consensusMode == ConsensusMode::Proposing)
1384 return "proposing";
1385
1386 if (consensus_.validating())
1387 return "validating";
1388 }
1389 }
1390
1391 return kStates[static_cast<std::size_t>(mode)];
1392}
1393
1394void
1396{
1397 if (isNeedNetworkLedger())
1398 {
1399 // Nothing we can do if we've never been in sync
1400 return;
1401 }
1402
1403 // Reject any transaction with the tfInnerBatchTxn flag at the network
1404 // boundary, regardless of amendment state.
1405 if (iTrans->isFlag(tfInnerBatchTxn))
1406 {
1407 JLOG(journal_.error()) << "Submitted transaction invalid: tfInnerBatchTxn flag present.";
1408 return;
1409 }
1410
1411 // this is an asynchronous interface
1412 auto const trans = sterilize(*iTrans);
1413
1414 auto const txid = trans->getTransactionID();
1415 auto const flags = registry_.get().getHashRouter().getFlags(txid);
1416
1418 {
1419 JLOG(journal_.warn()) << "Submitted transaction cached bad";
1420 return;
1421 }
1422
1423 try
1424 {
1425 auto const [validity, reason] = checkValidity(
1426 registry_.get().getHashRouter(), *trans, ledgerMaster_.getValidatedRules());
1427
1428 if (validity != Validity::Valid)
1429 {
1430 JLOG(journal_.warn()) << "Submitted transaction invalid: " << reason;
1431 return;
1432 }
1433 }
1434 catch (std::exception const& ex)
1435 {
1436 JLOG(journal_.warn()) << "Exception checking transaction " << txid << ": " << ex.what();
1437
1438 return;
1439 }
1440
1441 std::string reason;
1442
1443 auto const tx = std::make_shared<Transaction>(trans, reason, registry_.get().getApp());
1444
1445 jobQueue_.addJob(JtTransaction, "SubmitTxn", [this, tx] {
1446 auto t = tx;
1447 processTransaction(t, false, false, FailHard::No);
1448 });
1449}
1450
1451bool
1453{
1454 auto const newFlags = registry_.get().getHashRouter().getFlags(transaction->getID());
1455
1457 {
1458 // cached bad
1459 JLOG(journal_.warn()) << transaction->getID() << ": cached bad!\n";
1460 transaction->setStatus(TransStatus::INVALID);
1461 transaction->setResult(temBAD_SIGNATURE);
1462 return false;
1463 }
1464
1465 auto const view = ledgerMaster_.getCurrentLedger();
1466
1467 // This function is called by several different parts of the codebase
1468 // under no circumstances will we ever accept an inner txn within a batch
1469 // txn from the network.
1470 auto const& sttx = *transaction->getSTransaction();
1471 if (sttx.isFlag(tfInnerBatchTxn))
1472 {
1473 transaction->setStatus(TransStatus::INVALID);
1474 transaction->setResult(temINVALID_FLAG);
1475 registry_.get().getHashRouter().setFlags(transaction->getID(), HashRouterFlags::BAD);
1476 return false;
1477 }
1478
1479 // NOTE ximinez - I think this check is redundant,
1480 // but I'm not 100% sure yet.
1481 //
1482 // For an ordinary transaction it is: the relay and submit paths have
1483 // already run checkValidity, so this costs a HashRouter lookup. It is not
1484 // redundant for a role-signature transaction while fixCleanup3_4_0 is
1485 // activating. Those paths verify against the validated rules, which lag
1486 // the open ledger rules used here, and checkValidity scopes a cached
1487 // verdict to the rules that reached it, so this call can verify the
1488 // signature again and come to a different answer. SigBad is therefore
1489 // reachable, and the handler below is the correct response to it.
1490 auto const& viewRules = view->rules();
1491 auto const [validity, reason] = checkValidity(registry_.get().getHashRouter(), sttx, viewRules);
1492
1493 // Not concerned with local checks at this point.
1494 if (validity == Validity::SigBad)
1495 {
1496 JLOG(journal_.info()) << "Transaction has bad signature: " << reason;
1497 transaction->setStatus(TransStatus::INVALID);
1498 transaction->setResult(temBAD_SIGNATURE);
1499 // See the matching guard in PeerImp::checkTransaction: only cache
1500 // BAD for a role-signature transaction once fixCleanup3_4_0 is
1501 // enabled on this node. Remove together with the amendment.
1502 if (viewRules.enabled(fixCleanup3_4_0) ||
1503 (!sttx.isFieldPresent(sfSponsorSignature) &&
1504 !sttx.isFieldPresent(sfCounterpartySignature)))
1505 {
1506 registry_.get().getHashRouter().setFlags(transaction->getID(), HashRouterFlags::BAD);
1507 }
1508 return false;
1509 }
1510
1511 // canonicalize can change our pointer
1512 registry_.get().getMasterTransaction().canonicalize(&transaction);
1513
1514 return true;
1515}
1516
1517void
1519 std::shared_ptr<Transaction>& transaction,
1520 bool bUnlimited,
1521 bool bLocal,
1522 FailHard failType)
1523{
1524 auto const ev = jobQueue_.makeLoadEvent(JtTxnProc, "ProcessTXN");
1525
1526 // preProcessTransaction can change our pointer
1527 if (!preProcessTransaction(transaction))
1528 return;
1529
1530 if (bLocal)
1531 {
1532 doTransactionSync(transaction, bUnlimited, failType);
1533 }
1534 else
1535 {
1536 doTransactionAsync(transaction, bUnlimited, failType);
1537 }
1538}
1539
1540void
1542 std::shared_ptr<Transaction> transaction,
1543 bool bUnlimited,
1544 FailHard failType)
1545{
1546 std::scoped_lock const lock(mutex_);
1547
1548 if (transaction->getApplying())
1549 return;
1550
1551 transactions_.emplace_back(transaction, bUnlimited, false, failType);
1552 transaction->setApplying();
1553
1555 {
1556 if (jobQueue_.addJob(JtBatch, "TxBatchAsync", [this] { transactionBatch(); }))
1557 {
1559 }
1560 }
1561}
1562
1563void
1565 std::shared_ptr<Transaction> transaction,
1566 bool bUnlimited,
1567 FailHard failType)
1568{
1570
1571 if (!transaction->getApplying())
1572 {
1573 transactions_.emplace_back(transaction, bUnlimited, true, failType);
1574 transaction->setApplying();
1575 }
1576
1577 doTransactionSyncBatch(lock, [&transaction](std::unique_lock<std::mutex> const&) {
1578 return transaction->getApplying();
1579 });
1580}
1581
1582void
1585 std::function<bool(std::unique_lock<std::mutex> const&)> retryCallback)
1586{
1587 do
1588 {
1590 {
1591 // A batch processing job is already running, so wait.
1592 cond_.wait(lock);
1593 }
1594 else
1595 {
1596 apply(lock);
1597
1598 if (!transactions_.empty())
1599 {
1600 // More transactions need to be applied, but by another job.
1601 if (jobQueue_.addJob(JtBatch, "TxBatchSync", [this] { transactionBatch(); }))
1602 {
1604 }
1605 }
1606 }
1607 } while (retryCallback(lock));
1608}
1609
1610void
1612{
1613 auto const ev = jobQueue_.makeLoadEvent(JtTxnProc, "ProcessTXNSet");
1615 candidates.reserve(set.size());
1616 for (auto const& [_, tx] : set)
1617 {
1618 std::string reason;
1619 auto transaction = std::make_shared<Transaction>(tx, reason, registry_.get().getApp());
1620
1621 if (transaction->getStatus() == TransStatus::INVALID)
1622 {
1623 if (!reason.empty())
1624 {
1625 JLOG(journal_.trace()) << "Exception checking transaction: " << reason;
1626 }
1627 registry_.get().getHashRouter().setFlags(tx->getTransactionID(), HashRouterFlags::BAD);
1628 continue;
1629 }
1630
1631 // preProcessTransaction can change our pointer
1632 if (!preProcessTransaction(transaction))
1633 continue;
1634
1635 candidates.emplace_back(transaction);
1636 }
1637
1639 transactions.reserve(candidates.size());
1640
1642
1643 for (auto const& transaction : candidates)
1644 {
1645 if (!transaction->getApplying())
1646 {
1647 transactions.emplace_back(transaction, false, false, FailHard::No);
1648 transaction->setApplying();
1649 }
1650 }
1651
1652 if (transactions_.empty())
1653 {
1655 }
1656 else
1657 {
1658 transactions_.reserve(transactions_.size() + transactions.size());
1659 for (auto& t : transactions)
1660 transactions_.push_back(std::move(t));
1661 }
1662 if (transactions_.empty())
1663 {
1664 JLOG(journal_.debug()) << "No transaction to process!";
1665 return;
1666 }
1667
1669 XRPL_ASSERT(lock.owns_lock(), "xrpl::NetworkOPsImp::processTransactionSet has lock");
1670 return std::ranges::any_of(
1671 transactions_, [](auto const& t) { return t.transaction->getApplying(); });
1672 });
1673}
1674
1675void
1677{
1679
1681 return;
1682
1683 while (!transactions_.empty())
1684 {
1685 apply(lock);
1686 }
1687}
1688
1689void
1691{
1695 XRPL_ASSERT(!transactions.empty(), "xrpl::NetworkOPsImp::apply : non-empty transactions");
1696 XRPL_ASSERT(
1697 dispatchState_ != DispatchState::Running, "xrpl::NetworkOPsImp::apply : is not running");
1698
1700
1701 batchLock.unlock();
1702
1703 {
1704 std::unique_lock masterLock{registry_.get().getApp().getMasterMutex(), std::defer_lock};
1705 bool changed = false;
1706 {
1707 std::unique_lock ledgerLock{ledgerMaster_.peekMutex(), std::defer_lock};
1708 std::lock(masterLock, ledgerLock);
1709 registry_.get().getOpenLedger().modify([&](OpenView& view, beast::Journal j) {
1711 {
1712 // we check before adding to the batch
1713 ApplyFlags flags = TapNone;
1714 if (e.admin)
1715 flags |= TapUnlimited;
1716
1717 if (e.failType == FailHard::Yes)
1718 flags |= TapFailHard;
1719
1720 auto const result = registry_.get().getTxQ().apply(
1721 registry_.get().getApp(), view, e.transaction->getSTransaction(), flags, j);
1722 e.result = result.ter;
1723 e.applied = result.applied;
1724 changed = changed || result.applied;
1725 }
1726 return changed;
1727 });
1728 }
1729 if (changed)
1731
1732 std::optional<LedgerIndex> validatedLedgerIndex;
1733 if (auto const l = ledgerMaster_.getValidatedLedger())
1734 validatedLedgerIndex = l->header().seq;
1735
1736 auto const newOL = registry_.get().getOpenLedger().current();
1737 for (TransactionStatus const& e : transactions)
1738 {
1739 e.transaction->clearSubmitResult();
1740
1741 if (e.applied)
1742 {
1743 pubProposedTransaction(newOL, e.transaction->getSTransaction(), e.result);
1744 e.transaction->setApplied();
1745 }
1746
1747 e.transaction->setResult(e.result);
1748
1749 if (isTemMalformed(e.result))
1750 {
1751 registry_.get().getHashRouter().setFlags(
1752 e.transaction->getID(), HashRouterFlags::BAD);
1753 }
1754
1755 bool const addLocal = e.local;
1756
1757 if (isTesSuccess(e.result))
1758 {
1759 JLOG(journal_.debug()) << "Transaction is now included in open ledger";
1760 e.transaction->setStatus(TransStatus::INCLUDED);
1761
1762 // Pop as many "reasonable" transactions for this account as
1763 // possible. "Reasonable" means they have sequential sequence
1764 // numbers, or use tickets.
1765 auto const& txCur = e.transaction->getSTransaction();
1766
1767 std::size_t count = 0;
1768 for (auto txNext = ledgerMaster_.popAcctTransaction(txCur);
1769 txNext && count < kMaxPoppedTransactions;
1770 txNext = ledgerMaster_.popAcctTransaction(txCur), ++count)
1771 {
1772 if (!batchLock.owns_lock())
1773 batchLock.lock();
1774 std::string reason;
1775 auto const trans = sterilize(*txNext);
1776 auto const t =
1777 std::make_shared<Transaction>(trans, reason, registry_.get().getApp());
1778 if (t->getApplying())
1779 break;
1780 submitHeld.emplace_back(t, false, false, FailHard::No);
1781 t->setApplying();
1782 }
1783 if (batchLock.owns_lock())
1784 batchLock.unlock();
1785 }
1786 else if (e.result == tefPAST_SEQ)
1787 {
1788 // duplicate or conflict
1789 JLOG(journal_.debug()) << "Transaction is obsolete";
1790 e.transaction->setStatus(TransStatus::OBSOLETE);
1791 }
1792 else if (e.result == terQUEUED)
1793 {
1794 JLOG(journal_.debug()) << "Transaction is likely to claim a"
1795 << " fee, but is queued until fee drops";
1796
1797 e.transaction->setStatus(TransStatus::HELD);
1798 // Add to held transactions, because it could get
1799 // kicked out of the queue, and this will try to
1800 // put it back.
1801 ledgerMaster_.addHeldTransaction(e.transaction);
1802 e.transaction->setQueued();
1803 e.transaction->setKept();
1804 }
1805 else if (isTerRetry(e.result) || isTelLocal(e.result) || isTefFailure(e.result))
1806 {
1807 if (e.failType != FailHard::Yes)
1808 {
1809 auto const lastLedgerSeq =
1810 e.transaction->getSTransaction()->at(~sfLastLedgerSequence);
1811 auto const ledgersLeft = lastLedgerSeq
1812 ? *lastLedgerSeq - ledgerMaster_.getCurrentLedgerIndex()
1814 // If any of these conditions are met, the transaction can
1815 // be held:
1816 // 1. It was submitted locally. (Note that this flag is only
1817 // true on the initial submission.)
1818 // 2. The transaction has a LastLedgerSequence, and the
1819 // LastLedgerSequence is fewer than LocalTxs::kHoldLedgers
1820 // (5) ledgers into the future. (Remember that an
1821 // unseated optional compares as less than all seated
1822 // values, so it has to be checked explicitly first.)
1823 // 3. The HashRouterFlags::BAD flag is not set on the txID.
1824 // (setFlags
1825 // checks before setting. If the flag is set, it returns
1826 // false, which means it's been held once without one of
1827 // the other conditions, so don't hold it again. Time's
1828 // up!)
1829 //
1830 if (e.local || (ledgersLeft && ledgersLeft <= LocalTxs::kHoldLedgers) ||
1831 registry_.get().getHashRouter().setFlags(
1832 e.transaction->getID(), HashRouterFlags::HELD))
1833 {
1834 // transaction should be held
1835 JLOG(journal_.debug()) << "Transaction should be held: " << e.result;
1836 e.transaction->setStatus(TransStatus::HELD);
1837 ledgerMaster_.addHeldTransaction(e.transaction);
1838 e.transaction->setKept();
1839 }
1840 else
1841 {
1842 JLOG(journal_.debug())
1843 << "Not holding transaction " << e.transaction->getID() << ": "
1844 << (e.local ? "local" : "network") << ", "
1845 << "result: " << e.result << " ledgers left: "
1846 << (ledgersLeft ? to_string(*ledgersLeft) : "unspecified");
1847 }
1848 }
1849 }
1850 else
1851 {
1852 JLOG(journal_.debug()) << "Status other than success " << e.result;
1853 e.transaction->setStatus(TransStatus::INVALID);
1854 }
1855
1856 auto const enforceFailHard = e.failType == FailHard::Yes && !isTesSuccess(e.result);
1857
1858 if (addLocal && !enforceFailHard)
1859 {
1860 localTX_->pushBack(
1861 ledgerMaster_.getCurrentLedgerIndex(), e.transaction->getSTransaction());
1862 e.transaction->setKept();
1863 }
1864
1865 if ((e.applied ||
1866 ((mode_ != OperatingMode::FULL) && (e.failType != FailHard::Yes) && e.local) ||
1867 (e.result == terQUEUED)) &&
1868 !enforceFailHard)
1869 {
1870 auto const toSkip =
1871 registry_.get().getHashRouter().shouldRelay(e.transaction->getID());
1872 if (auto const& sttx = *e.transaction->getSTransaction(); toSkip &&
1873 // Skip relaying if it's an inner batch txn. The flag should
1874 // only be set if the Batch feature is enabled. If Batch is
1875 // not enabled, the flag is always invalid, so don't relay
1876 // it regardless.
1877 !sttx.isFlag(tfInnerBatchTxn))
1878 {
1879 protocol::TMTransaction tx;
1880 Serializer s;
1881
1882 sttx.add(s);
1883 tx.set_rawtransaction(s.data(), s.size());
1884 tx.set_status(protocol::tsCURRENT);
1885 tx.set_deferred(e.result == terQUEUED);
1886 // FIXME: This should be when we received it
1887 registry_.get().getOverlay().relay(sttx, tx, *toSkip);
1888 e.transaction->setBroadcast();
1889 }
1890 }
1891
1892 if (validatedLedgerIndex)
1893 {
1894 auto maybeFeeAndSeq = registry_.get().getTxQ().getTxRequiredFeeAndSeq(
1895 *newOL, e.transaction->getSTransaction());
1896 if (maybeFeeAndSeq.has_value())
1897 {
1898 auto [fee, accountSeq, availableSeq] = *maybeFeeAndSeq;
1899 e.transaction->setCurrentLedgerState(
1900 *validatedLedgerIndex, fee, accountSeq, availableSeq);
1901 }
1902 else
1903 {
1904 JLOG(journal_.debug())
1905 << "Unable to compute current ledger state for tx "
1906 << e.transaction->getID() << " in validated ledger "
1907 << *validatedLedgerIndex << ": " << transToken(maybeFeeAndSeq.error());
1908 }
1909 }
1910 }
1911 }
1912
1913 batchLock.lock();
1914
1915 for (TransactionStatus const& e : transactions)
1916 e.transaction->clearApplying();
1917
1918 if (!submitHeld.empty())
1919 {
1920 if (transactions_.empty())
1921 {
1922 transactions_.swap(submitHeld);
1923 }
1924 else
1925 {
1926 transactions_.reserve(transactions_.size() + submitHeld.size());
1927 for (auto& e : submitHeld)
1928 transactions_.push_back(std::move(e));
1929 }
1930 }
1931
1932 cond_.notify_all();
1933
1935}
1936
1937//
1938// Owner functions
1939//
1940
1943{
1945 auto const root = keylet::ownerDir(account);
1946 auto sleNode = lpLedger->read(keylet::page(root));
1947 if (sleNode)
1948 {
1949 std::uint64_t uNodeDir = 0;
1950
1951 do
1952 {
1953 for (auto const& uDirEntry : sleNode->getFieldV256(sfIndexes))
1954 {
1955 auto const sleCur = lpLedger->read(keylet::child(uDirEntry));
1956 XRPL_ASSERT(sleCur, "xrpl::NetworkOPsImp::getOwnerInfo : non-null child SLE");
1957
1958 switch (sleCur->getType())
1959 {
1960 case ltOFFER:
1961 if (!jvObjects.isMember(jss::offers))
1962 jvObjects[jss::offers] = json::Value(json::ValueType::Array);
1963
1964 jvObjects[jss::offers].append(sleCur->getJson(JsonOptions::Values::None));
1965 break;
1966
1967 case ltRIPPLE_STATE:
1968 if (!jvObjects.isMember(jss::ripple_lines))
1969 {
1970 jvObjects[jss::ripple_lines] = json::Value(json::ValueType::Array);
1971 }
1972
1973 jvObjects[jss::ripple_lines].append(
1974 sleCur->getJson(JsonOptions::Values::None));
1975 break;
1976
1977 case ltACCOUNT_ROOT:
1978 case ltDIR_NODE:
1979 // LCOV_EXCL_START
1980 default:
1981 UNREACHABLE(
1982 "xrpl::NetworkOPsImp::getOwnerInfo : invalid "
1983 "type");
1984 break;
1985 // LCOV_EXCL_STOP
1986 }
1987 }
1988
1989 uNodeDir = sleNode->getFieldU64(sfIndexNext);
1990
1991 if (uNodeDir != 0u)
1992 {
1993 sleNode = lpLedger->read(keylet::page(root, uNodeDir));
1994 XRPL_ASSERT(sleNode, "xrpl::NetworkOPsImp::getOwnerInfo : read next page");
1995 }
1996 } while (uNodeDir != 0u);
1997 }
1998
1999 return jvObjects;
2000}
2001
2002//
2003// Other
2004//
2005
2006inline bool
2011
2012inline bool
2017
2018void
2024
2025inline bool
2030
2031inline void
2036
2037inline void
2042
2043inline bool
2045{
2046 return unlBlocked_;
2047}
2048
2049void
2055
2056inline void
2061
2062bool
2064{
2065 // Returns true if there's an *abnormal* ledger issue, normal changing in
2066 // TRACKING mode should return false. Do we have sufficient validations for
2067 // our last closed ledger? Or do sufficient nodes agree? And do we have no
2068 // better ledger available? If so, we are either tracking or full.
2069
2070 JLOG(journal_.trace()) << "NetworkOPsImp::checkLastClosedLedger";
2071
2072 auto const ourClosed = ledgerMaster_.getClosedLedger();
2073
2074 if (!ourClosed)
2075 return false;
2076
2077 UInt256 closedLedger = ourClosed->header().hash;
2078 UInt256 const prevClosedLedger = ourClosed->header().parentHash;
2079 JLOG(journal_.trace()) << "OurClosed: " << closedLedger;
2080 JLOG(journal_.trace()) << "PrevClosed: " << prevClosedLedger;
2081
2082 //-------------------------------------------------------------------------
2083 // Determine preferred last closed ledger
2084
2085 auto& validations = registry_.get().getValidations();
2086 JLOG(journal_.debug()) << "ValidationTrie " << json::Compact(validations.getJsonTrie());
2087
2088 // Will rely on peer LCL if no trusted validations exist
2090 peerCounts[closedLedger] = 0;
2092 peerCounts[closedLedger]++;
2093
2094 for (auto& peer : peerList)
2095 {
2096 UInt256 const peerLedger = peer->getClosedLedgerHash();
2097
2098 if (peerLedger.isNonZero())
2099 ++peerCounts[peerLedger];
2100 }
2101
2102 for (auto const& it : peerCounts)
2103 JLOG(journal_.debug()) << "L: " << it.first << " n=" << it.second;
2104
2105 UInt256 const preferredLCL = validations.getPreferredLCL(
2106 RCLValidatedLedger{ourClosed, validations.adaptor().journal()},
2107 ledgerMaster_.getValidLedgerIndex(),
2108 peerCounts);
2109
2110 bool switchLedgers = preferredLCL != closedLedger;
2111 if (switchLedgers)
2112 closedLedger = preferredLCL;
2113 //-------------------------------------------------------------------------
2114 if (switchLedgers && (closedLedger == prevClosedLedger))
2115 {
2116 // don't switch to our own previous ledger
2117 JLOG(journal_.info()) << "We won't switch to our own previous ledger";
2118 networkClosed = ourClosed->header().hash;
2119 switchLedgers = false;
2120 }
2121 else
2122 {
2123 networkClosed = closedLedger;
2124 }
2125
2126 if (!switchLedgers)
2127 return false;
2128
2129 auto consensus = ledgerMaster_.getLedgerByHash(closedLedger);
2130
2131 if (!consensus)
2132 {
2133 consensus = registry_.get().getInboundLedgers().acquire(
2134 closedLedger, 0, InboundLedger::Reason::CONSENSUS);
2135 }
2136
2137 if (consensus &&
2138 (!ledgerMaster_.canBeCurrent(consensus) ||
2139 !ledgerMaster_.isCompatible(*consensus, journal_.debug(), "Not switching")))
2140 {
2141 // Don't switch to a ledger not on the validated chain
2142 // or with an invalid close time or sequence
2143 networkClosed = ourClosed->header().hash;
2144 return false;
2145 }
2146
2147 JLOG(journal_.warn()) << "We are not running on the consensus ledger";
2148 JLOG(journal_.info()) << "Our LCL: " << ourClosed->header().hash << getJson({*ourClosed, {}});
2149 JLOG(journal_.info()) << "Net LCL " << closedLedger;
2150
2152 {
2154 }
2155
2156 if (consensus)
2157 {
2158 // FIXME: If this rewinds the ledger sequence, or has the same
2159 // sequence, we should update the status on any stored transactions
2160 // in the invalidated ledgers.
2161 switchLastClosedLedger(consensus);
2162 }
2163
2164 return true;
2165}
2166
2167void
2169{
2170 // set the newLCL as our last closed ledger -- this is abnormal code
2171 JLOG(journal_.error()) << "JUMP last closed ledger to " << newLCL->header().hash;
2172
2174
2175 // Update fee computations.
2176 registry_.get().getTxQ().processClosedLedger(registry_.get().getApp(), *newLCL, true);
2177
2178 // Caller must own master lock
2179 {
2180 // Apply tx in old open ledger to new
2181 // open ledger. Then apply local tx.
2182
2183 auto retries = localTX_->getTxSet();
2184 auto const lastVal = registry_.get().getLedgerMaster().getValidatedLedger();
2186 if (lastVal)
2187 {
2188 rules = makeRulesGivenLedger(*lastVal, registry_.get().getApp().config().features);
2189 }
2190 else
2191 {
2192 rules.emplace(registry_.get().getApp().config().features);
2193 }
2194 registry_.get().getOpenLedger().accept(
2195 registry_.get().getApp(),
2196 *rules,
2197 newLCL,
2198 OrderedTxs({}),
2199 false,
2200 retries,
2201 TapNone,
2202 "jump",
2203 [&](OpenView& view, beast::Journal j) {
2204 // Stuff the ledger with transactions from the queue.
2205 return registry_.get().getTxQ().accept(registry_.get().getApp(), view);
2206 });
2207 }
2208
2209 ledgerMaster_.switchLCL(newLCL);
2210
2211 protocol::TMStatusChange s;
2212 s.set_newevent(protocol::neSWITCHED_LEDGER);
2213 s.set_ledgerseq(newLCL->header().seq);
2214 s.set_networktime(registry_.get().getTimeKeeper().now().time_since_epoch().count());
2215 s.set_ledgerhashprevious(
2216 newLCL->header().parentHash.begin(), newLCL->header().parentHash.size());
2217 s.set_ledgerhash(newLCL->header().hash.begin(), newLCL->header().hash.size());
2218 registry_.get().getOverlay().foreach(
2219 SendAlways(std::make_shared<Message>(s, protocol::mtSTATUS_CHANGE)));
2220}
2221
2222bool
2224 UInt256 const& networkClosed,
2226{
2227 XRPL_ASSERT(networkClosed.isNonZero(), "xrpl::NetworkOPsImp::beginConsensus : nonzero input");
2228
2229 auto const closingInfo = ledgerMaster_.getCurrentLedger()->header();
2230
2231 JLOG(journal_.info()) << "Consensus time for #" << closingInfo.seq << " with LCL "
2232 << closingInfo.parentHash;
2233
2234 auto const prevLedger = ledgerMaster_.getLedgerByHash(closingInfo.parentHash);
2235
2236 if (!prevLedger)
2237 {
2238 // this shouldn't happen unless we jump ledgers
2240 {
2241 JLOG(journal_.warn()) << "Don't have LCL, going to tracking";
2243 CLOG(clog) << "beginConsensus Don't have LCL, going to tracking. ";
2244 }
2245
2246 CLOG(clog) << "beginConsensus no previous ledger. ";
2247 return false;
2248 }
2249
2250 XRPL_ASSERT(
2251 prevLedger->header().hash == closingInfo.parentHash,
2252 "xrpl::NetworkOPsImp::beginConsensus : prevLedger hash matches "
2253 "parent");
2254 XRPL_ASSERT(
2255 closingInfo.parentHash == ledgerMaster_.getClosedLedger()->header().hash,
2256 "xrpl::NetworkOPsImp::beginConsensus : closedLedger parent matches "
2257 "hash");
2258
2259 registry_.get().getValidators().setNegativeUNL(prevLedger->negativeUNL());
2260 TrustChanges const changes = registry_.get().getValidators().updateTrusted(
2261 registry_.get().getValidations().getCurrentNodeIDs(),
2262 closingInfo.parentCloseTime,
2263 *this,
2264 registry_.get().getOverlay(),
2265 registry_.get().getHashRouter());
2266
2267 if (!changes.added.empty() || !changes.removed.empty())
2268 {
2269 registry_.get().getValidations().trustChanged(changes.added, changes.removed);
2270 // Update the AmendmentTable so it tracks the current validators.
2271 registry_.get().getAmendmentTable().trustChanged(
2272 registry_.get().getValidators().getQuorumKeys().second);
2273 }
2274
2275 consensus_.startRound(
2276 registry_.get().getTimeKeeper().closeTime(),
2277 networkClosed,
2278 prevLedger,
2279 changes.removed,
2280 changes.added,
2281 clog);
2282
2283 ConsensusPhase const currPhase = consensus_.phase();
2284 if (lastConsensusPhase_ != currPhase)
2285 {
2286 reportConsensusStateChange(currPhase);
2287 lastConsensusPhase_ = currPhase;
2288 }
2289
2290 JLOG(journal_.debug()) << "Initiating consensus engine";
2291 return true;
2292}
2293
2294bool
2296{
2297 auto const& peerKey = peerPos.publicKey();
2298 if (validatorPK_ == peerKey || validatorMasterPK_ == peerKey)
2299 {
2300 // Could indicate a operator misconfiguration where two nodes are
2301 // running with the same validator key configured, so this isn't fatal,
2302 // and it doesn't necessarily indicate peer misbehavior. But since this
2303 // is a trusted message, it could be a very big deal. Either way, we
2304 // don't want to relay the proposal. Note that the byzantine behavior
2305 // detection in handleNewValidation will notify other peers.
2306 //
2307 // Another, innocuous explanation is unusual message routing and delays,
2308 // causing this node to receive its own messages back.
2309 JLOG(journal_.error()) << "Received a proposal signed by MY KEY from a peer. This may "
2310 "indicate a misconfiguration where another node has the same "
2311 "validator key, or may be caused by unusual message routing and "
2312 "delays.";
2313 return false;
2314 }
2315
2316 return consensus_.peerProposal(registry_.get().getTimeKeeper().closeTime(), peerPos);
2317}
2318
2319void
2321{
2322 // We now have an additional transaction set
2323 // Inform peers we have this set
2324 protocol::TMHaveTransactionSet msg;
2325 msg.set_hash(map->getHash().asUInt256().begin(), 256 / 8);
2326 msg.set_status(protocol::tsHAVE);
2327 registry_.get().getOverlay().foreach(
2328 SendAlways(std::make_shared<Message>(msg, protocol::mtHAVE_SET)));
2329
2330 // We acquired it because consensus asked us to
2331 if (fromAcquire)
2332 consensus_.gotTxSet(registry_.get().getTimeKeeper().closeTime(), RCLTxSet{map});
2333}
2334
2335void
2337{
2338 UInt256 const deadLedger = ledgerMaster_.getClosedLedger()->header().parentHash;
2339 for (auto const& it : registry_.get().getOverlay().getActivePeers())
2340 {
2341 if (it && (it->getClosedLedgerHash() == deadLedger))
2342 {
2343 JLOG(journal_.trace()) << "Killing obsolete peer status";
2344 it->cycleStatus();
2345 }
2346 }
2347
2348 UInt256 networkClosed;
2349 bool const ledgerChange =
2350 checkLastClosedLedger(registry_.get().getOverlay().getActivePeers(), networkClosed);
2351
2352 if (networkClosed.isZero())
2353 {
2354 CLOG(clog) << "endConsensus last closed ledger is zero. ";
2355 return;
2356 }
2357
2358 // WRITEME: Unless we are in FULL and in the process of doing a consensus,
2359 // we must count how many nodes share our LCL, how many nodes disagree with
2360 // our LCL, and how many validations our LCL has. We also want to check
2361 // timing to make sure there shouldn't be a newer LCL. We need this
2362 // information to do the next three tests.
2363
2364 if (((mode_ == OperatingMode::CONNECTED) || (mode_ == OperatingMode::SYNCING)) && !ledgerChange)
2365 {
2366 // Count number of peers that agree with us and UNL nodes whose
2367 // validations we have for LCL. If the ledger is good enough, go to
2368 // TRACKING - TODO
2369 if (!needNetworkLedger_)
2371 }
2372
2374 !ledgerChange)
2375 {
2376 // check if the ledger is good enough to go to FULL
2377 // Note: Do not go to FULL if we don't have the previous ledger
2378 // check if the ledger is bad enough to go to CONNECTED -- TODO
2379 auto const current = ledgerMaster_.getCurrentLedger();
2380 if (registry_.get().getTimeKeeper().now() <
2381 (current->header().parentCloseTime + 2 * current->header().closeTimeResolution))
2382 {
2384 }
2385 }
2386
2387 beginConsensus(networkClosed, clog);
2388}
2389
2390void
2398
2399void
2401{
2402 // Hold each locked subscriber alive until after streamLock_ is released:
2403 // if this is the last reference, ~InfoSub re-acquires streamLock_ (via its
2404 // unsub* calls), which would self-deadlock on this non-recursive mutex.
2405 // Declared before the lock so it is destroyed after the lock is dropped.
2407
2408 // VFALCO consider std::shared_mutex
2409 std::scoped_lock const sl(streamLock_);
2410
2411 if (!streamMaps_[SManifests].empty())
2412 {
2414
2415 jvObj[jss::type] = "manifestReceived";
2416 jvObj[jss::master_key] = toBase58(TokenType::NodePublic, mo.masterKey);
2417 if (mo.signingKey)
2418 jvObj[jss::signing_key] = toBase58(TokenType::NodePublic, *mo.signingKey);
2419 jvObj[jss::seq] = json::UInt(mo.sequence);
2420 if (auto sig = mo.getSignature())
2421 jvObj[jss::signature] = strHex(*sig);
2422 jvObj[jss::master_signature] = strHex(mo.getMasterSignature());
2423 if (!mo.domain.empty())
2424 jvObj[jss::domain] = mo.domain;
2425 jvObj[jss::manifest] = strHex(mo.serialized);
2426
2427 for (auto i = streamMaps_[SManifests].begin(); i != streamMaps_[SManifests].end();)
2428 {
2429 if (auto p = i->second.lock())
2430 {
2431 p->send(jvObj, true);
2432 toRelease.push_back(std::move(p));
2433 ++i;
2434 }
2435 else
2436 {
2437 i = streamMaps_[SManifests].erase(i);
2438 }
2439 }
2440 }
2441}
2442
2444 XRPAmount fee,
2445 TxQ::Metrics escalationMetrics, // trivially copyable
2446 LoadFeeTrack const& loadFeeTrack)
2447 : loadFactorServer{loadFeeTrack.getLoadFactor()}
2448 , loadBaseServer{loadFeeTrack.getLoadBase()}
2449 , baseFee{fee}
2450 , em{escalationMetrics}
2451{
2452}
2453
2454bool
2456{
2458 baseFee != b.baseFee || em.has_value() != b.em.has_value())
2459 return true;
2460
2461 if (em && b.em)
2462 {
2463 return (
2464 em->minProcessingFeeLevel != b.em->minProcessingFeeLevel ||
2465 em->openLedgerFeeLevel != b.em->openLedgerFeeLevel ||
2466 em->referenceFeeLevel != b.em->referenceFeeLevel);
2467 }
2468
2469 return false;
2470}
2471
2472// Need to cap to uint64 to uint32 due to JSON limitations
2473static std::uint32_t
2475{
2477
2478 return std::min(kMax32, v);
2479};
2480
2481void
2483{
2484 // Hold each locked subscriber alive until after streamLock_ is released; a
2485 // last-reference ~InfoSub would otherwise re-acquire this non-recursive
2486 // mutex and self-deadlock. Declared before the lock, destroyed after it.
2488
2489 // VFALCO TODO Don't hold the lock across calls to send...make a copy of the
2490 // list into a local array while holding the lock then release
2491 // the lock and call send on everyone.
2492 //
2493 std::scoped_lock const sl(streamLock_);
2494
2495 if (!streamMaps_[SServer].empty())
2496 {
2498
2500 registry_.get().getOpenLedger().current()->fees().base,
2501 registry_.get().getTxQ().getMetrics(*registry_.get().getOpenLedger().current()),
2502 registry_.get().getFeeTrack()};
2503
2504 jvObj[jss::type] = "serverStatus";
2505 jvObj[jss::server_status] = strOperatingMode();
2506 jvObj[jss::load_base] = f.loadBaseServer;
2507 jvObj[jss::load_factor_server] = f.loadFactorServer;
2508 jvObj[jss::base_fee] = f.baseFee.jsonClipped();
2509
2510 if (f.em)
2511 {
2512 auto const loadFactor = std::max(
2514 mulDiv(f.em->openLedgerFeeLevel, f.loadBaseServer, f.em->referenceFeeLevel)
2515 .value_or(xrpl::kMuldivMax));
2516
2517 jvObj[jss::load_factor] = trunc32(loadFactor);
2518 jvObj[jss::load_factor_fee_escalation] = f.em->openLedgerFeeLevel.jsonClipped();
2519 jvObj[jss::load_factor_fee_queue] = f.em->minProcessingFeeLevel.jsonClipped();
2520 jvObj[jss::load_factor_fee_reference] = f.em->referenceFeeLevel.jsonClipped();
2521 }
2522 else
2523 {
2524 jvObj[jss::load_factor] = f.loadFactorServer;
2525 }
2526
2527 lastFeeSummary_ = f;
2528
2529 for (auto i = streamMaps_[SServer].begin(); i != streamMaps_[SServer].end();)
2530 {
2531 InfoSub::pointer p = i->second.lock();
2532
2533 // VFALCO TODO research the possibility of using thread queues and
2534 // linearizing the deletion of subscribers with the
2535 // sending of JSON data.
2536 if (p)
2537 {
2538 p->send(jvObj, true);
2539 toRelease.push_back(std::move(p));
2540 ++i;
2541 }
2542 else
2543 {
2544 i = streamMaps_[SServer].erase(i);
2545 }
2546 }
2547 }
2548}
2549
2550void
2552{
2553 // Hold each locked subscriber alive until after streamLock_ is released; a
2554 // last-reference ~InfoSub would otherwise re-acquire this non-recursive
2555 // mutex and self-deadlock. Declared before the lock, destroyed after it.
2557
2558 std::scoped_lock const sl(streamLock_);
2559
2560 auto& streamMap = streamMaps_[SConsensusPhase];
2561 if (!streamMap.empty())
2562 {
2564 jvObj[jss::type] = "consensusPhase";
2565 jvObj[jss::consensus] = to_string(phase);
2566
2567 for (auto i = streamMap.begin(); i != streamMap.end();)
2568 {
2569 if (auto p = i->second.lock())
2570 {
2571 p->send(jvObj, true);
2572 toRelease.push_back(std::move(p));
2573 ++i;
2574 }
2575 else
2576 {
2577 i = streamMap.erase(i);
2578 }
2579 }
2580 }
2581}
2582
2583void
2585{
2586 // Hold each locked subscriber alive until after streamLock_ is released; a
2587 // last-reference ~InfoSub would otherwise re-acquire this non-recursive
2588 // mutex and self-deadlock. Declared before the lock, destroyed after it.
2590
2591 // VFALCO consider std::shared_mutex
2592 std::scoped_lock const sl(streamLock_);
2593
2594 if (!streamMaps_[SValidations].empty())
2595 {
2597
2598 auto const signerPublic = val->getSignerPublic();
2599
2600 jvObj[jss::type] = "validationReceived";
2601 jvObj[jss::validation_public_key] = toBase58(TokenType::NodePublic, signerPublic);
2602 jvObj[jss::ledger_hash] = to_string(val->getLedgerHash());
2603 jvObj[jss::signature] = strHex(val->getSignature());
2604 jvObj[jss::full] = val->isFull();
2605 jvObj[jss::flags] = val->getFlags();
2606 jvObj[jss::signing_time] = *(*val)[~sfSigningTime];
2607 jvObj[jss::data] = strHex(val->getSerializer().slice());
2608 jvObj[jss::network_id] = registry_.get().getNetworkIDService().getNetworkID();
2609
2610 if (auto const version = (*val)[~sfServerVersion])
2611 jvObj[jss::server_version] = std::to_string(*version);
2612
2613 if (auto const cookie = (*val)[~sfCookie])
2614 jvObj[jss::cookie] = std::to_string(*cookie);
2615
2616 if (auto const hash = (*val)[~sfValidatedHash])
2617 jvObj[jss::validated_hash] = strHex(*hash);
2618
2619 auto const masterKey = registry_.get().getValidatorManifests().getMasterKey(signerPublic);
2620
2621 if (masterKey != signerPublic)
2622 jvObj[jss::master_key] = toBase58(TokenType::NodePublic, masterKey);
2623
2624 // NOTE *seq is a number, but old API versions used string. We replace
2625 // number with a string using MultiApiJson near end of this function
2626 if (auto const seq = (*val)[~sfLedgerSequence])
2627 jvObj[jss::ledger_index] = *seq;
2628
2629 if (val->isFieldPresent(sfAmendments))
2630 {
2631 jvObj[jss::amendments] = json::Value(json::ValueType::Array);
2632 for (auto const& amendment : val->getFieldV256(sfAmendments))
2633 jvObj[jss::amendments].append(to_string(amendment));
2634 }
2635
2636 if (auto const closeTime = (*val)[~sfCloseTime])
2637 jvObj[jss::close_time] = *closeTime;
2638
2639 if (auto const loadFee = (*val)[~sfLoadFee])
2640 jvObj[jss::load_fee] = *loadFee;
2641
2642 // (The ~ operator converts the Proxy to a std::optional, which
2643 // simplifies later operations)
2644 if (auto const baseFeeXRP = ~val->at(~sfBaseFeeDrops); baseFeeXRP && baseFeeXRP->native())
2645 jvObj[jss::base_fee] = baseFeeXRP->xrp().jsonClipped();
2646
2647 if (auto const reserveBaseXRP = ~val->at(~sfReserveBaseDrops);
2648 reserveBaseXRP && reserveBaseXRP->native())
2649 jvObj[jss::reserve_base] = reserveBaseXRP->xrp().jsonClipped();
2650
2651 if (auto const reserveIncXRP = ~val->at(~sfReserveIncrementDrops);
2652 reserveIncXRP && reserveIncXRP->native())
2653 jvObj[jss::reserve_inc] = reserveIncXRP->xrp().jsonClipped();
2654
2655 if (auto const gasLimit = ~val->at(~sfGasLimit); gasLimit)
2656 jvObj[jss::gas_limit] = *gasLimit;
2657
2658 if (auto const bytecodeSizeLimit = ~val->at(~sfBytecodeSizeLimit); bytecodeSizeLimit)
2659 jvObj[jss::bytecode_size_limit] = *bytecodeSizeLimit;
2660
2661 if (auto const gasPrice = ~val->at(~sfGasPrice); gasPrice)
2662 jvObj[jss::gas_price] = *gasPrice;
2663
2664 // NOTE Use MultiApiJson to publish two slightly different JSON objects
2665 // for consumers supporting different API versions
2666 MultiApiJson multiObj{jvObj};
2667 multiObj.visit(
2669 [](json::Value& jvTx) {
2670 // Type conversion for older API versions to string
2671 if (jvTx.isMember(jss::ledger_index))
2672 {
2673 jvTx[jss::ledger_index] = std::to_string(jvTx[jss::ledger_index].asUInt());
2674 }
2675 });
2676
2677 for (auto i = streamMaps_[SValidations].begin(); i != streamMaps_[SValidations].end();)
2678 {
2679 if (auto p = i->second.lock())
2680 {
2681 multiObj.visit(
2682 p->getApiVersion(), //
2683 [&](json::Value const& jv) { p->send(jv, true); });
2684 toRelease.push_back(std::move(p));
2685 ++i;
2686 }
2687 else
2688 {
2689 i = streamMaps_[SValidations].erase(i);
2690 }
2691 }
2692 }
2693}
2694
2695void
2697{
2698 // Hold each locked subscriber alive until after streamLock_ is released; a
2699 // last-reference ~InfoSub would otherwise re-acquire this non-recursive
2700 // mutex and self-deadlock. Declared before the lock, destroyed after it.
2702
2703 std::scoped_lock const sl(streamLock_);
2704
2705 if (!streamMaps_[SPeerStatus].empty())
2706 {
2707 json::Value jvObj(func());
2708
2709 jvObj[jss::type] = "peerStatusChange";
2710
2711 for (auto i = streamMaps_[SPeerStatus].begin(); i != streamMaps_[SPeerStatus].end();)
2712 {
2713 InfoSub::pointer p = i->second.lock();
2714
2715 if (p)
2716 {
2717 p->send(jvObj, true);
2718 toRelease.push_back(std::move(p));
2719 ++i;
2720 }
2721 else
2722 {
2723 i = streamMaps_[SPeerStatus].erase(i);
2724 }
2725 }
2726 }
2727}
2728
2729void
2731{
2732 using namespace std::chrono_literals;
2733 if (om == OperatingMode::CONNECTED)
2734 {
2735 if (registry_.get().getLedgerMaster().getValidatedLedgerAge() < 1min)
2737 }
2738 else if (om == OperatingMode::SYNCING)
2739 {
2740 if (registry_.get().getLedgerMaster().getValidatedLedgerAge() >= 1min)
2742 }
2743
2744 if ((om > OperatingMode::CONNECTED) && isBlocked())
2746
2747 if (mode_ == om)
2748 return;
2749
2750 mode_ = om;
2751
2752 accounting_.mode(om);
2753
2754 JLOG(journal_.info()) << "STATE->" << strOperatingMode();
2755 pubServer();
2756}
2757
2758bool
2760{
2761 JLOG(journal_.trace()) << "recvValidation " << val->getLedgerHash() << " from " << source;
2762
2764 BypassAccept bypassAccept = BypassAccept::No;
2765 try
2766 {
2767 if (pendingValidations_.contains(val->getLedgerHash()))
2768 {
2769 bypassAccept = BypassAccept::Yes;
2770 }
2771 else
2772 {
2773 pendingValidations_.insert(val->getLedgerHash());
2774 }
2775 ScopeUnlock const unlock(lock);
2776 handleNewValidation(registry_.get().getApp(), val, source, bypassAccept, journal_);
2777 }
2778 catch (std::exception const& e)
2779 {
2780 JLOG(journal_.warn()) << "Exception thrown for handling new validation "
2781 << val->getLedgerHash() << ": " << e.what();
2782 }
2783 catch (...)
2784 {
2785 JLOG(journal_.warn()) << "Unknown exception thrown for handling new validation "
2786 << val->getLedgerHash();
2787 }
2788 if (bypassAccept == BypassAccept::No)
2789 {
2790 pendingValidations_.erase(val->getLedgerHash());
2791 }
2792 lock.unlock();
2793
2794 pubValidation(val);
2795
2796 JLOG(journal_.debug()) << [this, &val] -> auto {
2798 ss << "VALIDATION: " << val->render() << " master_key: ";
2799 auto master = registry_.get().getValidators().getTrustedKey(val->getSignerPublic());
2800 if (master)
2801 {
2802 ss << toBase58(TokenType::NodePublic, *master);
2803 }
2804 else
2805 {
2806 ss << "none";
2807 }
2808 return ss.str();
2809 }();
2810
2811 // We will always relay trusted validations; if configured, we will
2812 // also relay all untrusted validations.
2813 return registry_.get().getApp().config().relayUntrustedValidations == 1 || val->isTrusted();
2814}
2815
2818{
2819 return consensus_.getJson(true);
2820}
2821
2823NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters)
2824{
2826
2827 // System-level warnings
2828 {
2830 if (isAmendmentBlocked())
2831 {
2833 w[jss::id] = WarnRpcAmendmentBlocked;
2834 w[jss::message] =
2835 "This server is amendment blocked, and must be updated to be "
2836 "able to stay in sync with the network.";
2837 }
2838 if (isUNLBlocked())
2839 {
2841 w[jss::id] = WarnRpcExpiredValidatorList;
2842 w[jss::message] =
2843 "This server has an expired validator list. validators.txt "
2844 "may be incorrectly configured or some [validator_list_sites] "
2845 "may be unreachable.";
2846 }
2847 if (admin && isAmendmentWarned())
2848 {
2850 w[jss::id] = WarnRpcUnsupportedMajority;
2851 w[jss::message] =
2852 "One or more unsupported amendments have reached majority. "
2853 "Upgrade to the latest version before they are activated "
2854 "to avoid being amendment blocked.";
2855 if (auto const expected =
2856 registry_.get().getAmendmentTable().firstUnsupportedExpected())
2857 {
2858 auto& d = w[jss::details] = json::ValueType::Object;
2859 d[jss::expected_date] = expected->time_since_epoch().count();
2860 d[jss::expected_date_UTC] = to_string(*expected);
2861 }
2862 }
2863
2864 if (warnings.size() != 0u)
2865 info[jss::warnings] = std::move(warnings);
2866 }
2867
2868 // hostid: unique string describing the machine
2869 if (human)
2870 info[jss::hostid] = getHostId(admin);
2871
2872 // domain: if configured with a domain, report it:
2873 if (!registry_.get().getApp().config().serverDomain.empty())
2874 info[jss::server_domain] = registry_.get().getApp().config().serverDomain;
2875
2876 info[jss::build_version] = build_info::getVersionString();
2877
2878 info[jss::server_state] = strOperatingMode(admin);
2879
2880 info[jss::time] =
2881 to_string(std::chrono::floor<std::chrono::microseconds>(std::chrono::system_clock::now()));
2882
2884 info[jss::network_ledger] = "waiting";
2885
2886 info[jss::validation_quorum] =
2887 static_cast<json::UInt>(registry_.get().getValidators().quorum());
2888
2889 if (admin)
2890 {
2891 // Note: By default the node size is "tiny". When parsing it's an error if the final
2892 // NODE_SIZE is over 4 so below code should be safe.
2893 // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
2894 switch (registry_.get().getApp().config().nodeSize)
2895 {
2896 case 0:
2897 info[jss::node_size] = "tiny";
2898 break;
2899 case 1:
2900 info[jss::node_size] = "small";
2901 break;
2902 case 2:
2903 info[jss::node_size] = "medium";
2904 break;
2905 case 3:
2906 info[jss::node_size] = "large";
2907 break;
2908 case 4:
2909 info[jss::node_size] = "huge";
2910 break;
2911 }
2912
2913 auto when = registry_.get().getValidators().expires();
2914
2915 if (!human)
2916 {
2917 if (when)
2918 {
2919 info[jss::validator_list_expires] =
2920 safeCast<json::UInt>(when->time_since_epoch().count());
2921 }
2922 else
2923 {
2924 info[jss::validator_list_expires] = 0;
2925 }
2926 }
2927 else
2928 {
2929 auto& x = (info[jss::validator_list] = json::ValueType::Object);
2930
2931 x[jss::count] = static_cast<json::UInt>(registry_.get().getValidators().count());
2932
2933 if (when)
2934 {
2935 if (*when == TimeKeeper::time_point::max())
2936 {
2937 x[jss::expiration] = "never";
2938 x[jss::status] = "active";
2939 }
2940 else
2941 {
2942 x[jss::expiration] = to_string(*when);
2943
2944 if (*when > registry_.get().getTimeKeeper().now())
2945 {
2946 x[jss::status] = "active";
2947 }
2948 else
2949 {
2950 x[jss::status] = "expired";
2951 }
2952 }
2953 }
2954 else
2955 {
2956 x[jss::status] = "unknown";
2957 x[jss::expiration] = "unknown";
2958 }
2959 }
2960
2961 if (!xrpl::git::getCommitHash().empty() || !xrpl::git::getBuildBranch().empty())
2962 {
2963 auto& x = (info[jss::git] = json::ValueType::Object);
2964 if (!xrpl::git::getCommitHash().empty())
2965 x[jss::hash] = xrpl::git::getCommitHash();
2966 if (!xrpl::git::getBuildBranch().empty())
2967 x[jss::branch] = xrpl::git::getBuildBranch();
2968 }
2969 }
2970 info[jss::io_latency_ms] =
2971 static_cast<json::UInt>(registry_.get().getApp().getIOLatency().count());
2972
2973 if (admin)
2974 {
2975 if (auto const localPubKey = registry_.get().getValidators().localPublicKey();
2976 localPubKey && registry_.get().getApp().getValidationPublicKey())
2977 {
2978 info[jss::pubkey_validator] = toBase58(TokenType::NodePublic, localPubKey.value());
2979 }
2980 else
2981 {
2982 info[jss::pubkey_validator] = "none";
2983 }
2984 }
2985
2986 if (counters)
2987 {
2988 info[jss::counters] = registry_.get().getPerfLog().countersJson();
2989
2991 registry_.get().getNodeStore().getCountsJson(nodestore);
2992 info[jss::counters][jss::nodestore] = nodestore;
2993 info[jss::current_activities] = registry_.get().getPerfLog().currentJson();
2994 }
2995
2996 info[jss::pubkey_node] =
2997 toBase58(TokenType::NodePublic, registry_.get().getApp().nodeIdentity().first);
2998
2999 info[jss::complete_ledgers] = registry_.get().getLedgerMaster().getCompleteLedgers();
3000
3002 info[jss::amendment_blocked] = true;
3003
3004 auto const fp = ledgerMaster_.getFetchPackCacheSize();
3005
3006 if (fp != 0)
3007 info[jss::fetch_pack] = json::UInt(fp);
3008
3009 info[jss::peers] = json::UInt(registry_.get().getOverlay().size());
3010
3012 lastClose[jss::proposers] = json::UInt(consensus_.prevProposers());
3013
3014 if (human)
3015 {
3016 lastClose[jss::converge_time_s] =
3018 }
3019 else
3020 {
3021 lastClose[jss::converge_time] = json::Int(consensus_.prevRoundTime().count());
3022 }
3023
3024 info[jss::last_close] = lastClose;
3025
3026 // info[jss::consensus] = consensus_.getJson();
3027
3028 if (admin)
3029 info[jss::load] = jobQueue_.getJson();
3030
3031 if (auto const netid = registry_.get().getOverlay().networkID())
3032 info[jss::network_id] = static_cast<json::UInt>(*netid);
3033
3034 auto const escalationMetrics =
3035 registry_.get().getTxQ().getMetrics(*registry_.get().getOpenLedger().current());
3036
3037 auto const loadFactorServer = registry_.get().getFeeTrack().getLoadFactor();
3038 auto const loadBaseServer = registry_.get().getFeeTrack().getLoadBase();
3039 /* Scale the escalated fee level to unitless "load factor".
3040 In practice, this just strips the units, but it will continue
3041 to work correctly if either base value ever changes. */
3042 auto const loadFactorFeeEscalation = mulDiv(
3043 escalationMetrics.openLedgerFeeLevel,
3044 loadBaseServer,
3045 escalationMetrics.referenceFeeLevel)
3047
3048 auto const loadFactor =
3049 std::max(safeCast<std::uint64_t>(loadFactorServer), loadFactorFeeEscalation);
3050
3051 if (!human)
3052 {
3053 info[jss::load_base] = loadBaseServer;
3054 info[jss::load_factor] = trunc32(loadFactor);
3055 info[jss::load_factor_server] = loadFactorServer;
3056
3057 /* json::Value doesn't support uint64, so clamp to max
3058 uint32 value. This is mostly theoretical, since there
3059 probably isn't enough extant XRP to drive the factor
3060 that high.
3061 */
3062 info[jss::load_factor_fee_escalation] = escalationMetrics.openLedgerFeeLevel.jsonClipped();
3063 info[jss::load_factor_fee_queue] = escalationMetrics.minProcessingFeeLevel.jsonClipped();
3064 info[jss::load_factor_fee_reference] = escalationMetrics.referenceFeeLevel.jsonClipped();
3065 }
3066 else
3067 {
3068 info[jss::load_factor] = static_cast<double>(loadFactor) / loadBaseServer;
3069
3070 if (loadFactorServer != loadFactor)
3071 info[jss::load_factor_server] = static_cast<double>(loadFactorServer) / loadBaseServer;
3072
3073 if (admin)
3074 {
3075 std::uint32_t fee = registry_.get().getFeeTrack().getLocalFee();
3076 if (fee != loadBaseServer)
3077 info[jss::load_factor_local] = static_cast<double>(fee) / loadBaseServer;
3078 fee = registry_.get().getFeeTrack().getRemoteFee();
3079 if (fee != loadBaseServer)
3080 info[jss::load_factor_net] = static_cast<double>(fee) / loadBaseServer;
3081 fee = registry_.get().getFeeTrack().getClusterFee();
3082 if (fee != loadBaseServer)
3083 info[jss::load_factor_cluster] = static_cast<double>(fee) / loadBaseServer;
3084 }
3085 if (escalationMetrics.openLedgerFeeLevel != escalationMetrics.referenceFeeLevel &&
3086 (admin || loadFactorFeeEscalation != loadFactor))
3087 {
3088 info[jss::load_factor_fee_escalation] =
3089 escalationMetrics.openLedgerFeeLevel.decimalFromReference(
3090 escalationMetrics.referenceFeeLevel);
3091 }
3092 if (escalationMetrics.minProcessingFeeLevel != escalationMetrics.referenceFeeLevel)
3093 {
3094 info[jss::load_factor_fee_queue] =
3095 escalationMetrics.minProcessingFeeLevel.decimalFromReference(
3096 escalationMetrics.referenceFeeLevel);
3097 }
3098 }
3099
3100 bool valid = false;
3101 auto lpClosed = ledgerMaster_.getValidatedLedger();
3102
3103 if (lpClosed)
3104 {
3105 valid = true;
3106 }
3107 else
3108 {
3109 lpClosed = ledgerMaster_.getClosedLedger();
3110 }
3111
3112 if (lpClosed)
3113 {
3114 XRPAmount const baseFee = lpClosed->fees().base;
3116 l[jss::seq] = json::UInt(lpClosed->header().seq);
3117 l[jss::hash] = to_string(lpClosed->header().hash);
3118
3119 bool const smartEscrowEnabled = lpClosed->rules().enabled(featureSmartEscrow);
3120 if (!human)
3121 {
3122 l[jss::base_fee] = baseFee.jsonClipped();
3123 l[jss::reserve_base] = lpClosed->fees().reserve.jsonClipped();
3124 l[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
3125 if (smartEscrowEnabled)
3126 {
3127 l[jss::gas_limit] = lpClosed->fees().gasLimit;
3128 l[jss::bytecode_size_limit] = lpClosed->fees().bytecodeSizeLimit;
3129 l[jss::gas_price] = lpClosed->fees().gasPrice;
3130 }
3131 l[jss::close_time] =
3132 json::Value::UInt(lpClosed->header().closeTime.time_since_epoch().count());
3133 }
3134 else
3135 {
3136 l[jss::base_fee_xrp] = baseFee.decimalXRP();
3137 l[jss::reserve_base_xrp] = lpClosed->fees().reserve.decimalXRP();
3138 l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP();
3139 if (smartEscrowEnabled)
3140 {
3141 l[jss::gas_limit] = lpClosed->fees().gasLimit;
3142 l[jss::bytecode_size_limit] = lpClosed->fees().bytecodeSizeLimit;
3143 l[jss::gas_price] = lpClosed->fees().gasPrice;
3144 }
3145
3146 if (auto const closeOffset = registry_.get().getTimeKeeper().closeOffset();
3147 std::abs(closeOffset.count()) >= 60)
3148 l[jss::close_time_offset] = static_cast<std::uint32_t>(closeOffset.count());
3149
3150 static constexpr std::chrono::seconds kHighAgeThreshold{1000000};
3151 if (ledgerMaster_.haveValidated())
3152 {
3153 auto const age = ledgerMaster_.getValidatedLedgerAge();
3154 l[jss::age] = json::UInt(age < kHighAgeThreshold ? age.count() : 0);
3155 }
3156 else
3157 {
3158 auto const lCloseTime = lpClosed->header().closeTime;
3159 auto const closeTime = registry_.get().getTimeKeeper().closeTime();
3160 if (lCloseTime <= closeTime)
3161 {
3162 using namespace std::chrono_literals;
3163 auto const age = closeTime - lCloseTime;
3164 l[jss::age] = json::UInt(age < kHighAgeThreshold ? age.count() : 0);
3165 }
3166 }
3167 }
3168
3169 if (valid)
3170 {
3171 info[jss::validated_ledger] = l;
3172 }
3173 else
3174 {
3175 info[jss::closed_ledger] = l;
3176 }
3177
3178 auto const lpPublished = ledgerMaster_.getPublishedLedger();
3179 if (!lpPublished)
3180 {
3181 info[jss::published_ledger] = "none";
3182 }
3183 else if (lpPublished->header().seq != lpClosed->header().seq)
3184 {
3185 info[jss::published_ledger] = lpPublished->header().seq;
3186 }
3187 }
3188
3189 accounting_.json(info);
3190 info[jss::uptime] = UptimeClock::now().time_since_epoch().count();
3191 info[jss::jq_trans_overflow] =
3192 std::to_string(registry_.get().getOverlay().getJqTransOverflow());
3193 info[jss::peer_disconnects] = std::to_string(registry_.get().getOverlay().getPeerDisconnect());
3194 info[jss::peer_disconnects_resources] =
3195 std::to_string(registry_.get().getOverlay().getPeerDisconnectCharges());
3196
3197 // This array must be sorted in increasing order.
3198 static constexpr std::array<std::string_view, 7> kProtocols{
3199 "http",
3200 "https",
3201 "peer",
3202 "ws",
3203 "ws2",
3204 "wss",
3205 "wss2",
3206 };
3207 static_assert(std::ranges::is_sorted(kProtocols));
3208 {
3210 for (auto const& port : registry_.get().getServerHandler().setup().ports)
3211 {
3212 // Don't publish admin ports for non-admin users
3213 if (!admin &&
3214 !(port.adminNetsV4.empty() && port.adminNetsV6.empty() && port.adminUser.empty() &&
3215 port.adminPassword.empty()))
3216 continue;
3218 // NOLINTNEXTLINE(modernize-use-ranges)
3220 std::begin(port.protocol),
3221 std::end(port.protocol),
3222 std::begin(kProtocols),
3223 std::end(kProtocols),
3224 std::back_inserter(proto));
3225 if (!proto.empty())
3226 {
3227 auto& jv = ports.append(json::Value(json::ValueType::Object));
3228 jv[jss::port] = std::to_string(port.port);
3229 jv[jss::protocol] = json::Value{json::ValueType::Array};
3230 for (auto const& p : proto)
3231 jv[jss::protocol].append(p);
3232 }
3233 }
3234
3235 if (registry_.get().getApp().config().exists(Sections::kPortGrpc))
3236 {
3237 auto const& grpcSection =
3238 registry_.get().getApp().config().section(Sections::kPortGrpc);
3239 auto const optPort = grpcSection.get(Keys::kPort);
3240 if (optPort && grpcSection.get(Keys::kIp))
3241 {
3242 auto& jv = ports.append(json::Value(json::ValueType::Object));
3243 jv[jss::port] = *optPort;
3244 jv[jss::protocol] = json::Value{json::ValueType::Array};
3245 jv[jss::protocol].append("grpc");
3246 }
3247 }
3248 info[jss::ports] = std::move(ports);
3249 }
3250
3251 return info;
3252}
3253
3254void
3256{
3257 registry_.get().getInboundLedgers().clearFailures();
3258}
3259
3262{
3263 return registry_.get().getInboundLedgers().getInfo();
3264}
3265
3266void
3268 std::shared_ptr<ReadView const> const& ledger,
3269 std::shared_ptr<STTx const> const& transaction,
3270 TER result)
3271{
3272 // never publish an inner txn inside a batch txn. The flag should
3273 // only be set if the Batch feature is enabled. If Batch is not
3274 // enabled, the flag is always invalid, so don't publish it
3275 // regardless.
3276 if (transaction->isFlag(tfInnerBatchTxn))
3277 return;
3278
3279 MultiApiJson const jvObj = transJson(transaction, result, false, ledger, std::nullopt);
3280
3281 {
3282 // Hold each locked subscriber alive until after streamLock_ is
3283 // released; a last-reference ~InfoSub would otherwise re-acquire this
3284 // non-recursive mutex and self-deadlock. Declared before the lock,
3285 // destroyed after the block ends.
3287
3288 std::scoped_lock const sl(streamLock_);
3289
3290 auto it = streamMaps_[SRtTransactions].begin();
3291 while (it != streamMaps_[SRtTransactions].end())
3292 {
3293 InfoSub::pointer p = it->second.lock();
3294
3295 if (p)
3296 {
3297 jvObj.visit(
3298 p->getApiVersion(), //
3299 [&](json::Value const& jv) { p->send(jv, true); });
3300 toRelease.push_back(std::move(p));
3301 ++it;
3302 }
3303 else
3304 {
3305 it = streamMaps_[SRtTransactions].erase(it);
3306 }
3307 }
3308 }
3309
3310 pubProposedAccountTransaction(ledger, transaction, result);
3311}
3312
3313void
3315{
3316 // Ledgers are published only when they acquire sufficient validations
3317 // Holes are filled across connection loss or other catastrophe
3318
3320 registry_.get().getAcceptedLedgerCache().fetch(lpAccepted->header().hash);
3321 if (!alpAccepted)
3322 {
3323 alpAccepted = std::make_shared<AcceptedLedger>(lpAccepted);
3324 registry_.get().getAcceptedLedgerCache().canonicalizeReplaceClient(
3325 lpAccepted->header().hash, alpAccepted);
3326 }
3327
3328 XRPL_ASSERT(
3329 alpAccepted->getLedger().get() == lpAccepted.get(),
3330 "xrpl::NetworkOPsImp::pubLedger : accepted input");
3331
3332 JLOG(journal_.debug()) << "Publishing ledger " << lpAccepted->header().seq << " "
3333 << lpAccepted->header().hash;
3334
3335 // Stream updates and the account-history kick-off touch different lock
3336 // domains; each helper takes only its own lock, so the two are never held
3337 // together.
3338 publishLedgerStreams(lpAccepted, alpAccepted);
3339 kickoffAccountHistory(alpAccepted);
3340
3341 // Don't lock since pubAcceptedTransaction is locking.
3342 for (auto const& accTx : *alpAccepted)
3343 {
3344 JLOG(journal_.trace()) << "pubAccepted: " << accTx->getJson();
3345 bool const last = &*accTx == &alpAccepted->back();
3346 pubValidatedTransaction(lpAccepted, *accTx, last);
3347 }
3348}
3349
3350void
3352 std::shared_ptr<ReadView const> const& lpAccepted,
3353 std::shared_ptr<AcceptedLedger const> const& alpAccepted)
3354{
3355 // Hold each locked subscriber alive until after streamLock_ is released; a
3356 // last-reference ~InfoSub would otherwise re-acquire this non-recursive
3357 // mutex and self-deadlock. Declared before the lock, destroyed after it;
3358 // covers both the ledger and book-changes loops below.
3360
3361 std::scoped_lock const sl(streamLock_);
3362
3363 if (!streamMaps_[SLedger].empty())
3364 {
3366
3367 jvObj[jss::type] = "ledgerClosed";
3368 jvObj[jss::ledger_index] = lpAccepted->header().seq;
3369 jvObj[jss::ledger_hash] = to_string(lpAccepted->header().hash);
3370 jvObj[jss::ledger_time] =
3371 json::Value::UInt(lpAccepted->header().closeTime.time_since_epoch().count());
3372
3373 jvObj[jss::network_id] = registry_.get().getNetworkIDService().getNetworkID();
3374
3375 jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped();
3376 jvObj[jss::reserve_base] = lpAccepted->fees().reserve.jsonClipped();
3377 jvObj[jss::reserve_inc] = lpAccepted->fees().increment.jsonClipped();
3378 if (lpAccepted->rules().enabled(featureSmartEscrow))
3379 {
3380 jvObj[jss::gas_limit] = lpAccepted->fees().gasLimit;
3381 jvObj[jss::bytecode_size_limit] = lpAccepted->fees().bytecodeSizeLimit;
3382 jvObj[jss::gas_price] = lpAccepted->fees().gasPrice;
3383 }
3384
3385 jvObj[jss::txn_count] = json::UInt(alpAccepted->size());
3386
3388 {
3389 jvObj[jss::validated_ledgers] = registry_.get().getLedgerMaster().getCompleteLedgers();
3390 }
3391 auto it = streamMaps_[SLedger].begin();
3392 while (it != streamMaps_[SLedger].end())
3393 {
3394 InfoSub::pointer p = it->second.lock();
3395 if (p)
3396 {
3397 p->send(jvObj, true);
3398 toRelease.push_back(std::move(p));
3399 ++it;
3400 }
3401 else
3402 {
3403 it = streamMaps_[SLedger].erase(it);
3404 }
3405 }
3406 }
3407
3408 if (!streamMaps_[SBookChanges].empty())
3409 {
3410 json::Value const jvObj = xrpl::rpc::computeBookChanges(lpAccepted);
3411
3412 auto it = streamMaps_[SBookChanges].begin();
3413 while (it != streamMaps_[SBookChanges].end())
3414 {
3415 InfoSub::pointer p = it->second.lock();
3416 if (p)
3417 {
3418 p->send(jvObj, true);
3419 toRelease.push_back(std::move(p));
3420 ++it;
3421 }
3422 else
3423 {
3424 it = streamMaps_[SBookChanges].erase(it);
3425 }
3426 }
3427 }
3428}
3429
3430void
3432{
3433 // Runs exactly once, the first time a ledger is published. The atomic
3434 // exchange lets the common post-first-ledger path return without taking
3435 // accountLock_, while still admitting exactly one caller even if ledger
3436 // publishing is ever made concurrent.
3437 static std::atomic<bool> done{false};
3438 if (done.exchange(true))
3439 return;
3440
3441 // It only reads/writes subAccountHistory_, so it takes accountLock_ alone.
3443 for (auto& outer : subAccountHistory_)
3444 {
3445 for (auto& inner : outer.second)
3446 {
3447 auto& subInfo = inner.second;
3448 if (subInfo.index->separationLedgerSeq == 0)
3449 subAccountHistoryStart(alpAccepted->getLedger(), subInfo);
3450 }
3451 }
3452}
3453
3454void
3456{
3457 ServerFeeSummary const f{
3458 registry_.get().getOpenLedger().current()->fees().base,
3459 registry_.get().getTxQ().getMetrics(*registry_.get().getOpenLedger().current()),
3460 registry_.get().getFeeTrack()};
3461
3462 // only schedule the job if something has changed
3463 if (f != lastFeeSummary_)
3464 {
3465 jobQueue_.addJob(JtClientFeeChange, "PubFee", [this] { pubServer(); });
3466 }
3467}
3468
3469void
3471{
3472 jobQueue_.addJob(JtClientConsensus, "PubCons", [this, phase] { pubConsensus(phase); });
3473}
3474
3475inline void
3477{
3478 localTX_->sweep(view);
3479}
3480inline std::size_t
3482{
3483 return localTX_->size();
3484}
3485
3488{
3489 std::scoped_lock const sl(bookLock_);
3490 std::size_t total = 0;
3491 for (auto const& [_, subs] : subBook_)
3492 total += subs.size();
3493 return total;
3494}
3495
3496// This routine should only be used to publish accepted or validated
3497// transactions.
3500 std::shared_ptr<STTx const> const& transaction,
3501 TER result,
3502 bool validated,
3503 std::shared_ptr<ReadView const> const& ledger,
3505{
3507 std::string sToken;
3508 std::string sHuman;
3509
3510 transResultInfo(result, sToken, sHuman);
3511
3512 jvObj[jss::type] = "transaction";
3513 // NOTE jvObj is not a finished object for either API version. After
3514 // it's populated, we need to finish it for a specific API version. This is
3515 // done in a loop, near the end of this function.
3516 jvObj[jss::transaction] = transaction->getJson(JsonOptions::Values::DisableApiPriorV2, false);
3517
3518 if (meta)
3519 {
3520 jvObj[jss::meta] = meta->get().getJson(JsonOptions::Values::None);
3521 rpc::insertAllSyntheticInJson(jvObj[jss::meta], *ledger, transaction, meta->get());
3522 }
3523
3524 // add CTID where the needed data for it exists
3525 if (auto const& lookup = ledger->txRead(transaction->getTransactionID());
3526 lookup.second && lookup.second->isFieldPresent(sfTransactionIndex))
3527 {
3528 uint32_t const txnSeq = lookup.second->getFieldU32(sfTransactionIndex);
3529 uint32_t netID = registry_.get().getNetworkIDService().getNetworkID();
3530 if (transaction->isFieldPresent(sfNetworkID))
3531 netID = transaction->getFieldU32(sfNetworkID);
3532
3533 if (std::optional<std::string> ctid = rpc::encodeCTID(ledger->header().seq, txnSeq, netID);
3534 ctid)
3535 jvObj[jss::ctid] = *ctid;
3536 }
3537 if (!ledger->open())
3538 jvObj[jss::ledger_hash] = to_string(ledger->header().hash);
3539
3540 if (validated)
3541 {
3542 jvObj[jss::ledger_index] = ledger->header().seq;
3543 jvObj[jss::transaction][jss::date] = ledger->header().closeTime.time_since_epoch().count();
3544 jvObj[jss::validated] = true;
3545 jvObj[jss::close_time_iso] = toStringIso(ledger->header().closeTime);
3546
3547 // WRITEME: Put the account next seq here
3548 }
3549 else
3550 {
3551 jvObj[jss::validated] = false;
3552 jvObj[jss::ledger_current_index] = ledger->header().seq;
3553 }
3554
3555 jvObj[jss::status] = validated ? "closed" : "proposed";
3556 jvObj[jss::engine_result] = sToken;
3557 jvObj[jss::engine_result_code] = result;
3558 jvObj[jss::engine_result_message] = sHuman;
3559
3560 if (transaction->getTxnType() == ttOFFER_CREATE)
3561 {
3562 auto const account = transaction->getAccountID(sfAccount);
3563 auto const amount = transaction->getFieldAmount(sfTakerGets);
3564
3565 // If the offer create is not self funded then add the owner balance
3566 if (account != amount.getIssuer())
3567 {
3568 auto const ownerFunds = accountFunds(
3569 *ledger,
3570 account,
3571 amount,
3574 registry_.get().getJournal("View"));
3575 jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText();
3576 }
3577 }
3578
3579 std::string const hash = to_string(transaction->getTransactionID());
3580 MultiApiJson multiObj{jvObj};
3582 multiObj.visit(), //
3583 [&]<unsigned Version>(json::Value& jvTx, std::integral_constant<unsigned, Version>) {
3584 rpc::insertDeliverMax(jvTx[jss::transaction], transaction->getTxnType(), Version);
3585
3586 if constexpr (Version > 1)
3587 {
3588 jvTx[jss::tx_json] = jvTx.removeMember(jss::transaction);
3589 jvTx[jss::hash] = hash;
3590 }
3591 else
3592 {
3593 jvTx[jss::transaction][jss::hash] = hash;
3594 }
3595 });
3596
3597 return multiObj;
3598}
3599
3600void
3602 std::shared_ptr<ReadView const> const& ledger,
3603 AcceptedLedgerTx const& transaction,
3604 bool last)
3605{
3606 auto const& stTxn = transaction.getTxn();
3607
3608 // Create two different Json objects, for different API versions
3609 auto const metaRef = std::ref(transaction.getMeta());
3610 auto const trResult = transaction.getResult();
3611 MultiApiJson const jvObj = transJson(stTxn, trResult, true, ledger, metaRef);
3612
3613 {
3614 // Hold each locked subscriber alive until after streamLock_ is
3615 // released; a last-reference ~InfoSub would otherwise re-acquire this
3616 // non-recursive mutex and self-deadlock. Declared before the lock,
3617 // destroyed after the block ends; covers both loops below.
3619
3620 std::scoped_lock const sl(streamLock_);
3621
3622 auto it = streamMaps_[STransactions].begin();
3623 while (it != streamMaps_[STransactions].end())
3624 {
3625 InfoSub::pointer p = it->second.lock();
3626
3627 if (p)
3628 {
3629 jvObj.visit(
3630 p->getApiVersion(), //
3631 [&](json::Value const& jv) { p->send(jv, true); });
3632 toRelease.push_back(std::move(p));
3633 ++it;
3634 }
3635 else
3636 {
3637 it = streamMaps_[STransactions].erase(it);
3638 }
3639 }
3640
3641 it = streamMaps_[SRtTransactions].begin();
3642
3643 while (it != streamMaps_[SRtTransactions].end())
3644 {
3645 InfoSub::pointer p = it->second.lock();
3646
3647 if (p)
3648 {
3649 jvObj.visit(
3650 p->getApiVersion(), //
3651 [&](json::Value const& jv) { p->send(jv, true); });
3652 toRelease.push_back(std::move(p));
3653 ++it;
3654 }
3655 else
3656 {
3657 it = streamMaps_[SRtTransactions].erase(it);
3658 }
3659 }
3660 }
3661
3662 if (transaction.getResult() == tesSUCCESS)
3663 pubBookTransaction(transaction, jvObj);
3664
3665 pubAccountTransaction(ledger, transaction, last);
3666 pubMPTTransaction(transaction, jvObj);
3667}
3668
3669void
3671{
3672 auto const books = affectedBooks(alTx, journal_);
3673 if (books.empty())
3674 return;
3675
3676 // Two-pass design:
3677 //
3678 // 1. Under bookLock_, walk subBook_, collect a strong pointer for each
3679 // unique listener (and prune any expired weak_ptrs we encounter).
3680 // 2. Release bookLock_, then send to each collected listener.
3681 //
3682 // Reasoning:
3683 // * send() can be slow / blocking, so holding bookLock_ across it would
3684 // stall every other book sub/unsub/pub path on this server (see the
3685 // matching TODO above pubServer at line ~2275).
3686 // * A strong pointer destructed while bookLock_ is held risks running
3687 // ~InfoSub() in-line, which re-enters unsubBook() and mutates the very
3688 // subBook_/SubMapType being iterated -> dangling iterator UB.
3689 //
3690 // Releasing bookLock_ before any InfoSub::pointer can decay solves both.
3691 // ~InfoSub() reacquires bookLock_ via unsubBook() on its own and serializes
3692 // safely with concurrent traffic.
3693
3696
3697 // Sized for the common case where every affected book has at most
3698 // one subscriber. Multi-subscriber books trigger reallocation, but
3699 // that is rare and the upper-bound estimate (sum of per-book sizes)
3700 // would itself require walking subBook_ twice.
3701 listeners.reserve(books.size());
3702 seen.reserve(books.size());
3703
3704 {
3705 std::scoped_lock const sl(bookLock_);
3706
3707 for (auto const& book : books)
3708 {
3709 auto const it = subBook_.find(book);
3710 if (it == subBook_.end())
3711 continue;
3712
3713 for (auto sit = it->second.begin(); sit != it->second.end();)
3714 {
3715 if (auto p = sit->second.lock())
3716 {
3717 // Defensive: subBook_ entries are normally cleared by
3718 // ~InfoSub() -> unsubBook(), so we rarely see expired
3719 // weak_ptrs here. The else branch covers the narrow race
3720 // where the last strong ref is dropped between insertion
3721 // and our lock() call.
3722 if (seen.emplace(p->getSeq()).second)
3723 listeners.emplace_back(std::move(p));
3724 ++sit;
3725 }
3726 else
3727 {
3728 JLOG(journal_.debug())
3729 << "pubBookTransaction: pruning expired weak_ptr for seq=" << sit->first;
3730 sit = it->second.erase(sit);
3731 }
3732 }
3733
3734 if (it->second.empty())
3735 subBook_.erase(it);
3736 }
3737 }
3738
3739 for (auto const& p : listeners)
3740 {
3741 jvObj.visit(p->getApiVersion(), [&](json::Value const& jv) { p->send(jv, true); });
3742 }
3743 // listeners destructs here, outside bookLock_; ~InfoSub (if any fires)
3744 // will reacquire bookLock_ via unsubBook with no iterator hazard.
3745}
3746
3747void
3749 std::shared_ptr<ReadView const> const& ledger,
3750 AcceptedLedgerTx const& transaction,
3751 bool last)
3752{
3754 int iProposed = 0;
3755 int iAccepted = 0;
3756
3757 std::vector<SubAccountHistoryInfo> accountHistoryNotify;
3758 auto const currLedgerSeq = ledger->seq();
3759 {
3761
3762 if (!subAccount_.empty() || !subRTAccount_.empty() || !subAccountHistory_.empty())
3763 {
3764 for (auto const& affectedAccount : transaction.getAffected())
3765 {
3766 if (auto const simiIt = subRTAccount_.find(affectedAccount);
3767 simiIt != subRTAccount_.end())
3768 {
3769 auto it = simiIt->second.begin();
3770
3771 while (it != simiIt->second.end())
3772 {
3773 InfoSub::pointer const p = it->second.lock();
3774
3775 if (p)
3776 {
3777 notify.insert(p);
3778 ++it;
3779 ++iProposed;
3780 }
3781 else
3782 {
3783 it = simiIt->second.erase(it);
3784 }
3785 }
3786 }
3787
3788 if (auto const simiIt = subAccount_.find(affectedAccount);
3789 simiIt != subAccount_.end())
3790 {
3791 auto it = simiIt->second.begin();
3792 while (it != simiIt->second.end())
3793 {
3794 InfoSub::pointer const p = it->second.lock();
3795
3796 if (p)
3797 {
3798 notify.insert(p);
3799 ++it;
3800 ++iAccepted;
3801 }
3802 else
3803 {
3804 it = simiIt->second.erase(it);
3805 }
3806 }
3807 }
3808
3809 if (auto const historyIt = subAccountHistory_.find(affectedAccount);
3810 historyIt != subAccountHistory_.end())
3811 {
3812 auto& subs = historyIt->second;
3813 auto it = subs.begin();
3814 while (it != subs.end())
3815 {
3816 SubAccountHistoryInfoWeak const& info = it->second;
3817 if (currLedgerSeq <= info.index->separationLedgerSeq)
3818 {
3819 ++it;
3820 continue;
3821 }
3822
3823 if (auto const isSptr = info.sinkWptr.lock(); isSptr)
3824 {
3825 accountHistoryNotify.emplace_back(
3826 SubAccountHistoryInfo{.sink = isSptr, .index = info.index});
3827 ++it;
3828 }
3829 else
3830 {
3831 it = subs.erase(it);
3832 }
3833 }
3834 if (subs.empty())
3835 subAccountHistory_.erase(historyIt);
3836 }
3837 }
3838 }
3839 }
3840
3841 JLOG(journal_.trace()) << "pubAccountTransaction: "
3842 << "proposed=" << iProposed << ", accepted=" << iAccepted;
3843
3844 if (!notify.empty() || !accountHistoryNotify.empty())
3845 {
3846 auto const& stTxn = transaction.getTxn();
3847
3848 // Create two different Json objects, for different API versions
3849 auto const metaRef = std::ref(transaction.getMeta());
3850 auto const trResult = transaction.getResult();
3851 MultiApiJson jvObj = transJson(stTxn, trResult, true, ledger, metaRef);
3852
3853 for (InfoSub::Ref isrListener : notify)
3854 {
3855 jvObj.visit(
3856 isrListener->getApiVersion(), //
3857 [&](json::Value const& jv) { isrListener->send(jv, true); });
3858 }
3859
3860 if (last)
3861 jvObj.set(jss::account_history_boundary, true);
3862
3863 XRPL_ASSERT(
3864 jvObj.isMember(jss::account_history_tx_stream) == MultiApiJson::IsMemberResult::None,
3865 "xrpl::NetworkOPsImp::pubAccountTransaction : "
3866 "account_history_tx_stream not set");
3867 for (auto& info : accountHistoryNotify)
3868 {
3869 auto const& index = info.index;
3870 if (index->forwardTxIndex == 0 && !index->haveHistorical)
3871 jvObj.set(jss::account_history_tx_first, true);
3872
3873 jvObj.set(jss::account_history_tx_index, index->forwardTxIndex++);
3874
3875 jvObj.visit(
3876 info.sink->getApiVersion(), //
3877 [&](json::Value const& jv) { info.sink->send(jv, true); });
3878 }
3879 }
3880}
3881
3882void
3884 std::shared_ptr<ReadView const> const& ledger,
3886 TER result)
3887{
3889 int iProposed = 0;
3890
3891 {
3893
3894 if (subRTAccount_.empty())
3895 return;
3896
3897 for (auto const& affectedAccount : tx->getMentionedAccounts())
3898 {
3899 if (auto const simiIt = subRTAccount_.find(affectedAccount);
3900 simiIt != subRTAccount_.end())
3901 {
3902 auto it = simiIt->second.begin();
3903
3904 while (it != simiIt->second.end())
3905 {
3906 InfoSub::pointer const p = it->second.lock();
3907
3908 if (p)
3909 {
3910 notify.insert(p);
3911 ++it;
3912 ++iProposed;
3913 }
3914 else
3915 {
3916 it = simiIt->second.erase(it);
3917 }
3918 }
3919 }
3920 }
3921 }
3922
3923 JLOG(journal_.trace()) << "pubProposedAccountTransaction: " << iProposed;
3924
3925 if (!notify.empty())
3926 {
3927 // Create two different Json objects, for different API versions
3928 MultiApiJson const jvObj = transJson(tx, result, false, ledger, std::nullopt);
3929
3930 for (InfoSub::Ref isrListener : notify)
3931 {
3932 jvObj.visit(
3933 isrListener->getApiVersion(), //
3934 [&](json::Value const& jv) { isrListener->send(jv, true); });
3935 }
3936 }
3937}
3938
3939//
3940// Monitoring
3941//
3942
3943void
3945 InfoSub::Ref isrListener,
3946 HashSet<AccountID> const& vnaAccountIDs,
3947 bool rt)
3948{
3949 SubInfoMapType& subMap = rt ? subRTAccount_ : subAccount_;
3950
3951 for (auto const& naAccountID : vnaAccountIDs)
3952 {
3953 JLOG(journal_.trace()) << "subAccount: account: " << toBase58(naAccountID);
3954
3955 isrListener->insertSubAccountInfo(naAccountID, rt);
3956 }
3957
3959
3960 for (auto const& naAccountID : vnaAccountIDs)
3961 {
3962 auto const simIterator = subMap.find(naAccountID);
3963 if (simIterator == subMap.end())
3964 {
3965 // Not found, note that account has a new single listener.
3966 SubMapType usisElement;
3967 usisElement[isrListener->getSeq()] = isrListener;
3968 // VFALCO NOTE This is making a needless copy of naAccountID
3969 subMap.insert(simIterator, make_pair(naAccountID, usisElement));
3970 }
3971 else
3972 {
3973 // Found, note that the account has another listener.
3974 simIterator->second[isrListener->getSeq()] = isrListener;
3975 }
3976 }
3977}
3978
3979void
3981 InfoSub::Ref isrListener,
3982 HashSet<AccountID> const& vnaAccountIDs,
3983 bool rt)
3984{
3985 for (auto const& naAccountID : vnaAccountIDs)
3986 {
3987 // Remove from the InfoSub
3988 isrListener->deleteSubAccountInfo(naAccountID, rt);
3989 }
3990
3991 // Remove from the server
3992 unsubAccountInternal(isrListener->getSeq(), vnaAccountIDs, rt);
3993}
3994
3995void
3997 std::uint64_t uSeq,
3998 HashSet<AccountID> const& vnaAccountIDs,
3999 bool rt)
4000{
4002
4003 SubInfoMapType& subMap = rt ? subRTAccount_ : subAccount_;
4004
4005 for (auto const& naAccountID : vnaAccountIDs)
4006 {
4007 auto const simIterator = subMap.find(naAccountID);
4008
4009 if (simIterator != subMap.end())
4010 {
4011 // Found
4012 simIterator->second.erase(uSeq);
4013
4014 if (simIterator->second.empty())
4015 {
4016 // Don't need hash entry.
4017 subMap.erase(simIterator);
4018 }
4019 }
4020 }
4021}
4022
4023template <typename OuterMap, typename BeforeErase>
4024void
4026 std::uint64_t seq,
4027 HashSet<AccountID> const& accounts,
4028 OuterMap& outerMap,
4029 BeforeErase&& beforeErase)
4030{
4031 // Walk the disconnecting connection's accounts in chunks. Each chunk takes
4032 // accountLock_, erases up to kAccountCleanupChunk entries, then releases
4033 // the lock so a competing account-publish can run before the next chunk.
4034 // No iterator into outerMap is held across the unlock: every chunk re-finds
4035 // each account, so a concurrent mutation between chunks cannot dangle.
4036 auto it = accounts.begin();
4037 auto const end = accounts.end();
4038 while (it != end)
4039 {
4041
4042 for (std::size_t n = 0; n < kAccountCleanupChunk && it != end; ++n, ++it)
4043 {
4044 auto const outerIter = outerMap.find(*it);
4045 if (outerIter != outerMap.end())
4046 {
4047 // Give the caller a chance to tear down this connection's inner
4048 // entry before it is erased (the history map stops its paging
4049 // job here); the plain account maps pass a no-op.
4050 auto const innerIter = outerIter->second.find(seq);
4051 if (innerIter != outerIter->second.end())
4052 beforeErase(innerIter->second);
4053
4054 // Erase only this connection's seq; other connections sharing
4055 // the account keep their entry, so a reconnect is unaffected.
4056 outerIter->second.erase(seq);
4057 if (outerIter->second.empty())
4058 outerMap.erase(outerIter);
4059 }
4060 }
4061 }
4062}
4063
4064void
4066 std::uint64_t seq,
4067 HashSet<AccountID> const& accounts,
4068 SubInfoMapType& subMap)
4069{
4070 // Plain account maps need no per-entry teardown before erase.
4071 cleanupSubscriptionMap(seq, accounts, subMap, [](InfoSub::Wptr const&) {});
4072}
4073
4074void
4076 std::uint64_t seq,
4077 HashSet<AccountID> const& accounts)
4078{
4079 // Cancel any in-flight historical paging job for this connection before
4080 // dropping its record. The job holds its own shared_ptr to the index, so
4081 // erasing the map entry alone would not stop it; it reads this atomic
4082 // between pages and exits promptly once set.
4084 seq, accounts, subAccountHistory_, [](SubAccountHistoryInfoWeak const& info) {
4085 info.index->stopHistorical = true;
4086 });
4087}
4088
4089void
4091 std::uint64_t seq,
4092 HashSet<AccountID> rtAccounts,
4093 HashSet<AccountID> normalAccounts,
4094 HashSet<AccountID> historyAccounts)
4095{
4096 // Nothing to do for a connection that never subscribed to any account.
4097 if (rtAccounts.empty() && normalAccounts.empty() && historyAccounts.empty())
4098 return;
4099
4100 // Post the erase work to a low-priority job so the disconnect thread (and
4101 // ~InfoSub) returns immediately. The job captures the sets BY MOVE and
4102 // operates purely on seq + the captured accounts; it never touches the
4103 // destroyed InfoSub. `this` outlives the job per the Source lifetime
4104 // contract. Running on a JobQueue thread, it cannot re-enter accountLock_
4105 // held by the disconnecting thread, so the plain std::mutex is safe.
4106 //
4107 // The body is exception-guarded: the JobQueue invokes it bare, so an
4108 // escaping exception on the worker thread would terminate the process.
4109 //
4110 // addJob returns false only once the JobQueue has been stopped, i.e. during
4111 // process shutdown. At that point NetworkOPsImp's maps are about to be
4112 // destroyed wholesale and no publish path can run, so dropping the cleanup
4113 // is harmless; no inline fallback is needed.
4114 jobQueue_.addJob(
4116 "SubCleanup",
4117 [this,
4118 seq,
4119 rt = std::move(rtAccounts),
4120 normal = std::move(normalAccounts),
4121 history = std::move(historyAccounts)] noexcept {
4122 try
4123 {
4127 }
4128 catch (std::exception const& e)
4129 {
4130 JLOG(journal_.error()) << "SubCleanup[seq=" << seq << "]: " << e.what();
4131 }
4132 catch (...)
4133 {
4134 JLOG(journal_.error()) << "SubCleanup[seq=" << seq << "]: unknown exception";
4135 }
4136 });
4137}
4138
4139void
4141{
4142 {
4143 std::scoped_lock const sl(mptLock_);
4144 if (subMPT_.empty())
4145 return;
4146 }
4147
4148 // getAffectedMPTs derives the issuance id for MPTokenIssuance entries from
4149 // the metadata, so it also covers transactions whose top-level STTx carries
4150 // no MPTokenIssuanceID, such as the inner transactions of a Batch. It reads
4151 // only the metadata, so it runs outside mptLock_.
4152 auto const affectedMPTs = alTx.getMeta().getAffectedMPTs();
4153 if (affectedMPTs.empty())
4154 return;
4155
4156 // Declared before the lock so a last-reference ~InfoSub runs after
4157 // mptLock_ is released (see the deferred-destruction rule).
4159
4160 {
4161 std::scoped_lock const sl(mptLock_);
4162
4163 for (auto const& affectedMPT : affectedMPTs)
4164 {
4165 if (auto const simiIt = subMPT_.find(affectedMPT); simiIt != subMPT_.end())
4166 {
4167 auto it = simiIt->second.begin();
4168 while (it != simiIt->second.end())
4169 {
4170 InfoSub::pointer const p = it->second.lock();
4171
4172 if (p)
4173 {
4174 notify.insert(p);
4175 ++it;
4176 }
4177 else
4178 {
4179 it = simiIt->second.erase(it);
4180 }
4181 }
4182 }
4183 }
4184 }
4185
4186 if (notify.empty())
4187 return;
4188
4189 for (InfoSub::Ref isrListener : notify)
4190 {
4191 jvObj.visit(isrListener->getApiVersion(), [&](json::Value const& jv) {
4192 isrListener->send(jv, true);
4193 });
4194 }
4195}
4196
4197void
4199{
4200 // Insert into subMPT_ before the InfoSub (unsubMPT removes in reverse), as
4201 // subBook does, so a racing unsubMPT cannot leave a subMPT_ entry that the
4202 // InfoSub doesn't know about.
4203 {
4204 std::scoped_lock const sl(mptLock_);
4205
4206 for (auto const& mptID : mptIDs)
4207 {
4208 JLOG(journal_.trace()) << "subMPT: MPT: " << to_string(mptID);
4209
4210 auto const simIterator = subMPT_.find(mptID);
4211 if (simIterator == subMPT_.end())
4212 {
4213 // Not found, note that the MPT issuance has a new single listener.
4214 SubMapType usisElement;
4215 usisElement[isrListener->getSeq()] = isrListener;
4216 subMPT_.insert(simIterator, make_pair(mptID, usisElement));
4217 }
4218 else
4219 {
4220 // Found, note that the MPT issuance has another listener.
4221 simIterator->second[isrListener->getSeq()] = isrListener;
4222 }
4223 }
4224 }
4225
4226 for (auto const& mptID : mptIDs)
4227 isrListener->insertSubMPTInfo(mptID);
4228}
4229
4230void
4232{
4233 for (auto const& mptID : mptIDs)
4234 {
4235 // Remove from the InfoSub first so ~InfoSub does not re-issue an
4236 // unsubMPTInternal for an issuance the caller already removed, then
4237 // remove from the server.
4238 isrListener->deleteSubMPTInfo(mptID);
4239 unsubMPTInternal(isrListener->getSeq(), mptID);
4240 }
4241}
4242
4243void
4245{
4246 // Only weak_ptrs are erased, so no InfoSub can be destroyed under the lock.
4247 std::scoped_lock const sl(mptLock_);
4248
4249 auto const simIterator = subMPT_.find(mptID);
4250 if (simIterator == subMPT_.end())
4251 return;
4252
4253 simIterator->second.erase(uSeq);
4254 if (simIterator->second.empty())
4255 {
4256 // Don't need hash entry.
4257 subMPT_.erase(simIterator);
4258 }
4259}
4260
4261void
4263{
4264 registry_.get().getJobQueue().addJob(JtClientAcctHist, "HistTxStream", [this, subInfo] {
4265 auto const& accountId = subInfo.index->accountId;
4266 auto& lastLedgerSeq = subInfo.index->historyLastLedgerSeq;
4267 auto& txHistoryIndex = subInfo.index->historyTxIndex;
4268
4269 JLOG(journal_.trace()) << "AccountHistory job for account " << toBase58(accountId)
4270 << " started. lastLedgerSeq=" << lastLedgerSeq;
4271
4272 auto const isFirstTx = [&](std::shared_ptr<Transaction> const& tx,
4273 std::shared_ptr<TxMeta> const& meta) -> bool {
4274 /*
4275 * genesis account: first tx is the one with seq 1
4276 * other account: first tx is the one created the account
4277 */
4278 if (accountId == kGenesisAccountId)
4279 {
4280 auto const stx = tx->getSTransaction();
4281 if (stx->getAccountID(sfAccount) == accountId && stx->getSeqProxy().value() == 1)
4282 return true;
4283 }
4284
4285 return std::ranges::any_of(meta->getNodes(), [&](auto& node) {
4286 if (node.getFieldU16(sfLedgerEntryType) != ltACCOUNT_ROOT)
4287 return false;
4288
4289 if (node.isFieldPresent(sfNewFields))
4290 {
4291 if (auto inner = dynamic_cast<STObject const*>(node.peekAtPField(sfNewFields));
4292 inner)
4293 {
4294 if (inner->isFieldPresent(sfAccount) &&
4295 inner->getAccountID(sfAccount) == accountId)
4296 {
4297 return true;
4298 }
4299 }
4300 }
4301 return false;
4302 });
4303 };
4304
4305 auto const send = [&](json::Value const& jvObj, bool unsubscribe) -> bool {
4306 if (auto const sptr = subInfo.sinkWptr.lock())
4307 {
4308 sptr->send(jvObj, true);
4309 if (unsubscribe)
4310 unsubAccountHistory(sptr, accountId, false);
4311 return true;
4312 }
4313
4314 return false;
4315 };
4316
4317 auto const sendMultiApiJson = [&](MultiApiJson const& jvObj, bool unsubscribe) -> bool {
4318 if (auto sptr = subInfo.sinkWptr.lock())
4319 {
4320 jvObj.visit(
4321 sptr->getApiVersion(), //
4322 [&](json::Value const& jv) { sptr->send(jv, true); });
4323
4324 if (unsubscribe)
4325 unsubAccountHistory(sptr, accountId, false);
4326 return true;
4327 }
4328
4329 return false;
4330 };
4331
4332 auto const getMoreTxns = [&](std::uint32_t minLedger,
4333 std::uint32_t maxLedger,
4335 -> std::pair<
4338 auto& db = registry_.get().getRelationalDatabase();
4340 .account = accountId,
4341 .ledgerRange = {.min = minLedger, .max = maxLedger},
4342 .marker = marker,
4343 .limit = 0,
4344 .bAdmin = true,
4345 .delegate = std::nullopt,
4346 };
4347 return db.newestAccountTxPage(options);
4348 };
4349
4350 /*
4351 * search backward until the genesis ledger or asked to stop
4352 */
4353 while (lastLedgerSeq >= 2 && !subInfo.index->stopHistorical)
4354 {
4355 int feeChargeCount = 0;
4356 if (auto const sptr = subInfo.sinkWptr.lock(); sptr)
4357 {
4358 sptr->getConsumer().charge(resource::kFeeMediumBurdenRpc);
4359 ++feeChargeCount;
4360 }
4361 else
4362 {
4363 JLOG(journal_.trace())
4364 << "AccountHistory job for account " << toBase58(accountId)
4365 << " no InfoSub. Fee charged " << feeChargeCount << " times.";
4366 return;
4367 }
4368
4369 // try to search in 1024 ledgers till reaching genesis ledgers
4370 auto startLedgerSeq = (lastLedgerSeq > 1024 + 2 ? lastLedgerSeq - 1024 : 2);
4371 JLOG(journal_.trace())
4372 << "AccountHistory job for account " << toBase58(accountId)
4373 << ", working on ledger range [" << startLedgerSeq << "," << lastLedgerSeq << "]";
4374
4375 auto const haveRange = [&] -> bool {
4376 std::uint32_t validatedMin = UINT_MAX;
4377 std::uint32_t validatedMax = 0;
4378 auto const haveSomeValidatedLedgers =
4379 registry_.get().getLedgerMaster().getValidatedRange(validatedMin, validatedMax);
4380
4381 return haveSomeValidatedLedgers && validatedMin <= startLedgerSeq &&
4382 lastLedgerSeq <= validatedMax;
4383 }();
4384
4385 if (!haveRange)
4386 {
4387 JLOG(journal_.debug()) << "AccountHistory reschedule job for account "
4388 << toBase58(accountId) << ", incomplete ledger range ["
4389 << startLedgerSeq << "," << lastLedgerSeq << "]";
4391 return;
4392 }
4393
4395 while (!subInfo.index->stopHistorical)
4396 {
4397 auto const dbResult = getMoreTxns(startLedgerSeq, lastLedgerSeq, marker);
4398
4399 auto const& txns = dbResult.first;
4400 marker = dbResult.second;
4401 size_t const numTxns = txns.size();
4402 for (size_t i = 0; i < numTxns; ++i)
4403 {
4404 auto const& [tx, meta] = txns[i];
4405
4406 if (!tx || !meta)
4407 {
4408 JLOG(journal_.debug()) << "AccountHistory job for account "
4409 << toBase58(accountId) << " empty tx or meta.";
4410 send(rpcError(RpcInternal), true);
4411 return;
4412 }
4413 auto const curTxLedger =
4414 registry_.get().getLedgerMaster().getLedgerBySeq(tx->getLedger());
4415 if (!curTxLedger)
4416 {
4417 // LCOV_EXCL_START
4418 UNREACHABLE(
4419 "xrpl::NetworkOPsImp::addAccountHistoryJob : "
4420 "getLedgerBySeq failed");
4421 JLOG(journal_.debug()) << "AccountHistory job for account "
4422 << toBase58(accountId) << " no ledger.";
4423 send(rpcError(RpcInternal), true);
4424 return;
4425 // LCOV_EXCL_STOP
4426 }
4427 std::shared_ptr<STTx const> const stTxn = tx->getSTransaction();
4428 if (!stTxn)
4429 {
4430 // LCOV_EXCL_START
4431 UNREACHABLE(
4432 "NetworkOPsImp::addAccountHistoryJob : "
4433 "getSTransaction failed");
4434 JLOG(journal_.debug()) << "AccountHistory job for account "
4435 << toBase58(accountId) << " getSTransaction failed.";
4436 send(rpcError(RpcInternal), true);
4437 return;
4438 // LCOV_EXCL_STOP
4439 }
4440
4441 auto const ref = std::ref(*meta);
4442 auto const trR = meta->getResultTER();
4443 MultiApiJson jvTx = transJson(stTxn, trR, true, curTxLedger, ref);
4444
4445 jvTx.set(jss::account_history_tx_index, txHistoryIndex--);
4446 if (i + 1 == numTxns || txns[i + 1].first->getLedger() != tx->getLedger())
4447 jvTx.set(jss::account_history_boundary, true);
4448
4449 if (isFirstTx(tx, meta))
4450 {
4451 jvTx.set(jss::account_history_tx_first, true);
4452 sendMultiApiJson(jvTx, false);
4453
4454 JLOG(journal_.trace()) << "AccountHistory job for account "
4455 << toBase58(accountId) << " done, found last tx.";
4456 return;
4457 }
4458
4459 sendMultiApiJson(jvTx, false);
4460 }
4461
4462 if (marker)
4463 {
4464 JLOG(journal_.trace())
4465 << "AccountHistory job for account " << toBase58(accountId)
4466 << " paging, marker=" << marker->ledgerSeq << ":" << marker->txnSeq;
4467 }
4468 else
4469 {
4470 break;
4471 }
4472 }
4473
4474 if (!subInfo.index->stopHistorical)
4475 {
4476 lastLedgerSeq = startLedgerSeq - 1;
4477 if (lastLedgerSeq <= 1)
4478 {
4479 JLOG(journal_.trace())
4480 << "AccountHistory job for account " << toBase58(accountId)
4481 << " done, reached genesis ledger.";
4482 return;
4483 }
4484 }
4485 }
4486 });
4487}
4488
4489void
4491 std::shared_ptr<ReadView const> const& ledger,
4493{
4494 subInfo.index->separationLedgerSeq = ledger->seq();
4495 auto const& accountId = subInfo.index->accountId;
4496 auto const accountKeylet = keylet::account(accountId);
4497 if (!ledger->exists(accountKeylet))
4498 {
4499 JLOG(journal_.debug()) << "subAccountHistoryStart, no account " << toBase58(accountId)
4500 << ", no need to add AccountHistory job.";
4501 return;
4502 }
4503 if (accountId == kGenesisAccountId)
4504 {
4505 if (auto const sleAcct = ledger->read(accountKeylet); sleAcct)
4506 {
4507 if (sleAcct->getFieldU32(sfSequence) == 1)
4508 {
4509 JLOG(journal_.debug())
4510 << "subAccountHistoryStart, genesis account " << toBase58(accountId)
4511 << " does not have tx, no need to add AccountHistory job.";
4512 return;
4513 }
4514 }
4515 else
4516 {
4517 // LCOV_EXCL_START
4518 UNREACHABLE(
4519 "xrpl::NetworkOPsImp::subAccountHistoryStart : failed to "
4520 "access genesis account");
4521 return;
4522 // LCOV_EXCL_STOP
4523 }
4524 }
4525 subInfo.index->historyLastLedgerSeq = ledger->seq();
4526 subInfo.index->haveHistorical = true;
4527
4528 JLOG(journal_.debug()) << "subAccountHistoryStart, add AccountHistory job: accountId="
4529 << toBase58(accountId) << ", currentLedgerSeq=" << ledger->seq();
4530
4531 addAccountHistoryJob(subInfo);
4532}
4533
4536{
4537 if (!isrListener->insertSubAccountHistory(accountId))
4538 {
4539 JLOG(journal_.debug()) << "subAccountHistory, already subscribed to account "
4540 << toBase58(accountId);
4541 return RpcInvalidParams;
4542 }
4543
4546 .sinkWptr = isrListener,
4547 .index = std::make_shared<SubAccountHistoryIndex>(accountId),
4548 };
4549 auto const simIterator = subAccountHistory_.find(accountId);
4550 if (simIterator == subAccountHistory_.end())
4551 {
4553 inner.emplace(isrListener->getSeq(), ahi);
4554 subAccountHistory_.insert(simIterator, std::make_pair(accountId, inner));
4555 }
4556 else
4557 {
4558 simIterator->second.emplace(isrListener->getSeq(), ahi);
4559 }
4560
4561 auto const ledger = registry_.get().getLedgerMaster().getValidatedLedger();
4562 if (ledger)
4563 {
4564 subAccountHistoryStart(ledger, ahi);
4565 }
4566 else
4567 {
4568 // The node does not have validated ledgers, so wait for
4569 // one before start streaming.
4570 // In this case, the subscription is also considered successful.
4571 JLOG(journal_.debug()) << "subAccountHistory, no validated ledger yet, delay start";
4572 }
4573
4574 return RpcSuccess;
4575}
4576
4577void
4579 InfoSub::Ref isrListener,
4580 AccountID const& account,
4581 bool historyOnly)
4582{
4583 if (!historyOnly)
4584 isrListener->deleteSubAccountHistory(account);
4585 unsubAccountHistoryInternal(isrListener->getSeq(), account, historyOnly);
4586}
4587
4588void
4590 std::uint64_t seq,
4591 AccountID const& account,
4592 bool historyOnly)
4593{
4595 auto const simIterator = subAccountHistory_.find(account);
4596 if (simIterator != subAccountHistory_.end())
4597 {
4598 auto& subInfoMap = simIterator->second;
4599 auto const subInfoIter = subInfoMap.find(seq);
4600 if (subInfoIter != subInfoMap.end())
4601 {
4602 subInfoIter->second.index->stopHistorical = true;
4603 }
4604
4605 if (!historyOnly)
4606 {
4607 simIterator->second.erase(seq);
4608 if (simIterator->second.empty())
4609 {
4610 subAccountHistory_.erase(simIterator);
4611 }
4612 }
4613 JLOG(journal_.debug()) << "unsubAccountHistory, account " << toBase58(account)
4614 << ", historyOnly = " << (historyOnly ? "true" : "false");
4615 }
4616}
4617
4618bool
4620{
4621 // Server-side insert first, then InfoSub bookkeeping. If the InfoSub-side
4622 // insert throws, the orphan in subBook_ is cleared by the expired-weak_ptr
4623 // prune in pubBookTransaction. With the reverse ordering, ~InfoSub would
4624 // call unsubBookInternal for a key that was never inserted server-side.
4625 {
4626 std::scoped_lock const sl(bookLock_);
4627 subBook_[book].try_emplace(isrListener->getSeq(), isrListener);
4628 }
4629 isrListener->insertBookSubscription(book);
4630 return true;
4631}
4632
4633bool
4635{
4636 // Mirrors unsubAccount: clear the per-subscriber tracking set first so
4637 // ~InfoSub does not re-issue an unsubBookInternal for a book the caller
4638 // already removed, then erase the server-side entry.
4639 isrListener->deleteBookSubscription(book);
4640 return unsubBookInternal(isrListener->getSeq(), book);
4641}
4642
4643bool
4645{
4646 std::scoped_lock const sl(bookLock_);
4647 auto const it = subBook_.find(book);
4648 if (it == subBook_.end())
4649 return false;
4650 bool const erased = it->second.erase(uSeq) != 0u;
4651 if (it->second.empty())
4652 subBook_.erase(it);
4653 return erased;
4654}
4655
4658{
4659 // This code-path is exclusively used when the server is in standalone
4660 // mode via `ledger_accept`
4661 XRPL_ASSERT(standalone_, "xrpl::NetworkOPsImp::acceptLedger : is standalone");
4662
4663 if (!standalone_)
4664 Throw<std::runtime_error>("Operation only possible in STANDALONE mode.");
4665
4666 // FIXME Could we improve on this and remove the need for a specialized
4667 // API in Consensus?
4668 beginConsensus(ledgerMaster_.getClosedLedger()->header().hash, {});
4669 consensus_.simulate(registry_.get().getTimeKeeper().closeTime(), consensusDelay);
4670 return ledgerMaster_.getCurrentLedger()->header().seq;
4671}
4672
4673// <-- bool: true=added, false=already there
4674bool
4676{
4677 if (auto const lpClosed = ledgerMaster_.getValidatedLedger())
4678 {
4679 jvResult[jss::ledger_index] = lpClosed->header().seq;
4680 jvResult[jss::ledger_hash] = to_string(lpClosed->header().hash);
4681 jvResult[jss::ledger_time] =
4682 json::Value::UInt(lpClosed->header().closeTime.time_since_epoch().count());
4683 jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped();
4684 jvResult[jss::reserve_base] = lpClosed->fees().reserve.jsonClipped();
4685 jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped();
4686 jvResult[jss::network_id] = registry_.get().getNetworkIDService().getNetworkID();
4687 if (lpClosed->rules().enabled(featureSmartEscrow))
4688 {
4689 jvResult[jss::gas_limit] = lpClosed->fees().gasLimit;
4690 jvResult[jss::bytecode_size_limit] = lpClosed->fees().bytecodeSizeLimit;
4691 jvResult[jss::gas_price] = lpClosed->fees().gasPrice;
4692 }
4693 }
4694
4696 {
4697 jvResult[jss::validated_ledgers] = registry_.get().getLedgerMaster().getCompleteLedgers();
4698 }
4699
4700 std::scoped_lock const sl(streamLock_);
4701 return streamMaps_[SLedger].emplace(isrListener->getSeq(), isrListener).second;
4702}
4703
4704// <-- bool: true=added, false=already there
4705bool
4707{
4708 std::scoped_lock const sl(streamLock_);
4709 return streamMaps_[SBookChanges].emplace(isrListener->getSeq(), isrListener).second;
4710}
4711
4712// <-- bool: true=erased, false=was not there
4713bool
4715{
4716 std::scoped_lock const sl(streamLock_);
4717 return streamMaps_[SLedger].erase(uSeq) != 0u;
4718}
4719
4720// <-- bool: true=erased, false=was not there
4721bool
4723{
4724 std::scoped_lock const sl(streamLock_);
4725 return streamMaps_[SBookChanges].erase(uSeq) != 0u;
4726}
4727
4728// <-- bool: true=added, false=already there
4729bool
4731{
4732 std::scoped_lock const sl(streamLock_);
4733 return streamMaps_[SManifests].emplace(isrListener->getSeq(), isrListener).second;
4734}
4735
4736// <-- bool: true=erased, false=was not there
4737bool
4739{
4740 std::scoped_lock const sl(streamLock_);
4741 return streamMaps_[SManifests].erase(uSeq) != 0u;
4742}
4743
4744// <-- bool: true=added, false=already there
4745bool
4746NetworkOPsImp::subServer(InfoSub::Ref isrListener, json::Value& jvResult, bool admin)
4747{
4748 UInt256 uRandom;
4749
4750 if (standalone_)
4751 jvResult[jss::stand_alone] = standalone_;
4752
4753 // CHECKME: is it necessary to provide a random number here?
4754 beast::rngfill(uRandom.begin(), uRandom.size(), cryptoPrng());
4755
4756 auto const& feeTrack = registry_.get().getFeeTrack();
4757 jvResult[jss::random] = to_string(uRandom);
4758 jvResult[jss::server_status] = strOperatingMode(admin);
4759 jvResult[jss::load_base] = feeTrack.getLoadBase();
4760 jvResult[jss::load_factor] = feeTrack.getLoadFactor();
4761 jvResult[jss::hostid] = getHostId(admin);
4762 jvResult[jss::pubkey_node] =
4763 toBase58(TokenType::NodePublic, registry_.get().getApp().nodeIdentity().first);
4764
4765 std::scoped_lock const sl(streamLock_);
4766 return streamMaps_[SServer].emplace(isrListener->getSeq(), isrListener).second;
4767}
4768
4769// <-- bool: true=erased, false=was not there
4770bool
4772{
4773 std::scoped_lock const sl(streamLock_);
4774 return streamMaps_[SServer].erase(uSeq) != 0u;
4775}
4776
4777// <-- bool: true=added, false=already there
4778bool
4780{
4781 std::scoped_lock const sl(streamLock_);
4782 return streamMaps_[STransactions].emplace(isrListener->getSeq(), isrListener).second;
4783}
4784
4785// <-- bool: true=erased, false=was not there
4786bool
4788{
4789 std::scoped_lock const sl(streamLock_);
4790 return streamMaps_[STransactions].erase(uSeq) != 0u;
4791}
4792
4793// <-- bool: true=added, false=already there
4794bool
4796{
4797 std::scoped_lock const sl(streamLock_);
4798 return streamMaps_[SRtTransactions].emplace(isrListener->getSeq(), isrListener).second;
4799}
4800
4801// <-- bool: true=erased, false=was not there
4802bool
4804{
4805 std::scoped_lock const sl(streamLock_);
4806 return streamMaps_[SRtTransactions].erase(uSeq) != 0u;
4807}
4808
4809// <-- bool: true=added, false=already there
4810bool
4812{
4813 std::scoped_lock const sl(streamLock_);
4814 return streamMaps_[SValidations].emplace(isrListener->getSeq(), isrListener).second;
4815}
4816
4817void
4822
4823// <-- bool: true=erased, false=was not there
4824bool
4826{
4827 std::scoped_lock const sl(streamLock_);
4828 return streamMaps_[SValidations].erase(uSeq) != 0u;
4829}
4830
4831// <-- bool: true=added, false=already there
4832bool
4834{
4835 std::scoped_lock const sl(streamLock_);
4836 return streamMaps_[SPeerStatus].emplace(isrListener->getSeq(), isrListener).second;
4837}
4838
4839// <-- bool: true=erased, false=was not there
4840bool
4842{
4843 std::scoped_lock const sl(streamLock_);
4844 return streamMaps_[SPeerStatus].erase(uSeq) != 0u;
4845}
4846
4847// <-- bool: true=added, false=already there
4848bool
4850{
4851 std::scoped_lock const sl(streamLock_);
4852 return streamMaps_[SConsensusPhase].emplace(isrListener->getSeq(), isrListener).second;
4853}
4854
4855// <-- bool: true=erased, false=was not there
4856bool
4858{
4859 std::scoped_lock const sl(streamLock_);
4860 return streamMaps_[SConsensusPhase].erase(uSeq) != 0u;
4861}
4862
4865{
4866 // Caller already holds streamLock_; this performs the lookup only.
4867 auto const it = rpcSubMap_.find(strUrl);
4868
4869 if (it != rpcSubMap_.end())
4870 return it->second;
4871
4872 return InfoSub::pointer();
4873}
4874
4877{
4878 std::scoped_lock const sl(streamLock_);
4879 return findRpcSubLocked(strUrl);
4880}
4881
4884{
4885 std::scoped_lock const sl(streamLock_);
4886
4887 rpcSubMap_.emplace(strUrl, rspEntry);
4888
4889 return rspEntry;
4890}
4891
4892bool
4894{
4895 // Declared before the lock so it outlives the scoped_lock and is destroyed
4896 // only after streamLock_ is released. The erase below may drop the last
4897 // strong reference; if so, ~InfoSub runs and its unsub* calls re-acquire
4898 // the non-recursive streamLock_. Destroying pInfo inside the lock would
4899 // self-deadlock.
4900 InfoSub::pointer pInfo;
4901 {
4902 std::scoped_lock const sl(streamLock_);
4903 // Use the no-lock helper: we already hold streamLock_ and the mutex is
4904 // not recursive, so calling the public findRpcSub here would deadlock.
4905 pInfo = findRpcSubLocked(strUrl);
4906
4907 if (!pInfo)
4908 return false;
4909
4910 // check to see if any of the stream maps still hold a weak reference to
4911 // this entry before removing
4912 for (SubMapType const& map : streamMaps_)
4913 {
4914 if (map.contains(pInfo->getSeq()))
4915 return false;
4916 }
4917 rpcSubMap_.erase(strUrl);
4918 }
4919 // pInfo destroyed here, after streamLock_ is released.
4920 return true;
4921}
4922
4923#ifndef USE_NEW_BOOK_PAGE
4924
4925// Same as std::min(takerPays, multiply(funded, rate, asset)), but compares
4926// before building the amount, so an unrepresentable product is never built.
4927// multiply() uses this same Number product (the rate is a quality, never
4928// native or MPT), so the result is unchanged.
4929static STAmount
4930takerPaysFunded(STAmount const& takerPays, STAmount const& takerGetsFunded, STAmount const& rate)
4931{
4932 Number const product = Number{takerGetsFunded} * Number{rate};
4933 if (product >= Number{takerPays})
4934 return takerPays;
4935 return STAmount{takerPays.asset(), product};
4936}
4937
4938// NIKB FIXME this should be looked at. There's no reason why this shouldn't
4939// work, but it demonstrated poor performance.
4940//
4941void
4944 Book const& book,
4945 AccountID const& uTakerID,
4946 bool const bProof,
4947 unsigned int iLimit,
4948 json::Value const& jvMarker,
4949 json::Value& jvResult)
4950{ // CAUTION: This is the old get book page logic
4951 json::Value& jvOffers = (jvResult[jss::offers] = json::Value(json::ValueType::Array));
4952
4954 UInt256 const uBookBase = getBookBase(book);
4955 UInt256 const uBookEnd = getQualityNext(uBookBase);
4956 UInt256 uTipIndex = uBookBase;
4957
4958 if (auto const stream = journal_.trace())
4959 {
4960 stream << "getBookPage:" << book;
4961 stream << "getBookPage: uBookBase=" << uBookBase;
4962 stream << "getBookPage: uBookEnd=" << uBookEnd;
4963 stream << "getBookPage: uTipIndex=" << uTipIndex;
4964 }
4965
4966 ReadView const& view = *lpLedger;
4967
4968 bool const bGlobalFreeze = isGlobalFrozen(view, book.out) || isGlobalFrozen(view, book.in);
4969
4970 bool bDone = false;
4971 bool bDirectAdvance = true;
4972
4973 SLE::const_pointer sleOfferDir;
4974 UInt256 offerIndex;
4975 unsigned int uBookEntry = 0;
4976 STAmount saDirRate;
4977
4978 auto const rate = transferRate(view, book.out);
4979 auto const viewJ = registry_.get().getJournal("View");
4980
4981 while (!bDone && iLimit-- > 0)
4982 {
4983 if (bDirectAdvance)
4984 {
4985 bDirectAdvance = false;
4986
4987 JLOG(journal_.trace()) << "getBookPage: bDirectAdvance";
4988
4989 auto const ledgerIndex = view.succ(uTipIndex, uBookEnd);
4990 if (ledgerIndex)
4991 {
4992 sleOfferDir = view.read(keylet::page(*ledgerIndex));
4993 }
4994 else
4995 {
4996 sleOfferDir.reset();
4997 }
4998
4999 if (!sleOfferDir)
5000 {
5001 JLOG(journal_.trace()) << "getBookPage: bDone";
5002 bDone = true;
5003 }
5004 else
5005 {
5006 uTipIndex = sleOfferDir->key();
5007 saDirRate = amountFromQuality(getQuality(uTipIndex));
5008
5009 cdirFirst(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex);
5010
5011 JLOG(journal_.trace()) << "getBookPage: uTipIndex=" << uTipIndex;
5012 JLOG(journal_.trace()) << "getBookPage: offerIndex=" << offerIndex;
5013 }
5014 }
5015
5016 if (!bDone)
5017 {
5018 auto const sleOffer = view.read(keylet::offer(offerIndex));
5019
5020 if (sleOffer)
5021 {
5022 auto const uOfferOwnerID = sleOffer->getAccountID(sfAccount);
5023 auto const& saTakerGets = sleOffer->getFieldAmount(sfTakerGets);
5024 auto const& saTakerPays = sleOffer->getFieldAmount(sfTakerPays);
5025 STAmount saOwnerFunds;
5026 bool firstOwnerOffer(true);
5027 auto foundBalance = [&] {
5028 auto const umBalanceEntry = umBalance.find(uOfferOwnerID);
5029 if (umBalanceEntry == umBalance.end())
5030 return false;
5031
5032 // Found in running balance table.
5033 saOwnerFunds = umBalanceEntry->second;
5034 firstOwnerOffer = false;
5035 return true;
5036 };
5037
5038 if (book.out.getIssuer() == uOfferOwnerID)
5039 {
5040 book.out.visit(
5041 [&](Issue const&) {
5042 // If an offer is selling issuer's own IOUs, it is
5043 // fully funded.
5044 saOwnerFunds = saTakerGets;
5045 },
5046 [&](MPTIssue const& issue) {
5047 // MPT issuers have bounded self-issuance. Use the
5048 // running balance table so multiple issuer-owned
5049 // offers share the same remaining issuance
5050 // headroom.
5051 if (!foundBalance())
5052 {
5053 // Did not find balance in table.
5054
5055 saOwnerFunds = issuerFundsToSelfIssue(view, issue);
5056 }
5057 });
5058 }
5059 else if (bGlobalFreeze)
5060 {
5061 // If either asset is globally frozen, consider all offers
5062 // that aren't ours to be totally unfunded
5063 saOwnerFunds.clear(book.out);
5064 }
5065 else
5066 {
5067 if (!foundBalance())
5068 {
5069 // Did not find balance in table.
5070
5071 saOwnerFunds = accountHolds(
5072 view,
5073 uOfferOwnerID,
5074 book.out,
5077 viewJ);
5078
5079 if (saOwnerFunds < beast::kZero)
5080 {
5081 // Treat negative funds as zero.
5082
5083 saOwnerFunds.clear();
5084 }
5085 }
5086 }
5087
5088 json::Value jvOffer = sleOffer->getJson(JsonOptions::Values::None);
5089
5090 STAmount saTakerGetsFunded;
5091 STAmount saOwnerFundsLimit = saOwnerFunds;
5092 Rate offerRate = kParityRate;
5093
5094 if (rate != kParityRate
5095 // Have a transfer fee.
5096 && uTakerID != book.out.getIssuer()
5097 // Not taking offers of own IOUs.
5098 && book.out.getIssuer() != uOfferOwnerID)
5099 // Offer owner not issuing ownfunds
5100 {
5101 // Need to charge a transfer fee to offer owner.
5102 offerRate = rate;
5103 // Why MPT does not use divide(): divide() is built for an
5104 // IOU mantissa, which is always normalized into
5105 // [1e15, 1e16]. An MPT mantissa is the raw int64 balance,
5106 // and divide() scales the numerator by 1e17, so a balance
5107 // over ~1.8e17 leaves uint64 range and throws -- failing
5108 // the whole RPC rather than this one offer.
5109 //
5110 // Why mulRatio is safe: it evaluates in 128 bits, and here
5111 // it cannot overflow either. offerRate is
5112 // 1e9 + 10'000 * TransferFee, so this branch runs only with
5113 // offerRate > kParityRate, making the quotient smaller than
5114 // saOwnerFunds. Rounded down, so reported liquidity is
5115 // never overstated.
5116 saOwnerFundsLimit = saOwnerFunds.holds<MPTIssue>()
5117 ? toSTAmount(
5118 mulRatio(
5119 saOwnerFunds.mpt(),
5120 kParityRate.value,
5121 offerRate.value,
5122 /*roundUp*/ false),
5123 saOwnerFunds.asset())
5124 : divide(saOwnerFunds, offerRate);
5125 }
5126
5127 if (saOwnerFundsLimit >= saTakerGets)
5128 {
5129 // Sufficient funds no shenanigans.
5130 saTakerGetsFunded = saTakerGets;
5131 }
5132 else
5133 {
5134 // Only provide, if not fully funded.
5135
5136 saTakerGetsFunded = saOwnerFundsLimit;
5137
5138 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
5139 takerPaysFunded(saTakerPays, saTakerGetsFunded, saDirRate)
5140 .setJson(jvOffer[jss::taker_pays_funded]);
5141 }
5142
5143 // What the owner pays for this offer, charged against the
5144 // running balance for the owner's later offers. BookStep
5145 // rounds the MPT owner's fee-grossed cost up; multiply() rounds
5146 // to nearest and would leave one unit per offer over-reported
5147 // to the next offer. Can't overflow: saTakerGetsFunded <=
5148 // floor(saOwnerFunds / offerRate).
5149 auto const grossed = [&] {
5150 return saOwnerFunds.asset().visit(
5151 [&](MPTIssue const&) {
5152 auto const mpt = mulRatio(
5153 saTakerGetsFunded.mpt(),
5154 offerRate.value,
5155 kParityRate.value,
5156 /*roundUp*/ true);
5157 return toSTAmount(mpt, saOwnerFunds.asset());
5158 },
5159 [&](Issue const&) { return multiply(saTakerGetsFunded, offerRate); });
5160 };
5161 STAmount const saOwnerPays = (kParityRate == offerRate)
5162 ? saTakerGetsFunded
5163 : std::min(saOwnerFunds, grossed());
5164
5165 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
5166
5167 // Include all offers funded and unfunded
5168 json::Value& jvOf = jvOffers.append(jvOffer);
5169 jvOf[jss::quality] = saDirRate.getText();
5170
5171 if (firstOwnerOffer)
5172 jvOf[jss::owner_funds] = saOwnerFunds.getText();
5173 }
5174 else
5175 {
5176 JLOG(journal_.warn()) << "Missing offer";
5177 }
5178
5179 if (!cdirNext(view, uTipIndex, sleOfferDir, uBookEntry, offerIndex))
5180 {
5181 bDirectAdvance = true;
5182 }
5183 else
5184 {
5185 JLOG(journal_.trace()) << "getBookPage: offerIndex=" << offerIndex;
5186 }
5187 }
5188 }
5189
5190 // jvResult[jss::marker] = json::Value(json::ValueType::Array);
5191 // jvResult[jss::nodes] = json::Value(json::ValueType::Array);
5192}
5193
5194#else
5195
5196// This is the new code that uses the book iterators
5197// It has temporarily been disabled
5198// If this path is re-enabled, add MPT support mirroring the functional
5199// getBookPage() implementation above.
5200
5201void
5204 Book const& book,
5205 AccountID const& uTakerID,
5206 bool const bProof,
5207 unsigned int iLimit,
5208 json::Value const& jvMarker,
5209 json::Value& jvResult)
5210{
5211 auto& jvOffers = (jvResult[jss::offers] = json::Value(json::ValueType::Array));
5212
5214
5215 MetaView lesActive(lpLedger, tapNONE, true);
5216 OrderBookIterator obIterator(lesActive, book);
5217
5218 auto const rate = transferRate(lesActive, book.out.account);
5219
5220 bool const bGlobalFreeze =
5221 lesActive.isGlobalFrozen(book.out.account) || lesActive.isGlobalFrozen(book.in.account);
5222
5223 while (iLimit-- > 0 && obIterator.nextOffer())
5224 {
5225 SLE::pointer sleOffer = obIterator.getCurrentOffer();
5226 if (sleOffer)
5227 {
5228 auto const uOfferOwnerID = sleOffer->getAccountID(sfAccount);
5229 auto const& saTakerGets = sleOffer->getFieldAmount(sfTakerGets);
5230 auto const& saTakerPays = sleOffer->getFieldAmount(sfTakerPays);
5231 STAmount saDirRate = obIterator.getCurrentRate();
5232 STAmount saOwnerFunds;
5233
5234 if (book.out.account == uOfferOwnerID)
5235 {
5236 // If offer is selling issuer's own IOUs, it is fully funded.
5237 saOwnerFunds = saTakerGets;
5238 }
5239 else if (bGlobalFreeze)
5240 {
5241 // If either asset is globally frozen, consider all offers
5242 // that aren't ours to be totally unfunded
5243 saOwnerFunds.clear(book.out);
5244 }
5245 else
5246 {
5247 auto umBalanceEntry = umBalance.find(uOfferOwnerID);
5248
5249 if (umBalanceEntry != umBalance.end())
5250 {
5251 // Found in running balance table.
5252
5253 saOwnerFunds = umBalanceEntry->second;
5254 }
5255 else
5256 {
5257 // Did not find balance in table.
5258
5259 saOwnerFunds = lesActive.accountHolds(
5260 uOfferOwnerID,
5261 book.out.currency,
5262 book.out.account,
5264
5265 if (saOwnerFunds.isNegative())
5266 {
5267 // Treat negative funds as zero.
5268
5269 saOwnerFunds.zero();
5270 }
5271 }
5272 }
5273
5274 json::Value jvOffer = sleOffer->getJson(JsonOptions::Values::None);
5275
5276 STAmount saTakerGetsFunded;
5277 STAmount saOwnerFundsLimit = saOwnerFunds;
5278 Rate offerRate = parityRate;
5279
5280 if (rate != parityRate
5281 // Have a transfer fee.
5282 && uTakerID != book.out.account
5283 // Not taking offers of own IOUs.
5284 && book.out.account != uOfferOwnerID)
5285 // Offer owner not issuing ownfunds
5286 {
5287 // Need to charge a transfer fee to offer owner.
5288 offerRate = rate;
5289 saOwnerFundsLimit = divide(saOwnerFunds, offerRate);
5290 }
5291
5292 if (saOwnerFundsLimit >= saTakerGets)
5293 {
5294 // Sufficient funds no shenanigans.
5295 saTakerGetsFunded = saTakerGets;
5296 }
5297 else
5298 {
5299 // Only provide, if not fully funded.
5300 saTakerGetsFunded = saOwnerFundsLimit;
5301
5302 saTakerGetsFunded.setJson(jvOffer[jss::taker_gets_funded]);
5303
5304 // TODO(tom): The result of this expression is not used - what's
5305 // going on here?
5306 std::min(saTakerPays, multiply(saTakerGetsFunded, saDirRate, saTakerPays.asset()))
5307 .setJson(jvOffer[jss::taker_pays_funded]);
5308 }
5309
5310 STAmount saOwnerPays = (parityRate == offerRate)
5311 ? saTakerGetsFunded
5312 : std::min(saOwnerFunds, multiply(saTakerGetsFunded, offerRate));
5313
5314 umBalance[uOfferOwnerID] = saOwnerFunds - saOwnerPays;
5315
5316 if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
5317 {
5318 // Only provide funded offers and offers of the taker.
5319 json::Value& jvOf = jvOffers.append(jvOffer);
5320 jvOf[jss::quality] = saDirRate.getText();
5321 }
5322 }
5323 }
5324
5325 // jvResult[jss::marker] = json::Value(json::ValueType::Array);
5326 // jvResult[jss::nodes] = json::Value(json::ValueType::Array);
5327}
5328
5329#endif
5330
5331inline void
5333{
5334 auto [counters, mode, start, initialSync] = accounting_.getCounterData();
5337 counters[static_cast<std::size_t>(mode)].dur += current;
5338
5339 std::scoped_lock const lock(statsMutex_);
5340 stats_.disconnectedDuration.set(
5341 counters[static_cast<std::size_t>(OperatingMode::DISCONNECTED)].dur.count());
5342 stats_.connectedDuration.set(
5343 counters[static_cast<std::size_t>(OperatingMode::CONNECTED)].dur.count());
5344 stats_.syncingDuration.set(
5345 counters[static_cast<std::size_t>(OperatingMode::SYNCING)].dur.count());
5346 stats_.trackingDuration.set(
5347 counters[static_cast<std::size_t>(OperatingMode::TRACKING)].dur.count());
5348 stats_.fullDuration.set(counters[static_cast<std::size_t>(OperatingMode::FULL)].dur.count());
5349
5350 stats_.disconnectedTransitions.set(
5351 counters[static_cast<std::size_t>(OperatingMode::DISCONNECTED)].transitions);
5352 stats_.connectedTransitions.set(
5353 counters[static_cast<std::size_t>(OperatingMode::CONNECTED)].transitions);
5354 stats_.syncingTransitions.set(
5355 counters[static_cast<std::size_t>(OperatingMode::SYNCING)].transitions);
5356 stats_.trackingTransitions.set(
5357 counters[static_cast<std::size_t>(OperatingMode::TRACKING)].transitions);
5358 stats_.fullTransitions.set(counters[static_cast<std::size_t>(OperatingMode::FULL)].transitions);
5359}
5360
5361void
5363{
5364 auto const now = std::chrono::steady_clock::now();
5365
5366 std::scoped_lock const lock(mutex_);
5367 ++counters_[static_cast<std::size_t>(om)].transitions;
5368 if (om == OperatingMode::FULL && counters_[static_cast<std::size_t>(om)].transitions == 1)
5369 {
5372 }
5373 counters_[static_cast<std::size_t>(mode_)].dur +=
5375
5376 mode_ = om;
5377 start_ = now;
5378}
5379
5380void
5382{
5383 auto [counters, mode, start, initialSync] = getCounterData();
5386 counters[static_cast<std::size_t>(mode)].dur += current;
5387
5388 obj[jss::state_accounting] = json::ValueType::Object;
5389 for (auto i = static_cast<std::size_t>(OperatingMode::DISCONNECTED);
5390 i <= static_cast<std::size_t>(OperatingMode::FULL);
5391 ++i)
5392 {
5393 obj[jss::state_accounting][kStates[i]] = json::ValueType::Object;
5394 auto& state = obj[jss::state_accounting][kStates[i]];
5395 state[jss::transitions] = std::to_string(counters[i].transitions);
5396 state[jss::duration_us] = std::to_string(counters[i].dur.count());
5397 }
5398 obj[jss::server_state_duration_us] = std::to_string(current.count());
5399 if (initialSync != 0u)
5400 obj[jss::initial_sync_duration_us] = std::to_string(initialSync);
5401}
5402
5403//------------------------------------------------------------------------------
5404
5407 ServiceRegistry& registry,
5408 NetworkOPs::ClockType& clock,
5409 bool standalone,
5410 std::size_t minPeerCount,
5411 bool startValid,
5412 JobQueue& jobQueue,
5413 LedgerMaster& ledgerMaster,
5414 ValidatorKeys const& validatorKeys,
5415 boost::asio::io_context& ioCtx,
5417 beast::insight::Collector::Ptr const& collector)
5418{
5420 registry,
5421 clock,
5422 standalone,
5423 minPeerCount,
5424 startValid,
5425 jobQueue,
5426 ledgerMaster,
5427 validatorKeys,
5428 ioCtx,
5429 journal,
5430 collector);
5431}
5432
5433} // namespace xrpl
T any_of(T... args)
T back_inserter(T... args)
T begin(T... args)
A generic endpoint for log messages.
Definition Journal.h:44
std::shared_ptr< Collector > Ptr
Definition Collector.h:29
A metric for measuring an integral value.
Definition Gauge.h:21
A reference to a handler for performing polled collection.
Definition Hook.h:14
Decorator for streaming out compact json.
Lightweight wrapper to tag static string.
Definition json_value.h:52
Represents a JSON value.
Definition json_value.h:121
Value get(UInt index, Value const &defaultValue) const
If the array contains at least index+1 elements, returns the element value, otherwise returns default...
json::UInt UInt
Definition json_value.h:128
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
bool isMember(char const *key) const
Return true if the object has a member named key.
A transaction that is in a closed ledger.
TxMeta const & getMeta() const
boost::container::flat_set< AccountID > const & getAffected() const
std::shared_ptr< STTx const > const & getTxn() const
constexpr auto visit(Visitors &&... visitors) const -> decltype(auto)
Definition Asset.h:117
bool isZero() const
Definition base_uint.h:563
bool isNonZero() const
Definition base_uint.h:568
iterator begin()
Definition base_uint.h:128
static constexpr std::size_t size()
Definition base_uint.h:549
Specifies an order book.
Definition Book.h:28
Holds transactions which were deferred to the next pass of consensus.
The role of a ClosureCounter is to assist in shutdown by letting callers wait for the completion of c...
std::uint32_t getLoadFee() const
Definition ClusterNode.h:33
NetClock::time_point getReportTime() const
Definition ClusterNode.h:39
PublicKey const & identity() const
Definition ClusterNode.h:45
std::string const & name() const
Definition ClusterNode.h:27
std::shared_ptr< InfoSub > const & Ref
Definition InfoSub.h:98
std::shared_ptr< InfoSub > pointer
Definition InfoSub.h:92
std::weak_ptr< InfoSub > Wptr
Definition InfoSub.h:96
A currency issued by an account.
Definition Issue.h:18
A pool of threads to perform work.
Definition JobQueue.h:60
Tracks the current ledger and any ledgers in the process of closing.
Manages the current fee schedule.
Manages load sources.
Definition LoadManager.h:28
void heartbeat()
Reset the stall detection timer.
static constexpr int kHoldLedgers
Definition LocalTxs.h:23
State accounting records two attributes for each possible server state: 1) Amount of time spent in ea...
void json(json::Value &obj) const
Output state counters in JSON format.
std::chrono::steady_clock::time_point const processStart_
static std::array< json::StaticString const, 5 > const kStates
std::array< Counters, 5 > counters_
void mode(OperatingMode om)
Record state transition.
std::chrono::steady_clock::time_point start_
Transaction with input flags and results to be applied in batches.
std::shared_ptr< Transaction > const transaction
TransactionStatus(std::shared_ptr< Transaction > t, bool a, bool l, FailHard f)
SubBookMapType subBook_
Guarded by bookLock_.
std::string getHostId(bool forAdmin)
void reportConsensusStateChange(ConsensusPhase phase)
void addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo)
void clearNeedNetworkLedger() override
SubInfoMapType subAccount_
HashMap< AccountID, HashMap< std::uint64_t, SubAccountHistoryInfoWeak > > SubAccountHistoryMapType
static constexpr std::size_t kAccountCleanupChunk
Maximum number of account entries erased per accountLock_ acquisition during disconnect-time cleanup.
bool subManifests(InfoSub::Ref ispListener) override
std::size_t const minPeerCount_
bool subServer(InfoSub::Ref ispListener, json::Value &jvResult, bool admin) override
std::vector< TransactionStatus > transactions_
bool subPeerStatus(InfoSub::Ref ispListener) override
void pubAccountTransaction(std::shared_ptr< ReadView const > const &ledger, AcceptedLedgerTx const &transaction, bool last)
void subMPT(InfoSub::Ref ispListener, HashSet< MPTID > const &mptIDs) override
void unsubAccount(InfoSub::Ref ispListener, HashSet< AccountID > const &vnaAccountIDs, bool rt) override
void pubPeerStatus(std::function< json::Value()> const &) override
bool subValidations(InfoSub::Ref ispListener) override
ClosureCounter< void, boost::system::error_code const & > waitHandlerCounter_
std::condition_variable cond_
MultiApiJson transJson(std::shared_ptr< STTx const > const &transaction, TER result, bool validated, std::shared_ptr< ReadView const > const &ledger, std::optional< std::reference_wrapper< TxMeta const > > meta)
bool unsubManifests(std::uint64_t uListener) override
json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account) override
void unsubMPTInternal(std::uint64_t seq, MPTID const &mptID) override
Remove an MPT issuance subscription during InfoSub teardown.
HashMap< Book, SubMapType > SubBookMapType
Maps each order book to its current set of subscribers.
void cleanupAccountHistorySubscriptions(std::uint64_t seq, HashSet< AccountID > const &accounts)
Erase one connection's entries from subAccountHistory_ in accountLock_-bounded chunks.
void stateAccounting(json::Value &obj) override
void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted) override
void stop() override
DispatchState dispatchState_
InfoSub::pointer addRpcSub(std::string const &strUrl, InfoSub::Ref) override
void transactionBatch()
Apply transactions in batches.
void setTimer(boost::asio::steady_timer &timer, std::chrono::milliseconds const &expiryTime, std::function< void()> onExpire, std::function< void()> onError)
bool unsubRTTransactions(std::uint64_t uListener) override
beast::Journal const & journal() const override
Journal used by InfoSub for diagnostics that occur after the owning subsystem (e.g.
json::Value getLedgerFetchInfo() override
bool processTrustedProposal(RCLCxPeerPos proposal) override
InfoSub::pointer findRpcSubLocked(std::string const &strUrl)
Look up an RPC subscription without taking streamLock_.
void kickoffAccountHistory(std::shared_ptr< AcceptedLedger const > const &alpAccepted)
On the first published ledger only, start the delayed account-history streaming for any subscriptions...
void subAccountHistoryStart(std::shared_ptr< ReadView const > const &ledger, SubAccountHistoryInfoWeak &subInfo)
void pubValidation(std::shared_ptr< STValidation > const &val) override
json::Value getConsensusInfo() override
ConsensusPhase lastConsensusPhase_
beast::Journal journal_
void endConsensus(std::unique_ptr< std::stringstream > const &clog) override
bool beginConsensus(UInt256 const &networkClosed, std::unique_ptr< std::stringstream > const &clog) override
void setMode(OperatingMode om) override
void setAmendmentBlocked() override
bool subBook(InfoSub::Ref ispListener, Book const &) override
ErrorCodeI subAccountHistory(InfoSub::Ref ispListener, AccountID const &account) override
subscribe an account's new transactions and retrieve the account's historical transactions
HashMap< AccountID, SubMapType > SubInfoMapType
void pubConsensus(ConsensusPhase phase)
bool isNeedNetworkLedger() override
bool unsubBookInternal(std::uint64_t uListener, Book const &) override
Remove a book subscription during InfoSub teardown.
DispatchState
Synchronization states for transaction batches.
SubInfoMapType subRTAccount_
std::atomic< bool > needNetworkLedger_
boost::asio::steady_timer heartbeatTimer_
std::mutex mptLock_
Guards subMPT_.
std::array< SubMapType, SubTypes::SLastEntry > streamMaps_
One weak_ptr subscriber map per stream type.
std::reference_wrapper< ServiceRegistry > registry_
static std::array< char const *, 5 > const kStates
bool unsubLedger(std::uint64_t uListener) override
void pubProposedAccountTransaction(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &transaction, TER result)
void unsubAccountHistoryInternal(std::uint64_t seq, AccountID const &account, bool historyOnly) override
void pubValidatedTransaction(std::shared_ptr< ReadView const > const &ledger, AcceptedLedgerTx const &transaction, bool last)
void pubBookTransaction(AcceptedLedgerTx const &transaction, MultiApiJson const &jvObj)
Fan transaction notifications out to all book subscribers.
void cleanupAccountSubscriptions(std::uint64_t seq, HashSet< AccountID > const &accounts, SubInfoMapType &subMap)
Erase one connection's entries from the given account map (subAccount_ or subRTAccount_) in accountLo...
void switchLastClosedLedger(std::shared_ptr< Ledger const > const &newLCL)
std::optional< PublicKey > const validatorPK_
std::mutex streamLock_
Guards streamMaps_[] and rpcSubMap_.
std::atomic< bool > amendmentBlocked_
bool unsubBook(InfoSub::Ref ispListener, Book const &) override
Remove a book subscription for a live subscriber.
bool isFull() override
void clearAmendmentWarned() override
LedgerMaster & ledgerMaster_
void publishLedgerStreams(std::shared_ptr< ReadView const > const &lpAccepted, std::shared_ptr< AcceptedLedger const > const &alpAccepted)
Send the ledgerClosed and book-changes stream updates for a ledger.
std::atomic< OperatingMode > mode_
void updateLocalTx(ReadView const &view) override
void clearLedgerFetch() override
std::unique_ptr< LocalTxs > localTX_
void apply(std::unique_lock< std::mutex > &batchLock)
Attempt to apply transactions and post-process based on the results.
InfoSub::pointer findRpcSub(std::string const &strUrl) override
bool isAmendmentBlocked() override
std::string strOperatingMode(OperatingMode const mode, bool const admin) const override
bool subBookChanges(InfoSub::Ref ispListener) override
SubRpcMapType rpcSubMap_
HashMap< std::string, InfoSub::pointer > SubRpcMapType
void setStandAlone() override
void setNeedNetworkLedger() override
HashMap< MPTID, SubMapType > SubMPTInfoMapType
std::size_t getBookSubscribersCount() override
Total number of (book, subscriber) entries currently tracked.
std::mutex bookLock_
Guards subBook_.
bool unsubServer(std::uint64_t uListener) override
bool unsubConsensus(std::uint64_t uListener) override
bool subConsensus(InfoSub::Ref ispListener) override
void pubManifest(Manifest const &) override
std::mutex accountLock_
Guards subAccount_, subRTAccount_, subAccountHistory_.
void consensusViewChange() override
boost::asio::steady_timer accountHistoryTxTimer_
NetworkOPsImp(ServiceRegistry &registry, NetworkOPs::ClockType &clock, bool standalone, std::size_t minPeerCount, bool startValid, JobQueue &jobQueue, LedgerMaster &ledgerMaster, ValidatorKeys const &validatorKeys, boost::asio::io_context &ioCtx, beast::Journal journal, beast::insight::Collector::Ptr const &collector)
bool recvValidation(std::shared_ptr< STValidation > const &val, std::string const &source) override
void setUNLBlocked() override
bool unsubValidations(std::uint64_t uListener) override
void scheduleAccountCleanup(std::uint64_t seq, HashSet< AccountID > rtAccounts, HashSet< AccountID > normalAccounts, HashSet< AccountID > historyAccounts) override
Schedule the server-side teardown of a disconnecting connection's account subscriptions off the destr...
void pubMPTTransaction(AcceptedLedgerTx const &transaction, MultiApiJson const &jvObj)
void doTransactionAsync(std::shared_ptr< Transaction > transaction, bool bUnlimited, FailHard failtype)
For transactions not submitted by a locally connected client, fire and forget.
std::set< UInt256 > pendingValidations_
bool subRTTransactions(InfoSub::Ref ispListener) override
OperatingMode getOperatingMode() const override
std::optional< PublicKey > const validatorMasterPK_
void doTransactionSyncBatch(std::unique_lock< std::mutex > &lock, std::function< bool(std::unique_lock< std::mutex > const &)> retryCallback)
HashMap< std::uint64_t, InfoSub::Wptr > SubMapType
bool tryRemoveRpcSub(std::string const &strUrl) override
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...
void submitTransaction(std::shared_ptr< STTx const > const &) override
bool subTransactions(InfoSub::Ref ispListener) override
void setAmendmentWarned() override
void unsubMPT(InfoSub::Ref ispListener, HashSet< MPTID > const &mptIDs) override
StateAccounting accounting_
SubAccountHistoryMapType subAccountHistory_
SubMPTInfoMapType subMPT_
Guarded by mptLock_.
void setAccountHistoryJobTimer(SubAccountHistoryInfoWeak subInfo)
std::atomic< bool > unlBlocked_
void unsubAccountHistory(InfoSub::Ref ispListener, AccountID const &account, bool historyOnly) override
unsubscribe an account's transactions
bool subLedger(InfoSub::Ref ispListener, json::Value &jvResult) override
bool unsubBookChanges(std::uint64_t uListener) override
void unsubAccountInternal(std::uint64_t seq, HashSet< AccountID > const &vnaAccountIDs, bool rt) override
void setStateTimer() override
Called to initially start our timers.
std::size_t getLocalTxCount() override
bool preProcessTransaction(std::shared_ptr< Transaction > &transaction)
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.
RCLConsensus consensus_
bool unsubTransactions(std::uint64_t uListener) override
bool isAmendmentWarned() override
void getBookPage(std::shared_ptr< ReadView const > &lpLedger, Book const &, AccountID const &uTakerID, bool const bProof, unsigned int iLimit, json::Value const &jvMarker, json::Value &jvResult) override
std::mutex validationsMutex_
std::uint32_t acceptLedger(std::optional< std::chrono::milliseconds > consensusDelay) override
Accepts the current transaction tree, return the new ledger's sequence.
void clearUNLBlocked() override
void subAccount(InfoSub::Ref ispListener, HashSet< AccountID > const &vnaAccountIDs, bool rt) override
bool isUNLBlocked() override
void pubProposedTransaction(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &transaction, TER result) override
std::atomic< bool > amendmentWarned_
boost::asio::steady_timer clusterTimer_
void cleanupSubscriptionMap(std::uint64_t seq, HashSet< AccountID > const &accounts, OuterMap &outerMap, BeforeErase &&beforeErase)
Erase one connection's entries from a subscription map in accountLock_-bounded chunks.
bool checkLastClosedLedger(Overlay::PeerSequence const &, UInt256 &networkClosed)
bool unsubPeerStatus(std::uint64_t uListener) override
void reportFeeChange() override
ServerFeeSummary lastFeeSummary_
void processTransactionSet(CanonicalTXSet const &set) override
Process a set of transactions synchronously, and ensuring that they are processed in one batch.
void mapComplete(std::shared_ptr< SHAMap > const &map, bool fromAcquire) override
bool isBlocked() override
~NetworkOPsImp() override
json::Value getServerInfo(bool human, bool admin, bool counters) override
Provides server functionality for clients.
Definition NetworkOPs.h:82
beast::AbstractClock< std::chrono::steady_clock > ClockType
Definition NetworkOPs.h:84
Number is a floating point type that can represent a wide range of values.
Definition Number.h:351
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
std::vector< std::shared_ptr< Peer > > PeerSequence
Definition Overlay.h:68
Manages the generic consensus algorithm for use by the RCL.
A peer's signed, proposed position for use in RCLConsensus.
PublicKey const & publicKey() const
Public key of peer that sent the proposal.
Represents a set of transactions in RCLConsensus.
Definition RCLCxTx.h:60
Wraps a ledger instance for use in generic Validations LedgerTrie.
static std::string getWordFromBlob(void const *blob, size_t bytes)
Chooses a single dictionary word from the data.
Definition RFC1751.cpp:435
Collects logging information.
std::unique_ptr< std::stringstream > const & ss()
A view into a ledger.
Definition ReadView.h:41
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
std::vector< AccountTx > AccountTxs
constexpr bool holds() const noexcept
Definition STAmount.h:478
std::string getText() const override
Asset const & asset() const
Definition STAmount.h:496
void setJson(json::Value &) const
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const_pointer
Automatically unlocks and re-locks a unique_lock object.
Definition scope.h:197
std::size_t size() const noexcept
Definition Serializer.h:147
void const * data() const noexcept
Definition Serializer.h:153
Service registry for dependency injection.
std::flat_set< MPTID > getAffectedMPTs() const
Definition TxMeta.cpp:153
static time_point now()
Validator keys and manifest as set in configuration file.
json::Value jsonClipped() const
Definition XRPAmount.h:203
constexpr double decimalXRP() const
Definition XRPAmount.h:250
T duration_cast(T... args)
T emplace_back(T... args)
T emplace(T... args)
T empty(T... args)
T end(T... args)
T erase(T... args)
T exchange(T... args)
T find(T... args)
T get(T... args)
T insert(T... args)
T is_sorted(T... args)
T lock(T... args)
T make_pair(T... args)
T make_shared(T... args)
T make_unique(T... args)
T max(T... args)
T min(T... args)
void rngfill(void *const buffer, std::size_t const bytes, Generator &g)
Definition rngfill.h:11
constexpr Zero kZero
Definition Zero.h:30
JSON (JavaScript Object Notation).
Definition json_errors.h:5
int Int
unsigned int UInt
@ Array
array value (ordered list)
Definition json_value.h:32
@ Object
object value (collection of name/value pairs).
Definition json_value.h:33
STL namespace.
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:63
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
std::string const & getCommitHash()
Definition Git.cpp:18
std::string const & getBuildBranch()
Definition Git.cpp:25
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Definition Indexes.cpp:310
Keylet book(Book const &b)
The beginning of an order book.
Definition Indexes.cpp:281
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:415
Keylet page(UInt256 const &root, std::uint64_t const index=0) noexcept
A page in a directory.
Definition Indexes.cpp:421
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:233
Keylet child(UInt256 const &key) noexcept
Any item that can be in an owner dir.
Definition Indexes.cpp:239
std::optional< std::string > encodeCTID(uint32_t ledgerSeq, uint32_t txnIndex, uint32_t networkID) noexcept
Encodes ledger sequence, transaction index, and network ID into a CTID string.
Definition CTID.h:36
static constexpr std::integral_constant< unsigned, Version > kApiVersion
Definition ApiVersion.h:29
void insertAllSyntheticInJson(json::Value &metadata, ReadView const &ledger, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
Adds all synthetic fields to transaction metadata JSON.
json::Value computeBookChanges(std::shared_ptr< L const > const &lpAccepted)
Definition BookChanges.h:41
Rate rate(Env const &env, Account const &account, std::uint32_t const &seq)
Definition escrow.cpp:60
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool cdirFirst(ReadView const &view, UInt256 const &root, SLE::const_pointer &page, unsigned int &index, UInt256 &entry)
Returns the first entry in the directory, advancing the index.
@ WarnRpcAmendmentBlocked
Definition ErrorCodes.h:159
@ WarnRpcUnsupportedMajority
Definition ErrorCodes.h:158
@ WarnRpcExpiredValidatorList
Definition ErrorCodes.h:160
STAmount divide(STAmount const &amount, Rate const &rate)
Definition Rate2.cpp:69
@ terQUEUED
Definition TER.h:227
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
constexpr FlagValue tfInnerBatchTxn
Definition TxFlags.h:44
bool isTerRetry(TER x) noexcept
Definition TER.h:680
ErrorCodeI
Definition ErrorCodes.h:23
@ RpcSuccess
Definition ErrorCodes.h:27
@ RpcInvalidParams
Definition ErrorCodes.h:67
void handleNewValidation(Application &app, std::shared_ptr< STValidation > const &val, std::string const &source, BypassAccept const bypassAccept, std::optional< beast::Journal > j)
Handle a new validation.
UInt256 getBookBase(Book const &book)
Definition Indexes.cpp:136
@ WrongLedger
We have the wrong ledger and are attempting to acquire it.
@ Proposing
We are normal participant in consensus and propose our position.
std::optional< std::uint64_t > mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
Return value*mul/div accurately.
SendIfPred< Predicate > sendIf(std::shared_ptr< Message > const &m, Predicate const &f)
Helper function to aid in type deduction.
Definition predicates.h:61
void forAllApiVersions(Fn const &fn, Args &&... args)
Definition ApiVersion.h:159
@ SigBad
Signature is bad.
Definition apply.h:28
@ Valid
Signature and local checks are good / passed.
Definition apply.h:36
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
constexpr std::size_t kMaxPoppedTransactions
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
std::uint64_t getQuality(UInt256 const &uBase)
Definition Indexes.cpp:207
std::unique_ptr< FeeVote > makeFeeVote(FeeSetup const &setup, beast::Journal journal)
Create an instance of the FeeVote logic.
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules)
Checks transaction signature and local checks.
Definition apply.cpp:62
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition ReadView.cpp:62
FeeSetup setupFeeVote(Section const &section)
@ tefPAST_SEQ
Definition TER.h:169
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
std::unique_ptr< NetworkOPs > makeNetworkOPs(ServiceRegistry &registry, NetworkOPs::ClockType &clock, bool standalone, std::size_t minPeerCount, bool startValid, JobQueue &jobQueue, LedgerMaster &ledgerMaster, ValidatorKeys const &validatorKeys, boost::asio::io_context &ioSvc, beast::Journal journal, beast::insight::Collector::Ptr const &collector)
UInt256 getQualityNext(UInt256 const &uBase)
Definition Indexes.cpp:199
Number root(Number f, unsigned d)
CsprngEngine & cryptoPrng()
The default cryptographically secure PRNG.
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:244
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:58
constexpr Dest safeCast(Src s) noexcept
Definition safe_cast.h:21
std::string transToken(TER code)
Definition TER.cpp:259
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:658
std::string toStringIso(date::sys_time< Duration > tp)
Definition chrono.h:70
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
bool isGlobalFrozen(ReadView const &view, AccountID const &issuer)
Check if the issuer has the global freeze flag set.
BaseUInt< 256 > UInt256
Definition base_uint.h:581
STAmount amountFromQuality(std::uint64_t rate)
@ JtClientAcctHist
Definition Job.h:35
@ JtTransaction
Definition Job.h:48
@ JtBatch
Definition Job.h:51
@ JtTxnProc
Definition Job.h:68
@ JtClientConsensus
Definition Job.h:34
@ JtNetopCluster
Definition Job.h:61
@ JtClientFeeChange
Definition Job.h:33
bool isTefFailure(TER x) noexcept
Definition TER.h:674
HashSet< Book > affectedBooks(AcceptedLedgerTx const &alTx, beast::Journal const &j)
Extract the set of books affected by a transaction.
std::unique_ptr< LocalTxs > makeLocalTxs()
Definition LocalTxs.cpp:185
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:54
ConsensusPhase
Phases of consensus for a single ledger round.
@ Open
We haven't closed our ledger yet, but others might have.
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
json::Value getJson(LedgerFill const &fill)
Return a new json::Value representing the ledger with given options.
std::unordered_set< Value, Hash, Pred, Allocator > HashSet
bool cdirNext(ReadView const &view, UInt256 const &root, SLE::const_pointer &page, unsigned int &index, UInt256 &entry)
Returns the next entry in the directory, advancing the index.
AccountID calcAccountID(PublicKey const &pk)
static std::array< char const *, 5 > const kStateNames
constexpr auto kMuldivMax
Definition mulDiv.h:8
ApplyFlags
Definition ApplyView.h:27
@ TapUnlimited
Definition ApplyView.h:39
@ TapFailHard
Definition ApplyView.h:32
@ TapNone
Definition ApplyView.h:28
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
detail::MultiApiJson< rpc::kApiMinimumSupportedVersion, rpc::kApiMaximumValidVersion > MultiApiJson
bool isTelLocal(TER x) noexcept
Definition TER.h:662
@ temINVALID_FLAG
Definition TER.h:99
@ temBAD_SIGNATURE
Definition TER.h:93
bool isTesSuccess(TER x) noexcept
Definition TER.h:686
static std::uint32_t trunc32(std::uint64_t v)
TERSubset< CanCvtToTER > TER
Definition TER.h:657
STAmount multiply(STAmount const &amount, Number const &frac, Number::RoundingMode rm)
std::unordered_map< Key, Value, Hash, Pred, Allocator > HashMap
OperatingMode
Specifies the mode under which the server believes it's operating.
Definition NetworkOPs.h:60
@ TRACKING
convinced we agree with the network
Definition NetworkOPs.h:64
@ DISCONNECTED
not ready to process requests
Definition NetworkOPs.h:61
@ CONNECTED
convinced we are talking to the network
Definition NetworkOPs.h:62
@ FULL
we have the ledger and can even validate
Definition NetworkOPs.h:65
@ SYNCING
fallen slightly behind
Definition NetworkOPs.h:63
static STAmount takerPaysFunded(STAmount const &takerPays, STAmount const &takerGetsFunded, STAmount const &rate)
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition STTx.cpp:880
STAmount issuerFundsToSelfIssue(ReadView const &view, MPTIssue const &issue)
Determine funds available for an issuer to sell in an issuer owned offer.
static auto const kGenesisAccountId
bool isTemMalformed(TER x) noexcept
Definition TER.h:668
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const &currency, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=SpendableHandling::SimpleBalance)
@ tesSUCCESS
Definition TER.h:253
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
STAmount toSTAmount(IOUAmount const &iou, Asset const &asset)
CanonicalTXSet OrderedTxs
Definition OpenLedger.h:35
T owns_lock(T... args)
T push_back(T... args)
T ref(T... args)
T reserve(T... args)
T reset(T... args)
T set_intersection(T... args)
T size(T... args)
T str(T... args)
static constexpr auto kPort
Definition Constants.h:149
static constexpr auto kIp
Definition Constants.h:117
PublicKey masterKey
The master key associated with this manifest.
Definition Manifest.h:84
std::string serialized
The manifest in serialized form.
Definition Manifest.h:79
Blob getMasterSignature() const
Returns manifest master key signature.
std::string domain
The domain, if one was specified in the manifest; empty otherwise.
Definition Manifest.h:102
std::optional< Blob > getSignature() const
Returns manifest signature.
std::optional< PublicKey > signingKey
The ephemeral key associated with this manifest.
Definition Manifest.h:92
std::uint32_t sequence
The sequence number of this manifest.
Definition Manifest.h:97
Server fees published on server subscription.
std::optional< TxQ::Metrics > em
bool operator!=(ServerFeeSummary const &b) const
bool operator==(ServerFeeSummary const &b) const
beast::insight::Gauge fullTransitions
beast::insight::Gauge disconnectedTransitions
beast::insight::Gauge connectedDuration
beast::insight::Gauge trackingTransitions
beast::insight::Gauge fullDuration
beast::insight::Gauge syncingDuration
Stats(Handler const &handler, beast::insight::Collector::Ptr const &collector)
beast::insight::Gauge disconnectedDuration
beast::insight::Gauge connectedTransitions
beast::insight::Gauge trackingDuration
beast::insight::Hook hook
beast::insight::Gauge syncingTransitions
SubAccountHistoryIndex(AccountID const &accountId)
std::shared_ptr< SubAccountHistoryIndex > index
std::shared_ptr< SubAccountHistoryIndex > index
Select all peers (except optional excluded) that are in our cluster.
Definition predicates.h:127
Represents a transfer rate.
Definition Rate.h:21
std::uint32_t value
Definition Rate.h:22
static constexpr auto kPortGrpc
Definition Constants.h:45
Sends a message to all peers.
Definition predicates.h:15
Changes in trusted nodes after updating validator list.
HashSet< NodeID > added
HashSet< NodeID > removed
Structure returned by TxQ::getMetrics, expressed in reference fee level units.
Definition TxQ.h:186
void set(char const *key, auto const &v)
IsMemberResult isMember(char const *key) const
Data format for exchanging consumption information across peers.
Definition Gossip.h:13
std::vector< Item > items
Definition Gossip.h:27
T time_since_epoch(T... args)
T to_string(T... args)
T unlock(T... args)
T value_or(T... args)
T what(T... args)