xrpld
Loading...
Searching...
No Matches
AssetCache.h
1#pragma once
2
3#include <xrpld/rpc/detail/MPT.h>
4#include <xrpld/rpc/detail/TrustLine.h>
5
6#include <xrpl/basics/CountedObject.h>
7#include <xrpl/basics/UnorderedContainers.h>
8#include <xrpl/basics/hardened_hash.h>
9#include <xrpl/beast/utility/Journal.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/protocol/AccountID.h>
12
13#include <cstddef>
14#include <memory>
15#include <mutex>
16#include <vector>
17
18namespace xrpl {
19
20// Used by Pathfinder
21class AssetCache final : public CountedObject<AssetCache>
22{
23public:
26
27 [[nodiscard]] std::shared_ptr<ReadView const> const&
28 getLedger() const
29 {
30 return ledger_;
31 }
32
47 getRippleLines(AccountID const& accountID, LineDirection direction);
48
50 getMPTs(AccountID const& account);
51
52private:
54
57
59
60 struct AccountKey final : public CountedObject<AccountKey>
61 {
65
70
71 AccountKey(AccountKey const& other) = default;
72
74 operator=(AccountKey const& other) = default;
75
76 bool
77 operator==(AccountKey const& lhs) const
78 {
79 return hashValue == lhs.hashValue && account == lhs.account &&
80 direction == lhs.direction;
81 }
82
83 [[nodiscard]] std::size_t
84 getHash() const
85 {
86 return hashValue;
87 }
88
89 struct Hash
90 {
91 Hash() = default;
92
94 operator()(AccountKey const& key) const noexcept
95 {
96 return key.getHash();
97 }
98 };
99 };
100
101 // Use a shared_ptr so entries can be removed from the map safely.
102 // Even though a shared_ptr to a vector will take more memory just a vector,
103 // most accounts are not going to have any entries (estimated over 90%), so
104 // vectors will not need to be created for them. This should lead to far
105 // less memory usage overall.
109};
110
111} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
AssetCache(std::shared_ptr< ReadView const > l, beast::Journal j)
beast::Journal journal_
Definition AssetCache.h:58
std::shared_ptr< std::vector< PathFindTrustLine > > getRippleLines(AccountID const &accountID, LineDirection direction)
Find the trust lines associated with an account.
hash_map< AccountID, std::shared_ptr< std::vector< PathFindMPT > > > mpts_
Definition AssetCache.h:108
std::shared_ptr< std::vector< PathFindMPT > > const & getMPTs(AccountID const &account)
xrpl::HardenedHash hasher_
Definition AssetCache.h:55
hash_map< AccountKey, std::shared_ptr< std::vector< PathFindTrustLine > >, AccountKey::Hash > lines_
Definition AssetCache.h:106
std::shared_ptr< ReadView const > const & getLedger() const
Definition AssetCache.h:28
std::size_t totalLineCount_
Definition AssetCache.h:107
std::mutex lock_
Definition AssetCache.h:53
std::shared_ptr< ReadView const > ledger_
Definition AssetCache.h:56
Seed functor once per construction.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition TrustLine.h:27
std::unordered_map< Key, Value, Hash, Pred, Allocator > hash_map
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
std::size_t operator()(AccountKey const &key) const noexcept
Definition AssetCache.h:94
AccountKey & operator=(AccountKey const &other)=default
bool operator==(AccountKey const &lhs) const
Definition AssetCache.h:77
std::size_t getHash() const
Definition AssetCache.h:84
AccountKey(AccountKey const &other)=default
AccountKey(AccountID const &account, LineDirection direction, std::size_t hash)
Definition AssetCache.h:66