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/beast/utility/instrumentation.h>
10#include <xrpl/core/Job.h>
11#include <xrpl/core/JobQueue.h>
12#include <xrpl/protocol/HashPrefix.h>
13#include <xrpl/protocol/Serializer.h>
14#include <xrpl/protocol/digest.h> // IWYU pragma: keep
15#include <xrpl/server/NetworkOPs.h>
16#include <xrpl/shamap/SHAMapTreeNode.h>
17
18#include <cstdint>
19#include <exception>
20#include <functional>
21#include <memory>
22#include <optional>
23
24namespace xrpl {
25
27 : app_(app), nodeCache_(nodeCache), j_(app.getJournal("TransactionAcquire"))
28{
29}
30
31void
33 bool fromFilter,
34 SHAMapHash const& nodeHash,
36 Blob&& nodeData, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
37 SHAMapNodeType type) const
38{
39 if (fromFilter)
40 return;
41
42 nodeCache_.insert(nodeHash, nodeData);
43
44 if ((type == SHAMapNodeType::TnTransactionNm) && (nodeData.size() > 16))
45 {
46 // this is a transaction, and we didn't have it
47 JLOG(j_.debug()) << "Node on our acquiring TX set is TXN we may not have";
48
49 try
50 {
51 // skip prefix
52 Serializer const s(nodeData.data() + 4, nodeData.size() - 4);
53 SerialIter sit(s.slice());
55 XRPL_ASSERT(
56 stx->getTransactionID() == nodeHash.asUInt256(),
57 "xrpl::ConsensusTransSetSF::gotNode : transaction hash "
58 "match");
59 auto const pap = &app_;
60 app_.getJobQueue().addJob(
61 JtTransaction, "TxsToTxn", [pap, stx]() { pap->getOPs().submitTransaction(stx); });
62 }
63 catch (std::exception const& ex)
64 {
65 JLOG(j_.warn()) << "Fetched invalid transaction in proposed set. Exception: "
66 << ex.what();
67 }
68 }
69}
70
73{
74 Blob nodeData;
75 if (nodeCache_.retrieve(nodeHash, nodeData))
76 return nodeData;
77
78 auto txn = app_.getMasterTransaction().fetchFromCache(nodeHash.asUInt256());
79
80 if (txn)
81 {
82 // this is a transaction, and we have it
83 JLOG(j_.trace()) << "Node in our acquiring TX set is TXN we have";
84 Serializer s;
86 txn->getSTransaction()->add(s);
87 XRPL_ASSERT(
88 sha512Half(s.slice()) == nodeHash.asUInt256(),
89 "xrpl::ConsensusTransSetSF::getNode : transaction hash match");
90 nodeData = s.peekData();
91 return nodeData;
92 }
93
94 return std::nullopt;
95}
96
97} // 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:24
Blob const & peekData() const
Definition Serializer.h:176
Slice slice() const noexcept
Definition Serializer.h:44
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:204
@ JtTransaction
Definition Job.h:43
@ TransactionId
transaction plus signature to give transaction ID
Definition HashPrefix.h:36
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:10
T ref(T... args)
T what(T... args)