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
6#include <xrpl/basics/Log.h>
7#include <xrpl/core/JobQueue.h>
8#include <xrpl/nodestore/Database.h>
9#include <xrpl/protocol/HashPrefix.h>
10#include <xrpl/protocol/digest.h>
11
12namespace xrpl {
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()) << "Node on our acquiring TX set is TXN we may not have";
36
37 try
38 {
39 // skip prefix
40 Serializer s(nodeData.data() + 4, nodeData.size() - 4);
41 SerialIter sit(s.slice());
43 XRPL_ASSERT(
44 stx->getTransactionID() == nodeHash.as_uint256(),
45 "xrpl::ConsensusTransSetSF::gotNode : transaction hash "
46 "match");
47 auto const pap = &app_;
49 jtTRANSACTION, "TxsToTxn", [pap, stx]() { pap->getOPs().submitTransaction(stx); });
50 }
51 catch (std::exception const& ex)
52 {
53 JLOG(j_.warn()) << "Fetched invalid transaction in proposed set. Exception: " << 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
virtual TransactionMaster & getMasterTransaction()=0
virtual JobQueue & getJobQueue()=0
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:146
uint256 const & as_uint256() const
Definition SHAMapHash.h:25
Blob const & peekData() const
Definition Serializer.h:177
Slice slice() const noexcept
Definition Serializer.h:45
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
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:205
@ jtTRANSACTION
Definition Job.h:42
@ transactionID
transaction plus signature to give transaction ID
T ref(T... args)
T what(T... args)