rippled
Loading...
Searching...
No Matches
ConsensusTransSetSF.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/ledger/ConsensusTransSetSF.h>
21#include <xrpld/app/ledger/TransactionMaster.h>
22#include <xrpld/app/misc/NetworkOPs.h>
23#include <xrpld/app/misc/Transaction.h>
24#include <xrpld/core/JobQueue.h>
25#include <xrpld/nodestore/Database.h>
26
27#include <xrpl/basics/Log.h>
28#include <xrpl/protocol/HashPrefix.h>
29#include <xrpl/protocol/digest.h>
30
31namespace ripple {
32
34 : app_(app), m_nodeCache(nodeCache), j_(app.journal("TransactionAcquire"))
35{
36}
37
38void
40 bool fromFilter,
41 SHAMapHash const& nodeHash,
43 Blob&& nodeData,
44 SHAMapNodeType type) const
45{
46 if (fromFilter)
47 return;
48
49 m_nodeCache.insert(nodeHash, nodeData);
50
51 if ((type == SHAMapNodeType::tnTRANSACTION_NM) && (nodeData.size() > 16))
52 {
53 // this is a transaction, and we didn't have it
54 JLOG(j_.debug())
55 << "Node on our acquiring TX set is TXN we may not have";
56
57 try
58 {
59 // skip prefix
60 Serializer s(nodeData.data() + 4, nodeData.size() - 4);
61 SerialIter sit(s.slice());
62 auto stx = std::make_shared<STTx const>(std::ref(sit));
63 XRPL_ASSERT(
64 stx->getTransactionID() == nodeHash.as_uint256(),
65 "ripple::ConsensusTransSetSF::gotNode : transaction hash "
66 "match");
67 auto const pap = &app_;
68 app_.getJobQueue().addJob(jtTRANSACTION, "TXS->TXN", [pap, stx]() {
69 pap->getOPs().submitTransaction(stx);
70 });
71 }
72 catch (std::exception const& ex)
73 {
74 JLOG(j_.warn())
75 << "Fetched invalid transaction in proposed set. Exception: "
76 << ex.what();
77 }
78 }
79}
80
83{
84 Blob nodeData;
85 if (m_nodeCache.retrieve(nodeHash, nodeData))
86 return nodeData;
87
88 auto txn =
90
91 if (txn)
92 {
93 // this is a transaction, and we have it
94 JLOG(j_.trace()) << "Node in our acquiring TX set is TXN we have";
95 Serializer s;
97 txn->getSTransaction()->add(s);
98 XRPL_ASSERT(
99 sha512Half(s.slice()) == nodeHash.as_uint256(),
100 "ripple::ConsensusTransSetSF::getNode : transaction hash match");
101 nodeData = s.peekData();
102 return nodeData;
103 }
104
105 return std::nullopt;
106}
107
108} // namespace ripple
Stream debug() const
Definition: Journal.h:328
Stream trace() const
Severity stream access functions.
Definition: Journal.h:322
Stream warn() const
Definition: Journal.h:340
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:168
uint256 const & as_uint256() const
Definition: SHAMapHash.h:44
Slice slice() const noexcept
Definition: Serializer.h:66
Blob const & peekData() const
Definition: Serializer.h:202
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 &)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
@ transactionID
transaction plus signature to give transaction ID
@ jtTRANSACTION
Definition: Job.h:62
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition: digest.h:224
T ref(T... args)
T what(T... args)