Skip to content

Commit de075a9

Browse files
committed
[validation] better handle errors in SubmitPackage
Behavior change: don't quit right after LimitMempoolSize() when a package is partially submitted. We should still send TransactionAddedToMempool notifications for transactions that were submitted. Not behavior change: add a new package validation result for mempool logic errors.
1 parent 9d88853 commit de075a9

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/policy/packages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum class PackageValidationResult {
2525
PCKG_RESULT_UNSET = 0, //!< Initial value. The package has not yet been rejected.
2626
PCKG_POLICY, //!< The package itself is invalid (e.g. too many transactions).
2727
PCKG_TX, //!< At least one tx is invalid.
28+
PCKG_MEMPOOL_ERROR, //!< Mempool logic error.
2829
};
2930

3031
/** A package is an ordered list of transactions. The transactions cannot conflict with (spend the

src/validation.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,10 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
10581058
if (!ConsensusScriptChecks(args, ws)) {
10591059
results.emplace(ws.m_ptx->GetWitnessHash(), MempoolAcceptResult::Failure(ws.m_state));
10601060
// Since PolicyScriptChecks() passed, this should never fail.
1061-
all_submitted = Assume(false);
1061+
all_submitted = false;
1062+
package_state.Invalid(PackageValidationResult::PCKG_MEMPOOL_ERROR,
1063+
strprintf("BUG! PolicyScriptChecks succeeded but ConsensusScriptChecks failed: %s",
1064+
ws.m_ptx->GetHash().ToString()));
10621065
}
10631066

10641067
// Re-calculate mempool ancestors to call addUnchecked(). They may have changed since the
@@ -1069,7 +1072,10 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
10691072
m_limit_descendant_size, unused_err_string)) {
10701073
results.emplace(ws.m_ptx->GetWitnessHash(), MempoolAcceptResult::Failure(ws.m_state));
10711074
// Since PreChecks() and PackageMempoolChecks() both enforce limits, this should never fail.
1072-
all_submitted = Assume(false);
1075+
all_submitted = false;
1076+
package_state.Invalid(PackageValidationResult::PCKG_MEMPOOL_ERROR,
1077+
strprintf("BUG! Mempool ancestors or descendants were underestimated: %s",
1078+
ws.m_ptx->GetHash().ToString()));
10731079
}
10741080
// If we call LimitMempoolSize() for each individual Finalize(), the mempool will not take
10751081
// the transaction's descendant feerate into account because it hasn't seen them yet. Also,
@@ -1079,7 +1085,9 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
10791085
if (!Finalize(args, ws)) {
10801086
results.emplace(ws.m_ptx->GetWitnessHash(), MempoolAcceptResult::Failure(ws.m_state));
10811087
// Since LimitMempoolSize() won't be called, this should never fail.
1082-
all_submitted = Assume(false);
1088+
all_submitted = false;
1089+
package_state.Invalid(PackageValidationResult::PCKG_MEMPOOL_ERROR,
1090+
strprintf("BUG! Adding to mempool failed: %s", ws.m_ptx->GetHash().ToString()));
10831091
}
10841092
}
10851093

@@ -1088,7 +1096,6 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
10881096
LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip(),
10891097
gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000,
10901098
std::chrono::hours{gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
1091-
if (!all_submitted) return false;
10921099

10931100
// Find the wtxids of the transactions that made it into the mempool. Allow partial submission,
10941101
// but don't report success unless they all made it into the mempool.
@@ -1194,7 +1201,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
11941201
if (args.m_test_accept) return PackageMempoolAcceptResult(package_state, std::move(results));
11951202

11961203
if (!SubmitPackage(args, workspaces, package_state, results)) {
1197-
package_state.Invalid(PackageValidationResult::PCKG_TX, "submission failed");
1204+
// PackageValidationState filled in by SubmitPackage().
11981205
return PackageMempoolAcceptResult(package_state, std::move(results));
11991206
}
12001207

0 commit comments

Comments
 (0)