diff options
author | chinggg <24590067+chinggg@users.noreply.github.com> | 2022-07-16 09:41:50 +0800 |
---|---|---|
committer | chinggg <24590067+chinggg@users.noreply.github.com> | 2022-07-17 08:04:24 +0800 |
commit | 2315830491b2cfa6b6e3e277700238e5ac92a8e0 (patch) | |
tree | dfe1e04f3426f6b8218546e3805b065b67d0e9b8 /src/test | |
parent | 826fae6a0fe184518af625ebb6d1ef9e64631385 (diff) |
fuzz: Fix assert bug in txorphan target
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/txorphan.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/test/fuzz/txorphan.cpp b/src/test/fuzz/txorphan.cpp index d318baa6a2..b18d783259 100644 --- a/src/test/fuzz/txorphan.cpp +++ b/src/test/fuzz/txorphan.cpp @@ -3,8 +3,10 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <consensus/amount.h> -#include <net.h> +#include <consensus/validation.h> #include <net_processing.h> +#include <node/eviction.h> +#include <policy/policy.h> #include <primitives/transaction.h> #include <script/script.h> #include <sync.h> @@ -99,16 +101,20 @@ FUZZ_TARGET_INIT(txorphan, initialize_orphanage) [&] { bool have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash())); // AddTx should return false if tx is too big or already have it + // tx weight is unknown, we only check when tx is already in orphanage { LOCK(g_cs_orphans); - Assert(have_tx != orphanage.AddTx(tx, peer_id)); + bool add_tx = orphanage.AddTx(tx, peer_id); + // have_tx == true -> add_tx == false + Assert(!have_tx || !add_tx); } have_tx = orphanage.HaveTx(GenTxid::Txid(tx->GetHash())) || orphanage.HaveTx(GenTxid::Wtxid(tx->GetHash())); - // tx should already be added since it will not be too big in the test - // have_tx should be true and AddTx should fail { LOCK(g_cs_orphans); - Assert(have_tx && !orphanage.AddTx(tx, peer_id)); + bool add_tx = orphanage.AddTx(tx, peer_id); + // if have_tx is still false, it must be too big + Assert(!have_tx == GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT); + Assert(!have_tx || !add_tx); } }, [&] { |