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 xrpl {
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
46{
48
49 if (auto txn = fetch_from_cache(txnID); txn && !txn->isValidated())
50 return std::pair{std::move(txn), nullptr};
51
52 auto v = Transaction::load(txnID, mApp, ec);
53
55 return v;
56
57 auto [txn, txnMeta] = std::get<TxPair>(v);
58
59 if (txn)
60 mCache.canonicalize_replace_client(txnID, txn);
61
62 return std::pair{std::move(txn), std::move(txnMeta)};
63}
64
67 uint256 const& txnID,
69 error_code_i& ec)
70{
72
73 if (auto txn = fetch_from_cache(txnID); txn && !txn->isValidated())
74 return std::pair{std::move(txn), nullptr};
75
76 auto v = Transaction::load(txnID, mApp, range, ec);
77
79 return v;
80
81 auto [txn, txnMeta] = std::get<TxPair>(v);
82
83 if (txn)
84 mCache.canonicalize_replace_client(txnID, txn);
85
86 return std::pair{std::move(txn), std::move(txnMeta)};
87}
88
91 boost::intrusive_ptr<SHAMapItem> const& item,
92 SHAMapNodeType type,
93 std::uint32_t uCommitLedger)
94{
96 auto iTx = fetch_from_cache(item->key());
97
98 if (!iTx)
99 {
101 {
102 SerialIter sit(item->slice());
104 }
105 else if (type == SHAMapNodeType::tnTRANSACTION_MD)
106 {
107 auto blob = SerialIter{item->slice()}.getVL();
108 txn = std::make_shared<STTx const>(SerialIter{blob.data(), blob.size()});
109 }
110 }
111 else
112 {
113 if (uCommitLedger)
114 iTx->setStatus(COMMITTED, uCommitLedger);
115
116 txn = iTx->getSTransaction();
117 }
118
119 return txn;
120}
121
122void
124{
125 uint256 const tid = (*pTransaction)->getID();
126 if (tid != beast::zero)
127 {
128 auto txn = *pTransaction;
129 // VFALCO NOTE canonicalize can change the value of txn!
130 mCache.canonicalize_replace_client(tid, txn);
131 *pTransaction = txn;
132 }
133}
134
135void
137{
138 mCache.sweep();
139}
140
143{
144 return mCache;
145}
146
147} // namespace xrpl
Map/cache combination.
Definition TaggedCache.h:42
std::shared_ptr< Transaction > fetch_from_cache(uint256 const &)
bool inLedger(uint256 const &hash, std::uint32_t ledger, std::optional< uint32_t > tseq, std::optional< uint32_t > netID)
TransactionMaster(Application &app)
void canonicalize(std::shared_ptr< Transaction > *pTransaction)
std::variant< std::pair< std::shared_ptr< Transaction >, std::shared_ptr< TxMeta > >, TxSearched > fetch(uint256 const &, error_code_i &ec)
TaggedCache< uint256, Transaction > & getCache()
TaggedCache< uint256, Transaction > mCache
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
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition chrono.h:94
@ COMMITTED
Definition Transaction.h:32
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition RangeSet.h:34
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition RangeSet.h:25
TxSearched
Definition TxSearched.h:5
error_code_i
Definition ErrorCodes.h:20
T ref(T... args)