xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
detail
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
18
namespace
xrpl
{
19
20
// Used by Pathfinder
21
class
AssetCache
final :
public
CountedObject
<AssetCache>
22
{
23
public
:
24
explicit
AssetCache
(
std::shared_ptr<ReadView const>
l,
beast::Journal
j);
25
~AssetCache
();
26
27
[[nodiscard]]
std::shared_ptr<ReadView const>
const
&
28
getLedger
()
const
29
{
30
return
ledger_
;
31
}
32
46
std::shared_ptr<std::vector<PathFindTrustLine>
>
47
getRippleLines
(
AccountID
const
& accountID,
LineDirection
direction);
48
49
std::shared_ptr<std::vector<PathFindMPT>
>
const
&
50
getMPTs
(
AccountID
const
& account);
51
52
private
:
53
std::mutex
lock_
;
54
55
xrpl::HardenedHash<>
hasher_
;
56
std::shared_ptr<ReadView const>
ledger_
;
57
58
beast::Journal
journal_
;
59
60
struct
AccountKey
final :
public
CountedObject
<AccountKey>
61
{
62
AccountID
account
;
63
LineDirection
direction
;
64
std::size_t
hashValue
;
65
66
AccountKey
(
AccountID
const
&
account
,
LineDirection
direction
,
std::size_t
hash)
67
:
account
(
account
),
direction
(
direction
),
hashValue
(hash)
68
{
69
}
70
71
AccountKey
(
AccountKey
const
& other) =
default
;
72
73
AccountKey
&
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
93
std::size_t
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.
106
HashMap<AccountKey, std::shared_ptr<std::vector<PathFindTrustLine>
>,
AccountKey::Hash
>
lines_
;
107
std::size_t
totalLineCount_
= 0;
108
HashMap<AccountID, std::shared_ptr<std::vector<PathFindMPT>
>>
mpts_
;
109
};
110
111
}
// namespace xrpl
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
xrpl::AssetCache::AssetCache
AssetCache(std::shared_ptr< ReadView const > l, beast::Journal j)
Definition
AssetCache.cpp:25
xrpl::AssetCache::journal_
beast::Journal journal_
Definition
AssetCache.h:58
xrpl::AssetCache::getRippleLines
std::shared_ptr< std::vector< PathFindTrustLine > > getRippleLines(AccountID const &accountID, LineDirection direction)
Find the trust lines associated with an account.
Definition
AssetCache.cpp:39
xrpl::AssetCache::lines_
HashMap< AccountKey, std::shared_ptr< std::vector< PathFindTrustLine > >, AccountKey::Hash > lines_
Definition
AssetCache.h:106
xrpl::AssetCache::getMPTs
std::shared_ptr< std::vector< PathFindMPT > > const & getMPTs(AccountID const &account)
Definition
AssetCache.cpp:118
xrpl::AssetCache::hasher_
xrpl::HardenedHash hasher_
Definition
AssetCache.h:55
xrpl::AssetCache::getLedger
std::shared_ptr< ReadView const > const & getLedger() const
Definition
AssetCache.h:28
xrpl::AssetCache::totalLineCount_
std::size_t totalLineCount_
Definition
AssetCache.h:107
xrpl::AssetCache::lock_
std::mutex lock_
Definition
AssetCache.h:53
xrpl::AssetCache::~AssetCache
~AssetCache()
Definition
AssetCache.cpp:31
xrpl::AssetCache::ledger_
std::shared_ptr< ReadView const > ledger_
Definition
AssetCache.h:56
xrpl::AssetCache::mpts_
HashMap< AccountID, std::shared_ptr< std::vector< PathFindMPT > > > mpts_
Definition
AssetCache.h:108
xrpl::CountedObject< AssetCache >::CountedObject
CountedObject() noexcept
Definition
CountedObject.h:119
xrpl::HardenedHash
Seed functor once per construction.
Definition
hardened_hash.h:72
cstddef
memory
mutex
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::LineDirection
LineDirection
Describes how an account was found in a path, and how to find the next set of paths.
Definition
TrustLine.h:27
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::HashMap
std::unordered_map< Key, Value, Hash, Pred, Allocator > HashMap
Definition
UnorderedContainers.h:36
std::shared_ptr
std::size_t
xrpl::AssetCache::AccountKey::Hash
Definition
AssetCache.h:90
xrpl::AssetCache::AccountKey::Hash::operator()
std::size_t operator()(AccountKey const &key) const noexcept
Definition
AssetCache.h:94
xrpl::AssetCache::AccountKey::Hash::Hash
Hash()=default
xrpl::AssetCache::AccountKey::operator=
AccountKey & operator=(AccountKey const &other)=default
xrpl::AssetCache::AccountKey::operator==
bool operator==(AccountKey const &lhs) const
Definition
AssetCache.h:77
xrpl::AssetCache::AccountKey::getHash
std::size_t getHash() const
Definition
AssetCache.h:84
xrpl::AssetCache::AccountKey::AccountKey
AccountKey(AccountKey const &other)=default
xrpl::AssetCache::AccountKey::direction
LineDirection direction
Definition
AssetCache.h:63
xrpl::AssetCache::AccountKey::hashValue
std::size_t hashValue
Definition
AssetCache.h:64
xrpl::AssetCache::AccountKey::AccountKey
AccountKey(AccountID const &account, LineDirection direction, std::size_t hash)
Definition
AssetCache.h:66
xrpl::AssetCache::AccountKey::account
AccountID account
Definition
AssetCache.h:62
vector
Generated by
1.17.0