rippled
Loading...
Searching...
No Matches
Pathfinder.h
1#ifndef XRPL_APP_PATHS_PATHFINDER_H_INCLUDED
2#define XRPL_APP_PATHS_PATHFINDER_H_INCLUDED
3
4#include <xrpld/app/ledger/Ledger.h>
5#include <xrpld/app/paths/RippleLineCache.h>
6#include <xrpld/core/LoadEvent.h>
7
8#include <xrpl/basics/CountedObject.h>
9#include <xrpl/protocol/STAmount.h>
10#include <xrpl/protocol/STPathSet.h>
11
12namespace ripple {
13
20class Pathfinder : public CountedObject<Pathfinder>
21{
22public:
26 AccountID const& srcAccount,
27 AccountID const& dstAccount,
28 Currency const& uSrcCurrency,
29 std::optional<AccountID> const& uSrcIssuer,
30 STAmount const& dstAmount,
31 std::optional<STAmount> const& srcAmount,
32 std::optional<uint256> const& domain,
33 Application& app);
34 Pathfinder(Pathfinder const&) = delete;
36 operator=(Pathfinder const&) = delete;
37 ~Pathfinder() = default;
38
39 static void
41
42 bool
44 int searchLevel,
45 std::function<bool(void)> const& continueCallback = {});
46
48 void
50 int maxPaths,
51 std::function<bool(void)> const& continueCallback = {});
52
53 /* Get the best paths, up to maxPaths in number, from mCompletePaths.
54
55 On return, if fullLiquidityPath is not empty, then it contains the best
56 additional single path which can consume all the liquidity.
57 */
58 STPathSet
60 int maxPaths,
61 STPath& fullLiquidityPath,
62 STPathSet const& extraPaths,
63 AccountID const& srcIssuer,
64 std::function<bool(void)> const& continueCallback = {});
65
66 enum NodeType {
67 nt_SOURCE, // The source account: with an issuer account, if needed.
68 nt_ACCOUNTS, // Accounts that connect from this source/currency.
69 nt_BOOKS, // Order books that connect to this currency.
70 nt_XRP_BOOK, // The order book from this currency to XRP.
71 nt_DEST_BOOK, // The order book to the destination currency/issuer.
72 nt_DESTINATION // The destination account only.
73 };
74
75 // The PathType is a list of the NodeTypes for a path.
77
78 // PaymentType represents the types of the source and destination currencies
79 // in a path request.
84 pt_nonXRP_to_same, // Destination currency is the same as source.
85 pt_nonXRP_to_nonXRP // Destination currency is NOT the same as source.
86 };
87
95
96private:
97 /*
98 Call graph of Pathfinder methods.
99
100 findPaths:
101 addPathsForType:
102 addLinks:
103 addLink:
104 getPathsOut
105 issueMatchesOrigin
106 isNoRippleOut:
107 isNoRipple
108
109 computePathRanks:
110 rippleCalculate
111 getPathLiquidity:
112 rippleCalculate
113
114 getBestPaths
115 */
116
117 // Add all paths of one type to mCompletePaths.
118 STPathSet&
120 PathType const& type,
121 std::function<bool(void)> const& continueCallback);
122
123 bool
125
126 int
128 Currency const& currency,
129 AccountID const& account,
130 LineDirection direction,
131 bool isDestCurrency,
132 AccountID const& dest,
133 std::function<bool(void)> const& continueCallback);
134
135 void
136 addLink(
137 STPath const& currentPath,
138 STPathSet& incompletePaths,
139 int addFlags,
140 std::function<bool(void)> const& continueCallback);
141
142 // Call addLink() for each path in currentPaths.
143 void
144 addLinks(
145 STPathSet const& currentPaths,
146 STPathSet& incompletePaths,
147 int addFlags,
148 std::function<bool(void)> const& continueCallback);
149
150 // Compute the liquidity for a path. Return tesSUCCESS if it has enough
151 // liquidity to be worth keeping, otherwise an error.
152 TER
154 STPath const& path, // IN: The path to check.
155 STAmount const& minDstAmount, // IN: The minimum output this path must
156 // deliver to be worth keeping.
157 STAmount& amountOut, // OUT: The actual liquidity on the path.
158 uint64_t& qualityOut) const; // OUT: The returned initial quality
159
160 // Does this path end on an account-to-account link whose last account has
161 // set the "no ripple" flag on the link?
162 bool
163 isNoRippleOut(STPath const& currentPath);
164
165 // Is the "no ripple" flag set from one account to another?
166 bool
168 AccountID const& fromAccount,
169 AccountID const& toAccount,
170 Currency const& currency);
171
172 void
173 rankPaths(
174 int maxPaths,
175 STPathSet const& paths,
176 std::vector<PathRank>& rankedPaths,
177 std::function<bool(void)> const& continueCallback);
178
181 AccountID mEffectiveDst; // The account the paths need to end at
191
195
200
202
205
206 // Add ripple paths
207 static std::uint32_t const afADD_ACCOUNTS = 0x001;
208
209 // Add order books
210 static std::uint32_t const afADD_BOOKS = 0x002;
211
212 // Add order book to XRP only
213 static std::uint32_t const afOB_XRP = 0x010;
214
215 // Must link to destination currency
216 static std::uint32_t const afOB_LAST = 0x040;
217
218 // Destination account only
219 static std::uint32_t const afAC_LAST = 0x080;
220};
221
222} // namespace ripple
223
224#endif
A generic endpoint for log messages.
Definition Journal.h:41
Tracks the number of instances of an object.
A currency issued by an account.
Definition Issue.h:14
Calculates payment paths.
Definition Pathfinder.h:21
bool issueMatchesOrigin(Issue const &)
void rankPaths(int maxPaths, STPathSet const &paths, std::vector< PathRank > &rankedPaths, std::function< bool(void)> const &continueCallback)
bool findPaths(int searchLevel, std::function< bool(void)> const &continueCallback={})
std::optional< AccountID > mSrcIssuer
Definition Pathfinder.h:184
STPathSet mCompletePaths
Definition Pathfinder.h:197
AccountID mSrcAccount
Definition Pathfinder.h:179
std::unique_ptr< LoadEvent > m_loadEvent
Definition Pathfinder.h:193
Pathfinder & operator=(Pathfinder const &)=delete
std::shared_ptr< RippleLineCache > mRLCache
Definition Pathfinder.h:194
TER getPathLiquidity(STPath const &path, STAmount const &minDstAmount, STAmount &amountOut, uint64_t &qualityOut) const
AccountID mEffectiveDst
Definition Pathfinder.h:181
std::map< PathType, STPathSet > mPaths
Definition Pathfinder.h:199
Currency mSrcCurrency
Definition Pathfinder.h:183
static std::uint32_t const afADD_ACCOUNTS
Definition Pathfinder.h:207
Application & app_
Definition Pathfinder.h:203
void computePathRanks(int maxPaths, std::function< bool(void)> const &continueCallback={})
Compute the rankings of the paths.
STAmount mRemainingAmount
The amount remaining from mSrcAccount after the default liquidity has been removed.
Definition Pathfinder.h:188
bool isNoRippleOut(STPath const &currentPath)
void addLinks(STPathSet const &currentPaths, STPathSet &incompletePaths, int addFlags, std::function< bool(void)> const &continueCallback)
static std::uint32_t const afADD_BOOKS
Definition Pathfinder.h:210
int getPathsOut(Currency const &currency, AccountID const &account, LineDirection direction, bool isDestCurrency, AccountID const &dest, std::function< bool(void)> const &continueCallback)
Pathfinder(Pathfinder const &)=delete
beast::Journal const j_
Definition Pathfinder.h:204
~Pathfinder()=default
bool isNoRipple(AccountID const &fromAccount, AccountID const &toAccount, Currency const &currency)
STPathElement mSource
Definition Pathfinder.h:196
STPathSet & addPathsForType(PathType const &type, std::function< bool(void)> const &continueCallback)
static std::uint32_t const afOB_XRP
Definition Pathfinder.h:213
static void initPathTable()
hash_map< Issue, int > mPathsOutCountMap
Definition Pathfinder.h:201
std::vector< PathRank > mPathRanks
Definition Pathfinder.h:198
AccountID mDstAccount
Definition Pathfinder.h:180
std::optional< uint256 > mDomain
Definition Pathfinder.h:190
void addLink(STPath const &currentPath, STPathSet &incompletePaths, int addFlags, std::function< bool(void)> const &continueCallback)
STPathSet getBestPaths(int maxPaths, STPath &fullLiquidityPath, STPathSet const &extraPaths, AccountID const &srcIssuer, std::function< bool(void)> const &continueCallback={})
static std::uint32_t const afAC_LAST
Definition Pathfinder.h:219
std::shared_ptr< ReadView const > mLedger
Definition Pathfinder.h:192
static std::uint32_t const afOB_LAST
Definition Pathfinder.h:216
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:29
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition TrustLine.h:22