xrpld
Loading...
Searching...
No Matches
ConsensusTransSetSF.cpp
1#include <xrpld/app/ledger/ConsensusTransSetSF.h>
2
3#include <xrpld/app/ledger/TransactionMaster.h>
4#include <xrpld/app/misc/Transaction.h>
5
6#include <xrpl/basics/Blob.h>
7#include <xrpl/basics/Log.h>
8#include <xrpl/basics/SHAMapHash.h>
9#include <xrpl/basics/TaggedCache.ipp> // IWYU pragma: keep
10#include <xrpl/beast/utility/instrumentation.h>
11#include <xrpl/core/Job.h>
12#include <xrpl/core/JobQueue.h>
13#include <xrpl/protocol/HashPrefix.h>
14#include <xrpl/protocol/Serializer.h>
15#include <xrpl/protocol/digest.h> // IWYU pragma: keep
16#include <xrpl/server/NetworkOPs.h>
17#include <xrpl/shamap/SHAMapTreeNode.h>
18
19#include <cstdint>
20#include <exception>
21#include <functional>
22#include <memory>
23#include <optional>
24
25namespace xrpl {
26
28 : app_(app), nodeCache_(nodeCache), j_(app.getJournal("TransactionAcquire"))
29{
30}
31
32void
34 bool fromFilter,
35 SHAMapHash const& nodeHash,
37 Blob&& nodeData, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
38 SHAMapNodeType type) const
39{
40 if (fromFilter)
41 return;
42
43 nodeCache_.insert(nodeHash, nodeData);
44
45 if ((type == SHAMapNodeType::TnTransactionNm) && (nodeData.size() > 16))
46 {
47 // this is a transaction, and we didn't have it
48 JLOG(j_.debug()) << "Node on our acquiring TX set is TXN we may not have";
49
50 try
51 {
52 // skip prefix
53 Serializer const s(nodeData.data() + 4, nodeData.size() - 4);
54 SerialIter sit(s.slice());
56 XRPL_ASSERT(
57 stx->getTransactionID() == nodeHash.asUInt256(),
58 "xrpl::ConsensusTransSetSF::gotNode : transaction hash "
59 "match");
60 auto const pap = &app_;
61 app_.getJobQueue().addJob(
62 JtTransaction, "TxsToTxn", [pap, stx]() { pap->getOPs().submitTransaction(stx); });
63 }
64 catch (std::exception const& ex)
65 {
66 JLOG(j_.warn()) << "Fetched invalid transaction in proposed set. Exception: "
67 << ex.what();
68 }
69 }
70}
71
74{
75 Blob nodeData;
76 if (nodeCache_.retrieve(nodeHash, nodeData))
77 return nodeData;
78
79 auto txn = app_.getMasterTransaction().fetchFromCache(nodeHash.asUInt256());
80
81 if (txn)
82 {
83 // this is a transaction, and we have it
84 JLOG(j_.trace()) << "Node in our acquiring TX set is TXN we have";
85 Serializer s;
87 txn->getSTransaction()->add(s);
88 XRPL_ASSERT(
89 sha512Half(s.slice()) == nodeHash.asUInt256(),
90 "xrpl::ConsensusTransSetSF::getNode : transaction hash match");
91 nodeData = s.peekData();
92 return nodeData;
93 }
94
95 return std::nullopt;
96}
97
98} // namespace xrpl
ConsensusTransSetSF(Application &app, NodeCache &nodeCache)
TaggedCache< SHAMapHash, Blob > NodeCache
std::optional< Blob > getNode(SHAMapHash const &nodeHash) const override
void gotNode(bool fromFilter, SHAMapHash const &nodeHash, std::uint32_t ledgerSeq, Blob &&nodeData, SHAMapNodeType type) const override
uint256 const & asUInt256() const
Definition SHAMapHash.h:26
Blob const & peekData() const
Definition Serializer.h:177
Slice slice() const noexcept
Definition Serializer.h:45
T make_shared(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:215
@ JtTransaction
Definition Job.h:48
@ TransactionId
transaction plus signature to give transaction ID
Definition HashPrefix.h:39
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
T ref(T... args)
T what(T... args)