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), mCache("TransactionCache", 65536, std::chrono::minutes{30}, stopwatch(), mApp.journal("TaggedCache"))
13{
14}
15
16bool
18 uint256 const& hash,
19 std::uint32_t ledger,
22{
23 auto txn = mCache.fetch(hash);
24
25 if (!txn)
26 return false;
27
28 txn->setStatus(COMMITTED, ledger, tseq, netID);
29 return true;
30}
31
34{
35 return mCache.fetch(txnID);
36}
37
40{
42
43 if (auto txn = fetch_from_cache(txnID); txn && !txn->isValidated())
44 return std::pair{std::move(txn), nullptr};
45
46 auto v = Transaction::load(txnID, mApp, ec);
47
49 return v;
50
51 auto [txn, txnMeta] = std::get<TxPair>(v);
52
53 if (txn)
54 mCache.canonicalize_replace_client(txnID, txn);
55
56 return std::pair{std::move(txn), std::move(txnMeta)};
57}
58
61{
63
64 if (auto txn = fetch_from_cache(txnID); txn && !txn->isValidated())
65 return std::pair{std::move(txn), nullptr};
66
67 auto v = Transaction::load(txnID, mApp, range, ec);
68
70 return v;
71
72 auto [txn, txnMeta] = std::get<TxPair>(v);
73
74 if (txn)
75 mCache.canonicalize_replace_client(txnID, txn);
76
77 return std::pair{std::move(txn), std::move(txnMeta)};
78}
79
81TransactionMaster::fetch(boost::intrusive_ptr<SHAMapItem> const& item, SHAMapNodeType type, std::uint32_t uCommitLedger)
82{
84 auto iTx = fetch_from_cache(item->key());
85
86 if (!iTx)
87 {
89 {
90 SerialIter sit(item->slice());
92 }
93 else if (type == SHAMapNodeType::tnTRANSACTION_MD)
94 {
95 auto blob = SerialIter{item->slice()}.getVL();
96 txn = std::make_shared<STTx const>(SerialIter{blob.data(), blob.size()});
97 }
98 }
99 else
100 {
101 if (uCommitLedger)
102 iTx->setStatus(COMMITTED, uCommitLedger);
103
104 txn = iTx->getSTransaction();
105 }
106
107 return txn;
108}
109
110void
112{
113 uint256 const tid = (*pTransaction)->getID();
114 if (tid != beast::zero)
115 {
116 auto txn = *pTransaction;
117 // VFALCO NOTE canonicalize can change the value of txn!
118 mCache.canonicalize_replace_client(tid, txn);
119 *pTransaction = txn;
120 }
121}
122
123void
125{
126 mCache.sweep();
127}
128
131{
132 return mCache;
133}
134
135} // namespace xrpl
Map/cache combination.
Definition TaggedCache.h:43
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:6
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:35
boost::icl::closed_interval< T > ClosedInterval
A closed interval over the domain T.
Definition RangeSet.h:26
error_code_i
Definition ErrorCodes.h:21
T ref(T... args)