Skip to content

Commit 3d4d4f0

Browse files
monlovesmangoglozow
authored andcommitted
scripted-diff: rename "ann" variables to "latency_score"
-BEGIN VERIFY SCRIPT- sed -i 's/max_global_ann/max_global_latency_score/g' src/node/txorphanage.cpp sed -i 's/max_global_ann/max_global_latency_score/g' src/node/txorphanage.h sed -i 's/max_global_ann/max_global_latency_score/g' src/test/orphanage_tests.cpp sed -i 's/max_global_ann/max_global_latency_score/g' src/test/fuzz/txorphan.cpp sed -i 's/max_global_ann/max_global_latency_score/g' src/bench/txorphanage.cpp sed -i 's/max_ann/max_lat/g' src/node/txorphanage.cpp -END VERIFY SCRIPT-
1 parent 3b92448 commit 3d4d4f0

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

src/bench/txorphanage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void OrphanageSinglePeerEviction(benchmark::Bench& bench)
6868
auto large_tx = MakeTransactionBulkedTo(1, MAX_STANDARD_TX_WEIGHT, det_rand);
6969
assert(GetTransactionWeight(*large_tx) <= MAX_STANDARD_TX_WEIGHT);
7070

71-
const auto orphanage{node::MakeTxOrphanage(/*max_global_ann=*/node::DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE, /*reserved_peer_usage=*/node::DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER)};
71+
const auto orphanage{node::MakeTxOrphanage(/*max_global_latency_score=*/node::DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE, /*reserved_peer_usage=*/node::DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER)};
7272

7373
// Populate the orphanage. To maximize the number of evictions, first fill up with tiny transactions, then add a huge one.
7474
NodeId peer{0};
@@ -131,7 +131,7 @@ static void OrphanageMultiPeerEviction(benchmark::Bench& bench)
131131
indexes.resize(NUM_UNIQUE_TXNS);
132132
std::iota(indexes.begin(), indexes.end(), 0);
133133

134-
const auto orphanage{node::MakeTxOrphanage(/*max_global_ann=*/node::DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE, /*reserved_peer_usage=*/node::DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER)};
134+
const auto orphanage{node::MakeTxOrphanage(/*max_global_latency_score=*/node::DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE, /*reserved_peer_usage=*/node::DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER)};
135135
// Every peer sends the same transactions, all from shared_txs.
136136
// Each peer has 1 or 2 assigned transactions, which they must place as the last and second-to-last positions.
137137
// The assignments ensure that every transaction is in some peer's last 2 transactions, and is thus remains in the orphanage until the end of LimitOrphans.
@@ -189,7 +189,7 @@ static void OrphanageMultiPeerEviction(benchmark::Bench& bench)
189189
static void OrphanageEraseAll(benchmark::Bench& bench, bool block_or_disconnect)
190190
{
191191
FastRandomContext det_rand{true};
192-
const auto orphanage{node::MakeTxOrphanage(/*max_global_ann=*/node::DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE, /*reserved_peer_usage=*/node::DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER)};
192+
const auto orphanage{node::MakeTxOrphanage(/*max_global_latency_score=*/node::DEFAULT_MAX_ORPHANAGE_LATENCY_SCORE, /*reserved_peer_usage=*/node::DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER)};
193193
// This is an unrealistically large number of inputs for a block, as there is almost no room given to witness data,
194194
// outputs, and overhead for individual transactions. The entire block is 1 transaction with 20,000 inputs.
195195
constexpr unsigned int NUM_BLOCK_INPUTS{MAX_BLOCK_WEIGHT / APPROX_WEIGHT_PER_INPUT};

src/node/txorphanage.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ class TxOrphanageImpl final : public TxOrphanage {
189189

190190
public:
191191
TxOrphanageImpl() = default;
192-
TxOrphanageImpl(Count max_global_ann, Usage reserved_peer_usage) :
193-
m_max_global_latency_score{max_global_ann},
192+
TxOrphanageImpl(Count max_global_latency_score, Usage reserved_peer_usage) :
193+
m_max_global_latency_score{max_global_latency_score},
194194
m_reserved_usage_per_peer{reserved_peer_usage}
195195
{}
196196
~TxOrphanageImpl() noexcept override = default;
@@ -447,7 +447,7 @@ void TxOrphanageImpl::LimitOrphans()
447447

448448
// Even though it's possible for MaxPeerLatencyScore to increase within this call to LimitOrphans
449449
// (e.g. if a peer's orphans are removed entirely, changing the number of peers), use consistent limits throughout.
450-
const auto max_ann{MaxPeerLatencyScore()};
450+
const auto max_lat{MaxPeerLatencyScore()};
451451
const auto max_mem{ReservedPeerUsage()};
452452

453453
// We have exceeded the global limit(s). Now, identify who is using too much and evict their orphans.
@@ -456,7 +456,7 @@ void TxOrphanageImpl::LimitOrphans()
456456
heap_peer_dos.reserve(m_peer_orphanage_info.size());
457457
for (const auto& [nodeid, entry] : m_peer_orphanage_info) {
458458
// Performance optimization: only consider peers with a DoS score > 1.
459-
const auto dos_score = entry.GetDosScore(max_ann, max_mem);
459+
const auto dos_score = entry.GetDosScore(max_lat, max_mem);
460460
if (dos_score >> FeeFrac{1, 1}) {
461461
heap_peer_dos.emplace_back(nodeid, dos_score);
462462
}
@@ -506,7 +506,7 @@ void TxOrphanageImpl::LimitOrphans()
506506

507507
// If we erased the last orphan from this peer, it_worst_peer will be invalidated.
508508
it_worst_peer = m_peer_orphanage_info.find(worst_peer);
509-
if (it_worst_peer == m_peer_orphanage_info.end() || it_worst_peer->second.GetDosScore(max_ann, max_mem) <= dos_threshold) break;
509+
if (it_worst_peer == m_peer_orphanage_info.end() || it_worst_peer->second.GetDosScore(max_lat, max_mem) <= dos_threshold) break;
510510
}
511511
LogDebug(BCLog::TXPACKAGES, "peer=%d orphanage overflow, removed %u of %u announcements\n", worst_peer, num_erased_this_round, starting_num_ann);
512512

@@ -515,7 +515,7 @@ void TxOrphanageImpl::LimitOrphans()
515515
// Unless this peer is empty, put it back in the heap so we continue to consider evicting its orphans.
516516
// We may select this peer for evictions again if there are multiple DoSy peers.
517517
if (it_worst_peer != m_peer_orphanage_info.end() && it_worst_peer->second.m_count_announcements > 0) {
518-
heap_peer_dos.emplace_back(worst_peer, it_worst_peer->second.GetDosScore(max_ann, max_mem));
518+
heap_peer_dos.emplace_back(worst_peer, it_worst_peer->second.GetDosScore(max_lat, max_mem));
519519
std::push_heap(heap_peer_dos.begin(), heap_peer_dos.end(), compare_score);
520520
}
521521
} while (true);
@@ -774,8 +774,8 @@ std::unique_ptr<TxOrphanage> MakeTxOrphanage() noexcept
774774
{
775775
return std::make_unique<TxOrphanageImpl>();
776776
}
777-
std::unique_ptr<TxOrphanage> MakeTxOrphanage(TxOrphanage::Count max_global_ann, TxOrphanage::Usage reserved_peer_usage) noexcept
777+
std::unique_ptr<TxOrphanage> MakeTxOrphanage(TxOrphanage::Count max_global_latency_score, TxOrphanage::Usage reserved_peer_usage) noexcept
778778
{
779-
return std::make_unique<TxOrphanageImpl>(max_global_ann, reserved_peer_usage);
779+
return std::make_unique<TxOrphanageImpl>(max_global_latency_score, reserved_peer_usage);
780780
}
781781
} // namespace node

src/node/txorphanage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ class TxOrphanage {
146146

147147
/** Create a new TxOrphanage instance */
148148
std::unique_ptr<TxOrphanage> MakeTxOrphanage() noexcept;
149-
std::unique_ptr<TxOrphanage> MakeTxOrphanage(TxOrphanage::Count max_global_ann, TxOrphanage::Usage reserved_peer_usage) noexcept;
149+
std::unique_ptr<TxOrphanage> MakeTxOrphanage(TxOrphanage::Count max_global_latency_score, TxOrphanage::Usage reserved_peer_usage) noexcept;
150150
} // namespace node
151151
#endif // BITCOIN_NODE_TXORPHANAGE_H

src/test/fuzz/txorphan.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ FUZZ_TARGET(txorphanage_sim)
470470
// 3. Initialize real orphanage
471471
//
472472

473-
auto max_global_ann = provider.ConsumeIntegralInRange<node::TxOrphanage::Count>(NUM_PEERS, MAX_ANN);
473+
auto max_global_latency_score = provider.ConsumeIntegralInRange<node::TxOrphanage::Count>(NUM_PEERS, MAX_ANN);
474474
auto reserved_peer_usage = provider.ConsumeIntegralInRange<node::TxOrphanage::Usage>(1, total_usage);
475-
auto real = node::MakeTxOrphanage(max_global_ann, reserved_peer_usage);
475+
auto real = node::MakeTxOrphanage(max_global_latency_score, reserved_peer_usage);
476476

477477
//
478478
// 4. Functions and data structures for the simulation.
@@ -683,7 +683,7 @@ FUZZ_TARGET(txorphanage_sim)
683683
}
684684
}
685685
// Always trim after each command if needed.
686-
const auto max_ann = max_global_ann / std::max<unsigned>(1, count_peers_fn());
686+
const auto max_ann = max_global_latency_score / std::max<unsigned>(1, count_peers_fn());
687687
const auto max_mem = reserved_peer_usage;
688688
while (true) {
689689
// Count global usage and number of peers.
@@ -813,12 +813,12 @@ FUZZ_TARGET(txorphanage_sim)
813813
// CountUniqueOrphans
814814
assert(unique_orphans == real->CountUniqueOrphans());
815815
// MaxGlobalLatencyScore
816-
assert(max_global_ann == real->MaxGlobalLatencyScore());
816+
assert(max_global_latency_score == real->MaxGlobalLatencyScore());
817817
// ReservedPeerUsage
818818
assert(reserved_peer_usage == real->ReservedPeerUsage());
819819
// MaxPeerLatencyScore
820820
auto present_peers = count_peers_fn();
821-
assert(max_global_ann / std::max<unsigned>(1, present_peers) == real->MaxPeerLatencyScore());
821+
assert(max_global_latency_score / std::max<unsigned>(1, present_peers) == real->MaxPeerLatencyScore());
822822
// MaxGlobalUsage
823823
assert(reserved_peer_usage * std::max<unsigned>(1, present_peers) == real->MaxGlobalUsage());
824824
// TotalLatencyScore.

src/test/orphanage_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ BOOST_AUTO_TEST_CASE(peer_dos_limits)
9494
{
9595
// Test announcement limits
9696
NodeId peer{8};
97-
auto orphanage_low_ann = node::MakeTxOrphanage(/*max_global_ann=*/1, /*reserved_peer_usage=*/TX_SIZE * 10);
98-
auto orphanage_low_mem = node::MakeTxOrphanage(/*max_global_ann=*/10, /*reserved_peer_usage=*/TX_SIZE);
97+
auto orphanage_low_ann = node::MakeTxOrphanage(/*max_global_latency_score=*/1, /*reserved_peer_usage=*/TX_SIZE * 10);
98+
auto orphanage_low_mem = node::MakeTxOrphanage(/*max_global_latency_score=*/10, /*reserved_peer_usage=*/TX_SIZE);
9999

100100
// Add the first transaction
101101
orphanage_low_ann->AddTx(txns.at(0), peer);
@@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(peer_dos_limits)
119119
{
120120
// Test latency score limits
121121
NodeId peer{10};
122-
auto orphanage_low_ann = node::MakeTxOrphanage(/*max_global_ann=*/5, /*reserved_peer_usage=*/TX_SIZE * 1000);
122+
auto orphanage_low_ann = node::MakeTxOrphanage(/*max_global_latency_score=*/5, /*reserved_peer_usage=*/TX_SIZE * 1000);
123123

124124
// Add the first transaction
125125
orphanage_low_ann->AddTx(txns.at(0), peer);
@@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(peer_dos_limits)
153153

154154
// Test announcement limits
155155
NodeId peer{9};
156-
auto orphanage = node::MakeTxOrphanage(/*max_global_ann=*/3, /*reserved_peer_usage=*/TX_SIZE * 10);
156+
auto orphanage = node::MakeTxOrphanage(/*max_global_latency_score=*/3, /*reserved_peer_usage=*/TX_SIZE * 10);
157157

158158
// First add a tx which will be made reconsiderable.
159159
orphanage->AddTx(children.at(0), peer);

0 commit comments

Comments
 (0)