Skip to content

Commit 2315830

Browse files
committed
fuzz: Fix assert bug in txorphan target
1 parent 826fae6 commit 2315830

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/test/fuzz/txorphan.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <consensus/amount.h>
6-
#include <net.h>
6+
#include <consensus/validation.h>
77
#include <net_processing.h>
8+
#include <node/eviction.h>
9+
#include <policy/policy.h>
810
#include <primitives/transaction.h>
911
#include <script/script.h>
1012
#include <sync.h>
@@ -99,16 +101,20 @@ FUZZ_TARGET_INIT(txorphan, initialize_orphanage)
99101
[&] {
100102
bool have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash()));
101103
// AddTx should return false if tx is too big or already have it
104+
// tx weight is unknown, we only check when tx is already in orphanage
102105
{
103106
LOCK(g_cs_orphans);
104-
Assert(have_tx != orphanage.AddTx(tx, peer_id));
107+
bool add_tx = orphanage.AddTx(tx, peer_id);
108+
// have_tx == true -> add_tx == false
109+
Assert(!have_tx || !add_tx);
105110
}
106111
have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash()));
107-
// tx should already be added since it will not be too big in the test
108-
// have_tx should be true and AddTx should fail
109112
{
110113
LOCK(g_cs_orphans);
111-
Assert(have_tx && !orphanage.AddTx(tx, peer_id));
114+
bool add_tx = orphanage.AddTx(tx, peer_id);
115+
// if have_tx is still false, it must be too big
116+
Assert(!have_tx == GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT);
117+
Assert(!have_tx || !add_tx);
112118
}
113119
},
114120
[&] {

0 commit comments

Comments
 (0)