LCOV - code coverage report
Current view: top level - src/rpc - mempool.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 97.5 % 878 856
Test Date: 2025-11-28 05:09:59 Functions: 100.0 % 38 38
Branches: 51.4 % 2990 1536

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2010 Satoshi Nakamoto
       2                 :             : // Copyright (c) 2009-2022 The Bitcoin Core developers
       3                 :             : // Distributed under the MIT software license, see the accompanying
       4                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5                 :             : 
       6                 :             : #include <rpc/blockchain.h>
       7                 :             : 
       8                 :             : #include <node/mempool_persist.h>
       9                 :             : 
      10                 :             : #include <chainparams.h>
      11                 :             : #include <consensus/validation.h>
      12                 :             : #include <core_io.h>
      13                 :             : #include <kernel/mempool_entry.h>
      14                 :             : #include <net_processing.h>
      15                 :             : #include <node/mempool_persist_args.h>
      16                 :             : #include <node/types.h>
      17                 :             : #include <policy/rbf.h>
      18                 :             : #include <policy/settings.h>
      19                 :             : #include <primitives/transaction.h>
      20                 :             : #include <rpc/server.h>
      21                 :             : #include <rpc/server_util.h>
      22                 :             : #include <rpc/util.h>
      23                 :             : #include <txmempool.h>
      24                 :             : #include <univalue.h>
      25                 :             : #include <util/fs.h>
      26                 :             : #include <util/moneystr.h>
      27                 :             : #include <util/strencodings.h>
      28                 :             : #include <util/time.h>
      29                 :             : #include <util/vector.h>
      30                 :             : 
      31                 :             : #include <string_view>
      32                 :             : #include <utility>
      33                 :             : 
      34                 :             : using node::DumpMempool;
      35                 :             : 
      36                 :             : using node::DEFAULT_MAX_BURN_AMOUNT;
      37                 :             : using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
      38                 :             : using node::MempoolPath;
      39                 :             : using node::NodeContext;
      40                 :             : using node::TransactionError;
      41                 :             : using util::ToString;
      42                 :             : 
      43                 :       26240 : static RPCHelpMan sendrawtransaction()
      44                 :             : {
      45                 :       26240 :     return RPCHelpMan{
      46                 :       26240 :         "sendrawtransaction",
      47         [ +  - ]:       52480 :         "Submit a raw transaction (serialized, hex-encoded) to local node and network.\n"
      48                 :             :         "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
      49                 :             :         "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
      50                 :             :         "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
      51                 :             :         "\nA specific exception, RPC_TRANSACTION_ALREADY_IN_UTXO_SET, may throw if the transaction cannot be added to the mempool.\n"
      52                 :             :         "\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
      53                 :             :         {
      54   [ +  -  +  - ]:       52480 :             {"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
      55   [ +  -  +  -  :       52480 :             {"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
                   +  - ]
      56         [ +  - ]:       52480 :              "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
      57                 :       26240 :                  "/kvB.\nFee rates larger than 1BTC/kvB are rejected.\nSet to 0 to accept any fee rate."},
      58   [ +  -  +  -  :       52480 :             {"maxburnamount", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_BURN_AMOUNT)},
                   +  - ]
      59         [ +  - ]:       52480 :              "Reject transactions with provably unspendable outputs (e.g. 'datacarrier' outputs that use the OP_RETURN opcode) greater than the specified value, expressed in " + CURRENCY_UNIT + ".\n"
      60                 :             :              "If burning funds through unspendable outputs is desired, increase this value.\n"
      61                 :       26240 :              "This check is based on heuristics and does not guarantee spendability of outputs.\n"},
      62                 :             :         },
      63         [ +  - ]:       52480 :         RPCResult{
      64   [ +  -  +  - ]:       52480 :             RPCResult::Type::STR_HEX, "", "The transaction hash in hex"
      65         [ +  - ]:       52480 :         },
      66                 :       26240 :         RPCExamples{
      67                 :             :             "\nCreate a transaction\n"
      68   [ +  -  +  -  :       52480 :             + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
             +  -  +  - ]
      69                 :       26240 :             "Sign the transaction, and get back the hex\n"
      70   [ +  -  +  -  :      104960 :             + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
             +  -  +  - ]
      71                 :       26240 :             "\nSend the transaction (signed hex)\n"
      72   [ +  -  +  -  :      104960 :             + HelpExampleCli("sendrawtransaction", "\"signedhex\"") +
             +  -  +  - ]
      73                 :       26240 :             "\nAs a JSON-RPC call\n"
      74   [ +  -  +  -  :      104960 :             + HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
             +  -  +  - ]
      75         [ +  - ]:       26240 :                 },
      76                 :       26240 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      77                 :             :         {
      78         [ +  + ]:       23878 :             const CAmount max_burn_amount = request.params[2].isNull() ? 0 : AmountFromValue(request.params[2]);
      79                 :             : 
      80                 :       23878 :             CMutableTransaction mtx;
      81   [ +  -  +  -  :       23878 :             if (!DecodeHexTx(mtx, request.params[0].get_str())) {
             +  -  +  + ]
      82   [ +  -  +  - ]:           4 :                 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
      83                 :             :             }
      84                 :             : 
      85         [ +  + ]:       84021 :             for (const auto& out : mtx.vout) {
      86   [ +  +  +  -  :       60149 :                 if((out.scriptPubKey.IsUnspendable() || !out.scriptPubKey.HasValidOps()) && out.nValue > max_burn_amount) {
             +  +  +  + ]
      87   [ +  -  +  - ]:           8 :                     throw JSONRPCTransactionError(TransactionError::MAX_BURN_EXCEEDED);
      88                 :             :                 }
      89                 :             :             }
      90                 :             : 
      91         [ +  - ]:       23872 :             CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
      92                 :             : 
      93   [ +  -  +  - ]:       23872 :             const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
      94                 :             : 
      95         [ +  - ]:       23872 :             int64_t virtual_size = GetVirtualTransactionSize(*tx);
      96         [ +  - ]:       23872 :             CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
      97                 :             : 
      98         [ +  - ]:       23872 :             std::string err_string;
      99                 :       23872 :             AssertLockNotHeld(cs_main);
     100         [ +  - ]:       23872 :             NodeContext& node = EnsureAnyNodeContext(request.context);
     101   [ +  -  +  -  :       47744 :             const TransactionError err = BroadcastTransaction(node,
                   +  - ]
     102                 :             :                                                               tx,
     103                 :             :                                                               err_string,
     104                 :             :                                                               max_raw_tx_fee,
     105                 :             :                                                               node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL,
     106                 :             :                                                               /*wait_callback=*/true);
     107         [ +  + ]:       23872 :             if (TransactionError::OK != err) {
     108         [ +  - ]:        4326 :                 throw JSONRPCTransactionError(err, err_string);
     109                 :             :             }
     110                 :             : 
     111   [ +  -  +  - ]:       39092 :             return tx->GetHash().GetHex();
     112         [ +  - ]:       67290 :         },
     113   [ +  -  +  -  :      183680 :     };
             +  +  -  - ]
     114   [ +  -  +  -  :      157440 : }
             +  -  -  - ]
     115                 :             : 
     116                 :        3861 : static RPCHelpMan testmempoolaccept()
     117                 :             : {
     118                 :        3861 :     return RPCHelpMan{
     119                 :        3861 :         "testmempoolaccept",
     120                 :             :         "Returns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n"
     121                 :             :         "\nIf multiple transactions are passed in, parents must come before children and package policies apply: the transactions cannot conflict with any mempool transactions or each other.\n"
     122                 :             :         "\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n"
     123   [ +  -  +  - ]:        7722 :         "\nThe maximum number of transactions allowed is " + ToString(MAX_PACKAGE_COUNT) + ".\n"
     124                 :             :         "\nThis checks if transactions violate the consensus or policy rules.\n"
     125                 :        3861 :         "\nSee sendrawtransaction call.\n",
     126                 :             :         {
     127   [ +  -  +  - ]:        7722 :             {"rawtxs", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of hex strings of raw transactions.",
     128                 :             :                 {
     129   [ +  -  +  - ]:        7722 :                     {"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
     130                 :             :                 },
     131                 :             :             },
     132   [ +  -  +  -  :        7722 :             {"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
                   +  - ]
     133         [ +  - ]:        7722 :              "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
     134                 :        3861 :                  "/kvB.\nFee rates larger than 1BTC/kvB are rejected.\nSet to 0 to accept any fee rate."},
     135                 :             :         },
     136         [ +  - ]:        7722 :         RPCResult{
     137   [ +  -  +  - ]:        7722 :             RPCResult::Type::ARR, "", "The result of the mempool acceptance test for each raw transaction in the input array.\n"
     138                 :             :                                       "Returns results for each transaction in the same order they were passed in.\n"
     139                 :             :                                       "Transactions that cannot be fully validated due to failures in other transactions will not contain an 'allowed' result.\n",
     140                 :             :             {
     141   [ +  -  +  - ]:        7722 :                 {RPCResult::Type::OBJ, "", "",
     142                 :             :                 {
     143   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
     144   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::STR_HEX, "wtxid", "The transaction witness hash in hex"},
     145   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::STR, "package-error", /*optional=*/true, "Package validation error, if any (only possible if rawtxs had more than 1 transaction)."},
     146   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::BOOL, "allowed", /*optional=*/true, "Whether this tx would be accepted to the mempool and pass client-specified maxfeerate. "
     147                 :             :                                                        "If not present, the tx was not fully validated due to a failure in another tx in the list."},
     148   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::NUM, "vsize", /*optional=*/true, "Virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted (only present when 'allowed' is true)"},
     149   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::OBJ, "fees", /*optional=*/true, "Transaction fees (only present if 'allowed' is true)",
     150                 :             :                     {
     151   [ +  -  +  - ]:        7722 :                         {RPCResult::Type::STR_AMOUNT, "base", "transaction fee in " + CURRENCY_UNIT},
     152   [ +  -  +  - ]:        7722 :                         {RPCResult::Type::STR_AMOUNT, "effective-feerate", /*optional=*/false, "the effective feerate in " + CURRENCY_UNIT + " per KvB. May differ from the base feerate if, for example, there are modified fees from prioritisetransaction or a package feerate was used."},
     153   [ +  -  +  - ]:        7722 :                         {RPCResult::Type::ARR, "effective-includes", /*optional=*/false, "transactions whose fees and vsizes are included in effective-feerate.",
     154   [ +  -  +  - ]:        7722 :                             {RPCResult{RPCResult::Type::STR_HEX, "", "transaction wtxid in hex"},
     155                 :             :                         }},
     156                 :             :                     }},
     157   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::STR, "reject-reason", /*optional=*/true, "Rejection reason (only present when 'allowed' is false)"},
     158   [ +  -  +  - ]:        7722 :                     {RPCResult::Type::STR, "reject-details", /*optional=*/true, "Rejection details (only present when 'allowed' is false and rejection details exist)"},
     159                 :             :                 }},
     160                 :             :             }
     161   [ +  -  +  -  :      104247 :         },
          +  -  +  -  +  
          -  +  +  +  +  
          +  +  +  +  -  
          -  -  -  -  -  
                   -  - ]
     162                 :        3861 :         RPCExamples{
     163                 :             :             "\nCreate a transaction\n"
     164   [ +  -  +  -  :        7722 :             + HelpExampleCli("createrawtransaction", "\"[{\\\"txid\\\" : \\\"mytxid\\\",\\\"vout\\\":0}]\" \"{\\\"myaddress\\\":0.01}\"") +
             +  -  +  - ]
     165                 :        3861 :             "Sign the transaction, and get back the hex\n"
     166   [ +  -  +  -  :       15444 :             + HelpExampleCli("signrawtransactionwithwallet", "\"myhex\"") +
             +  -  +  - ]
     167                 :        3861 :             "\nTest acceptance of the transaction (signed hex)\n"
     168   [ +  -  +  -  :       15444 :             + HelpExampleCli("testmempoolaccept", R"('["signedhex"]')") +
             +  -  +  - ]
     169                 :        3861 :             "\nAs a JSON-RPC call\n"
     170   [ +  -  +  -  :       15444 :             + HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")
             +  -  +  - ]
     171         [ +  - ]:        3861 :                 },
     172                 :        3861 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     173                 :             :         {
     174                 :        1499 :             const UniValue raw_transactions = request.params[0].get_array();
     175   [ -  +  +  +  :        1499 :             if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) {
                   +  + ]
     176                 :           2 :                 throw JSONRPCError(RPC_INVALID_PARAMETER,
     177   [ +  -  +  -  :           6 :                                    "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
                   +  - ]
     178                 :             :             }
     179                 :             : 
     180   [ +  -  +  + ]:        1497 :             const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
     181                 :             : 
     182                 :        1495 :             std::vector<CTransactionRef> txns;
     183   [ -  +  +  - ]:        1495 :             txns.reserve(raw_transactions.size());
     184   [ +  -  +  + ]:        3574 :             for (const auto& rawtx : raw_transactions.getValues()) {
     185         [ +  - ]:        2080 :                 CMutableTransaction mtx;
     186   [ +  -  +  -  :        2080 :                 if (!DecodeHexTx(mtx, rawtx.get_str())) {
                   +  + ]
     187                 :           1 :                     throw JSONRPCError(RPC_DESERIALIZATION_ERROR,
     188   [ +  -  +  -  :           3 :                                        "TX decode failed: " + rawtx.get_str() + " Make sure the tx has at least one input.");
                   +  - ]
     189                 :             :                 }
     190   [ +  -  +  - ]:        6237 :                 txns.emplace_back(MakeTransactionRef(std::move(mtx)));
     191                 :        2080 :             }
     192                 :             : 
     193         [ +  - ]:        1494 :             NodeContext& node = EnsureAnyNodeContext(request.context);
     194         [ +  - ]:        1494 :             CTxMemPool& mempool = EnsureMemPool(node);
     195         [ +  - ]:        1494 :             ChainstateManager& chainman = EnsureChainman(node);
     196         [ +  - ]:        1494 :             Chainstate& chainstate = chainman.ActiveChainstate();
     197                 :        2988 :             const PackageMempoolAcceptResult package_result = [&] {
     198                 :        1494 :                 LOCK(::cs_main);
     199   [ -  +  +  +  :        1494 :                 if (txns.size() > 1) return ProcessNewPackage(chainstate, mempool, txns, /*test_accept=*/true, /*client_maxfeerate=*/{});
                   +  - ]
     200         [ +  - ]:        1418 :                 return PackageMempoolAcceptResult(txns[0]->GetWitnessHash(),
     201   [ +  -  +  - ]:        1418 :                                                   chainman.ProcessTransaction(txns[0], /*test_accept=*/true));
     202         [ +  - ]:        2988 :             }();
     203                 :             : 
     204                 :        1494 :             UniValue rpc_result(UniValue::VARR);
     205                 :             :             // We will check transaction fees while we iterate through txns in order. If any transaction fee
     206                 :             :             // exceeds maxfeerate, we will leave the rest of the validation results blank, because it
     207                 :             :             // doesn't make sense to return a validation result for a transaction if its ancestor(s) would
     208                 :             :             // not be submitted.
     209                 :        1494 :             bool exit_early{false};
     210         [ +  + ]:        3573 :             for (const auto& tx : txns) {
     211                 :        2079 :                 UniValue result_inner(UniValue::VOBJ);
     212   [ +  -  +  -  :        4158 :                 result_inner.pushKV("txid", tx->GetHash().GetHex());
             +  -  +  - ]
     213   [ +  -  +  -  :        4158 :                 result_inner.pushKV("wtxid", tx->GetWitnessHash().GetHex());
             +  -  +  - ]
     214         [ +  + ]:        2079 :                 if (package_result.m_state.GetResult() == PackageValidationResult::PCKG_POLICY) {
     215   [ +  -  +  -  :         198 :                     result_inner.pushKV("package-error", package_result.m_state.ToString());
             +  -  +  - ]
     216                 :             :                 }
     217                 :        2079 :                 auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
     218   [ +  +  +  + ]:        2079 :                 if (exit_early || it == package_result.m_tx_results.end()) {
     219                 :             :                     // Validation unfinished. Just return the txid and wtxid.
     220         [ +  - ]:         138 :                     rpc_result.push_back(std::move(result_inner));
     221                 :         138 :                     continue;
     222                 :             :                 }
     223         [ +  - ]:        1941 :                 const auto& tx_result = it->second;
     224                 :             :                 // Package testmempoolaccept doesn't allow transactions to already be in the mempool.
     225         [ +  - ]:        1941 :                 CHECK_NONFATAL(tx_result.m_result_type != MempoolAcceptResult::ResultType::MEMPOOL_ENTRY);
     226         [ +  + ]:        1941 :                 if (tx_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
     227         [ +  - ]:        1693 :                     const CAmount fee = tx_result.m_base_fees.value();
     228                 :             :                     // Check that fee does not exceed maximum fee
     229         [ +  - ]:        1693 :                     const int64_t virtual_size = tx_result.m_vsize.value();
     230         [ +  - ]:        1693 :                     const CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
     231         [ +  + ]:        1693 :                     if (max_raw_tx_fee && fee > max_raw_tx_fee) {
     232   [ +  -  +  -  :           8 :                         result_inner.pushKV("allowed", false);
                   +  - ]
     233   [ +  -  +  -  :           4 :                         result_inner.pushKV("reject-reason", "max-fee-exceeded");
                   +  - ]
     234                 :           4 :                         exit_early = true;
     235                 :             :                     } else {
     236                 :             :                         // Only return the fee and vsize if the transaction would pass ATMP.
     237                 :             :                         // These can be used to calculate the feerate.
     238   [ +  -  +  -  :        3378 :                         result_inner.pushKV("allowed", true);
                   +  - ]
     239   [ +  -  +  -  :        3378 :                         result_inner.pushKV("vsize", virtual_size);
                   +  - ]
     240                 :        1689 :                         UniValue fees(UniValue::VOBJ);
     241   [ +  -  +  -  :        3378 :                         fees.pushKV("base", ValueFromAmount(fee));
                   +  - ]
     242   [ +  -  +  -  :        3378 :                         fees.pushKV("effective-feerate", ValueFromAmount(tx_result.m_effective_feerate.value().GetFeePerK()));
             +  -  +  - ]
     243                 :        1689 :                         UniValue effective_includes_res(UniValue::VARR);
     244   [ +  -  +  + ]:        3378 :                         for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) {
     245   [ +  -  +  -  :        1689 :                             effective_includes_res.push_back(wtxid.ToString());
                   +  - ]
     246                 :             :                         }
     247   [ +  -  +  - ]:        3378 :                         fees.pushKV("effective-includes", std::move(effective_includes_res));
     248   [ +  -  +  - ]:        3378 :                         result_inner.pushKV("fees", std::move(fees));
     249                 :        1689 :                     }
     250                 :             :                 } else {
     251   [ +  -  +  -  :         496 :                     result_inner.pushKV("allowed", false);
                   +  - ]
     252         [ +  - ]:         248 :                     const TxValidationState state = tx_result.m_state;
     253         [ +  + ]:         248 :                     if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
     254   [ +  -  +  -  :         232 :                         result_inner.pushKV("reject-reason", "missing-inputs");
                   +  - ]
     255                 :             :                     } else {
     256   [ -  +  +  -  :         396 :                         result_inner.pushKV("reject-reason", state.GetRejectReason());
             +  -  +  - ]
     257   [ +  -  +  -  :         264 :                         result_inner.pushKV("reject-details", state.ToString());
             +  -  +  - ]
     258                 :             :                     }
     259                 :         248 :                 }
     260         [ +  - ]:        1941 :                 rpc_result.push_back(std::move(result_inner));
     261                 :        2079 :             }
     262                 :        1494 :             return rpc_result;
     263                 :        1500 :         },
     264   [ +  -  +  -  :       34749 :     };
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     265   [ +  -  +  -  :       73359 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  -  
             -  -  -  - ]
     266                 :             : 
     267                 :        3490 : static std::vector<RPCResult> ClusterDescription()
     268                 :             : {
     269                 :        3490 :     return {
     270   [ +  -  +  - ]:        6980 :         RPCResult{RPCResult::Type::NUM, "weight", "total sigops-adjusted weight (as defined in BIP 141 and modified by '-bytespersigop'"},
     271   [ +  -  +  - ]:        6980 :         RPCResult{RPCResult::Type::NUM, "txcount", "number of transactions"},
     272   [ +  -  +  - ]:        6980 :         RPCResult{RPCResult::Type::ARR, "txs", "transactions in this cluster in mining order",
     273   [ +  -  +  - ]:        6980 :             {RPCResult{RPCResult::Type::OBJ, "txentry", "",
     274                 :             :                 {
     275   [ +  -  +  - ]:        6980 :                     RPCResult{RPCResult::Type::STR_HEX, "txid", "the transaction id"},
     276   [ +  -  +  - ]:        6980 :                     RPCResult{RPCResult::Type::NUM, "chunkfee", "fee of the chunk containing this tx"},
     277   [ +  -  +  - ]:        6980 :                     RPCResult{RPCResult::Type::NUM, "chunkweight", "sigops-adjusted weight of the chunk containing this transaction"}
     278                 :             :                 }
     279   [ +  -  +  +  :       17450 :             }}
                   -  - ]
     280   [ +  -  +  +  :       10470 :         }
                   -  - ]
     281   [ +  -  +  +  :       20940 :     };
                   -  - ]
     282   [ +  -  +  -  :       24430 : }
          +  -  +  -  +  
          -  +  -  +  -  
             -  -  -  - ]
     283                 :             : 
     284                 :       27650 : static std::vector<RPCResult> MempoolEntryDescription()
     285                 :             : {
     286                 :       27650 :     return {
     287   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "vsize", "virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted."},
     288   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "weight", "transaction weight as defined in BIP 141."},
     289   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM_TIME, "time", "local time transaction entered pool in seconds since 1 Jan 1970 GMT"},
     290   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "height", "block height when transaction entered pool"},
     291   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "descendantcount", "number of in-mempool descendant transactions (including this one)"},
     292   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "descendantsize", "virtual transaction size of in-mempool descendants (including this one)"},
     293   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "ancestorcount", "number of in-mempool ancestor transactions (including this one)"},
     294   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "ancestorsize", "virtual transaction size of in-mempool ancestors (including this one)"},
     295   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::NUM, "chunkweight", "sigops-adjusted weight (as defined in BIP 141 and modified by '-bytespersigop') of this transaction's chunk"},
     296   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::STR_HEX, "wtxid", "hash of serialized transaction, including witness data"},
     297   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::OBJ, "fees", "",
     298                 :             :             {
     299   [ +  -  +  - ]:       55300 :                 RPCResult{RPCResult::Type::STR_AMOUNT, "base", "transaction fee, denominated in " + CURRENCY_UNIT},
     300   [ +  -  +  - ]:       55300 :                 RPCResult{RPCResult::Type::STR_AMOUNT, "modified", "transaction fee with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
     301   [ +  -  +  - ]:       55300 :                 RPCResult{RPCResult::Type::STR_AMOUNT, "ancestor", "transaction fees of in-mempool ancestors (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
     302   [ +  -  +  - ]:       55300 :                 RPCResult{RPCResult::Type::STR_AMOUNT, "descendant", "transaction fees of in-mempool descendants (including this one) with fee deltas used for mining priority, denominated in " + CURRENCY_UNIT},
     303   [ +  -  +  - ]:       55300 :                 RPCResult{RPCResult::Type::STR_AMOUNT, "chunk", "transaction fees of chunk, denominated in " + CURRENCY_UNIT},
     304   [ +  -  +  +  :      193550 :             }},
                   -  - ]
     305   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::ARR, "depends", "unconfirmed transactions used as inputs for this transaction",
     306   [ +  -  +  -  :      110600 :             {RPCResult{RPCResult::Type::STR_HEX, "transactionid", "parent transaction id"}}},
          +  -  +  +  -  
                      - ]
     307   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::ARR, "spentby", "unconfirmed transactions spending outputs from this transaction",
     308   [ +  -  +  -  :      110600 :             {RPCResult{RPCResult::Type::STR_HEX, "transactionid", "child transaction id"}}},
          +  -  +  +  -  
                      - ]
     309   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::BOOL, "bip125-replaceable", "Whether this transaction signals BIP125 replaceability or has an unconfirmed ancestor signaling BIP125 replaceability. (DEPRECATED)\n"},
     310   [ +  -  +  - ]:       55300 :         RPCResult{RPCResult::Type::BOOL, "unbroadcast", "Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)"},
     311   [ +  -  +  +  :      497700 :     };
                   -  - ]
     312   [ +  -  +  -  :      608300 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             -  -  -  - ]
     313                 :             : 
     314                 :        1129 : static void clusterToJSON(const CTxMemPool& pool, UniValue& info, std::vector<const CTxMemPoolEntry *> cluster) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
     315                 :             : {
     316                 :        1129 :     AssertLockHeld(pool.cs);
     317                 :        1129 :     int total_weight{0};
     318         [ +  + ]:       26997 :     for (const auto& tx : cluster) {
     319                 :       25868 :         total_weight += tx->GetAdjustedWeight();
     320                 :             :     }
     321   [ +  -  +  - ]:        2258 :     info.pushKV("weight", total_weight);
     322   [ -  +  +  -  :        2258 :     info.pushKV("txcount", (int)cluster.size());
                   +  - ]
     323                 :        1129 :     UniValue txs(UniValue::VARR);
     324         [ +  + ]:       26997 :     for (const auto& tx : cluster) {
     325                 :       25868 :         UniValue txentry(UniValue::VOBJ);
     326                 :       25868 :         auto feerate = pool.GetMainChunkFeerate(*tx);
     327   [ +  -  +  -  :       51736 :         txentry.pushKV("txid", tx->GetTx().GetHash().ToString());
             +  -  +  - ]
     328   [ +  -  +  -  :       51736 :         txentry.pushKV("chunkfee", ValueFromAmount((int)feerate.fee));
                   +  - ]
     329   [ +  -  +  -  :       51736 :         txentry.pushKV("chunkweight", feerate.size);
                   +  - ]
     330   [ +  -  +  - ]:       25868 :         txs.push_back(txentry);
     331                 :       25868 :     }
     332   [ +  -  +  -  :        2258 :     info.pushKV("txs", txs);
                   +  - ]
     333                 :        1129 : }
     334                 :             : 
     335                 :        8684 : static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPoolEntry& e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
     336                 :             : {
     337                 :        8684 :     AssertLockHeld(pool.cs);
     338                 :             : 
     339                 :        8684 :     auto [ancestor_count, ancestor_size, ancestor_fees] = pool.CalculateAncestorData(e);
     340                 :        8684 :     auto [descendant_count, descendant_size, descendant_fees] = pool.CalculateDescendantData(e);
     341                 :             : 
     342   [ +  -  +  - ]:       17368 :     info.pushKV("vsize", (int)e.GetTxSize());
     343   [ +  -  +  - ]:       17368 :     info.pushKV("weight", (int)e.GetTxWeight());
     344   [ +  -  +  - ]:       17368 :     info.pushKV("time", count_seconds(e.GetTime()));
     345   [ +  -  +  - ]:       17368 :     info.pushKV("height", (int)e.GetHeight());
     346   [ +  -  +  - ]:       17368 :     info.pushKV("descendantcount", descendant_count);
     347   [ +  -  +  - ]:       17368 :     info.pushKV("descendantsize", descendant_size);
     348   [ +  -  +  - ]:       17368 :     info.pushKV("ancestorcount", ancestor_count);
     349   [ +  -  +  - ]:       17368 :     info.pushKV("ancestorsize", ancestor_size);
     350   [ +  -  +  -  :       17368 :     info.pushKV("wtxid", e.GetTx().GetWitnessHash().ToString());
                   +  - ]
     351                 :        8684 :     auto feerate = pool.GetMainChunkFeerate(e);
     352   [ +  -  +  - ]:       17368 :     info.pushKV("chunkweight", feerate.size);
     353                 :             : 
     354                 :        8684 :     UniValue fees(UniValue::VOBJ);
     355   [ +  -  +  -  :       17368 :     fees.pushKV("base", ValueFromAmount(e.GetFee()));
                   +  - ]
     356   [ +  -  +  -  :       17368 :     fees.pushKV("modified", ValueFromAmount(e.GetModifiedFee()));
                   +  - ]
     357   [ +  -  +  -  :       17368 :     fees.pushKV("ancestor", ValueFromAmount(ancestor_fees));
                   +  - ]
     358   [ +  -  +  -  :       17368 :     fees.pushKV("descendant", ValueFromAmount(descendant_fees));
                   +  - ]
     359   [ +  -  +  -  :       17368 :     fees.pushKV("chunk", ValueFromAmount((int)feerate.fee));
                   +  - ]
     360   [ +  -  +  - ]:       17368 :     info.pushKV("fees", std::move(fees));
     361                 :             : 
     362                 :        8684 :     const CTransaction& tx = e.GetTx();
     363                 :        8684 :     std::set<std::string> setDepends;
     364         [ +  + ]:       21088 :     for (const CTxIn& txin : tx.vin)
     365                 :             :     {
     366   [ +  -  +  + ]:       12404 :         if (pool.exists(txin.prevout.hash))
     367   [ +  -  +  - ]:       14158 :             setDepends.insert(txin.prevout.hash.ToString());
     368                 :             :     }
     369                 :             : 
     370                 :        8684 :     UniValue depends(UniValue::VARR);
     371         [ +  + ]:       15763 :     for (const std::string& dep : setDepends)
     372                 :             :     {
     373   [ +  -  +  - ]:        7079 :         depends.push_back(dep);
     374                 :             :     }
     375                 :             : 
     376   [ +  -  +  - ]:       17368 :     info.pushKV("depends", std::move(depends));
     377                 :             : 
     378                 :        8684 :     UniValue spent(UniValue::VARR);
     379   [ +  -  +  -  :       15788 :     for (const CTxMemPoolEntry& child : pool.GetChildren(e)) {
                   +  + ]
     380   [ +  -  +  -  :        7104 :         spent.push_back(child.GetTx().GetHash().ToString());
                   +  - ]
     381                 :           0 :     }
     382                 :             : 
     383   [ +  -  +  - ]:       17368 :     info.pushKV("spentby", std::move(spent));
     384                 :             : 
     385                 :             :     // Add opt-in RBF status
     386                 :        8684 :     bool rbfStatus = false;
     387         [ +  - ]:        8684 :     RBFTransactionState rbfState = IsRBFOptIn(tx, pool);
     388         [ -  + ]:        8684 :     if (rbfState == RBFTransactionState::UNKNOWN) {
     389   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_MISC_ERROR, "Transaction is not in mempool");
     390         [ +  + ]:        8684 :     } else if (rbfState == RBFTransactionState::REPLACEABLE_BIP125) {
     391                 :        7514 :         rbfStatus = true;
     392                 :             :     }
     393                 :             : 
     394   [ +  -  +  -  :       17368 :     info.pushKV("bip125-replaceable", rbfStatus);
                   +  - ]
     395   [ +  -  +  -  :       17368 :     info.pushKV("unbroadcast", pool.IsUnbroadcastTx(tx.GetHash()));
                   +  - ]
     396                 :        8684 : }
     397                 :             : 
     398                 :        7314 : UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempool_sequence)
     399                 :             : {
     400         [ +  + ]:        7314 :     if (verbose) {
     401         [ +  + ]:        1058 :         if (include_mempool_sequence) {
     402   [ +  -  +  - ]:           2 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "Verbose results cannot contain mempool sequence values.");
     403                 :             :         }
     404                 :        1057 :         LOCK(pool.cs);
     405                 :        1057 :         UniValue o(UniValue::VOBJ);
     406   [ +  -  +  + ]:        4825 :         for (const CTxMemPoolEntry& e : pool.entryAll()) {
     407                 :        3768 :             UniValue info(UniValue::VOBJ);
     408         [ +  - ]:        3768 :             entryToJSON(pool, info, e);
     409                 :             :             // Mempool has unique entries so there is no advantage in using
     410                 :             :             // UniValue::pushKV, which checks if the key already exists in O(N).
     411                 :             :             // UniValue::pushKVEnd is used instead which currently is O(1).
     412   [ +  -  +  - ]:        7536 :             o.pushKVEnd(e.GetTx().GetHash().ToString(), std::move(info));
     413                 :        3768 :         }
     414         [ +  - ]:        1057 :         return o;
     415                 :        1057 :     } else {
     416                 :        6256 :         UniValue a(UniValue::VARR);
     417                 :        6256 :         uint64_t mempool_sequence;
     418                 :        6256 :         {
     419         [ +  - ]:        6256 :             LOCK(pool.cs);
     420   [ +  -  +  -  :      327063 :             for (const CTxMemPoolEntry& e : pool.entryAll()) {
                   +  + ]
     421   [ +  -  +  -  :      320807 :                 a.push_back(e.GetTx().GetHash().ToString());
                   +  - ]
     422                 :             :             }
     423         [ +  - ]:        6256 :             mempool_sequence = pool.GetSequence();
     424                 :           0 :         }
     425         [ +  + ]:        6256 :         if (!include_mempool_sequence) {
     426                 :        6235 :             return a;
     427                 :             :         } else {
     428                 :          21 :             UniValue o(UniValue::VOBJ);
     429   [ +  -  +  - ]:          42 :             o.pushKV("txids", std::move(a));
     430   [ +  -  +  -  :          42 :             o.pushKV("mempool_sequence", mempool_sequence);
                   +  - ]
     431                 :          21 :             return o;
     432                 :          21 :         }
     433                 :        6256 :     }
     434                 :             : }
     435                 :             : 
     436                 :        2357 : static RPCHelpMan getmempoolfeeratediagram()
     437                 :             : {
     438                 :        2357 :     return RPCHelpMan{"getmempoolfeeratediagram",
     439         [ +  - ]:        4714 :         "Returns the feerate diagram for the whole mempool.",
     440                 :             :         {},
     441                 :             :         {
     442                 :           0 :             RPCResult{"mempool chunks",
     443   [ +  -  +  - ]:        4714 :                 RPCResult::Type::ARR, "", "",
     444                 :             :                 {
     445                 :             :                     {
     446   [ +  -  +  - ]:        4714 :                         RPCResult::Type::OBJ, "", "",
     447                 :             :                         {
     448   [ +  -  +  - ]:        4714 :                             {RPCResult::Type::NUM, "weight", "cumulative sigops-adjusted weight"},
     449   [ +  -  +  - ]:        4714 :                             {RPCResult::Type::NUM, "fee", "cumulative fee"}
     450                 :             :                         }
     451                 :             :                     }
     452                 :             :                 }
     453   [ +  -  +  -  :       16499 :             }
          +  +  +  +  -  
                -  -  - ]
     454                 :             :         },
     455                 :        2357 :         RPCExamples{
     456   [ +  -  +  -  :        4714 :             HelpExampleCli("getmempoolfeeratediagram", "")
                   +  - ]
     457   [ +  -  +  -  :        9428 :             + HelpExampleRpc("getmempoolfeeratediagram", "")
                   +  - ]
     458         [ +  - ]:        2357 :         },
     459                 :        2357 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     460                 :             :         {
     461                 :           5 :             const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
     462                 :           5 :             LOCK(mempool.cs);
     463                 :             : 
     464                 :           5 :             UniValue result(UniValue::VARR);
     465                 :             : 
     466         [ +  - ]:           5 :             auto diagram = mempool.GetFeerateDiagram();
     467                 :             : 
     468         [ +  + ]:         136 :             for (auto f : diagram) {
     469                 :         131 :                 UniValue o(UniValue::VOBJ);
     470   [ +  -  +  -  :         262 :                 o.pushKV("weight", f.size);
                   +  - ]
     471   [ +  -  +  -  :         262 :                 o.pushKV("fee", ValueFromAmount(f.fee));
                   +  - ]
     472   [ +  -  +  - ]:         131 :                 result.push_back(o);
     473                 :         131 :             }
     474                 :           5 :             return result;
     475         [ +  - ]:          10 :         }
     476   [ +  -  +  -  :       18856 :     };
          +  -  +  -  +  
                +  -  - ]
     477   [ +  -  +  -  :        9428 : }
          +  -  +  -  -  
                      - ]
     478                 :             : 
     479                 :        9671 : static RPCHelpMan getrawmempool()
     480                 :             : {
     481                 :        9671 :     return RPCHelpMan{
     482                 :        9671 :         "getrawmempool",
     483         [ +  - ]:       19342 :         "Returns all transaction ids in memory pool as a json array of string transaction ids.\n"
     484                 :             :         "\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n",
     485                 :             :         {
     486   [ +  -  +  -  :       29013 :             {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
                   +  - ]
     487   [ +  -  +  -  :       29013 :             {"mempool_sequence", RPCArg::Type::BOOL, RPCArg::Default{false}, "If verbose=false, returns a json object with transaction list and mempool sequence number attached."},
                   +  - ]
     488                 :             :         },
     489                 :             :         {
     490         [ +  - ]:        9671 :             RPCResult{"for verbose = false",
     491   [ +  -  +  - ]:       19342 :                 RPCResult::Type::ARR, "", "",
     492                 :             :                 {
     493   [ +  -  +  - ]:       19342 :                     {RPCResult::Type::STR_HEX, "", "The transaction id"},
     494   [ +  -  +  +  :       29013 :                 }},
                   -  - ]
     495         [ +  - ]:       19342 :             RPCResult{"for verbose = true",
     496   [ +  -  +  - ]:       19342 :                 RPCResult::Type::OBJ_DYN, "", "",
     497                 :             :                 {
     498   [ +  -  +  -  :       19342 :                     {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
                   +  - ]
     499   [ +  -  +  +  :       29013 :                 }},
                   -  - ]
     500         [ +  - ]:       19342 :             RPCResult{"for verbose = false and mempool_sequence = true",
     501   [ +  -  +  - ]:       19342 :                 RPCResult::Type::OBJ, "", "",
     502                 :             :                 {
     503   [ +  -  +  - ]:       19342 :                     {RPCResult::Type::ARR, "txids", "",
     504                 :             :                     {
     505   [ +  -  +  - ]:       19342 :                         {RPCResult::Type::STR_HEX, "", "The transaction id"},
     506                 :             :                     }},
     507   [ +  -  +  - ]:       19342 :                     {RPCResult::Type::NUM, "mempool_sequence", "The mempool sequence value."},
     508   [ +  -  +  -  :       67697 :                 }},
          +  +  +  +  -  
                -  -  - ]
     509                 :             :         },
     510                 :        9671 :         RPCExamples{
     511   [ +  -  +  -  :       19342 :             HelpExampleCli("getrawmempool", "true")
                   +  - ]
     512   [ +  -  +  -  :       38684 :             + HelpExampleRpc("getrawmempool", "true")
                   +  - ]
     513         [ +  - ]:        9671 :         },
     514                 :        9671 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     515                 :             : {
     516                 :        7310 :     bool fVerbose = false;
     517         [ +  + ]:        7310 :     if (!request.params[0].isNull())
     518                 :        1113 :         fVerbose = request.params[0].get_bool();
     519                 :             : 
     520                 :        7310 :     bool include_mempool_sequence = false;
     521         [ +  + ]:        7310 :     if (!request.params[1].isNull()) {
     522                 :          22 :         include_mempool_sequence = request.params[1].get_bool();
     523                 :             :     }
     524                 :             : 
     525                 :        7310 :     return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
     526                 :             : },
     527   [ +  -  +  -  :      116052 :     };
          +  -  +  -  +  
          +  +  +  -  -  
                   -  - ]
     528   [ +  -  +  -  :      116052 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  -  -  -  -  
                   -  - ]
     529                 :             : 
     530                 :        2974 : static RPCHelpMan getmempoolancestors()
     531                 :             : {
     532                 :        2974 :     return RPCHelpMan{
     533                 :        2974 :         "getmempoolancestors",
     534         [ +  - ]:        5948 :         "If txid is in the mempool, returns all in-mempool ancestors.\n",
     535                 :             :         {
     536   [ +  -  +  - ]:        5948 :             {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
     537   [ +  -  +  -  :        8922 :             {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
                   +  - ]
     538                 :             :         },
     539                 :             :         {
     540         [ +  - ]:        2974 :             RPCResult{"for verbose = false",
     541   [ +  -  +  - ]:        5948 :                 RPCResult::Type::ARR, "", "",
     542   [ +  -  +  -  :       11896 :                 {{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool ancestor transaction"}}},
          +  -  +  +  -  
                      - ]
     543         [ +  - ]:        5948 :             RPCResult{"for verbose = true",
     544   [ +  -  +  - ]:        5948 :                 RPCResult::Type::OBJ_DYN, "", "",
     545                 :             :                 {
     546   [ +  -  +  -  :        5948 :                     {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
                   +  - ]
     547   [ +  -  +  +  :        8922 :                 }},
                   -  - ]
     548                 :             :         },
     549                 :        2974 :         RPCExamples{
     550   [ +  -  +  -  :        5948 :             HelpExampleCli("getmempoolancestors", "\"mytxid\"")
                   +  - ]
     551   [ +  -  +  -  :       11896 :             + HelpExampleRpc("getmempoolancestors", "\"mytxid\"")
                   +  - ]
     552         [ +  - ]:        2974 :         },
     553                 :        2974 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     554                 :             : {
     555                 :         613 :     bool fVerbose = false;
     556         [ +  + ]:         613 :     if (!request.params[1].isNull())
     557                 :          65 :         fVerbose = request.params[1].get_bool();
     558                 :             : 
     559                 :         613 :     auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
     560                 :             : 
     561                 :         613 :     const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
     562                 :         613 :     LOCK(mempool.cs);
     563                 :             : 
     564         [ +  - ]:         613 :     const auto entry{mempool.GetEntry(txid)};
     565         [ -  + ]:         613 :     if (entry == nullptr) {
     566   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
     567                 :             :     }
     568                 :             : 
     569         [ +  - ]:         613 :     auto ancestors{mempool.CalculateMemPoolAncestors(*entry)};
     570                 :             : 
     571         [ +  + ]:         613 :     if (!fVerbose) {
     572                 :         548 :         UniValue o(UniValue::VARR);
     573         [ +  + ]:       11954 :         for (CTxMemPool::txiter ancestorIt : ancestors) {
     574   [ +  -  +  -  :       11406 :             o.push_back(ancestorIt->GetTx().GetHash().ToString());
                   +  - ]
     575                 :             :         }
     576                 :             :         return o;
     577                 :           0 :     } else {
     578                 :          65 :         UniValue o(UniValue::VOBJ);
     579         [ +  + ]:        2144 :         for (CTxMemPool::txiter ancestorIt : ancestors) {
     580                 :        2079 :             const CTxMemPoolEntry &e = *ancestorIt;
     581                 :        2079 :             UniValue info(UniValue::VOBJ);
     582         [ +  - ]:        2079 :             entryToJSON(mempool, info, e);
     583   [ +  -  +  - ]:        4158 :             o.pushKV(e.GetTx().GetHash().ToString(), std::move(info));
     584                 :        2079 :         }
     585                 :          65 :         return o;
     586                 :          65 :     }
     587         [ +  - ]:        1226 : },
     588   [ +  -  +  -  :       32714 :     };
          +  -  +  -  +  
          +  +  +  -  -  
                   -  - ]
     589   [ +  -  +  -  :       23792 : }
          +  -  +  -  +  
          -  +  -  -  -  
                   -  - ]
     590                 :             : 
     591                 :       11880 : static RPCHelpMan getmempooldescendants()
     592                 :             : {
     593                 :       11880 :     return RPCHelpMan{
     594                 :       11880 :         "getmempooldescendants",
     595         [ +  - ]:       23760 :         "If txid is in the mempool, returns all in-mempool descendants.\n",
     596                 :             :         {
     597   [ +  -  +  - ]:       23760 :             {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
     598   [ +  -  +  -  :       35640 :             {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "True for a json object, false for array of transaction ids"},
                   +  - ]
     599                 :             :         },
     600                 :             :         {
     601         [ +  - ]:       11880 :             RPCResult{"for verbose = false",
     602   [ +  -  +  - ]:       23760 :                 RPCResult::Type::ARR, "", "",
     603   [ +  -  +  -  :       47520 :                 {{RPCResult::Type::STR_HEX, "", "The transaction id of an in-mempool descendant transaction"}}},
          +  -  +  +  -  
                      - ]
     604         [ +  - ]:       23760 :             RPCResult{"for verbose = true",
     605   [ +  -  +  - ]:       23760 :                 RPCResult::Type::OBJ_DYN, "", "",
     606                 :             :                 {
     607   [ +  -  +  -  :       23760 :                     {RPCResult::Type::OBJ, "transactionid", "", MempoolEntryDescription()},
                   +  - ]
     608   [ +  -  +  +  :       35640 :                 }},
                   -  - ]
     609                 :             :         },
     610                 :       11880 :         RPCExamples{
     611   [ +  -  +  -  :       23760 :             HelpExampleCli("getmempooldescendants", "\"mytxid\"")
                   +  - ]
     612   [ +  -  +  -  :       47520 :             + HelpExampleRpc("getmempooldescendants", "\"mytxid\"")
                   +  - ]
     613         [ +  - ]:       11880 :         },
     614                 :       11880 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     615                 :             : {
     616                 :        9519 :     bool fVerbose = false;
     617         [ +  + ]:        9519 :     if (!request.params[1].isNull())
     618                 :          65 :         fVerbose = request.params[1].get_bool();
     619                 :             : 
     620                 :        9519 :     auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
     621                 :             : 
     622                 :        9519 :     const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
     623                 :        9519 :     LOCK(mempool.cs);
     624                 :             : 
     625         [ +  - ]:        9519 :     const auto it{mempool.GetIter(txid)};
     626         [ -  + ]:        9519 :     if (!it) {
     627   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
     628                 :             :     }
     629                 :             : 
     630         [ +  - ]:        9519 :     CTxMemPool::setEntries setDescendants;
     631         [ +  - ]:        9519 :     mempool.CalculateDescendants(*it, setDescendants);
     632                 :             :     // CTxMemPool::CalculateDescendants will include the given tx
     633                 :        9519 :     setDescendants.erase(*it);
     634                 :             : 
     635         [ +  + ]:        9519 :     if (!fVerbose) {
     636                 :        9454 :         UniValue o(UniValue::VARR);
     637         [ +  + ]:      175782 :         for (CTxMemPool::txiter descendantIt : setDescendants) {
     638   [ +  -  +  -  :      166328 :             o.push_back(descendantIt->GetTx().GetHash().ToString());
                   +  - ]
     639                 :             :         }
     640                 :             : 
     641                 :             :         return o;
     642                 :           0 :     } else {
     643                 :          65 :         UniValue o(UniValue::VOBJ);
     644         [ +  + ]:        2144 :         for (CTxMemPool::txiter descendantIt : setDescendants) {
     645                 :        2079 :             const CTxMemPoolEntry &e = *descendantIt;
     646                 :        2079 :             UniValue info(UniValue::VOBJ);
     647         [ +  - ]:        2079 :             entryToJSON(mempool, info, e);
     648   [ +  -  +  - ]:        4158 :             o.pushKV(e.GetTx().GetHash().ToString(), std::move(info));
     649                 :        2079 :         }
     650                 :          65 :         return o;
     651                 :          65 :     }
     652         [ +  - ]:       19038 : },
     653   [ +  -  +  -  :      130680 :     };
          +  -  +  -  +  
          +  +  +  -  -  
                   -  - ]
     654   [ +  -  +  -  :       95040 : }
          +  -  +  -  +  
          -  +  -  -  -  
                   -  - ]
     655                 :             : 
     656                 :        3490 : static RPCHelpMan getmempoolcluster()
     657                 :             : {
     658                 :        3490 :     return RPCHelpMan{"getmempoolcluster",
     659         [ +  - ]:        6980 :         "Returns mempool data for given cluster\n",
     660                 :             :         {
     661   [ +  -  +  - ]:        6980 :             {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The txid of a transaction in the cluster"},
     662                 :             :         },
     663         [ +  - ]:        6980 :         RPCResult{
     664   [ +  -  +  -  :        6980 :             RPCResult::Type::OBJ, "", "", ClusterDescription()},
             +  -  +  - ]
     665                 :        3490 :         RPCExamples{
     666   [ +  -  +  -  :        6980 :             HelpExampleCli("getmempoolcluster", "txid")
                   +  - ]
     667   [ +  -  +  -  :       13960 :             + HelpExampleRpc("getmempoolcluster", "txid")
             +  -  +  - ]
     668         [ +  - ]:        3490 :         },
     669                 :        3490 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     670                 :             : {
     671                 :        1129 :     uint256 hash = ParseHashV(request.params[0], "parameter 1");
     672                 :             : 
     673                 :        1129 :     const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
     674                 :        1129 :     LOCK(mempool.cs);
     675                 :             : 
     676         [ +  - ]:        1129 :     auto cluster = mempool.GetCluster(Txid::FromUint256(hash));
     677                 :             : 
     678                 :        1129 :     UniValue info(UniValue::VOBJ);
     679   [ +  -  +  - ]:        1129 :     clusterToJSON(mempool, info, cluster);
     680                 :        1129 :     return info;
     681         [ +  - ]:        2258 : },
     682   [ +  -  +  -  :       17450 :     };
             +  +  -  - ]
     683         [ +  - ]:        6980 : }
     684                 :             : 
     685                 :        3125 : static RPCHelpMan getmempoolentry()
     686                 :             : {
     687                 :        3125 :     return RPCHelpMan{
     688                 :        3125 :         "getmempoolentry",
     689         [ +  - ]:        6250 :         "Returns mempool data for given transaction\n",
     690                 :             :         {
     691   [ +  -  +  - ]:        6250 :             {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id (must be in mempool)"},
     692                 :             :         },
     693         [ +  - ]:        6250 :         RPCResult{
     694   [ +  -  +  -  :        6250 :             RPCResult::Type::OBJ, "", "", MempoolEntryDescription()},
             +  -  +  - ]
     695                 :        3125 :         RPCExamples{
     696   [ +  -  +  -  :        6250 :             HelpExampleCli("getmempoolentry", "\"mytxid\"")
                   +  - ]
     697   [ +  -  +  -  :       12500 :             + HelpExampleRpc("getmempoolentry", "\"mytxid\"")
             +  -  +  - ]
     698         [ +  - ]:        3125 :         },
     699                 :        3125 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     700                 :             : {
     701                 :         764 :     auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
     702                 :             : 
     703                 :         764 :     const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
     704                 :         764 :     LOCK(mempool.cs);
     705                 :             : 
     706         [ +  - ]:         764 :     const auto entry{mempool.GetEntry(txid)};
     707         [ +  + ]:         764 :     if (entry == nullptr) {
     708   [ +  -  +  - ]:          12 :         throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
     709                 :             :     }
     710                 :             : 
     711                 :         758 :     UniValue info(UniValue::VOBJ);
     712         [ +  - ]:         758 :     entryToJSON(mempool, info, *entry);
     713         [ +  - ]:         758 :     return info;
     714                 :         758 : },
     715   [ +  -  +  -  :       15625 :     };
             +  +  -  - ]
     716         [ +  - ]:        6250 : }
     717                 :             : 
     718                 :        2436 : static RPCHelpMan gettxspendingprevout()
     719                 :             : {
     720                 :        2436 :     return RPCHelpMan{"gettxspendingprevout",
     721         [ +  - ]:        4872 :         "Scans the mempool to find transactions spending any of the given outputs",
     722                 :             :         {
     723   [ +  -  +  - ]:        4872 :             {"outputs", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction outputs that we want to check, and within each, the txid (string) vout (numeric).",
     724                 :             :                 {
     725   [ +  -  +  - ]:        4872 :                     {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
     726                 :             :                         {
     727   [ +  -  +  - ]:        4872 :                             {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"},
     728   [ +  -  +  - ]:        4872 :                             {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"},
     729                 :             :                         },
     730                 :             :                     },
     731                 :             :                 },
     732                 :             :             },
     733                 :             :         },
     734         [ +  - ]:        4872 :         RPCResult{
     735   [ +  -  +  - ]:        4872 :             RPCResult::Type::ARR, "", "",
     736                 :             :             {
     737   [ +  -  +  - ]:        4872 :                 {RPCResult::Type::OBJ, "", "",
     738                 :             :                 {
     739   [ +  -  +  - ]:        4872 :                     {RPCResult::Type::STR_HEX, "txid", "the transaction id of the checked output"},
     740   [ +  -  +  - ]:        4872 :                     {RPCResult::Type::NUM, "vout", "the vout value of the checked output"},
     741   [ +  -  +  - ]:        4872 :                     {RPCResult::Type::STR_HEX, "spendingtxid", /*optional=*/true, "the transaction id of the mempool transaction spending this output (omitted if unspent)"},
     742                 :             :                 }},
     743                 :             :             }
     744   [ +  -  +  -  :       21924 :         },
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     745                 :        2436 :         RPCExamples{
     746   [ +  -  +  -  :        4872 :             HelpExampleCli("gettxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
                   +  - ]
     747   [ +  -  +  -  :        9744 :             + HelpExampleRpc("gettxspendingprevout", "\"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":3}]\"")
             +  -  +  - ]
     748         [ +  - ]:        2436 :         },
     749                 :        2436 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     750                 :             :         {
     751                 :          75 :             const UniValue& output_params = request.params[0].get_array();
     752   [ -  +  +  + ]:          75 :             if (output_params.empty()) {
     753   [ +  -  +  - ]:           2 :                 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, outputs are missing");
     754                 :             :             }
     755                 :             : 
     756                 :          74 :             std::vector<COutPoint> prevouts;
     757         [ +  - ]:          74 :             prevouts.reserve(output_params.size());
     758                 :             : 
     759   [ -  +  +  + ]:         146 :             for (unsigned int idx = 0; idx < output_params.size(); idx++) {
     760   [ +  -  +  - ]:          77 :                 const UniValue& o = output_params[idx].get_obj();
     761                 :             : 
     762   [ +  +  +  +  :         312 :                 RPCTypeCheckObj(o,
                   +  + ]
     763                 :             :                                 {
     764         [ +  - ]:          77 :                                     {"txid", UniValueType(UniValue::VSTR)},
     765         [ +  - ]:          77 :                                     {"vout", UniValueType(UniValue::VNUM)},
     766                 :             :                                 }, /*fAllowNull=*/false, /*fStrict=*/true);
     767                 :             : 
     768         [ +  - ]:          73 :                 const Txid txid = Txid::FromUint256(ParseHashO(o, "txid"));
     769   [ +  -  +  - ]:          73 :                 const int nOutput{o.find_value("vout").getInt<int>()};
     770         [ +  + ]:          73 :                 if (nOutput < 0) {
     771   [ +  -  +  - ]:           2 :                     throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
     772                 :             :                 }
     773                 :             : 
     774         [ +  - ]:          72 :                 prevouts.emplace_back(txid, nOutput);
     775                 :             :             }
     776                 :             : 
     777         [ +  - ]:          69 :             const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
     778         [ +  - ]:          69 :             LOCK(mempool.cs);
     779                 :             : 
     780                 :          69 :             UniValue result{UniValue::VARR};
     781                 :             : 
     782         [ +  + ]:         141 :             for (const COutPoint& prevout : prevouts) {
     783                 :          72 :                 UniValue o(UniValue::VOBJ);
     784   [ +  -  +  -  :         144 :                 o.pushKV("txid", prevout.hash.ToString());
             +  -  +  - ]
     785   [ +  -  +  -  :         144 :                 o.pushKV("vout", (uint64_t)prevout.n);
                   +  - ]
     786                 :             : 
     787         [ +  - ]:          72 :                 const CTransaction* spendingTx = mempool.GetConflictTx(prevout);
     788         [ +  + ]:          72 :                 if (spendingTx != nullptr) {
     789   [ +  -  +  -  :         138 :                     o.pushKV("spendingtxid", spendingTx->GetHash().ToString());
             +  -  +  - ]
     790                 :             :                 }
     791                 :             : 
     792         [ +  - ]:          72 :                 result.push_back(std::move(o));
     793                 :          72 :             }
     794                 :             : 
     795         [ +  - ]:          69 :             return result;
     796   [ +  -  +  -  :         150 :         },
             +  -  -  + ]
     797   [ +  -  +  -  :       29232 :     };
          +  -  +  -  +  
          +  +  +  +  +  
          -  -  -  -  -  
                      - ]
     798   [ +  -  +  -  :       29232 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  -  -  
                      - ]
     799                 :             : 
     800                 :        1353 : UniValue MempoolInfoToJSON(const CTxMemPool& pool)
     801                 :             : {
     802                 :             :     // Make sure this call is atomic in the pool.
     803                 :        1353 :     LOCK(pool.cs);
     804                 :        1353 :     UniValue ret(UniValue::VOBJ);
     805   [ +  -  +  -  :        2706 :     ret.pushKV("loaded", pool.GetLoadTried());
             +  -  +  - ]
     806   [ +  -  +  -  :        2706 :     ret.pushKV("size", (int64_t)pool.size());
             +  -  +  - ]
     807   [ +  -  +  -  :        2706 :     ret.pushKV("bytes", (int64_t)pool.GetTotalTxSize());
                   +  - ]
     808   [ +  -  +  -  :        2706 :     ret.pushKV("usage", (int64_t)pool.DynamicMemoryUsage());
             +  -  +  - ]
     809   [ +  -  +  -  :        2706 :     ret.pushKV("total_fee", ValueFromAmount(pool.GetTotalFee()));
                   +  - ]
     810   [ +  -  +  -  :        2706 :     ret.pushKV("maxmempool", pool.m_opts.max_size_bytes);
                   +  - ]
     811   [ +  -  +  -  :        2706 :     ret.pushKV("mempoolminfee", ValueFromAmount(std::max(pool.GetMinFee(), pool.m_opts.min_relay_feerate).GetFeePerK()));
             +  -  +  - ]
     812   [ +  -  +  -  :        2706 :     ret.pushKV("minrelaytxfee", ValueFromAmount(pool.m_opts.min_relay_feerate.GetFeePerK()));
                   +  - ]
     813   [ +  -  +  -  :        2706 :     ret.pushKV("incrementalrelayfee", ValueFromAmount(pool.m_opts.incremental_relay_feerate.GetFeePerK()));
                   +  - ]
     814   [ +  -  +  -  :        2706 :     ret.pushKV("unbroadcastcount", uint64_t{pool.GetUnbroadcastTxs().size()});
             +  -  +  - ]
     815   [ +  -  +  -  :        2706 :     ret.pushKV("fullrbf", true);
                   +  - ]
     816   [ +  -  +  -  :        2706 :     ret.pushKV("permitbaremultisig", pool.m_opts.permit_bare_multisig);
                   +  - ]
     817   [ +  +  +  -  :        4057 :     ret.pushKV("maxdatacarriersize", pool.m_opts.max_datacarrier_bytes.value_or(0));
             +  -  +  - ]
     818   [ +  -  +  -  :        2706 :     ret.pushKV("limitclustercount", pool.m_opts.limits.cluster_count);
                   +  - ]
     819   [ +  -  +  -  :        2706 :     ret.pushKV("limitclustersize", pool.m_opts.limits.cluster_size_vbytes);
                   +  - ]
     820         [ +  - ]:        1353 :     return ret;
     821                 :        1353 : }
     822                 :             : 
     823                 :        3713 : static RPCHelpMan getmempoolinfo()
     824                 :             : {
     825                 :        3713 :     return RPCHelpMan{"getmempoolinfo",
     826         [ +  - ]:        7426 :         "Returns details on the active state of the TX memory pool.",
     827                 :             :         {},
     828         [ +  - ]:        7426 :         RPCResult{
     829         [ +  - ]:        7426 :             RPCResult::Type::OBJ, "", "",
     830                 :             :             {
     831   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::BOOL, "loaded", "True if the initial load attempt of the persisted mempool finished"},
     832   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "size", "Current tx count"},
     833   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "bytes", "Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted"},
     834   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "usage", "Total memory usage for the mempool"},
     835   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::STR_AMOUNT, "total_fee", "Total fees for the mempool in " + CURRENCY_UNIT + ", ignoring modified fees through prioritisetransaction"},
     836   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "maxmempool", "Maximum memory usage for the mempool"},
     837   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::STR_AMOUNT, "mempoolminfee", "Minimum fee rate in " + CURRENCY_UNIT + "/kvB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee"},
     838   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::STR_AMOUNT, "minrelaytxfee", "Current minimum relay fee for transactions"},
     839   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "incrementalrelayfee", "minimum fee rate increment for mempool limiting or replacement in " + CURRENCY_UNIT + "/kvB"},
     840   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "unbroadcastcount", "Current number of transactions that haven't passed initial broadcast yet"},
     841   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::BOOL, "fullrbf", "True if the mempool accepts RBF without replaceability signaling inspection (DEPRECATED)"},
     842   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::BOOL, "permitbaremultisig", "True if the mempool accepts transactions with bare multisig outputs"},
     843   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "maxdatacarriersize", "Maximum number of bytes that can be used by OP_RETURN outputs in the mempool"},
     844   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "limitclustercount", "Maximum number of transactions that can be in a cluster (configured by -limitclustercount)"},
     845   [ +  -  +  - ]:        7426 :                 {RPCResult::Type::NUM, "limitclustersize", "Maximum size of a cluster in virtual bytes (configured by -limitclustersize)"},
     846   [ +  -  +  -  :      115103 :             }},
             +  +  -  - ]
     847                 :        3713 :         RPCExamples{
     848   [ +  -  +  -  :        7426 :             HelpExampleCli("getmempoolinfo", "")
                   +  - ]
     849   [ +  -  +  -  :       14852 :             + HelpExampleRpc("getmempoolinfo", "")
             +  -  +  - ]
     850         [ +  - ]:        3713 :         },
     851                 :        3713 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     852                 :             : {
     853                 :        1352 :     return MempoolInfoToJSON(EnsureAnyMemPool(request.context));
     854                 :             : },
     855   [ +  -  +  - ]:       14852 :     };
     856   [ +  -  +  -  :       55695 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  - ]
     857                 :             : 
     858                 :        2364 : static RPCHelpMan importmempool()
     859                 :             : {
     860                 :        2364 :     return RPCHelpMan{
     861                 :        2364 :         "importmempool",
     862         [ +  - ]:        4728 :         "Import a mempool.dat file and attempt to add its contents to the mempool.\n"
     863                 :             :         "Warning: Importing untrusted files is dangerous, especially if metadata from the file is taken over.",
     864                 :             :         {
     865   [ +  -  +  - ]:        4728 :             {"filepath", RPCArg::Type::STR, RPCArg::Optional::NO, "The mempool file"},
     866         [ +  - ]:        4728 :             {"options",
     867                 :             :              RPCArg::Type::OBJ_NAMED_PARAMS,
     868                 :        2364 :              RPCArg::Optional::OMITTED,
     869         [ +  - ]:        4728 :              "",
     870                 :             :              {
     871   [ +  -  +  - ]:        4728 :                  {"use_current_time", RPCArg::Type::BOOL, RPCArg::Default{true},
     872         [ +  - ]:        4728 :                   "Whether to use the current system time or use the entry time metadata from the mempool file.\n"
     873                 :             :                   "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior."},
     874   [ +  -  +  - ]:        4728 :                  {"apply_fee_delta_priority", RPCArg::Type::BOOL, RPCArg::Default{false},
     875         [ +  - ]:        4728 :                   "Whether to apply the fee delta metadata from the mempool file.\n"
     876                 :             :                   "It will be added to any existing fee deltas.\n"
     877                 :             :                   "The fee delta can be set by the prioritisetransaction RPC.\n"
     878                 :             :                   "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior.\n"
     879                 :             :                   "Only set this bool if you understand what it does."},
     880   [ +  -  +  - ]:        4728 :                  {"apply_unbroadcast_set", RPCArg::Type::BOOL, RPCArg::Default{false},
     881         [ +  - ]:        4728 :                   "Whether to apply the unbroadcast set metadata from the mempool file.\n"
     882                 :             :                   "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior."},
     883                 :             :              },
     884         [ +  - ]:        2364 :              RPCArgOptions{.oneline_description = "options"}},
     885                 :             :         },
     886   [ +  -  +  -  :        4728 :         RPCResult{RPCResult::Type::OBJ, "", "", std::vector<RPCResult>{}},
             +  -  +  - ]
     887   [ +  -  +  -  :        7092 :         RPCExamples{HelpExampleCli("importmempool", "/path/to/mempool.dat") + HelpExampleRpc("importmempool", "/path/to/mempool.dat")},
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     888                 :        2364 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
     889                 :           3 :             const NodeContext& node{EnsureAnyNodeContext(request.context)};
     890                 :             : 
     891                 :           3 :             CTxMemPool& mempool{EnsureMemPool(node)};
     892                 :           3 :             ChainstateManager& chainman = EnsureChainman(node);
     893                 :           3 :             Chainstate& chainstate = chainman.ActiveChainstate();
     894                 :             : 
     895         [ -  + ]:           3 :             if (chainman.IsInitialBlockDownload()) {
     896   [ #  #  #  # ]:           0 :                 throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Can only import the mempool after the block download and sync is done.");
     897                 :             :             }
     898                 :             : 
     899                 :           3 :             const fs::path load_path{fs::u8path(self.Arg<std::string_view>("filepath"))};
     900   [ +  -  +  -  :           3 :             const UniValue& use_current_time{request.params[1]["use_current_time"]};
                   +  - ]
     901   [ +  -  +  -  :           3 :             const UniValue& apply_fee_delta{request.params[1]["apply_fee_delta_priority"]};
                   +  - ]
     902   [ +  -  +  -  :           3 :             const UniValue& apply_unbroadcast{request.params[1]["apply_unbroadcast_set"]};
                   +  - ]
     903         [ -  + ]:           3 :             node::ImportMempoolOptions opts{
     904   [ -  +  -  - ]:           3 :                 .use_current_time = use_current_time.isNull() ? true : use_current_time.get_bool(),
     905   [ +  +  +  - ]:           3 :                 .apply_fee_delta_priority = apply_fee_delta.isNull() ? false : apply_fee_delta.get_bool(),
     906   [ +  +  +  - ]:           3 :                 .apply_unbroadcast_set = apply_unbroadcast.isNull() ? false : apply_unbroadcast.get_bool(),
     907   [ -  +  +  +  :           5 :             };
                   +  + ]
     908                 :             : 
     909   [ +  -  -  + ]:           3 :             if (!node::LoadMempool(mempool, load_path, chainstate, std::move(opts))) {
     910   [ #  #  #  # ]:           0 :                 throw JSONRPCError(RPC_MISC_ERROR, "Unable to import mempool file, see debug.log for details.");
     911                 :             :             }
     912                 :             : 
     913                 :           3 :             UniValue ret{UniValue::VOBJ};
     914                 :           3 :             return ret;
     915                 :           6 :         },
     916   [ +  -  +  -  :       26004 :     };
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     917   [ +  -  +  -  :       21276 : }
          +  -  +  -  +  
             -  -  -  -  
                      - ]
     918                 :             : 
     919                 :        2365 : static RPCHelpMan savemempool()
     920                 :             : {
     921                 :        2365 :     return RPCHelpMan{
     922                 :        2365 :         "savemempool",
     923         [ +  - ]:        4730 :         "Dumps the mempool to disk. It will fail until the previous dump is fully loaded.\n",
     924                 :             :         {},
     925         [ +  - ]:        4730 :         RPCResult{
     926         [ +  - ]:        4730 :             RPCResult::Type::OBJ, "", "",
     927                 :             :             {
     928   [ +  -  +  - ]:        4730 :                 {RPCResult::Type::STR, "filename", "the directory and file where the mempool was saved"},
     929   [ +  -  +  -  :        7095 :             }},
             +  +  -  - ]
     930                 :        2365 :         RPCExamples{
     931   [ +  -  +  -  :        4730 :             HelpExampleCli("savemempool", "")
                   +  - ]
     932   [ +  -  +  -  :        9460 :             + HelpExampleRpc("savemempool", "")
             +  -  +  - ]
     933         [ +  - ]:        2365 :         },
     934                 :        2365 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     935                 :             : {
     936                 :           4 :     const ArgsManager& args{EnsureAnyArgsman(request.context)};
     937                 :           4 :     const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
     938                 :             : 
     939         [ -  + ]:           4 :     if (!mempool.GetLoadTried()) {
     940   [ #  #  #  # ]:           0 :         throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
     941                 :             :     }
     942                 :             : 
     943                 :           4 :     const fs::path& dump_path = MempoolPath(args);
     944                 :             : 
     945   [ +  -  +  + ]:           4 :     if (!DumpMempool(mempool, dump_path)) {
     946   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
     947                 :             :     }
     948                 :             : 
     949                 :           3 :     UniValue ret(UniValue::VOBJ);
     950   [ +  -  +  -  :           6 :     ret.pushKV("filename", dump_path.utf8string());
             +  -  +  - ]
     951                 :             : 
     952                 :           6 :     return ret;
     953                 :           0 : },
     954   [ +  -  +  - ]:        9460 :     };
     955         [ +  - ]:        2365 : }
     956                 :             : 
     957                 :        5140 : static std::vector<RPCResult> OrphanDescription()
     958                 :             : {
     959                 :        5140 :     return {
     960   [ +  -  +  - ]:       10280 :         RPCResult{RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
     961   [ +  -  +  - ]:       10280 :         RPCResult{RPCResult::Type::STR_HEX, "wtxid", "The transaction witness hash in hex"},
     962   [ +  -  +  - ]:       10280 :         RPCResult{RPCResult::Type::NUM, "bytes", "The serialized transaction size in bytes"},
     963   [ +  -  +  - ]:       10280 :         RPCResult{RPCResult::Type::NUM, "vsize", "The virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted."},
     964   [ +  -  +  - ]:       10280 :         RPCResult{RPCResult::Type::NUM, "weight", "The transaction weight as defined in BIP 141."},
     965   [ +  -  +  - ]:       10280 :         RPCResult{RPCResult::Type::ARR, "from", "",
     966                 :             :         {
     967   [ +  -  +  - ]:       10280 :             RPCResult{RPCResult::Type::NUM, "peer_id", "Peer ID"},
     968   [ +  -  +  +  :       15420 :         }},
                   -  - ]
     969   [ +  -  +  +  :       46260 :     };
                   -  - ]
     970   [ +  -  +  -  :       35980 : }
          +  -  +  -  +  
          -  +  -  +  -  
                   -  - ]
     971                 :             : 
     972                 :          42 : static UniValue OrphanToJSON(const node::TxOrphanage::OrphanInfo& orphan)
     973                 :             : {
     974                 :          42 :     UniValue o(UniValue::VOBJ);
     975   [ +  -  +  -  :          84 :     o.pushKV("txid", orphan.tx->GetHash().ToString());
             +  -  +  - ]
     976   [ +  -  +  -  :          84 :     o.pushKV("wtxid", orphan.tx->GetWitnessHash().ToString());
             +  -  +  - ]
     977   [ +  -  +  -  :          84 :     o.pushKV("bytes", orphan.tx->GetTotalSize());
             +  -  +  - ]
     978   [ +  -  +  -  :          84 :     o.pushKV("vsize", GetVirtualTransactionSize(*orphan.tx));
             +  -  +  - ]
     979   [ +  -  +  -  :          84 :     o.pushKV("weight", GetTransactionWeight(*orphan.tx));
                   +  - ]
     980                 :          42 :     UniValue from(UniValue::VARR);
     981         [ +  + ]:          90 :     for (const auto fromPeer: orphan.announcers) {
     982   [ +  -  +  - ]:          48 :         from.push_back(fromPeer);
     983                 :             :     }
     984   [ +  -  +  -  :          84 :     o.pushKV("from", from);
                   +  - ]
     985                 :          42 :     return o;
     986                 :          42 : }
     987                 :             : 
     988                 :        2570 : static RPCHelpMan getorphantxs()
     989                 :             : {
     990                 :        2570 :     return RPCHelpMan{
     991                 :        2570 :         "getorphantxs",
     992         [ +  - ]:        5140 :         "Shows transactions in the tx orphanage.\n"
     993                 :             :         "\nEXPERIMENTAL warning: this call may be changed in future releases.\n",
     994                 :             :         {
     995   [ +  -  +  -  :        7710 :             {"verbosity", RPCArg::Type::NUM, RPCArg::Default{0}, "0 for an array of txids (may contain duplicates), 1 for an array of objects with tx details, and 2 for details from (1) and tx hex",
                   +  - ]
     996         [ +  - ]:        5140 :              RPCArgOptions{.skip_type_check = true}},
     997                 :             :         },
     998                 :             :         {
     999         [ +  - ]:        2570 :             RPCResult{"for verbose = 0",
    1000   [ +  -  +  - ]:        5140 :                 RPCResult::Type::ARR, "", "",
    1001                 :             :                 {
    1002   [ +  -  +  - ]:        5140 :                     {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
    1003   [ +  -  +  +  :        7710 :                 }},
                   -  - ]
    1004         [ +  - ]:        5140 :             RPCResult{"for verbose = 1",
    1005   [ +  -  +  - ]:        5140 :                 RPCResult::Type::ARR, "", "",
    1006                 :             :                 {
    1007   [ +  -  +  -  :        5140 :                     {RPCResult::Type::OBJ, "", "", OrphanDescription()},
                   +  - ]
    1008   [ +  -  +  +  :        7710 :                 }},
                   -  - ]
    1009         [ +  - ]:        5140 :             RPCResult{"for verbose = 2",
    1010   [ +  -  +  - ]:        5140 :                 RPCResult::Type::ARR, "", "",
    1011                 :             :                 {
    1012   [ +  -  +  - ]:        5140 :                     {RPCResult::Type::OBJ, "", "",
    1013   [ +  -  +  -  :       12850 :                         Cat<std::vector<RPCResult>>(
             +  +  -  - ]
    1014         [ +  - ]:        5140 :                             OrphanDescription(),
    1015   [ +  -  +  - ]:        5140 :                             {{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded transaction data"}}
    1016                 :             :                         )
    1017                 :             :                     },
    1018   [ +  -  +  +  :        7710 :                 }},
                   -  - ]
    1019                 :             :         },
    1020                 :        2570 :         RPCExamples{
    1021   [ +  -  +  -  :        5140 :             HelpExampleCli("getorphantxs", "2")
                   +  - ]
    1022   [ +  -  +  -  :       10280 :             + HelpExampleRpc("getorphantxs", "2")
                   +  - ]
    1023         [ +  - ]:        2570 :         },
    1024                 :        2570 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
    1025                 :             :         {
    1026                 :         217 :             const NodeContext& node = EnsureAnyNodeContext(request.context);
    1027                 :         217 :             PeerManager& peerman = EnsurePeerman(node);
    1028                 :         217 :             std::vector<node::TxOrphanage::OrphanInfo> orphanage = peerman.GetOrphanTransactions();
    1029                 :             : 
    1030   [ +  -  +  + ]:         217 :             int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0, /*allow_bool*/false)};
    1031                 :             : 
    1032                 :         215 :             UniValue ret(UniValue::VARR);
    1033                 :             : 
    1034         [ +  + ]:         215 :             if (verbosity == 0) {
    1035         [ +  + ]:       18479 :                 for (auto const& orphan : orphanage) {
    1036   [ +  -  +  -  :       18298 :                     ret.push_back(orphan.tx->GetHash().ToString());
                   +  - ]
    1037                 :             :                 }
    1038         [ +  + ]:          34 :             } else if (verbosity == 1) {
    1039         [ +  + ]:          55 :                 for (auto const& orphan : orphanage) {
    1040   [ +  -  +  - ]:          32 :                     ret.push_back(OrphanToJSON(orphan));
    1041                 :             :                 }
    1042         [ +  + ]:          11 :             } else if (verbosity == 2) {
    1043         [ +  + ]:          19 :                 for (auto const& orphan : orphanage) {
    1044         [ +  - ]:          10 :                     UniValue o{OrphanToJSON(orphan)};
    1045   [ +  -  +  -  :          20 :                     o.pushKV("hex", EncodeHexTx(*orphan.tx));
             +  -  +  - ]
    1046   [ +  -  +  - ]:          10 :                     ret.push_back(o);
    1047                 :          10 :                 }
    1048                 :             :             } else {
    1049   [ +  -  +  -  :           4 :                 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid verbosity value " + ToString(verbosity));
                   +  - ]
    1050                 :             :             }
    1051                 :             : 
    1052                 :         213 :             return ret;
    1053                 :         219 :         },
    1054   [ +  -  +  -  :       28270 :     };
          +  -  +  -  +  
          +  +  +  -  -  
                   -  - ]
    1055   [ +  -  +  -  :       20560 : }
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  - ]
    1056                 :             : 
    1057                 :        2479 : static RPCHelpMan submitpackage()
    1058                 :             : {
    1059                 :        2479 :     return RPCHelpMan{"submitpackage",
    1060         [ +  - ]:        4958 :         "Submit a package of raw transactions (serialized, hex-encoded) to local node.\n"
    1061                 :             :         "The package will be validated according to consensus and mempool policy rules. If any transaction passes, it will be accepted to mempool.\n"
    1062                 :             :         "This RPC is experimental and the interface may be unstable. Refer to doc/policy/packages.md for documentation on package policies.\n"
    1063                 :             :         "Warning: successful submission does not mean the transactions will propagate throughout the network.\n"
    1064                 :             :         ,
    1065                 :             :         {
    1066   [ +  -  +  - ]:        4958 :             {"package", RPCArg::Type::ARR, RPCArg::Optional::NO, "An array of raw transactions.\n"
    1067                 :             :                 "The package must consist of a transaction with (some, all, or none of) its unconfirmed parents. A single transaction is permitted.\n"
    1068                 :             :                 "None of the parents may depend on each other. Parents that are already in mempool do not need to be present in the package.\n"
    1069                 :             :                 "The package must be topologically sorted, with the child being the last element in the array if there are multiple elements.",
    1070                 :             :                 {
    1071   [ +  -  +  - ]:        4958 :                     {"rawtx", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, ""},
    1072                 :             :                 },
    1073                 :             :             },
    1074   [ +  -  +  -  :        4958 :             {"maxfeerate", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK())},
                   +  - ]
    1075         [ +  - ]:        4958 :              "Reject transactions whose fee rate is higher than the specified value, expressed in " + CURRENCY_UNIT +
    1076                 :        2479 :                  "/kvB.\nFee rates larger than 1BTC/kvB are rejected.\nSet to 0 to accept any fee rate."},
    1077   [ +  -  +  -  :        4958 :             {"maxburnamount", RPCArg::Type::AMOUNT, RPCArg::Default{FormatMoney(DEFAULT_MAX_BURN_AMOUNT)},
                   +  - ]
    1078         [ +  - ]:        4958 :              "Reject transactions with provably unspendable outputs (e.g. 'datacarrier' outputs that use the OP_RETURN opcode) greater than the specified value, expressed in " + CURRENCY_UNIT + ".\n"
    1079                 :             :              "If burning funds through unspendable outputs is desired, increase this value.\n"
    1080                 :        2479 :              "This check is based on heuristics and does not guarantee spendability of outputs.\n"
    1081                 :             :             },
    1082                 :             :         },
    1083         [ +  - ]:        4958 :         RPCResult{
    1084   [ +  -  +  - ]:        4958 :             RPCResult::Type::OBJ, "", "",
    1085                 :             :             {
    1086   [ +  -  +  - ]:        4958 :                 {RPCResult::Type::STR, "package_msg", "The transaction package result message. \"success\" indicates all transactions were accepted into or are already in the mempool."},
    1087   [ +  -  +  - ]:        4958 :                 {RPCResult::Type::OBJ_DYN, "tx-results", "The transaction results keyed by wtxid. An entry is returned for every submitted wtxid.",
    1088                 :             :                 {
    1089   [ +  -  +  - ]:        4958 :                     {RPCResult::Type::OBJ, "wtxid", "transaction wtxid", {
    1090   [ +  -  +  - ]:        4958 :                         {RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
    1091   [ +  -  +  - ]:        4958 :                         {RPCResult::Type::STR_HEX, "other-wtxid", /*optional=*/true, "The wtxid of a different transaction with the same txid but different witness found in the mempool. This means the submitted transaction was ignored."},
    1092   [ +  -  +  - ]:        4958 :                         {RPCResult::Type::NUM, "vsize", /*optional=*/true, "Sigops-adjusted virtual transaction size."},
    1093   [ +  -  +  - ]:        4958 :                         {RPCResult::Type::OBJ, "fees", /*optional=*/true, "Transaction fees", {
    1094   [ +  -  +  - ]:        4958 :                             {RPCResult::Type::STR_AMOUNT, "base", "transaction fee in " + CURRENCY_UNIT},
    1095   [ +  -  +  - ]:        4958 :                             {RPCResult::Type::STR_AMOUNT, "effective-feerate", /*optional=*/true, "if the transaction was not already in the mempool, the effective feerate in " + CURRENCY_UNIT + " per KvB. For example, the package feerate and/or feerate with modified fees from prioritisetransaction."},
    1096   [ +  -  +  - ]:        4958 :                             {RPCResult::Type::ARR, "effective-includes", /*optional=*/true, "if effective-feerate is provided, the wtxids of the transactions whose fees and vsizes are included in effective-feerate.",
    1097   [ +  -  +  - ]:        4958 :                                 {{RPCResult::Type::STR_HEX, "", "transaction wtxid in hex"},
    1098                 :             :                             }},
    1099                 :             :                         }},
    1100   [ +  -  +  - ]:        4958 :                         {RPCResult::Type::STR, "error", /*optional=*/true, "Error string if rejected from mempool, or \"package-not-validated\" when the package aborts before any per-tx processing."},
    1101                 :             :                     }}
    1102                 :             :                 }},
    1103   [ +  -  +  - ]:        4958 :                 {RPCResult::Type::ARR, "replaced-transactions", /*optional=*/true, "List of txids of replaced transactions",
    1104                 :             :                 {
    1105   [ +  -  +  - ]:        4958 :                     {RPCResult::Type::STR_HEX, "", "The transaction id"},
    1106                 :             :                 }},
    1107                 :             :             },
    1108   [ +  -  +  -  :       71891 :         },
          +  -  +  -  +  
          -  +  -  +  -  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  -  -  -  
          -  -  -  -  -  
             -  -  -  - ]
    1109                 :        2479 :         RPCExamples{
    1110   [ +  -  +  -  :        4958 :             HelpExampleRpc("submitpackage", R"(["raw-parent-tx-1", "raw-parent-tx-2", "raw-child-tx"])") +
                   +  - ]
    1111   [ +  -  +  -  :        7437 :             HelpExampleCli("submitpackage", R"('["raw-tx-without-unconfirmed-parents"]')")
             +  -  +  - ]
    1112         [ +  - ]:        2479 :         },
    1113                 :        2479 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
    1114                 :             :         {
    1115                 :         118 :             const UniValue raw_transactions = request.params[0].get_array();
    1116   [ -  +  +  +  :         118 :             if (raw_transactions.empty() || raw_transactions.size() > MAX_PACKAGE_COUNT) {
                   +  + ]
    1117                 :           2 :                 throw JSONRPCError(RPC_INVALID_PARAMETER,
    1118   [ +  -  +  -  :           6 :                                    "Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
                   +  - ]
    1119                 :             :             }
    1120                 :             : 
    1121                 :             :             // Fee check needs to be run with chainstate and package context
    1122   [ +  -  +  - ]:         116 :             const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
    1123         [ +  + ]:         116 :             std::optional<CFeeRate> client_maxfeerate{max_raw_tx_fee_rate};
    1124                 :             :             // 0-value is special; it's mapped to no sanity check
    1125         [ +  + ]:         116 :             if (max_raw_tx_fee_rate == CFeeRate(0)) {
    1126                 :          29 :                 client_maxfeerate = std::nullopt;
    1127                 :             :             }
    1128                 :             : 
    1129                 :             :             // Burn sanity check is run with no context
    1130   [ +  -  +  +  :         116 :             const CAmount max_burn_amount = request.params[2].isNull() ? 0 : AmountFromValue(request.params[2]);
             +  -  +  - ]
    1131                 :             : 
    1132                 :         116 :             std::vector<CTransactionRef> txns;
    1133   [ -  +  +  - ]:         116 :             txns.reserve(raw_transactions.size());
    1134   [ +  -  +  + ]:         495 :             for (const auto& rawtx : raw_transactions.getValues()) {
    1135         [ +  - ]:         381 :                 CMutableTransaction mtx;
    1136   [ +  -  +  -  :         381 :                 if (!DecodeHexTx(mtx, rawtx.get_str())) {
                   +  + ]
    1137                 :           1 :                     throw JSONRPCError(RPC_DESERIALIZATION_ERROR,
    1138   [ +  -  +  -  :           3 :                                        "TX decode failed: " + rawtx.get_str() + " Make sure the tx has at least one input.");
                   +  - ]
    1139                 :             :                 }
    1140                 :             : 
    1141         [ +  + ]:         893 :                 for (const auto& out : mtx.vout) {
    1142   [ +  +  +  -  :         514 :                     if((out.scriptPubKey.IsUnspendable() || !out.scriptPubKey.HasValidOps()) && out.nValue > max_burn_amount) {
             -  +  +  + ]
    1143   [ +  -  +  - ]:           2 :                         throw JSONRPCTransactionError(TransactionError::MAX_BURN_EXCEEDED);
    1144                 :             :                     }
    1145                 :             :                 }
    1146                 :             : 
    1147   [ +  -  +  - ]:        1137 :                 txns.emplace_back(MakeTransactionRef(std::move(mtx)));
    1148                 :         381 :             }
    1149         [ +  - ]:         114 :             CHECK_NONFATAL(!txns.empty());
    1150   [ -  +  +  +  :         114 :             if (txns.size() > 1 && !IsChildWithParentsTree(txns)) {
             +  -  +  + ]
    1151   [ +  -  +  - ]:           4 :                 throw JSONRPCTransactionError(TransactionError::INVALID_PACKAGE, "package topology disallowed. not child-with-parents or parents depend on each other.");
    1152                 :             :             }
    1153                 :             : 
    1154         [ +  - ]:         112 :             NodeContext& node = EnsureAnyNodeContext(request.context);
    1155         [ +  - ]:         112 :             CTxMemPool& mempool = EnsureMemPool(node);
    1156   [ +  -  +  - ]:         112 :             Chainstate& chainstate = EnsureChainman(node).ActiveChainstate();
    1157   [ +  -  +  - ]:         336 :             const auto package_result = WITH_LOCK(::cs_main, return ProcessNewPackage(chainstate, mempool, txns, /*test_accept=*/ false, client_maxfeerate));
    1158                 :             : 
    1159         [ +  - ]:         112 :             std::string package_msg = "success";
    1160                 :             : 
    1161                 :             :             // First catch package-wide errors, continue if we can
    1162   [ +  -  +  - ]:         112 :             switch(package_result.m_state.GetResult()) {
    1163                 :          57 :                 case PackageValidationResult::PCKG_RESULT_UNSET:
    1164                 :          57 :                 {
    1165                 :             :                     // Belt-and-suspenders check; everything should be successful here
    1166   [ -  +  +  - ]:          57 :                     CHECK_NONFATAL(package_result.m_tx_results.size() == txns.size());
    1167         [ +  + ]:         266 :                     for (const auto& tx : txns) {
    1168   [ +  -  +  - ]:         209 :                         CHECK_NONFATAL(mempool.exists(tx->GetHash()));
    1169                 :             :                     }
    1170                 :             :                     break;
    1171                 :             :                 }
    1172                 :           0 :                 case PackageValidationResult::PCKG_MEMPOOL_ERROR:
    1173                 :           0 :                 {
    1174                 :             :                     // This only happens with internal bug; user should stop and report
    1175                 :           0 :                     throw JSONRPCTransactionError(TransactionError::MEMPOOL_ERROR,
    1176   [ #  #  #  # ]:           0 :                         package_result.m_state.GetRejectReason());
    1177                 :             :                 }
    1178                 :          55 :                 case PackageValidationResult::PCKG_POLICY:
    1179                 :          55 :                 case PackageValidationResult::PCKG_TX:
    1180                 :          55 :                 {
    1181                 :             :                     // Package-wide error we want to return, but we also want to return individual responses
    1182         [ +  - ]:          55 :                     package_msg = package_result.m_state.ToString();
    1183   [ -  +  +  +  :          57 :                     CHECK_NONFATAL(package_result.m_tx_results.size() == txns.size() ||
             +  -  +  - ]
    1184                 :             :                             package_result.m_tx_results.empty());
    1185                 :             :                     break;
    1186                 :             :                 }
    1187                 :             :             }
    1188                 :             : 
    1189                 :         112 :             size_t num_broadcast{0};
    1190         [ +  + ]:         483 :             for (const auto& tx : txns) {
    1191                 :             :                 // We don't want to re-submit the txn for validation in BroadcastTransaction
    1192   [ +  -  +  + ]:         371 :                 if (!mempool.exists(tx->GetHash())) {
    1193                 :         100 :                     continue;
    1194                 :             :                 }
    1195                 :             : 
    1196                 :             :                 // We do not expect an error here; we are only broadcasting things already/still in mempool
    1197         [ +  - ]:         271 :                 std::string err_string;
    1198   [ +  -  +  - ]:         271 :                 const auto err = BroadcastTransaction(node,
    1199                 :             :                                                       tx,
    1200                 :             :                                                       err_string,
    1201         [ +  - ]:         271 :                                                       /*max_tx_fee=*/0,
    1202                 :             :                                                       node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL,
    1203                 :             :                                                       /*wait_callback=*/true);
    1204         [ -  + ]:         271 :                 if (err != TransactionError::OK) {
    1205                 :           0 :                     throw JSONRPCTransactionError(err,
    1206         [ #  # ]:           0 :                         strprintf("transaction broadcast failed: %s (%d transactions were broadcast successfully)",
    1207         [ #  # ]:           0 :                             err_string, num_broadcast));
    1208                 :             :                 }
    1209                 :         271 :                 num_broadcast++;
    1210                 :         271 :             }
    1211                 :             : 
    1212                 :         112 :             UniValue rpc_result{UniValue::VOBJ};
    1213   [ +  -  +  -  :         224 :             rpc_result.pushKV("package_msg", package_msg);
                   +  - ]
    1214                 :         224 :             UniValue tx_result_map{UniValue::VOBJ};
    1215                 :         224 :             std::set<Txid> replaced_txids;
    1216         [ +  + ]:         483 :             for (const auto& tx : txns) {
    1217                 :         371 :                 UniValue result_inner{UniValue::VOBJ};
    1218   [ +  -  +  -  :         742 :                 result_inner.pushKV("txid", tx->GetHash().GetHex());
             +  -  +  - ]
    1219         [ +  - ]:         371 :                 const auto wtxid_hex = tx->GetWitnessHash().GetHex();
    1220                 :         371 :                 auto it = package_result.m_tx_results.find(tx->GetWitnessHash());
    1221         [ +  + ]:         371 :                 if (it == package_result.m_tx_results.end()) {
    1222                 :             :                     // No per-tx result for this wtxid
    1223                 :             :                     // Current invariant: per-tx results are all-or-none (every member or empty on package abort).
    1224                 :             :                     // If any exist yet this one is missing, it's an unexpected partial map.
    1225         [ +  - ]:           6 :                     CHECK_NONFATAL(package_result.m_tx_results.empty());
    1226   [ +  -  +  -  :          12 :                     result_inner.pushKV("error", "package-not-validated");
                   +  - ]
    1227   [ -  +  +  - ]:          18 :                     tx_result_map.pushKV(wtxid_hex, std::move(result_inner));
    1228                 :           6 :                     continue;
    1229                 :             :                 }
    1230   [ -  +  +  - ]:         365 :                 const auto& tx_result = it->second;
    1231   [ -  +  +  - ]:         365 :                 switch(it->second.m_result_type) {
    1232                 :           0 :                 case MempoolAcceptResult::ResultType::DIFFERENT_WITNESS:
    1233   [ #  #  #  #  :           0 :                     result_inner.pushKV("other-wtxid", it->second.m_other_wtxid.value().GetHex());
          #  #  #  #  #  
                      # ]
    1234                 :           0 :                     break;
    1235                 :          95 :                 case MempoolAcceptResult::ResultType::INVALID:
    1236   [ +  -  +  -  :         190 :                     result_inner.pushKV("error", it->second.m_state.ToString());
             +  -  +  - ]
    1237                 :          95 :                     break;
    1238                 :         270 :                 case MempoolAcceptResult::ResultType::VALID:
    1239                 :         270 :                 case MempoolAcceptResult::ResultType::MEMPOOL_ENTRY:
    1240   [ +  -  +  -  :         540 :                     result_inner.pushKV("vsize", int64_t{it->second.m_vsize.value()});
             +  -  +  - ]
    1241                 :         270 :                     UniValue fees(UniValue::VOBJ);
    1242   [ +  -  +  -  :         540 :                     fees.pushKV("base", ValueFromAmount(it->second.m_base_fees.value()));
             +  -  +  - ]
    1243         [ +  + ]:         270 :                     if (tx_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
    1244                 :             :                         // Effective feerate is not provided for MEMPOOL_ENTRY transactions even
    1245                 :             :                         // though modified fees is known, because it is unknown whether package
    1246                 :             :                         // feerate was used when it was originally submitted.
    1247   [ +  -  +  -  :         342 :                         fees.pushKV("effective-feerate", ValueFromAmount(tx_result.m_effective_feerate.value().GetFeePerK()));
             +  -  +  - ]
    1248                 :         171 :                         UniValue effective_includes_res(UniValue::VARR);
    1249   [ +  -  +  + ]:         390 :                         for (const auto& wtxid : tx_result.m_wtxids_fee_calculations.value()) {
    1250   [ +  -  +  -  :         219 :                             effective_includes_res.push_back(wtxid.ToString());
                   +  - ]
    1251                 :             :                         }
    1252   [ +  -  +  - ]:         342 :                         fees.pushKV("effective-includes", std::move(effective_includes_res));
    1253                 :         171 :                     }
    1254   [ +  -  +  - ]:         540 :                     result_inner.pushKV("fees", std::move(fees));
    1255         [ +  + ]:         653 :                     for (const auto& ptx : it->second.m_replaced_transactions) {
    1256         [ +  - ]:         383 :                         replaced_txids.insert(ptx->GetHash());
    1257                 :             :                     }
    1258                 :         270 :                     break;
    1259                 :             :                 }
    1260   [ -  +  +  - ]:        1095 :                 tx_result_map.pushKV(wtxid_hex, std::move(result_inner));
    1261                 :         371 :             }
    1262   [ +  -  +  - ]:         224 :             rpc_result.pushKV("tx-results", std::move(tx_result_map));
    1263                 :         224 :             UniValue replaced_list(UniValue::VARR);
    1264   [ +  -  +  -  :         495 :             for (const auto& txid : replaced_txids) replaced_list.push_back(txid.ToString());
             +  -  +  + ]
    1265   [ +  -  +  - ]:         224 :             rpc_result.pushKV("replaced-transactions", std::move(replaced_list));
    1266                 :         224 :             return rpc_result;
    1267                 :         122 :         },
    1268   [ +  -  +  -  :       24790 :     };
          +  -  +  +  +  
             +  -  -  -  
                      - ]
    1269   [ +  -  +  -  :       54538 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  -  -  
             -  -  -  -  
                      - ]
    1270                 :             : 
    1271                 :        1306 : void RegisterMempoolRPCCommands(CRPCTable& t)
    1272                 :             : {
    1273                 :        1306 :     static const CRPCCommand commands[]{
    1274         [ +  - ]:        2350 :         {"rawtransactions", &sendrawtransaction},
    1275         [ +  - ]:        2350 :         {"rawtransactions", &testmempoolaccept},
    1276         [ +  - ]:        2350 :         {"blockchain", &getmempoolancestors},
    1277         [ +  - ]:        2350 :         {"blockchain", &getmempooldescendants},
    1278         [ +  - ]:        2350 :         {"blockchain", &getmempoolentry},
    1279         [ +  - ]:        2350 :         {"blockchain", &getmempoolcluster},
    1280         [ +  - ]:        2350 :         {"blockchain", &gettxspendingprevout},
    1281         [ +  - ]:        2350 :         {"blockchain", &getmempoolinfo},
    1282         [ +  - ]:        2350 :         {"hidden", &getmempoolfeeratediagram},
    1283         [ +  - ]:        2350 :         {"blockchain", &getrawmempool},
    1284         [ +  - ]:        2350 :         {"blockchain", &importmempool},
    1285         [ +  - ]:        2350 :         {"blockchain", &savemempool},
    1286         [ +  - ]:        2350 :         {"hidden", &getorphantxs},
    1287         [ +  - ]:        2350 :         {"rawtransactions", &submitpackage},
    1288   [ +  +  +  -  :       17756 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      - ]
    1289         [ +  + ]:       19590 :     for (const auto& c : commands) {
    1290                 :       18284 :         t.appendCommand(c.name, &c);
    1291                 :             :     }
    1292                 :        1306 : }
        

Generated by: LCOV version 2.0-1