diff options
author | glozow <gloriajzhao@gmail.com> | 2023-09-13 15:33:32 +0100 |
---|---|---|
committer | glozow <gloriajzhao@gmail.com> | 2023-09-13 16:14:17 +0100 |
commit | 7d7f7a1189432b1b6245ba25df572229870567cb (patch) | |
tree | 528f526514f2d398b15a9ecaf746014a5dd6a988 /src/policy/packages.cpp | |
parent | b2ec0326fd76e64a6d0d7e4745506b29f60d0be5 (diff) | |
download | bitcoin-7d7f7a1189432b1b6245ba25df572229870567cb.tar.xz |
[policy] check for duplicate txids in package
Duplicates of normal transactions would be found by looking for
conflicting inputs, but this doesn't catch identical empty transactions.
These wouldn't be valid but exiting early is good and AcceptPackage's
result sanity checks assume non-duplicate transactions.
Diffstat (limited to 'src/policy/packages.cpp')
-rw-r--r-- | src/policy/packages.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/policy/packages.cpp b/src/policy/packages.cpp index 6e70a94088..a901ef8f38 100644 --- a/src/policy/packages.cpp +++ b/src/policy/packages.cpp @@ -37,6 +37,13 @@ bool CheckPackage(const Package& txns, PackageValidationState& state) std::unordered_set<uint256, SaltedTxidHasher> later_txids; std::transform(txns.cbegin(), txns.cend(), std::inserter(later_txids, later_txids.end()), [](const auto& tx) { return tx->GetHash(); }); + + // Package must not contain any duplicate transactions, which is checked by txid. This also + // includes transactions with duplicate wtxids and same-txid-different-witness transactions. + if (later_txids.size() != txns.size()) { + return state.Invalid(PackageValidationResult::PCKG_POLICY, "package-contains-duplicates"); + } + for (const auto& tx : txns) { for (const auto& input : tx->vin) { if (later_txids.find(input.prevout.hash) != later_txids.end()) { |