[refactor] return MempoolAcceptResult

This creates a cleaner interface with ATMP, allows us to make results const,
and makes accessing values that don't make sense (e.g. fee when tx is
invalid) an error.
This commit is contained in:
gzhao408
2021-01-19 05:29:40 -08:00
parent 9db10a5506
commit f82baf0762
9 changed files with 106 additions and 92 deletions

View File

@@ -946,18 +946,13 @@ static RPCHelpMan testmempoolaccept()
result_0.pushKV("txid", tx->GetHash().GetHex());
result_0.pushKV("wtxid", tx->GetWitnessHash().GetHex());
TxValidationState state;
bool test_accept_res;
CAmount fee{0};
{
LOCK(cs_main);
test_accept_res = AcceptToMemoryPool(mempool, state, std::move(tx),
nullptr /* plTxnReplaced */, false /* bypass_limits */, /* test_accept */ true, &fee);
}
const MempoolAcceptResult accept_result = WITH_LOCK(cs_main, return AcceptToMemoryPool(mempool, std::move(tx),
false /* bypass_limits */, /* test_accept */ true));
// Only return the fee and vsize if the transaction would pass ATMP.
// These can be used to calculate the feerate.
if (test_accept_res) {
if (accept_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
const CAmount fee = accept_result.m_base_fees.value();
// Check that fee does not exceed maximum fee
if (max_raw_tx_fee && fee > max_raw_tx_fee) {
result_0.pushKV("allowed", false);
@@ -972,6 +967,7 @@ static RPCHelpMan testmempoolaccept()
result.push_back(std::move(result_0));
} else {
result_0.pushKV("allowed", false);
const TxValidationState state = accept_result.m_state;
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
result_0.pushKV("reject-reason", "missing-inputs");
} else {