aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2023-10-04 10:06:22 +0100
committerglozow <gloriajzhao@gmail.com>2023-11-07 11:26:17 +0000
commit1147e00e59e47f27024ec96629993c66a3ce4ef0 (patch)
treed33cde18586975b8582b3a6056d26731157d8c92 /src/test
parent10dd9f2441f4618321bfa2865449ac2223c572a0 (diff)
downloadbitcoin-1147e00e59e47f27024ec96629993c66a3ce4ef0.tar.xz
[validation] change package-fee-too-low, return wtxid(s) and effective feerate
With subpackage evaluation and de-duplication, it's not always the entire package that is used in CheckFeerate. To be more helpful to the caller, specify which transactions were included in the evaluation and what the feerate was. Instead of PCKG_POLICY (which is supposed to be for package-wide errors), use PCKG_TX.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/tx_pool.cpp9
-rw-r--r--src/test/txpackage_tests.cpp17
-rw-r--r--src/test/util/txmempool.cpp7
3 files changed, 25 insertions, 8 deletions
diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp
index 66e537a57b..96095539ec 100644
--- a/src/test/fuzz/tx_pool.cpp
+++ b/src/test/fuzz/tx_pool.cpp
@@ -154,12 +154,15 @@ void CheckATMPInvariants(const MempoolAcceptResult& res, bool txid_in_mempool, b
// It may be already in the mempool since in ATMP cases we don't set MEMPOOL_ENTRY or DIFFERENT_WITNESS
Assert(!res.m_state.IsValid());
Assert(res.m_state.IsInvalid());
+
+ const bool is_reconsiderable{res.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE};
Assert(!res.m_replaced_transactions);
Assert(!res.m_vsize);
Assert(!res.m_base_fees);
- // Unable or unwilling to calculate fees
- Assert(!res.m_effective_feerate);
- Assert(!res.m_wtxids_fee_calculations);
+ // Fee information is provided if the failure is TX_RECONSIDERABLE.
+ // In other cases, validation may be unable or unwilling to calculate the fees.
+ Assert(res.m_effective_feerate.has_value() == is_reconsiderable);
+ Assert(res.m_wtxids_fee_calculations.has_value() == is_reconsiderable);
Assert(!res.m_other_wtxid);
break;
}
diff --git a/src/test/txpackage_tests.cpp b/src/test/txpackage_tests.cpp
index 30e16ee365..84c9ecc3d1 100644
--- a/src/test/txpackage_tests.cpp
+++ b/src/test/txpackage_tests.cpp
@@ -753,15 +753,26 @@ BOOST_FIXTURE_TEST_CASE(package_cpfp_tests, TestChain100Setup)
BOOST_CHECK(m_node.mempool->GetMinFee().GetFee(GetVirtualTransactionSize(*tx_parent_cheap) + GetVirtualTransactionSize(*tx_child_cheap)) > parent_fee + child_fee);
BOOST_CHECK_EQUAL(m_node.mempool->size(), expected_pool_size);
- // Cheap package should fail with package-fee-too-low.
+ // Cheap package should fail for being too low fee.
{
const auto submit_package_too_low = ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool,
package_still_too_low, /*test_accept=*/false);
- BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetResult(), PackageValidationResult::PCKG_POLICY);
- BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetRejectReason(), "package-fee-too-low");
if (auto err_package_too_low{CheckPackageMempoolAcceptResult(package_still_too_low, submit_package_too_low, /*expect_valid=*/false, m_node.mempool.get())}) {
BOOST_ERROR(err_package_too_low.value());
+ } else {
+ // Individual feerate of parent is too low.
+ BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_state.GetResult(),
+ TxValidationResult::TX_RECONSIDERABLE);
+ BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_parent_cheap->GetWitnessHash()).m_effective_feerate.value() ==
+ CFeeRate(parent_fee, GetVirtualTransactionSize(*tx_parent_cheap)));
+ // Package feerate of parent + child is too low.
+ BOOST_CHECK_EQUAL(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_state.GetResult(),
+ TxValidationResult::TX_RECONSIDERABLE);
+ BOOST_CHECK(submit_package_too_low.m_tx_results.at(tx_child_cheap->GetWitnessHash()).m_effective_feerate.value() ==
+ CFeeRate(parent_fee + child_fee, GetVirtualTransactionSize(*tx_parent_cheap) + GetVirtualTransactionSize(*tx_child_cheap)));
}
+ BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetResult(), PackageValidationResult::PCKG_TX);
+ BOOST_CHECK_EQUAL(submit_package_too_low.m_state.GetRejectReason(), "transaction failed");
BOOST_CHECK_EQUAL(m_node.mempool->size(), expected_pool_size);
}
diff --git a/src/test/util/txmempool.cpp b/src/test/util/txmempool.cpp
index 147e589deb..6d3bb01be8 100644
--- a/src/test/util/txmempool.cpp
+++ b/src/test/util/txmempool.cpp
@@ -89,11 +89,14 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
}
// m_effective_feerate and m_wtxids_fee_calculations should exist iff the result was valid
- if (atmp_result.m_effective_feerate.has_value() != valid) {
+ // or if the failure was TX_RECONSIDERABLE
+ const bool valid_or_reconsiderable{atmp_result.m_result_type == MempoolAcceptResult::ResultType::VALID ||
+ atmp_result.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE};
+ if (atmp_result.m_effective_feerate.has_value() != valid_or_reconsiderable) {
return strprintf("tx %s result should %shave m_effective_feerate",
wtxid.ToString(), valid ? "" : "not ");
}
- if (atmp_result.m_wtxids_fee_calculations.has_value() != valid) {
+ if (atmp_result.m_wtxids_fee_calculations.has_value() != valid_or_reconsiderable) {
return strprintf("tx %s result should %shave m_effective_feerate",
wtxid.ToString(), valid ? "" : "not ");
}