mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
Merge bitcoin/bitcoin#32631: refactor: Convert GenTxid to std::variant
a60f863d3escripted-diff: Replace GenTxidVariant with GenTxid (marcofleon)c8ba199598Remove old GenTxid class (marcofleon)072a198ea4Convert remaining instances of GenTxid to GenTxidVariant (marcofleon)1b528391c7Convert `txrequest` to GenTxidVariant (marcofleon)bde4579b07Convert `txdownloadman_impl` to GenTxidVariant (marcofleon)c876a892ecReplace GenTxid with Txid/Wtxid overloads in `txmempool` (marcofleon)de858ce2bemove-only: make GetInfo a private CTxMemPool member (stickies-v)eee473d9f3Convert `CompareInvMempoolOrder` to GenTxidVariant (marcofleon)243553d590refactor: replace get_iter_from_wtxid with GetIter(const Wtxid&) (stickies-v)fcf92fd640refactor: make CTxMemPool::GetIter strongly typed (marcofleon)11d28f21bbImplement GenTxid as a variant (marcofleon) Pull request description: Part of the [type safety refactor](https://github.com/bitcoin/bitcoin/pull/32189). This PR changes the GenTxid class to a variant, which holds both Txids and Wtxids. This provides compile-time type safety and eliminates the manual type check (bool m_is_wtxid). Variables that can be either a Txid or a Wtxid are now using the new GenTxid variant, instead of uint256. ACKs for top commit: w0xlt: ACKa60f863d3edergoegge: Code review ACKa60f863d3emaflcko: review ACKa60f863d3e🎽 theStack: Code-review ACKa60f863d3eTree-SHA512: da9b73b7bdffee2eb9281a409205519ac330d3336094d17681896703fbca8099608782c9c85801e388e4d90af5af8abf1f34931f57bbbe6e9674d802d6066047
This commit is contained in:
@@ -321,7 +321,7 @@ void Chainstate::MaybeUpdateMempoolForReorg(
|
||||
// If the transaction doesn't make it in to the mempool, remove any
|
||||
// transactions that depend on it (which would now be orphans).
|
||||
m_mempool->removeRecursive(**it, MemPoolRemovalReason::REORG);
|
||||
} else if (m_mempool->exists(GenTxid::Txid((*it)->GetHash()))) {
|
||||
} else if (m_mempool->exists((*it)->GetHash())) {
|
||||
vHashUpdate.push_back((*it)->GetHash());
|
||||
}
|
||||
++it;
|
||||
@@ -372,7 +372,7 @@ void Chainstate::MaybeUpdateMempoolForReorg(
|
||||
// If the transaction spends any coinbase outputs, it must be mature.
|
||||
if (it->GetSpendsCoinbase()) {
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
if (m_mempool->exists(GenTxid::Txid(txin.prevout.hash))) continue;
|
||||
if (m_mempool->exists(txin.prevout.hash)) continue;
|
||||
const Coin& coin{CoinsTip().AccessCoin(txin.prevout)};
|
||||
assert(!coin.IsSpent());
|
||||
const auto mempool_spend_height{m_chain.Tip()->nHeight + 1};
|
||||
@@ -807,10 +807,10 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
|
||||
return state.Invalid(TxValidationResult::TX_PREMATURE_SPEND, "non-final");
|
||||
}
|
||||
|
||||
if (m_pool.exists(GenTxid::Wtxid(tx.GetWitnessHash()))) {
|
||||
if (m_pool.exists(tx.GetWitnessHash())) {
|
||||
// Exact transaction already exists in the mempool.
|
||||
return state.Invalid(TxValidationResult::TX_CONFLICT, "txn-already-in-mempool");
|
||||
} else if (m_pool.exists(GenTxid::Txid(tx.GetHash()))) {
|
||||
} else if (m_pool.exists(tx.GetHash())) {
|
||||
// Transaction with the same non-witness data but different witness (same txid, different
|
||||
// wtxid) already exists in the mempool.
|
||||
return state.Invalid(TxValidationResult::TX_CONFLICT, "txn-same-nonwitness-data-in-mempool");
|
||||
@@ -1135,8 +1135,7 @@ bool MemPoolAccept::PackageMempoolChecks(const std::vector<CTransactionRef>& txn
|
||||
AssertLockHeld(m_pool.cs);
|
||||
|
||||
// CheckPackageLimits expects the package transactions to not already be in the mempool.
|
||||
assert(std::all_of(txns.cbegin(), txns.cend(), [this](const auto& tx)
|
||||
{ return !m_pool.exists(GenTxid::Txid(tx->GetHash()));}));
|
||||
assert(std::all_of(txns.cbegin(), txns.cend(), [this](const auto& tx) { return !m_pool.exists(tx->GetHash()); }));
|
||||
|
||||
assert(txns.size() == workspaces.size());
|
||||
|
||||
@@ -1346,8 +1345,7 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
|
||||
AssertLockHeld(m_pool.cs);
|
||||
// Sanity check: none of the transactions should be in the mempool, and none of the transactions
|
||||
// should have a same-txid-different-witness equivalent in the mempool.
|
||||
assert(std::all_of(workspaces.cbegin(), workspaces.cend(), [this](const auto& ws){
|
||||
return !m_pool.exists(GenTxid::Txid(ws.m_ptx->GetHash())); }));
|
||||
assert(std::all_of(workspaces.cbegin(), workspaces.cend(), [this](const auto& ws) { return !m_pool.exists(ws.m_ptx->GetHash()); }));
|
||||
|
||||
bool all_submitted = true;
|
||||
FinalizeSubpackage(args);
|
||||
@@ -1472,7 +1470,7 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
|
||||
// Limit the mempool, if appropriate.
|
||||
if (!args.m_package_submission && !args.m_bypass_limits) {
|
||||
LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip());
|
||||
if (!m_pool.exists(GenTxid::Txid(ws.m_hash))) {
|
||||
if (!m_pool.exists(ws.m_hash)) {
|
||||
// The tx no longer meets our (new) mempool minimum feerate but could be reconsidered in a package.
|
||||
ws.m_state.Invalid(TxValidationResult::TX_RECONSIDERABLE, "mempool full");
|
||||
return MempoolAcceptResult::FeeFailure(ws.m_state, CFeeRate(ws.m_modified_fees, ws.m_vsize), {ws.m_ptx->GetWitnessHash()});
|
||||
@@ -1767,7 +1765,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
|
||||
// There are 3 possibilities: already in mempool, same-txid-diff-wtxid already in mempool,
|
||||
// or not in mempool. An already confirmed tx is treated as one not in mempool, because all
|
||||
// we know is that the inputs aren't available.
|
||||
if (m_pool.exists(GenTxid::Wtxid(wtxid))) {
|
||||
if (m_pool.exists(wtxid)) {
|
||||
// Exact transaction already exists in the mempool.
|
||||
// Node operators are free to set their mempool policies however they please, nodes may receive
|
||||
// transactions in different orders, and malicious counterparties may try to take advantage of
|
||||
@@ -1779,7 +1777,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
|
||||
// checking ancestor/descendant limits, or double-count transaction fees for fee-related policy.
|
||||
const auto& entry{*Assert(m_pool.GetEntry(txid))};
|
||||
results_final.emplace(wtxid, MempoolAcceptResult::MempoolTx(entry.GetTxSize(), entry.GetFee()));
|
||||
} else if (m_pool.exists(GenTxid::Txid(txid))) {
|
||||
} else if (m_pool.exists(txid)) {
|
||||
// Transaction with the same non-witness data but different witness (same txid,
|
||||
// different wtxid) already exists in the mempool.
|
||||
//
|
||||
@@ -1798,7 +1796,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
|
||||
if (single_res.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||
// The transaction succeeded on its own and is now in the mempool. Don't include it
|
||||
// in package validation, because its fees should only be "used" once.
|
||||
assert(m_pool.exists(GenTxid::Wtxid(wtxid)));
|
||||
assert(m_pool.exists(wtxid));
|
||||
results_final.emplace(wtxid, single_res);
|
||||
} else if (package.size() == 1 || // If there is only one transaction, no need to retry it "as a package"
|
||||
(single_res.m_state.GetResult() != TxValidationResult::TX_RECONSIDERABLE &&
|
||||
@@ -1843,7 +1841,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
|
||||
// If it was submitted, check to see if the tx is still in the mempool. It could have
|
||||
// been evicted due to LimitMempoolSize() above.
|
||||
const auto& txresult = multi_submission_result.m_tx_results.at(wtxid);
|
||||
if (txresult.m_result_type == MempoolAcceptResult::ResultType::VALID && !m_pool.exists(GenTxid::Wtxid(wtxid))) {
|
||||
if (txresult.m_result_type == MempoolAcceptResult::ResultType::VALID && !m_pool.exists(wtxid)) {
|
||||
package_state_final.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
|
||||
TxValidationState mempool_full_state;
|
||||
mempool_full_state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full");
|
||||
@@ -1857,7 +1855,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
|
||||
Assume(it->second.m_result_type != MempoolAcceptResult::ResultType::INVALID);
|
||||
Assume(individual_results_nonfinal.count(wtxid) == 0);
|
||||
// Query by txid to include the same-txid-different-witness ones.
|
||||
if (!m_pool.exists(GenTxid::Txid(tx->GetHash()))) {
|
||||
if (!m_pool.exists(tx->GetHash())) {
|
||||
package_state_final.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
|
||||
TxValidationState mempool_full_state;
|
||||
mempool_full_state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full");
|
||||
|
||||
Reference in New Issue
Block a user