Skip to content

Commit 9d88853

Browse files
committed
AcceptPackage fixups
No behavior changes, just clarifications.
1 parent 2db77cd commit 9d88853

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/validation.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ class MemPoolAccept
596596

597597
// Submit all transactions to the mempool and call ConsensusScriptChecks to add to the script
598598
// cache - should only be called after successful validation of all transactions in the package.
599-
// The package may end up partially-submitted after size limitting; returns true if all
599+
// The package may end up partially-submitted after size limiting; returns true if all
600600
// transactions are successfully added to the mempool, false otherwise.
601-
bool FinalizePackage(const ATMPArgs& args, std::vector<Workspace>& workspaces, PackageValidationState& package_state,
602-
std::map<const uint256, const MempoolAcceptResult>& results)
601+
bool SubmitPackage(const ATMPArgs& args, std::vector<Workspace>& workspaces, PackageValidationState& package_state,
602+
std::map<const uint256, const MempoolAcceptResult>& results)
603603
EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
604604

605605
// Compare a package's feerate against minimum allowed.
@@ -1038,12 +1038,17 @@ bool MemPoolAccept::Finalize(const ATMPArgs& args, Workspace& ws)
10381038
return true;
10391039
}
10401040

1041-
bool MemPoolAccept::FinalizePackage(const ATMPArgs& args, std::vector<Workspace>& workspaces,
1042-
PackageValidationState& package_state,
1043-
std::map<const uint256, const MempoolAcceptResult>& results)
1041+
bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>& workspaces,
1042+
PackageValidationState& package_state,
1043+
std::map<const uint256, const MempoolAcceptResult>& results)
10441044
{
10451045
AssertLockHeld(cs_main);
10461046
AssertLockHeld(m_pool.cs);
1047+
// Sanity check: none of the transactions should be in the mempool, and none of the transactions
1048+
// should have a same-txid-different-witness equivalent in the mempool.
1049+
assert(std::all_of(workspaces.cbegin(), workspaces.cend(), [this](const auto& ws){
1050+
return !m_pool.exists(GenTxid::Txid(ws.m_ptx->GetHash())); }));
1051+
10471052
bool all_submitted = true;
10481053
// ConsensusScriptChecks adds to the script cache and is therefore consensus-critical;
10491054
// CheckInputsFromMempoolAndCache asserts that transactions only spend coins available from the
@@ -1058,10 +1063,10 @@ bool MemPoolAccept::FinalizePackage(const ATMPArgs& args, std::vector<Workspace>
10581063

10591064
// Re-calculate mempool ancestors to call addUnchecked(). They may have changed since the
10601065
// last calculation done in PreChecks, since package ancestors have already been submitted.
1061-
std::string err_string;
1066+
std::string unused_err_string;
10621067
if(!m_pool.CalculateMemPoolAncestors(*ws.m_entry, ws.m_ancestors, m_limit_ancestors,
10631068
m_limit_ancestor_size, m_limit_descendants,
1064-
m_limit_descendant_size, err_string)) {
1069+
m_limit_descendant_size, unused_err_string)) {
10651070
results.emplace(ws.m_ptx->GetWitnessHash(), MempoolAcceptResult::Failure(ws.m_state));
10661071
// Since PreChecks() and PackageMempoolChecks() both enforce limits, this should never fail.
10671072
all_submitted = Assume(false);
@@ -1188,7 +1193,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
11881193

11891194
if (args.m_test_accept) return PackageMempoolAcceptResult(package_state, std::move(results));
11901195

1191-
if (!FinalizePackage(args, workspaces, package_state, results)) {
1196+
if (!SubmitPackage(args, workspaces, package_state, results)) {
11921197
package_state.Invalid(PackageValidationResult::PCKG_TX, "submission failed");
11931198
return PackageMempoolAcceptResult(package_state, std::move(results));
11941199
}
@@ -1214,11 +1219,13 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
12141219
return PackageMempoolAcceptResult(package_state, {});
12151220
}
12161221

1217-
const auto& child = package[package.size() - 1];
1222+
// IsChildWithParents() guarantees the package is > 1 transactions.
1223+
assert(package.size() > 1);
12181224
// The package must be 1 child with all of its unconfirmed parents. The package is expected to
12191225
// be sorted, so the last transaction is the child.
1226+
const auto& child = package.back();
12201227
std::unordered_set<uint256, SaltedTxidHasher> unconfirmed_parent_txids;
1221-
std::transform(package.cbegin(), package.end() - 1,
1228+
std::transform(package.cbegin(), package.cend() - 1,
12221229
std::inserter(unconfirmed_parent_txids, unconfirmed_parent_txids.end()),
12231230
[](const auto& tx) { return tx->GetHash(); });
12241231

@@ -1348,12 +1355,12 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx
13481355
}();
13491356

13501357
// Uncache coins pertaining to transactions that were not submitted to the mempool.
1351-
// Ensure the coins cache is still within limits.
13521358
if (test_accept || result.m_state.IsInvalid()) {
13531359
for (const COutPoint& hashTx : coins_to_uncache) {
13541360
active_chainstate.CoinsTip().Uncache(hashTx);
13551361
}
13561362
}
1363+
// Ensure the coins cache is still within limits.
13571364
BlockValidationState state_dummy;
13581365
active_chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
13591366
return result;

0 commit comments

Comments
 (0)