Skip to content

Commit 910d38b

Browse files
committed
Merge bitcoin/bitcoin#30474: fuzz: Speed up PickValue in txorphan
fa33a63 fuzz: Speed up PickValue in txorphan (MarcoFalke) Pull request description: `PickValue` will advance a begin iterator on the `outpoints` set, which is expensive, because it only has a `++` operator. As it is called in a loop of `num_in` (~`outpoints.size()`), the runtime is `O(outpoints.size() ^ 2)`. Fix it by making the runtime linear. ACKs for top commit: glozow: ACK fa33a63, thanks for taking the suggestion dergoegge: utACK fa33a63 Tree-SHA512: 33f440d97c6834d907d43a8d29e4fb2c995f0d244460bd079af100f13d3607a53e44a0db52f4eb5c487d98df0ff4f2f6d987bf94b922ae9f4506f1295ad6214c
2 parents 8754d05 + fa33a63 commit 910d38b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/test/fuzz/txorphan.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022 The Bitcoin Core developers
1+
// Copyright (c) 2022-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -37,11 +37,11 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
3737
SetMockTime(ConsumeTime(fuzzed_data_provider));
3838

3939
TxOrphanage orphanage;
40-
std::set<COutPoint> outpoints;
40+
std::vector<COutPoint> outpoints; // Duplicates are tolerated
4141

4242
// initial outpoints used to construct transactions later
4343
for (uint8_t i = 0; i < 4; i++) {
44-
outpoints.emplace(Txid::FromUint256(uint256{i}), 0);
44+
outpoints.emplace_back(Txid::FromUint256(uint256{i}), 0);
4545
}
4646

4747
CTransactionRef ptx_potential_parent = nullptr;
@@ -67,7 +67,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
6767
auto new_tx = MakeTransactionRef(tx_mut);
6868
// add newly constructed outpoints to the coin pool
6969
for (uint32_t i = 0; i < num_out; i++) {
70-
outpoints.emplace(new_tx->GetHash(), i);
70+
outpoints.emplace_back(new_tx->GetHash(), i);
7171
}
7272
return new_tx;
7373
}();

0 commit comments

Comments
 (0)