Bitcoin ABC 0.34.5
P2P Digital Currency
Loading...
Searching...
No Matches
txdownloadman_impl.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
7
9#include <logging.h>
10#include <random.h>
11#include <txconflicting.h>
12#include <txmempool.h>
13#include <txorphanage.h>
14
15#include <numeric>
16
17namespace node {
18// TxDownloadManager wrappers
20 : m_impl{std::make_unique<TxDownloadManagerImpl>(options)} {}
22
27 return m_impl->RecentRejectsFilter();
28}
30 return m_impl->RecentConfirmedTransactionsFilter();
31}
33 m_impl->ActiveTipChange();
34}
36 const std::shared_ptr<const CBlock> &pblock) {
37 m_impl->BlockConnected(pblock);
38}
40 m_impl->BlockDisconnected();
41}
43 const TxDownloadConnectionInfo &info) {
44 m_impl->ConnectedPeer(nodeid, info);
45}
47 m_impl->DisconnectedPeer(nodeid);
48}
50 std::chrono::microseconds now) {
51 return m_impl->AddTxAnnouncement(peer, txid, now);
52}
53std::vector<TxId>
55 std::chrono::microseconds current_time) {
56 return m_impl->GetRequestsToSend(nodeid, current_time);
57}
59 const std::vector<TxId> &txids) {
60 m_impl->ReceivedNotFound(nodeid, txids);
61}
63 m_impl->MempoolAcceptedTx(tx);
64}
67 const TxValidationState &state,
68 NodeId nodeid, bool first_time_failure) {
69 return m_impl->MempoolRejectedTx(ptx, state, nodeid, first_time_failure);
70}
72 m_impl->MempoolRejectedPackage(package);
73}
74std::pair<bool, std::optional<PackageToValidate>>
76 return m_impl->ReceivedTx(nodeid, ptx);
77}
79 return m_impl->HaveMoreWork(nodeid);
80}
82 return m_impl->GetTxToReconsider(nodeid);
83}
85 m_impl->CheckIsEmpty();
86}
88 m_impl->CheckIsEmpty(nodeid);
89}
90std::vector<TxOrphanage::PoolTx>
92 return m_impl->GetOrphanTransactions();
93}
94
95// TxDownloadManagerImpl
100
102 const std::shared_ptr<const CBlock> &pblock) {
103 m_opts.m_mempool.withOrphanage([&pblock](TxOrphanage &orphanage) {
104 orphanage.EraseForBlock(*pblock);
105 });
106 m_opts.m_mempool.withConflicting([&pblock](TxConflicting &conflicting) {
107 conflicting.EraseForBlock(*pblock);
108 });
109
110 for (const CTransactionRef &ptx : pblock->vtx) {
112 m_txrequest.ForgetInvId(ptx->GetId());
113 }
114}
115
117 // To avoid relay problems with transactions that were previously
118 // confirmed, clear our filter of recently confirmed transactions whenever
119 // there's a reorg.
120 // This means that in a 1-block reorg (where 1 block is disconnected and
121 // then another block reconnected), our filter will drop to having only one
122 // block's worth of transactions in it, but that should be fine, since
123 // presumably the most common case of relaying a confirmed transaction
124 // should be just after a new block containing it is found.
126}
127
129 bool include_reconsiderable) {
130 if (m_opts.m_mempool.withOrphanage([&txid](const TxOrphanage &orphanage) {
131 return orphanage.HaveTx(txid);
132 })) {
133 return true;
134 }
135
137 [&txid](const TxConflicting &conflicting) {
138 return conflicting.HaveTx(txid);
139 })) {
140 return true;
141 }
142
143 if (include_reconsiderable &&
145 return true;
146 }
147
148 if (RecentConfirmedTransactionsFilter().contains(txid)) {
149 return true;
150 }
151
152 return RecentRejectsFilter().contains(txid) ||
153 m_opts.m_mempool.exists(txid);
154}
155
157 NodeId nodeid, const TxDownloadConnectionInfo &info) {
158 // If already connected (shouldn't happen in practice), exit early.
159 if (m_peer_info.contains(nodeid)) {
160 return;
161 }
162
163 m_peer_info.try_emplace(nodeid, info);
164}
165
168 [nodeid](TxOrphanage &orphanage) { orphanage.EraseForPeer(nodeid); });
170
171 if (auto it = m_peer_info.find(nodeid); it != m_peer_info.end()) {
172 m_peer_info.erase(it);
173 }
174}
175
177 std::chrono::microseconds now) {
178 // If this is an orphan we are trying to resolve, consider this peer as a
179 // orphan resolution candidate instead.
180 // - exists in orphanage
181 // - peer can be an orphan resolution candidate
182 if (auto orphan_tx{m_opts.m_mempool.withOrphanage(
183 [&txid](const TxOrphanage &orphanage) {
184 return orphanage.GetTx(txid);
185 })}) {
186 auto unique_parents{GetUniqueParents(*orphan_tx)};
187 std::erase_if(unique_parents, [&](const auto &parent_txid) {
188 return AlreadyHaveTx(parent_txid,
189 /*include_reconsiderable=*/false);
190 });
191
192 // The missing parents may have all been rejected or accepted since
193 // the orphan was added to the orphanage. Do not delete from the
194 // orphanage, as it may be queued for processing.
195 if (unique_parents.empty()) {
196 return true;
197 }
198
199 if (MaybeAddOrphanResolutionCandidate(unique_parents, txid, peer,
200 now)) {
202 [&txid, peer](TxOrphanage &orphanage) {
203 orphanage.AddAnnouncer(txid, peer);
204 });
205 }
206
207 // Return even if the peer isn't an orphan resolution candidate.
208 // This would be caught by AlreadyHaveTx.
209 return true;
210 }
211
212 // If this is an inv received from a peer and we already have it, we can
213 // drop it.
214 if (AlreadyHaveTx(txid, /*include_reconsiderable=*/true)) {
215 return true;
216 }
217
218 auto it = m_peer_info.find(peer);
219 if (it == m_peer_info.end()) {
220 return false;
221 }
222 const auto &info = it->second.m_connection_info;
224 /*bypass_limits=*/info.m_relay_permissions)) {
225 // Too many queued announcements for this peer
226 return false;
227 }
228 // Decide the InvRequestTracker parameters for this announcement:
229 // - "preferred": if fPreferredDownload is set (= outbound, or
230 // NetPermissionFlags::NoBan permission)
231 // - "reqtime": current time plus delays, see ComputeRequestTime
232 const auto reqtime = ComputeRequestTime(
233 m_txrequest, peer, TX_REQUEST_PARAMS, now, info.m_preferred,
234 /*bypass_limits=*/info.m_relay_permissions);
235
236 m_txrequest.ReceivedInv(peer, txid, info.m_preferred, reqtime);
237
238 return false;
239}
240
242 const std::vector<TxId> &unique_parents, const TxId &txid, NodeId nodeid,
243 std::chrono::microseconds now) {
244 auto it_peer = m_peer_info.find(nodeid);
245 if (it_peer == m_peer_info.end()) {
246 return false;
247 }
249 [&txid, nodeid](const TxOrphanage &orphanage) {
250 return orphanage.HaveTxFromPeer(txid, nodeid);
251 })) {
252 return false;
253 }
254
255 const auto &peer_entry = m_peer_info.at(nodeid);
256 const auto &info = peer_entry.m_connection_info;
257
258 // TODO: add delays and limits based on the amount of orphan resolution we
259 // are already doing with this peer, how much they are using the orphanage,
260 // etc.
261 if (!info.m_relay_permissions) {
262 // This mirrors the delaying and dropping behavior in AddTxAnnouncement
263 // in order to preserve existing behavior: drop if we are tracking too
264 // many invs for this peer already. Each orphan resolution involves at
265 // least 1 transaction request which may or may not be currently tracked
266 // in m_txrequest, so we include that in the count.
267 if (m_txrequest.Count(nodeid) + unique_parents.size() >
269 return false;
270 }
271 }
272
273 const auto reqtime = ComputeRequestTime(
274 m_txrequest, nodeid, TX_REQUEST_PARAMS, now, info.m_preferred,
275 /*bypass_limits=*/info.m_relay_permissions);
276
277 // Treat finding orphan resolution candidate as equivalent to the peer
278 // announcing all missing parents.
279 // In the future, orphan resolution may include more explicit steps
280 for (const auto &parent_txid : unique_parents) {
281 m_txrequest.ReceivedInv(nodeid, parent_txid, info.m_preferred, reqtime);
282 }
284 "added peer=%d as a candidate for resolving orphan %s\n", nodeid,
285 txid.ToString());
286 return true;
287}
288
290 NodeId nodeid, std::chrono::microseconds current_time) {
291 std::vector<TxId> requests;
292 std::vector<std::pair<NodeId, TxId>> expired;
293 auto requestable =
294 m_txrequest.GetRequestable(nodeid, current_time, &expired);
295 for (const auto &entry : expired) {
296 LogDebug(BCLog::NET, "timeout of inflight tx %s from peer=%d\n",
297 entry.second.ToString(), entry.first);
298 }
299 for (const TxId &txid : requestable) {
300 // Exclude m_recent_rejects_package_reconsiderable: we may be
301 // requesting a missing parent that was previously rejected for being
302 // too low feerate.
303 if (!AlreadyHaveTx(txid, /*include_reconsiderable=*/false)) {
304 requests.emplace_back(txid);
305 m_txrequest.RequestedData(nodeid, txid,
306 current_time +
308 } else {
309 // We have already seen this transaction, no need to download. This
310 // is just a belt-and-suspenders, as this should already be called
311 // whenever a transaction becomes AlreadyHaveTx().
313 }
314 }
315 return requests;
316}
317
319 const std::vector<TxId> &txids) {
320 for (const auto &txid : txids) {
321 // If we receive a NOTFOUND message for a tx we requested, mark the
322 // announcement for it as completed in InvRequestTracker.
323 m_txrequest.ReceivedResponse(nodeid, txid);
324 }
325}
326
327std::optional<PackageToValidate>
329 NodeId nodeid) {
330 const auto &parent_txid{ptx->GetId()};
331
332 Assume(RecentRejectsPackageReconsiderableFilter().contains(parent_txid));
333
334 // Only consider children from this peer. This helps prevent censorship
335 // attempts in which an attacker sends lots of fake children for the parent,
336 // and we (unluckily) keep selecting the fake children instead of the real
337 // one provided by the honest peer. Since we track all announcers of an
338 // orphan, this does not exclude parent + orphan pairs that we happened to
339 // request from different peers.
340 const auto cpfp_candidates_same_peer{m_opts.m_mempool.withOrphanage(
341 [&ptx, nodeid](const TxOrphanage &orphanage) {
342 return orphanage.GetChildrenFromSamePeer(ptx, nodeid);
343 })};
344
345 // These children should be sorted from newest to oldest.
346 for (const auto &child : cpfp_candidates_same_peer) {
347 Package maybe_cpfp_package{ptx, child};
349 GetPackageHash(maybe_cpfp_package)) &&
350 !RecentRejectsFilter().contains(child->GetId())) {
351 return PackageToValidate{ptx, child, nodeid, nodeid};
352 }
353 }
354 return std::nullopt;
355}
356
358 // As this version of the transaction was acceptable, we can forget about
359 // any requests for it. No-op if the tx is not in txrequest.
360 m_txrequest.ForgetInvId(tx->GetId());
361
362 m_opts.m_mempool.withOrphanage([this, &tx](TxOrphanage &orphanage) {
363 orphanage.AddChildrenToWorkSet(*tx, m_rng);
364 // If it came from the orphanage, remove it. No-op if the tx is not in
365 // txorphanage.
366 orphanage.EraseTx(tx->GetId());
367 });
368}
369
370std::vector<TxId>
372 std::vector<TxId> unique_parents;
373 unique_parents.reserve(tx.vin.size());
374 for (const CTxIn &txin : tx.vin) {
375 // We start with all parents, and then remove duplicates below.
376 unique_parents.push_back(txin.prevout.GetTxId());
377 }
378
379 std::sort(unique_parents.begin(), unique_parents.end());
380 unique_parents.erase(
381 std::unique(unique_parents.begin(), unique_parents.end()),
382 unique_parents.end());
383
384 return unique_parents;
385}
386
388 const CTransactionRef &ptx, const TxValidationState &state, NodeId nodeid,
389 bool first_time_failure) {
390 const CTransaction &tx{*ptx};
391 const TxId &txid = ptx->GetId();
392 // Results returned to caller
393 // Whether we should call AddToCompactExtraTransactions at the end
394 bool add_extra_compact_tx{first_time_failure};
395 // Hashes to pass to AddKnownTx later
396 std::vector<TxId> unique_parents;
397 // Populated if failure is reconsiderable and eligible package is found.
398 std::optional<PackageToValidate> package_to_validate;
399
401 // Only process a new orphan if this is a first time failure, as
402 // otherwise it must be either already in orphanage or from 1p1c
403 // processing.
404 if (first_time_failure && !RecentRejectsFilter().contains(txid)) {
405 // It may be the case that the orphans parents have all been
406 // rejected.
407 bool fRejectedParents = false;
408
409 // Deduplicate parent txids, so that we don't have to loop over
410 // the same parent txid more than once down below.
411 unique_parents = GetUniqueParents(tx);
412
413 // Distinguish between parents in m_recent_rejects and
414 // m_recent_rejects_package_reconsiderable. We can tolerate
415 // having up to 1 parent in
416 // m_recent_rejects_package_reconsiderable since we submit 1p1c
417 // packages. However, fail immediately if any are in
418 // m_recent_rejects.
419 std::optional<TxId> rejected_parent_reconsiderable;
420 for (const TxId &parent_txid : unique_parents) {
421 if (RecentRejectsFilter().contains(parent_txid)) {
422 fRejectedParents = true;
423 break;
424 }
425
427 parent_txid) &&
428 !m_opts.m_mempool.exists(parent_txid)) {
429 // More than 1 parent in
430 // m_recent_rejects_package_reconsiderable:
431 // 1p1c will not be sufficient to accept this package,
432 // so just give up here.
433 if (rejected_parent_reconsiderable.has_value()) {
434 fRejectedParents = true;
435 break;
436 }
437 rejected_parent_reconsiderable = parent_txid;
438 }
439 }
440 if (!fRejectedParents) {
441 // Filter parents that we already have.
442 // Exclude m_recent_rejects_package_reconsiderable: the missing
443 // parent may have been previously rejected for being too low
444 // feerate. This orphan might CPFP it.
445 std::erase_if(unique_parents, [&](const auto &parent_txid) {
446 return AlreadyHaveTx(parent_txid,
447 /*include_reconsiderable=*/false);
448 });
449 const auto now{GetTime<std::chrono::microseconds>()};
450 // Potentially flip add_extra_compact_tx to false if tx is
451 // already in orphanage, which means it was already added to
452 // vExtraTxnForCompact.
453 add_extra_compact_tx &= !m_opts.m_mempool.withOrphanage(
454 [&txid](const TxOrphanage &orphanage) {
455 return orphanage.HaveTx(txid);
456 });
457
458 // If there is no candidate for orphan resolution, AddTx will
459 // not be called. This means that if a peer is overloading us
460 // with invs and orphans, they will eventually not be able to
461 // add any more transactions to the orphanage.
462 std::vector<NodeId> orphan_resolution_candidates{nodeid};
464 orphan_resolution_candidates);
465
466 for (const auto &candidate : orphan_resolution_candidates) {
467 if (MaybeAddOrphanResolutionCandidate(unique_parents, txid,
468 candidate, now)) {
470 [&ptx, candidate](TxOrphanage &orphanage) {
471 orphanage.AddTx(ptx, candidate);
472 });
473 }
474 }
475
476 // Once added to the orphan pool, a tx is considered
477 // AlreadyHave, and we shouldn't request it anymore.
478 m_txrequest.ForgetInvId(tx.GetId());
479
480 // DoS prevention: do not allow the orphanage to grow unbounded
481 // (see CVE-2012-3789). Note that, if the orphanage reaches
482 // capacity, it's possible that we immediately evict the
483 // transaction we just added.
484 unsigned int nEvicted =
485 m_opts.m_mempool.withOrphanage([&](TxOrphanage &orphanage) {
486 return orphanage.LimitTxs(m_opts.m_max_orphan_txs,
487 m_rng);
488 });
489 if (nEvicted > 0) {
491 "orphanage overflow, removed %u tx\n", nEvicted);
492 }
493
494 } else {
495 unique_parents.clear();
497 "not keeping orphan with rejected parents %s\n",
498 tx.GetId().ToString());
499 // We will continue to reject this tx since it has rejected
500 // parents so avoid re-requesting it from other peers.
501 RecentRejectsFilter().insert(tx.GetId());
502 m_txrequest.ForgetInvId(tx.GetId());
503 }
504 }
505 } else {
506 if (state.GetResult() ==
508 // If the result is TX_PACKAGE_RECONSIDERABLE, add it to
509 // m_recent_rejects_package_reconsiderable because we should not
510 // download or submit this transaction by itself again, but may
511 // submit it as part of a package later.
513
514 if (first_time_failure) {
515 // When a transaction fails for TX_PACKAGE_RECONSIDERABLE, look
516 // for a matching child in the orphanage, as it is possible that
517 // they succeed as a package.
518 LogDebug(
520 "tx %s failed but reconsiderable, looking for child in "
521 "orphanage\n",
522 txid.ToString());
523 package_to_validate = Find1P1CPackage(ptx, nodeid);
524 }
525 } else {
527 }
529 }
530
531 // If the tx failed in ProcessOrphanTx, it should be removed from the
532 // orphanage unless the tx was still missing inputs. If the tx was not in
533 // the orphanage, EraseTx does nothing and returns 0.
535 m_opts.m_mempool.withOrphanage([&txid](TxOrphanage &orphanage) {
536 return orphanage.EraseTx(txid);
537 }) > 0) {
538 LogDebug(BCLog::TXPACKAGES, " removed orphan tx %s\n",
539 txid.ToString());
540 }
541
542 return RejectedTxTodo{.m_should_add_extra_compact_tx = add_extra_compact_tx,
543 .m_unique_parents = std::move(unique_parents),
544 .m_package_to_validate =
545 std::move(package_to_validate)};
546}
547
551
552std::pair<bool, std::optional<PackageToValidate>>
554 const TxId &txid = ptx->GetId();
555
556 // Mark that we have received a response
557 m_txrequest.ReceivedResponse(nodeid, txid);
558
559 // First check if we should drop this tx.
560 if (AlreadyHaveTx(txid, /*include_reconsiderable=*/false)) {
561 // If a tx is detected by m_recent_rejects it is ignored. Because we
562 // haven't submitted the tx to our mempool, we won't have computed a
563 // DoS score for it or determined exactly why we consider it invalid.
564 //
565 // This means we won't penalize any peer subsequently relaying a DoSy
566 // tx (even if we penalized the first peer who gave it to us) because
567 // we have to account for m_recent_rejects showing false positives. In
568 // other words, we shouldn't penalize a peer if we aren't *sure* they
569 // submitted a DoSy tx.
570 //
571 // Note that m_recent_rejects doesn't just record DoSy or invalid
572 // transactions, but any tx not accepted by the mempool, which may be
573 // due to node policy (vs. consensus). So we can't blanket penalize a
574 // peer simply for relaying a tx that our m_recent_rejects has caught,
575 // regardless of false positives.
576 return {false, std::nullopt};
577 } else if (RecentRejectsPackageReconsiderableFilter().contains(txid)) {
578 // When a transaction is already in
579 // m_recent_rejects_package_reconsiderable, we shouldn't submit it by
580 // itself again. However, look for a matching child in the orphanage,
581 // as it is possible that they succeed as a package.
583 "found tx %s in reconsiderable rejects, looking for child in "
584 "orphanage\n",
585 txid.ToString());
586 return {false, Find1P1CPackage(ptx, nodeid)};
587 }
588
589 return {true, std::nullopt};
590}
591
593 return m_opts.m_mempool.withOrphanage([nodeid](TxOrphanage &orphanage) {
594 return orphanage.HaveTxToReconsider(nodeid);
595 });
596}
597
599 return m_opts.m_mempool.withOrphanage([nodeid](TxOrphanage &orphanage) {
600 return orphanage.GetTxToReconsider(nodeid);
601 });
602}
603
608 assert(m_opts.m_mempool.withOrphanage([](const TxOrphanage &orphanage) {
609 return orphanage.Size();
610 }) == 0);
611 assert(m_txrequest.Size() == 0);
612}
613std::vector<TxOrphanage::PoolTx>
615 return m_opts.m_mempool.withOrphanage([](const TxOrphanage &orphanage) {
616 return orphanage.GetOrphanTransactions();
617 });
618}
619} // namespace node
#define Assume(val)
Assume is the identity function.
Definition check.h:100
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition bloom.h:115
void insert(Span< const uint8_t > vKey)
Definition bloom.cpp:215
bool contains(Span< const uint8_t > vKey) const
Definition bloom.cpp:249
bool exists(const TxId &txid) const
Definition txmempool.h:532
auto withOrphanage(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_orphanage)
Definition txmempool.h:593
auto withConflicting(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_conflicting)
Definition txmempool.h:601
std::vector< InvId > GetRequestable(NodeId peer, std::chrono::microseconds now, std::vector< std::pair< NodeId, InvId > > *expired)
Find the invids to request now from peer.
Definition invrequest.h:248
size_t Size() const
Count how many announcements are being tracked in total across all peers and inventory ids.
Definition invrequest.h:318
void RequestedData(NodeId peer, const InvId &invid, std::chrono::microseconds expiry)
Marks an inventory as requested, with a specified expiry.
Definition invrequest.h:278
void ForgetInvId(const InvId &invid)
Deletes all announcements for a given invid.
Definition invrequest.h:223
void DisconnectedPeer(NodeId peer)
Deletes all announcements for a given peer.
Definition invrequest.h:214
size_t Count(NodeId peer) const
Count how many announcements a peer has (REQUESTED, CANDIDATE, and COMPLETED combined).
Definition invrequest.h:312
void ReceivedInv(NodeId peer, const InvId &invid, bool preferred, std::chrono::microseconds reqtime)
Adds a new CANDIDATE announcement.
Definition invrequest.h:204
void ReceivedResponse(NodeId peer, const InvId &invid)
Converts a CANDIDATE or REQUESTED announcement to a COMPLETED one.
Definition invrequest.h:292
void GetCandidatePeers(const InvId &invid, std::vector< NodeId > &result_peers) const
For some invid, finds all peers with non-COMPLETED announcements and appends them to result_peers.
Definition invrequest.h:325
std::vector< PoolTx > GetOrphanTransactions() const
Definition txorphanage.h:21
void EraseForPeer(NodeId peer)
Maybe erase all txs announced by a peer (eg, after that peer disconnects).
Definition txpool.cpp:103
void EraseForBlock(const CBlock &block)
Erase all txs included in or invalidated by a new block.
Definition txpool.cpp:260
CTransactionRef GetTx(const TxId &txid) const
Definition txpool.cpp:208
CTransactionRef GetTxToReconsider(NodeId peer)
Extract a transaction from a peer's work set.
Definition txpool.cpp:234
bool AddAnnouncer(const TxId &txid, NodeId peer)
Add an additional announcer to a tx if it exists.
Definition txpool.cpp:50
void AddChildrenToWorkSet(const CTransaction &tx, FastRandomContext &rng)
Add any tx that list a particular tx as a parent into the from peer's work set.
Definition txpool.cpp:162
bool AddTx(const CTransactionRef &tx, NodeId peer)
Add a new transaction to the pool.
Definition txpool.cpp:15
unsigned int LimitTxs(unsigned int max_txs, FastRandomContext &rng)
Limit the txs to the given maximum.
Definition txpool.cpp:128
std::vector< CTransactionRef > GetChildrenFromSamePeer(const CTransactionRef &parent, NodeId nodeid) const
Get all children that spend from this tx and were received from nodeid.
Definition txpool.cpp:300
bool HaveTx(const TxId &txid) const
Check if we already have an the transaction.
Definition txpool.cpp:199
bool HaveTxToReconsider(NodeId peer)
Does this peer have any work to do?
Definition txpool.cpp:251
int EraseTx(const TxId &txid)
Erase a tx by txid.
Definition txpool.cpp:65
Result GetResult() const
Definition validation.h:122
std::string ToString() const
Definition uint256.h:117
const std::unique_ptr< TxDownloadManagerImpl > m_impl
std::vector< TxId > GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
Get getdata requests to send.
InvRequestTracker< TxId > & GetTxRequestRef()
std::pair< bool, std::optional< PackageToValidate > > ReceivedTx(NodeId nodeid, const CTransactionRef &ptx)
Marks a tx as ReceivedResponse in txrequest and checks whether AlreadyHaveTx.
std::vector< TxOrphanage::PoolTx > GetOrphanTransactions() const
Wrapper for TxOrphanage::GetOrphanTransactions.
void BlockConnected(const std::shared_ptr< const CBlock > &pblock)
CTransactionRef GetTxToReconsider(NodeId nodeid)
Returns next orphan tx to consider, or nullptr if none exist.
void CheckIsEmpty() const
Check that all data structures are empty.
void MempoolAcceptedTx(const CTransactionRef &tx)
Respond to successful transaction submission to mempool.
void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo &info)
Creates a new PeerInfo.
bool AddTxAnnouncement(NodeId peer, const TxId &txid, std::chrono::microseconds now)
Consider adding this tx hash to txrequest.
void MempoolRejectedPackage(const Package &package)
Respond to package rejected from mempool.
void DisconnectedPeer(NodeId nodeid)
Deletes all txrequest announcements and orphans for a given peer.
CRollingBloomFilter & RecentRejectsFilter()
RejectedTxTodo MempoolRejectedTx(const CTransactionRef &ptx, const TxValidationState &state, NodeId nodeid, bool first_time_failure)
Respond to transaction rejected from mempool.
TxDownloadManager(const TxDownloadOptions &options)
CRollingBloomFilter & RecentConfirmedTransactionsFilter()
void ReceivedNotFound(NodeId nodeid, const std::vector< TxId > &txids)
Should be called when a notfound for a tx has been received.
bool HaveMoreWork(NodeId nodeid) const
Whether there are any orphans to reconsider for this peer.
InvRequestTracker< TxId > m_txrequest
Tracks candidates for requesting and downloading transaction data.
std::optional< PackageToValidate > Find1P1CPackage(const CTransactionRef &ptx, NodeId nodeid)
Look for a child of this transaction in the orphanage to form a 1-parent-1-child package,...
CRollingBloomFilter & RecentConfirmedTransactionsFilter()
bool MaybeAddOrphanResolutionCandidate(const std::vector< TxId > &unique_parents, const TxId &txid, NodeId nodeid, std::chrono::microseconds now)
If this peer is an orphan resolution candidate for this transaction, treat the unique_parents as anno...
RejectedTxTodo MempoolRejectedTx(const CTransactionRef &ptx, const TxValidationState &state, NodeId nodeid, bool first_time_failure)
std::pair< bool, std::optional< PackageToValidate > > ReceivedTx(NodeId nodeid, const CTransactionRef &ptx)
void MempoolAcceptedTx(const CTransactionRef &tx)
void ReceivedNotFound(NodeId nodeid, const std::vector< TxId > &txids)
Marks a tx as ReceivedResponse in txrequest.
void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo &info)
std::map< NodeId, PeerInfo > m_peer_info
Information for all of the peers we may download transactions from.
std::vector< TxId > GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
Get getdata requests to send.
bool AlreadyHaveTx(const TxId &txid, bool include_reconsiderable)
Check whether we already have this txid in:
std::vector< TxOrphanage::PoolTx > GetOrphanTransactions() const
void BlockConnected(const std::shared_ptr< const CBlock > &pblock)
CTransactionRef GetTxToReconsider(NodeId nodeid)
std::vector< TxId > GetUniqueParents(const CTransaction &tx)
Helper for getting deduplicated vector of Txids in vin.
CRollingBloomFilter & RecentRejectsPackageReconsiderableFilter()
bool AddTxAnnouncement(NodeId peer, const TxId &txid, std::chrono::microseconds now)
Consider adding this tx hash to txrequest.
CRollingBloomFilter & RecentRejectsFilter()
void MempoolRejectedPackage(const Package &package)
@ TX_MISSING_INPUTS
transaction was missing some of its inputs
@ TX_PACKAGE_RECONSIDERABLE
fails some policy, but might be acceptable if submitted in a (different) package
int64_t NodeId
Definition eviction.h:16
std::chrono::microseconds ComputeRequestTime(const InvRequestTracker< InvId > &requestTracker, NodeId nodeid, const DataRequestParameters &requestParams, std::chrono::microseconds current_time, bool preferred, bool bypass_limits)
Compute the request time for this announcement, current time plus delays for:
Definition invrequest.h:414
bool TooManyAnnouncements(const InvRequestTracker< InvId > &requestTracker, NodeId nodeid, const DataRequestParameters &requestParams, bool bypass_limits)
Whether the peer already has too many announcements tracked to accept a new one.
Definition invrequest.h:396
#define LogDebug(category,...)
Definition logging.h:446
@ TXPACKAGES
Definition logging.h:99
@ MEMPOOL
Definition logging.h:71
@ NET
Definition logging.h:69
static constexpr DataRequestParameters TX_REQUEST_PARAMS
Parameters for the tx requests, see DataRequestParameters.
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition rcu.h:259
uint256 GetPackageHash(const Package &package)
Definition packages.cpp:129
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition packages.h:40
std::shared_ptr< const CTransaction > CTransactionRef
const size_t max_peer_announcements
Maximum number of inventories to consider for requesting, per peer.
Definition invrequest.h:366
const std::chrono::microseconds getdata_interval
How long to wait (in microseconds) before a data request from an additional peer.
Definition invrequest.h:381
A TxId is the identifier of a transaction.
Definition txid.h:14
const uint32_t m_max_orphan_txs
Maximum number of transactions allowed in orphanage.
const CTxMemPool & m_mempool
Read-only reference to mempool.
assert(!tx.IsCoinBase())