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/NetworkOPs.h>
4#include <xrpld/app/misc/Transaction.h>
5#include <xrpld/core/JobQueue.h>
6
7#include <xrpl/basics/Log.h>
8#include <xrpl/nodestore/Database.h>
9#include <xrpl/protocol/HashPrefix.h>
10#include <xrpl/protocol/digest.h>
11
12namespace ripple {
13
15 : app_(app), m_nodeCache(nodeCache), j_(app.journal("TransactionAcquire"))
16{
17}
18
19void
21 bool fromFilter,
22 SHAMapHash const& nodeHash,
24 Blob&& nodeData,
25 SHAMapNodeType type) const
26{
27 if (fromFilter)
28 return;
29
30 m_nodeCache.insert(nodeHash, nodeData);
31
32 if ((type == SHAMapNodeType::tnTRANSACTION_NM) && (nodeData.size() > 16))
33 {
34 // this is a transaction, and we didn't have it
35 JLOG(j_.debug())
36 << "Node on our acquiring TX set is TXN we may not have";
37
38 try
39 {
40 // skip prefix
41 Serializer s(nodeData.data() + 4, nodeData.size() - 4);
42 SerialIter sit(s.slice());
44 XRPL_ASSERT(
45 stx->getTransactionID() == nodeHash.as_uint256(),
46 "ripple::ConsensusTransSetSF::gotNode : transaction hash "
47 "match");
48 auto const pap = &app_;
49 app_.getJobQueue().addJob(jtTRANSACTION, "TXS->TXN", [pap, stx]() {
50 pap->getOPs().submitTransaction(stx);
51 });
52 }
53 catch (std::exception const& ex)
54 {
55 JLOG(j_.warn())
56 << "Fetched invalid transaction in proposed set. Exception: "
57 << ex.what();
58 }
59 }
60}
61
64{
65 Blob nodeData;
66 if (m_nodeCache.retrieve(nodeHash, nodeData))
67 return nodeData;
68
69 auto txn =
71
72 if (txn)
73 {
74 // this is a transaction, and we have it
75 JLOG(j_.trace()) << "Node in our acquiring TX set is TXN we have";
76 Serializer s;
78 txn->getSTransaction()->add(s);
79 XRPL_ASSERT(
80 sha512Half(s.slice()) == nodeHash.as_uint256(),
81 "ripple::ConsensusTransSetSF::getNode : transaction hash match");
82 nodeData = s.peekData();
83 return nodeData;
84 }
85
86 return std::nullopt;
87}
88
89} // namespace ripple
Stream debug() const
Definition Journal.h:309
Stream trace() const
Severity stream access functions.
Definition Journal.h:303
Stream warn() const
Definition Journal.h:321
virtual JobQueue & getJobQueue()=0
virtual TransactionMaster & getMasterTransaction()=0
void gotNode(bool fromFilter, SHAMapHash const &nodeHash, std::uint32_t ledgerSeq, Blob &&nodeData, SHAMapNodeType type) const override
std::optional< Blob > getNode(SHAMapHash const &nodeHash) const override
ConsensusTransSetSF(Application &app, NodeCache &nodeCache)
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
Definition JobQueue.h:149
uint256 const & as_uint256() const
Definition SHAMapHash.h:25
Slice slice() const noexcept
Definition Serializer.h:47
Blob const & peekData() const
Definition Serializer.h:183
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:6
@ transactionID
transaction plus signature to give transaction ID
@ jtTRANSACTION
Definition Job.h:43
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:205
T ref(T... args)
T what(T... args)