Skip to content

Commit fb49d62

Browse files
committed
Merge bitcoin/bitcoin#34177: policy/refactor: remove constant parameter from IsWellFormedPackage
658d381 policy: remove constant parameter from `IsWellFormedPackage` (Lőrinc) Pull request description: `IsWellFormedPackage()` already claims: "parents must appear before children." In practice the `require_sorted` argument was always passed as `true`, making the false-path dead code. It was introduced that way from the beginning in https://github.com/bitcoin/bitcoin/pull/28758/files#diff-f30090b30c9489972ee3f1181c302cf3a484bb890bade0fd7c9ca92ea8d347f6R79. Remove the unused parameter, updating callers/tests. ACKs for top commit: billymcbip: tACK 658d381 instagibbs: ACK 658d381 Tree-SHA512: 8b86dda7e2e1f0d48947ff258f0a3b6ec60676f54d4b506604d24e15c8b6465358ed2ccf174c7620125f5cad6bfc4df0bc482d920e5fc4cd0e1d72a9b16eafa5
2 parents adbb4b3 + 658d381 commit fb49d62

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/policy/packages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool IsConsistentPackage(const Package& txns)
7676
return true;
7777
}
7878

79-
bool IsWellFormedPackage(const Package& txns, PackageValidationState& state, bool require_sorted)
79+
bool IsWellFormedPackage(const Package& txns, PackageValidationState& state)
8080
{
8181
const unsigned int package_count = txns.size();
8282

@@ -105,7 +105,7 @@ bool IsWellFormedPackage(const Package& txns, PackageValidationState& state, boo
105105
// An unsorted package will fail anyway on missing-inputs, but it's better to quit earlier and
106106
// fail on something less ambiguous (missing-inputs could also be an orphan or trying to
107107
// spend nonexistent coins).
108-
if (require_sorted && !IsTopoSortedPackage(txns, later_txids)) {
108+
if (!IsTopoSortedPackage(txns, later_txids)) {
109109
return state.Invalid(PackageValidationResult::PCKG_POLICY, "package-not-sorted");
110110
}
111111

src/policy/packages.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bool IsConsistentPackage(const Package& txns);
7171
* 3. If any dependencies exist between transactions, parents must appear before children.
7272
* 4. Transactions cannot conflict, i.e., spend the same inputs.
7373
*/
74-
bool IsWellFormedPackage(const Package& txns, PackageValidationState& state, bool require_sorted);
74+
bool IsWellFormedPackage(const Package& txns, PackageValidationState& state);
7575

7676
/** Context-free check that a package is exactly one child and its parents; not all parents need to
7777
* be present, but the package must not contain any transactions that are not the child's parents.

src/test/txpackage_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(package_sanitization_tests)
139139
package_too_many.emplace_back(create_placeholder_tx(1, 1));
140140
}
141141
PackageValidationState state_too_many;
142-
BOOST_CHECK(!IsWellFormedPackage(package_too_many, state_too_many, /*require_sorted=*/true));
142+
BOOST_CHECK(!IsWellFormedPackage(package_too_many, state_too_many));
143143
BOOST_CHECK_EQUAL(state_too_many.GetResult(), PackageValidationResult::PCKG_POLICY);
144144
BOOST_CHECK_EQUAL(state_too_many.GetRejectReason(), "package-too-many-transactions");
145145

@@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(package_sanitization_tests)
154154
}
155155
BOOST_CHECK(package_too_large.size() <= MAX_PACKAGE_COUNT);
156156
PackageValidationState state_too_large;
157-
BOOST_CHECK(!IsWellFormedPackage(package_too_large, state_too_large, /*require_sorted=*/true));
157+
BOOST_CHECK(!IsWellFormedPackage(package_too_large, state_too_large));
158158
BOOST_CHECK_EQUAL(state_too_large.GetResult(), PackageValidationResult::PCKG_POLICY);
159159
BOOST_CHECK_EQUAL(state_too_large.GetRejectReason(), "package-too-large");
160160

@@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(package_sanitization_tests)
165165
package_duplicate_txids_empty.emplace_back(MakeTransactionRef(empty_tx));
166166
}
167167
PackageValidationState state_duplicates;
168-
BOOST_CHECK(!IsWellFormedPackage(package_duplicate_txids_empty, state_duplicates, /*require_sorted=*/true));
168+
BOOST_CHECK(!IsWellFormedPackage(package_duplicate_txids_empty, state_duplicates));
169169
BOOST_CHECK_EQUAL(state_duplicates.GetResult(), PackageValidationResult::PCKG_POLICY);
170170
BOOST_CHECK_EQUAL(state_duplicates.GetRejectReason(), "package-contains-duplicates");
171171
BOOST_CHECK(!IsConsistentPackage(package_duplicate_txids_empty));
@@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(package_sanitization_tests)
184184
// Transactions are considered sorted when they have no dependencies.
185185
BOOST_CHECK(IsTopoSortedPackage(package_conflicts));
186186
PackageValidationState state_conflicts;
187-
BOOST_CHECK(!IsWellFormedPackage(package_conflicts, state_conflicts, /*require_sorted=*/true));
187+
BOOST_CHECK(!IsWellFormedPackage(package_conflicts, state_conflicts));
188188
BOOST_CHECK_EQUAL(state_conflicts.GetResult(), PackageValidationResult::PCKG_POLICY);
189189
BOOST_CHECK_EQUAL(state_conflicts.GetRejectReason(), "conflict-in-package");
190190

@@ -274,8 +274,8 @@ BOOST_AUTO_TEST_CASE(noncontextual_package_tests)
274274
CTransactionRef tx_child = MakeTransactionRef(mtx_child);
275275

276276
PackageValidationState state;
277-
BOOST_CHECK(IsWellFormedPackage({tx_parent, tx_child}, state, /*require_sorted=*/true));
278-
BOOST_CHECK(!IsWellFormedPackage({tx_child, tx_parent}, state, /*require_sorted=*/true));
277+
BOOST_CHECK(IsWellFormedPackage({tx_parent, tx_child}, state));
278+
BOOST_CHECK(!IsWellFormedPackage({tx_child, tx_parent}, state));
279279
BOOST_CHECK_EQUAL(state.GetResult(), PackageValidationResult::PCKG_POLICY);
280280
BOOST_CHECK_EQUAL(state.GetRejectReason(), "package-not-sorted");
281281
BOOST_CHECK(IsChildWithParents({tx_parent, tx_child}));
@@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE(noncontextual_package_tests)
308308
package.push_back(MakeTransactionRef(child));
309309

310310
PackageValidationState state;
311-
BOOST_CHECK(IsWellFormedPackage(package, state, /*require_sorted=*/true));
311+
BOOST_CHECK(IsWellFormedPackage(package, state));
312312
BOOST_CHECK(IsChildWithParents(package));
313313
BOOST_CHECK(IsChildWithParentsTree(package));
314314

@@ -346,8 +346,8 @@ BOOST_AUTO_TEST_CASE(noncontextual_package_tests)
346346
BOOST_CHECK(!IsChildWithParentsTree({tx_parent, tx_parent_also_child, tx_child}));
347347
// IsChildWithParents does not detect unsorted parents.
348348
BOOST_CHECK(IsChildWithParents({tx_parent_also_child, tx_parent, tx_child}));
349-
BOOST_CHECK(IsWellFormedPackage({tx_parent, tx_parent_also_child, tx_child}, state, /*require_sorted=*/true));
350-
BOOST_CHECK(!IsWellFormedPackage({tx_parent_also_child, tx_parent, tx_child}, state, /*require_sorted=*/true));
349+
BOOST_CHECK(IsWellFormedPackage({tx_parent, tx_parent_also_child, tx_child}, state));
350+
BOOST_CHECK(!IsWellFormedPackage({tx_parent_also_child, tx_parent, tx_child}, state));
351351
BOOST_CHECK_EQUAL(state.GetResult(), PackageValidationResult::PCKG_POLICY);
352352
BOOST_CHECK_EQUAL(state.GetRejectReason(), "package-not-sorted");
353353
}

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactionsInternal(con
14401440

14411441
// These context-free package limits can be done before taking the mempool lock.
14421442
PackageValidationState package_state;
1443-
if (!IsWellFormedPackage(txns, package_state, /*require_sorted=*/true)) return PackageMempoolAcceptResult(package_state, {});
1443+
if (!IsWellFormedPackage(txns, package_state)) return PackageMempoolAcceptResult(package_state, {});
14441444

14451445
std::vector<Workspace> workspaces{};
14461446
workspaces.reserve(txns.size());
@@ -1637,7 +1637,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
16371637
// transactions and thus won't return any MempoolAcceptResults, just a package-wide error.
16381638

16391639
// Context-free package checks.
1640-
if (!IsWellFormedPackage(package, package_state_quit_early, /*require_sorted=*/true)) {
1640+
if (!IsWellFormedPackage(package, package_state_quit_early)) {
16411641
return PackageMempoolAcceptResult(package_state_quit_early, {});
16421642
}
16431643

0 commit comments

Comments
 (0)