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/hardened_hash.h>
8#include <xrpl/ledger/Ledger.h>
9
10#include <cstddef>
11#include <mutex>
12#include <vector>
13
14namespace xrpl {
15
16// Used by Pathfinder
17class AssetCache final : public CountedObject<AssetCache>
18{
19public:
22
23 [[nodiscard]] std::shared_ptr<ReadView const> const&
24 getLedger() const
25 {
26 return ledger_;
27 }
28
42 getRippleLines(AccountID const& accountID, LineDirection direction);
43
45 getMPTs(AccountID const& account);
46
47private:
49
52
54
55 struct AccountKey final : public CountedObject<AccountKey>
56 {
60
65
66 AccountKey(AccountKey const& other) = default;
67
69 operator=(AccountKey const& other) = default;
70
71 bool
72 operator==(AccountKey const& lhs) const
73 {
74 return hashValue == lhs.hashValue && account == lhs.account &&
75 direction == lhs.direction;
76 }
77
78 [[nodiscard]] std::size_t
79 getHash() const
80 {
81 return hashValue;
82 }
83
84 struct Hash
85 {
86 Hash() = default;
87
89 operator()(AccountKey const& key) const noexcept
90 {
91 return key.getHash();
92 }
93 };
94 };
95
96 // Use a shared_ptr so entries can be removed from the map safely.
97 // Even though a shared_ptr to a vector will take more memory just a vector,
98 // most accounts are not going to have any entries (estimated over 90%), so
99 // vectors will not need to be created for them. This should lead to far
100 // less memory usage overall.
104};
105
106} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
AssetCache(std::shared_ptr< ReadView const > l, beast::Journal j)
beast::Journal journal_
Definition AssetCache.h:53
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:103
std::shared_ptr< std::vector< PathFindMPT > > const & getMPTs(AccountID const &account)
xrpl::HardenedHash hasher_
Definition AssetCache.h:50
hash_map< AccountKey, std::shared_ptr< std::vector< PathFindTrustLine > >, AccountKey::Hash > lines_
Definition AssetCache.h:101
std::shared_ptr< ReadView const > const & getLedger() const
Definition AssetCache.h:24
std::size_t totalLineCount_
Definition AssetCache.h:102
std::mutex lock_
Definition AssetCache.h:48
std::shared_ptr< ReadView const > ledger_
Definition AssetCache.h:51
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:21
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:28
std::size_t operator()(AccountKey const &key) const noexcept
Definition AssetCache.h:89
AccountKey & operator=(AccountKey const &other)=default
bool operator==(AccountKey const &lhs) const
Definition AssetCache.h:72
std::size_t getHash() const
Definition AssetCache.h:79
AccountKey(AccountKey const &other)=default
AccountKey(AccountID const &account, LineDirection direction, std::size_t hash)
Definition AssetCache.h:61