1#include <xrpld/app/ledger/InboundTransactions.h>
3#include <xrpld/app/ledger/LedgerNodeHelpers.h>
4#include <xrpld/app/ledger/detail/TransactionAcquire.h>
5#include <xrpld/app/main/Application.h>
6#include <xrpld/overlay/PeerSet.h>
8#include <xrpl/basics/Log.h>
9#include <xrpl/basics/UnorderedContainers.h>
10#include <xrpl/beast/insight/Collector.h>
11#include <xrpl/protocol/RippleLedgerHash.h>
12#include <xrpl/resource/Fees.h>
13#include <xrpl/server/NetworkOPs.h>
14#include <xrpl/shamap/SHAMap.h>
15#include <xrpl/shamap/SHAMapMissingNode.h>
16#include <xrpl/shamap/SHAMapNodeID.h>
17#include <xrpl/shamap/SHAMapTreeNode.h>
66 ,
j_(
app_.getJournal(
"InboundTransactions"))
79 auto it =
map_.find(hash);
82 return it->second.acquire;
95 if (
auto it =
map_.find(hash); it !=
map_.end())
99 it->second.seq =
seq_;
100 if (it->second.acquire)
102 it->second.acquire->stillNeed();
105 return it->second.set;
113 auto& obj =
map_[hash];
132 protocol::TMLedgerData
const& packet = *packetPtr;
134 JLOG(
j_.trace()) <<
"Got data (" << packet.nodes().size()
135 <<
") for acquiring ledger: " << hash;
146 data.reserve(packet.nodes().size());
148 for (
auto const& ledgerNode : packet.nodes())
150 auto treeNode =
getTreeNode(ledgerNode.nodedata());
153 JLOG(
j_.warn()) <<
"Got invalid node data for TX set " << hash <<
" from peer "
162 JLOG(
j_.warn()) <<
"Got invalid node id for TX set " << hash <<
" from peer "
168 data.emplace_back(*nodeID, std::move(treeNode));
171 auto const san = ta->takeNodes(std::move(data), peer);
176 else if (!san.isUseful())
190 auto& inboundSet =
map_[hash];
200 inboundSet.set =
set;
203 inboundSet.acquire.reset();
222 auto it =
map_.begin();
227 while (it !=
map_.end())
229 if (it->second.seq < minSeq || it->second.seq > maxSeq)
A generic endpoint for log messages.
std::shared_ptr< Collector > ptr
TransactionAcquire::pointer acquire
std::shared_ptr< SHAMap > set
InboundTransactionSet(std::uint32_t seq, std::shared_ptr< SHAMap > const &set)
void giveSet(uint256 const &hash, std::shared_ptr< SHAMap > const &set, bool fromAcquire) override
Add a transaction set.
TransactionAcquire::pointer getAcquire(uint256 const &hash)
std::unique_ptr< PeerSetBuilder > peerSetBuilder_
std::function< void(std::shared_ptr< SHAMap > const &, bool)> gotSet_
void gotData(LedgerHash const &hash, std::shared_ptr< Peer > peer, std::shared_ptr< protocol::TMLedgerData > packetPtr) override
We received a TMLedgerData from a peer.
void newRound(std::uint32_t seq) override
Informs the container if a new consensus round.
std::shared_ptr< SHAMap > getSet(uint256 const &hash, bool acquire) override
Find and return a transaction set, or nullptr if it is missing.
std::recursive_mutex lock_
hash_map< uint256, InboundTransactionSet > MapType
InboundTransactionsImp(Application &app, beast::insight::Collector::ptr const &collector, std::function< void(std::shared_ptr< SHAMap > const &, bool)> gotSet, std::unique_ptr< PeerSetBuilder > peerSetBuilder)
InboundTransactionSet & zeroSet_
InboundTransactions()=default
virtual ~InboundTransactions()=0
std::shared_ptr< TransactionAcquire > pointer
Charge const kFeeUselessData
Charge const kFeeInvalidData
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::unique_ptr< InboundTransactions > makeInboundTransactions(Application &app, beast::insight::Collector::ptr const &collector, std::function< void(std::shared_ptr< SHAMap > const &, bool)> gotSet)
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
std::optional< SHAMapNodeID > getSHAMapNodeID(protocol::TMLedgerNode const &ledgerNode, SHAMapTreeNode const &treeNode)
Extracts or reconstructs the SHAMapNodeID from a ledger node proto message.
SHAMapTreeNodePtr getTreeNode(std::string_view data)
Deserializes a SHAMapTreeNode from wire format data.
std::unique_ptr< PeerSetBuilder > makePeerSetBuilder(Application &app)
static constexpr auto kStartPeers
std::unordered_map< Key, Value, Hash, Pred, Allocator > hash_map
static constexpr auto kSetKeepRounds