rippled
Loading...
Searching...
No Matches
TransactionMaster.cpp
1#include <xrpld/app/ledger/TransactionMaster.h>
2#include <xrpld/app/main/Application.h>
3#include <xrpld/app/misc/Transaction.h>
4
5#include <xrpl/basics/TaggedCache.ipp>
6#include <xrpl/basics/chrono.h>
7#include <xrpl/protocol/STTx.h>
8
9namespace ripple {
10
12 : mApp(app)
13 , mCache(
14 "TransactionCache",
15 65536,
16 std::chrono::minutes{30},
17 stopwatch(),
18 mApp.journal("TaggedCache"))
19{
20}
21
22bool
24 uint256 const& hash,
25 std::uint32_t ledger,
28{
29 auto txn = mCache.fetch(hash);
30
31 if (!txn)
32 return false;
33
34 txn->setStatus(COMMITTED, ledger, tseq, netID);
35 return true;
36}
37
40{
41 return mCache.fetch(txnID);
42}
43
48{
49 using TxPair =
51
52 if (auto txn = fetch_from_cache(txnID); txn && !txn->isValidated())
53 return std::pair{std::move(txn), nullptr};
54
55 auto v = Transaction::load(txnID, mApp, ec);
56
58 return v;
59
60 auto [txn, txnMeta] = std::get<TxPair>(v);
61
62 if (txn)
63 mCache.canonicalize_replace_client(txnID, txn);
64
65 return std::pair{std::move(txn), std::move(txnMeta)};
66}
67
72 uint256 const& txnID,
74 error_code_i& ec)
75{
76 using TxPair =
78
79 if (auto txn = fetch_from_cache(txnID); txn && !txn->isValidated())
80 return std::pair{std::move(txn), nullptr};
81
82 auto v = Transaction::load(txnID, mApp, range, ec);
83
85 return v;
86
87 auto [txn, txnMeta] = std::get<TxPair>(v);
88
89 if (txn)
90 mCache.canonicalize_replace_client(txnID, txn);
91
92 return std::pair{std::move(txn), std::move(txnMeta)};
93}
94
97 boost::intrusive_ptr<SHAMapItem> const& item,
98 SHAMapNodeType type,
99 std::uint32_t uCommitLedger)
100{
102 auto iTx = fetch_from_cache(item->key());
103
104 if (!iTx)
105 {
107 {
108 SerialIter sit(item->slice());
110 }
111 else if (type == SHAMapNodeType::tnTRANSACTION_MD)
112 {
113 auto blob = SerialIter{item->slice()}.getVL();
115 SerialIter{blob.data(), blob.size()});
116 }
117 }
118 else
119 {
120 if (uCommitLedger)
121 iTx->setStatus(COMMITTED, uCommitLedger);
122
123 txn = iTx->getSTransaction();
124 }
125
126 return txn;
127}
128
129void
131{
132 uint256 const tid = (*pTransaction)->getID();
133 if (tid != beast::zero)
134 {
135 auto txn = *pTransaction;
136 // VFALCO NOTE canonicalize can change the value of txn!
137 mCache.canonicalize_replace_client(tid, txn);
138 *pTransaction = txn;
139 }
140}
141
142void
144{
145 mCache.sweep();
146}
147
150{
151 return mCache;
152}
153
154} // namespace ripple
Map/cache combination.
Definition TaggedCache.h:43
std::shared_ptr< Transaction > fetch_from_cache(uint256 const &)
TransactionMaster(Application &app)
std::variant< std::pair< std::shared_ptr< Transaction >, std::shared_ptr< TxMeta > >, TxSearched > fetch(uint256 const &, error_code_i &ec)
bool inLedger(uint256 const &hash, std::uint32_t ledger, std::optional< uint32_t > tseq, std::optional< uint32_t > netID)
TaggedCache< uint256, Transaction > mCache
void canonicalize(std::shared_ptr< Transaction > *pTransaction)
TaggedCache< uint256, Transaction > & getCache()
static std::variant< std::pair< std::shared_ptr< Transaction >, std::shared_ptr< TxMeta > >, TxSearched > load(uint256 const &id, Application &app, error_code_i &ec)
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ COMMITTED
Definition Transaction.h:32
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition RangeSet.h:26
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition chrono.h:100
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition RangeSet.h:35
STL namespace.
T ref(T... args)