xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
app
ledger
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
25
namespace
xrpl
{
26
27
ConsensusTransSetSF::ConsensusTransSetSF
(
Application
& app,
NodeCache
& nodeCache)
28
:
app_
(app),
nodeCache_
(nodeCache),
j_
(app.getJournal(
"TransactionAcquire"
))
29
{
30
}
31
32
void
33
ConsensusTransSetSF::gotNode
(
34
bool
fromFilter,
35
SHAMapHash
const
& nodeHash,
36
std::uint32_t
,
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
());
55
auto
stx =
std::make_shared<STTx const>
(
std::ref
(sit));
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
72
std::optional<Blob>
73
ConsensusTransSetSF::getNode
(
SHAMapHash
const
& nodeHash)
const
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;
86
s.
add32
(
HashPrefix::TransactionId
);
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
xrpl::Application
Definition
Application.h:94
xrpl::ConsensusTransSetSF::ConsensusTransSetSF
ConsensusTransSetSF(Application &app, NodeCache &nodeCache)
Definition
ConsensusTransSetSF.cpp:27
xrpl::ConsensusTransSetSF::NodeCache
TaggedCache< SHAMapHash, Blob > NodeCache
Definition
ConsensusTransSetSF.h:25
xrpl::ConsensusTransSetSF::getNode
std::optional< Blob > getNode(SHAMapHash const &nodeHash) const override
Definition
ConsensusTransSetSF.cpp:73
xrpl::ConsensusTransSetSF::j_
beast::Journal const j_
Definition
ConsensusTransSetSF.h:44
xrpl::ConsensusTransSetSF::app_
Application & app_
Definition
ConsensusTransSetSF.h:42
xrpl::ConsensusTransSetSF::gotNode
void gotNode(bool fromFilter, SHAMapHash const &nodeHash, std::uint32_t ledgerSeq, Blob &&nodeData, SHAMapNodeType type) const override
Definition
ConsensusTransSetSF.cpp:33
xrpl::ConsensusTransSetSF::nodeCache_
NodeCache & nodeCache_
Definition
ConsensusTransSetSF.h:43
xrpl::SHAMapHash
Definition
SHAMapHash.h:16
xrpl::SHAMapHash::asUInt256
UInt256 const & asUInt256() const
Definition
SHAMapHash.h:26
xrpl::SerialIter
Definition
Serializer.h:478
xrpl::Serializer
Definition
Serializer.h:23
xrpl::Serializer::peekData
Blob const & peekData() const
Definition
Serializer.h:273
xrpl::Serializer::slice
Slice slice() const noexcept
Definition
Serializer.h:141
xrpl::Serializer::add32
int add32(T i)
Definition
Serializer.h:167
cstdint
exception
functional
std::uint32_t
std::make_shared
T make_shared(T... args)
memory
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::SHAMapNodeType
SHAMapNodeType
Definition
SHAMapTreeNode.h:30
xrpl::SHAMapNodeType::TnTransactionNm
@ TnTransactionNm
Definition
SHAMapTreeNode.h:32
xrpl::JtTransaction
@ JtTransaction
Definition
Job.h:48
xrpl::HashPrefix::TransactionId
@ TransactionId
transaction plus signature to give transaction ID
Definition
HashPrefix.h:39
xrpl::Blob
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition
Blob.h:11
xrpl::sha512Half
Sha512HalfHasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition
digest.h:215
optional
std::ref
T ref(T... args)
std::exception::what
T what(T... args)
Generated by
1.17.0