rippled
Loading...
Searching...
No Matches
ConsensusTransSetSF.cpp
1#include <xrpld/app/ledger/ConsensusTransSetSF.h>
2#include <xrpld/app/ledger/TransactionMaster.h>
3#include <xrpld/app/misc/Transaction.h>
4
5#include <xrpl/core/JobQueue.h>
6#include <xrpl/nodestore/Database.h>
7#include <xrpl/protocol/HashPrefix.h>
8#include <xrpl/protocol/digest.h>
9#include <xrpl/server/NetworkOPs.h>
10
11namespace xrpl {
12
14 : app_(app), m_nodeCache(nodeCache), j_(app.getJournal("TransactionAcquire"))
15{
16}
17
18void
20 bool fromFilter,
21 SHAMapHash const& nodeHash,
23 Blob&& nodeData, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
24 SHAMapNodeType type) const
25{
26 if (fromFilter)
27 return;
28
29 m_nodeCache.insert(nodeHash, nodeData);
30
31 if ((type == SHAMapNodeType::tnTRANSACTION_NM) && (nodeData.size() > 16))
32 {
33 // this is a transaction, and we didn't have it
34 JLOG(j_.debug()) << "Node on our acquiring TX set is TXN we may not have";
35
36 try
37 {
38 // skip prefix
39 Serializer const s(nodeData.data() + 4, nodeData.size() - 4);
40 SerialIter sit(s.slice());
42 XRPL_ASSERT(
43 stx->getTransactionID() == nodeHash.as_uint256(),
44 "xrpl::ConsensusTransSetSF::gotNode : transaction hash "
45 "match");
46 auto const pap = &app_;
48 jtTRANSACTION, "TxsToTxn", [pap, stx]() { pap->getOPs().submitTransaction(stx); });
49 }
50 catch (std::exception const& ex)
51 {
52 JLOG(j_.warn()) << "Fetched invalid transaction in proposed set. Exception: "
53 << ex.what();
54 }
55 }
56}
57
60{
61 Blob nodeData;
62 if (m_nodeCache.retrieve(nodeHash, nodeData))
63 return nodeData;
64
66
67 if (txn)
68 {
69 // this is a transaction, and we have it
70 JLOG(j_.trace()) << "Node in our acquiring TX set is TXN we have";
71 Serializer s;
73 txn->getSTransaction()->add(s);
74 XRPL_ASSERT(
75 sha512Half(s.slice()) == nodeHash.as_uint256(),
76 "xrpl::ConsensusTransSetSF::getNode : transaction hash match");
77 nodeData = s.peekData();
78 return nodeData;
79 }
80
81 return std::nullopt;
82}
83
84} // namespace xrpl
Stream debug() const
Definition Journal.h:301
Stream trace() const
Severity stream access functions.
Definition Journal.h:295
Stream warn() const
Definition Journal.h:313
ConsensusTransSetSF(Application &app, NodeCache &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
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
Definition JobQueue.h:147
uint256 const & as_uint256() const
Definition SHAMapHash.h:24
Blob const & peekData() const
Definition Serializer.h:176
Slice slice() const noexcept
Definition Serializer.h:44
virtual JobQueue & getJobQueue()=0
virtual TransactionMaster & getMasterTransaction()=0
bool retrieve(key_type const &key, T &data)
auto insert(key_type const &key, T const &value) -> std::enable_if_t<!IsKeyCache, ReturnType >
Insert the element into the container.
std::shared_ptr< Transaction > fetch_from_cache(uint256 const &)
T is_same_v
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:41
@ transactionID
transaction plus signature to give transaction ID
T ref(T... args)
T what(T... args)