Skip to content

Commit 3b92448

Browse files
committed
[doc] comment fixups for orphanage changes
1 parent 1384dba commit 3b92448

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/node/txorphanage.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TxOrphanageImpl final : public TxOrphanage {
5151

5252
/** Get an approximation for "memory usage". The total memory is a function of the memory used to store the
5353
* transaction itself, each entry in m_orphans, and each entry in m_outpoint_to_orphan_wtxids. We use weight because
54-
* it is often higher than the actual memory usage of the tranaction. This metric conveniently encompasses
54+
* it is often higher than the actual memory usage of the transaction. This metric conveniently encompasses
5555
* m_outpoint_to_orphan_wtxids usage since input data does not get the witness discount, and makes it easier to
5656
* reason about each peer's limits using well-understood transaction attributes. */
5757
TxOrphanage::Usage GetMemUsage() const {
@@ -158,13 +158,13 @@ class TxOrphanageImpl final : public TxOrphanage {
158158
* do not trim unless the orphanage exceeds global limits, but it means that this peer will
159159
* be selected for trimming sooner. If the global latency score or global memory usage
160160
* limits are exceeded, it must be that there is a peer whose DoS score > 1. */
161-
FeeFrac GetDosScore(TxOrphanage::Count max_peer_latency_score, TxOrphanage::Usage max_peer_bytes) const
161+
FeeFrac GetDosScore(TxOrphanage::Count max_peer_latency_score, TxOrphanage::Usage max_peer_memory) const
162162
{
163163
assert(max_peer_latency_score > 0);
164-
assert(max_peer_bytes > 0);
165-
const FeeFrac cpu_score(m_total_latency_score, max_peer_latency_score);
166-
const FeeFrac mem_score(m_total_usage, max_peer_bytes);
167-
return std::max<FeeFrac>(cpu_score, mem_score);
164+
assert(max_peer_memory > 0);
165+
const FeeFrac latency_score(m_total_latency_score, max_peer_latency_score);
166+
const FeeFrac mem_score(m_total_usage, max_peer_memory);
167+
return std::max<FeeFrac>(latency_score, mem_score);
168168
}
169169
};
170170
/** Store per-peer statistics. Used to determine each peer's DoS score. The size of this map is used to determine the
@@ -205,7 +205,7 @@ class TxOrphanageImpl final : public TxOrphanage {
205205
TxOrphanage::Count TotalLatencyScore() const override;
206206
TxOrphanage::Usage ReservedPeerUsage() const override;
207207

208-
/** Maximum allowed (deduplicated) latency score for all tranactions (see Announcement::GetLatencyScore()). Dynamic
208+
/** Maximum allowed (deduplicated) latency score for all transactions (see Announcement::GetLatencyScore()). Dynamic
209209
* based on number of peers. Each peer has an equal amount, but the global maximum latency score stays constant. The
210210
* number of peers times MaxPeerLatencyScore() (rounded) adds up to MaxGlobalLatencyScore(). As long as every peer's
211211
* m_total_latency_score / MaxPeerLatencyScore() < 1, MaxGlobalLatencyScore() is not exceeded. */
@@ -469,11 +469,11 @@ void TxOrphanageImpl::LimitOrphans()
469469
std::make_heap(heap_peer_dos.begin(), heap_peer_dos.end(), compare_score);
470470

471471
unsigned int num_erased{0};
472-
// This outer loop finds the peer with the highest DoS score, which is a fraction of {usage, announcements} used
472+
// This outer loop finds the peer with the highest DoS score, which is a fraction of memory and latency scores
473473
// over the respective allowances. We continue until the orphanage is within global limits. That means some peers
474474
// might still have a DoS score > 1 at the end.
475-
// Note: if ratios are the same, FeeFrac tiebreaks by denominator. In practice, since the CPU denominator (number of
476-
// announcements) is always lower, this means that a peer with only high number of announcements will be targeted
475+
// Note: if ratios are the same, FeeFrac tiebreaks by denominator. In practice, since the latency denominator (number of
476+
// announcements and inputs) is always lower, this means that a peer with only high latency scores will be targeted
477477
// before a peer using a lot of memory, even if they have the same ratios.
478478
do {
479479
Assume(!heap_peer_dos.empty());
@@ -640,8 +640,6 @@ void TxOrphanageImpl::EraseForBlock(const CBlock& block)
640640
LimitOrphans();
641641
}
642642

643-
/** Get all children that spend from this tx and were received from nodeid. Sorted from most
644-
* recent to least recent. */
645643
std::vector<CTransactionRef> TxOrphanageImpl::GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId peer) const
646644
{
647645
std::vector<CTransactionRef> children_found;

src/node/txorphanage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class TxOrphanage {
9494
/** Does this peer have any work to do? */
9595
virtual bool HaveTxToReconsider(NodeId peer) = 0;
9696

97-
/** Get all children that spend from this tx and were received from nodeid. Sorted from most
98-
* recent to least recent. */
97+
/** Get all children that spend from this tx and were received from nodeid. Sorted
98+
* reconsiderable before non-reconsiderable, then from most recent to least recent. */
9999
virtual std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const = 0;
100100

101101
/** Get all orphan transactions */

src/test/fuzz/txorphan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ FUZZ_TARGET(txorphan_protected, .init = initialize_orphanage)
367367
FUZZ_TARGET(txorphanage_sim)
368368
{
369369
SeedRandomStateForTest(SeedRand::ZEROS);
370-
// This is a comphehensive simulation fuzz test, which runs through a scenario involving up to
370+
// This is a comprehensive simulation fuzz test, which runs through a scenario involving up to
371371
// 16 transactions (which may have simple or complex topology, and may have duplicate txids
372372
// with distinct wtxids, and up to 16 peers. The scenario is performed both on a real
373373
// TxOrphanage object and the behavior is compared with a naive reimplementation (just a vector
@@ -726,7 +726,7 @@ FUZZ_TARGET(txorphanage_sim)
726726
}
727727
assert(done);
728728
}
729-
// We must now be within limits, otherwise LimitOrphans should have continued further).
729+
// We must now be within limits, otherwise LimitOrphans should have continued further.
730730
// We don't check the contents of the orphanage until the end to make fuzz runs faster.
731731
assert(real->TotalLatencyScore() <= real->MaxGlobalLatencyScore());
732732
assert(real->TotalOrphanUsage() <= real->MaxGlobalUsage());

0 commit comments

Comments
 (0)