Skip to content

Commit

Permalink
fuzz: Check package rbf invariants in tx_package_eval
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Dec 8, 2023
1 parent 880486a commit 7aee728
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/test/util/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <chainparams.h>
#include <node/context.h>
#include <node/mempool_args.h>
#include <policy/rbf.h>
#include <txmempool.h>
#include <util/check.h>
#include <util/time.h>
Expand Down Expand Up @@ -66,10 +67,24 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
return strprintf("tx %s unexpectedly failed: %s", wtxid.ToString(), atmp_result.m_state.ToString());
}

//m_replaced_transactions should exist iff the result was VALID
if (atmp_result.m_replaced_transactions.has_value() != valid) {
return strprintf("tx %s result should %shave m_replaced_transactions",
if (atmp_result.m_replaced_transactions.has_value()) {
// m_replaced_transactions should exist iff the result was VALID
if (!valid) {
return strprintf("tx %s result should %shave m_replaced_transactions",
wtxid.ToString(), valid ? "" : "not ");
}
// Each subpackage is allowed MAX_REPLACEMENT_CANDIDATES replacements (only checking individually here)
if (atmp_result.m_replaced_transactions.value().size() > MAX_REPLACEMENT_CANDIDATES) {
return strprintf("tx %s result replaced too many transactions",
wtxid.ToString());
}

// Replacements can't happen for subpackages larger than 2
if (!atmp_result.m_replaced_transactions.value().empty() &&
atmp_result.m_wtxids_fee_calculations.has_value() && atmp_result.m_wtxids_fee_calculations.value().size() > 2) {
return strprintf("tx %s was part of a too-large package RBF subpackage",
wtxid.ToString());
}
}

// m_vsize and m_base_fees should exist iff the result was VALID or MEMPOOL_ENTRY
Expand Down Expand Up @@ -112,6 +127,11 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
return strprintf("wtxid %s should not be in mempool", wtxid.ToString());
}
}
for (const auto& tx_ref : atmp_result.m_replaced_transactions.value()) {
if (mempool->exists(GenTxid::Txid(tx_ref->GetHash()))) {
return strprintf("tx %s should not be in mempool as it was replaced", tx_ref->GetWitnessHash().ToString());
}
}
}
}
return std::nullopt;
Expand Down

0 comments on commit 7aee728

Please sign in to comment.