LCOV - code coverage report
Current view: top level - src/rpc - node.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 93.3 % 210 196
Test Date: 2025-06-01 06:26:32 Functions: 95.7 % 23 22
Branches: 50.5 % 832 420

             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 <bitcoin-build-config.h> // IWYU pragma: keep
       7                 :             : 
       8                 :             : #include <chainparams.h>
       9                 :             : #include <httpserver.h>
      10                 :             : #include <index/blockfilterindex.h>
      11                 :             : #include <index/coinstatsindex.h>
      12                 :             : #include <index/txindex.h>
      13                 :             : #include <interfaces/chain.h>
      14                 :             : #include <interfaces/echo.h>
      15                 :             : #include <interfaces/init.h>
      16                 :             : #include <interfaces/ipc.h>
      17                 :             : #include <kernel/cs_main.h>
      18                 :             : #include <logging.h>
      19                 :             : #include <node/context.h>
      20                 :             : #include <rpc/server.h>
      21                 :             : #include <rpc/server_util.h>
      22                 :             : #include <rpc/util.h>
      23                 :             : #include <scheduler.h>
      24                 :             : #include <univalue.h>
      25                 :             : #include <util/any.h>
      26                 :             : #include <util/check.h>
      27                 :             : #include <util/time.h>
      28                 :             : 
      29                 :             : #include <stdint.h>
      30                 :             : #ifdef HAVE_MALLOC_INFO
      31                 :             : #include <malloc.h>
      32                 :             : #endif
      33                 :             : 
      34                 :             : using node::NodeContext;
      35                 :             : 
      36                 :        3332 : static RPCHelpMan setmocktime()
      37                 :             : {
      38                 :        3332 :     return RPCHelpMan{
      39                 :             :         "setmocktime",
      40                 :             :         "Set the local time to given timestamp (-regtest only)\n",
      41                 :             :         {
      42         [ +  - ]:        6664 :             {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, UNIX_EPOCH_TIME + "\n"
      43                 :        3332 :              "Pass 0 to go back to using the system time."},
      44                 :             :         },
      45   [ +  -  +  -  :        6664 :         RPCResult{RPCResult::Type::NONE, "", ""},
                   +  - ]
      46   [ +  -  +  - ]:        9996 :         RPCExamples{""},
      47                 :        1173 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      48                 :             : {
      49         [ -  + ]:        1173 :     if (!Params().IsMockableChain()) {
      50         [ #  # ]:           0 :         throw std::runtime_error("setmocktime is for regression testing (-regtest mode) only");
      51                 :             :     }
      52                 :             : 
      53                 :             :     // For now, don't change mocktime if we're in the middle of validation, as
      54                 :             :     // this could have an effect on mempool time-based eviction, as well as
      55                 :             :     // IsCurrentForFeeEstimation() and IsInitialBlockDownload().
      56                 :             :     // TODO: figure out the right way to synchronize around mocktime, and
      57                 :             :     // ensure all call sites of GetTime() are accessing this safely.
      58                 :        1173 :     LOCK(cs_main);
      59                 :             : 
      60   [ +  -  +  - ]:        1173 :     const int64_t time{request.params[0].getInt<int64_t>()};
      61                 :        1173 :     constexpr int64_t max_time{Ticks<std::chrono::seconds>(std::chrono::nanoseconds::max())};
      62         [ +  + ]:        1173 :     if (time < 0 || time > max_time) {
      63   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime must be in the range [0, %s], not %s.", max_time, time));
      64                 :             :     }
      65                 :             : 
      66         [ +  - ]:        1172 :     SetMockTime(time);
      67         [ +  - ]:        1172 :     const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
      68         [ +  + ]:        1258 :     for (const auto& chain_client : node_context.chain_clients) {
      69         [ +  - ]:          86 :         chain_client->setMockTime(time);
      70                 :             :     }
      71                 :             : 
      72         [ +  - ]:        1172 :     return UniValue::VNULL;
      73                 :        1172 : },
      74   [ +  -  +  -  :       29988 :     };
          +  -  +  -  +  
          -  +  -  +  +  
                   -  - ]
      75   [ +  -  +  - ]:        9996 : }
      76                 :             : 
      77                 :        2169 : static RPCHelpMan mockscheduler()
      78                 :             : {
      79                 :        2169 :     return RPCHelpMan{
      80                 :             :         "mockscheduler",
      81                 :             :         "Bump the scheduler into the future (-regtest only)\n",
      82                 :             :         {
      83         [ +  - ]:        2169 :             {"delta_time", RPCArg::Type::NUM, RPCArg::Optional::NO, "Number of seconds to forward the scheduler into the future." },
      84                 :             :         },
      85   [ +  -  +  -  :        4338 :         RPCResult{RPCResult::Type::NONE, "", ""},
                   +  - ]
      86   [ +  -  +  - ]:        6507 :         RPCExamples{""},
      87                 :          10 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
      88                 :             : {
      89         [ -  + ]:          10 :     if (!Params().IsMockableChain()) {
      90         [ #  # ]:           0 :         throw std::runtime_error("mockscheduler is for regression testing (-regtest mode) only");
      91                 :             :     }
      92                 :             : 
      93                 :          10 :     int64_t delta_seconds = request.params[0].getInt<int64_t>();
      94         [ -  + ]:          10 :     if (delta_seconds <= 0 || delta_seconds > 3600) {
      95         [ #  # ]:           0 :         throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)");
      96                 :             :     }
      97                 :             : 
      98                 :          10 :     const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
      99                 :          10 :     CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
     100                 :          10 :     CHECK_NONFATAL(node_context.validation_signals)->SyncWithValidationInterfaceQueue();
     101         [ +  + ]:          16 :     for (const auto& chain_client : node_context.chain_clients) {
     102                 :           6 :         chain_client->schedulerMockForward(std::chrono::seconds(delta_seconds));
     103                 :             :     }
     104                 :             : 
     105                 :          10 :     return UniValue::VNULL;
     106                 :             : },
     107   [ +  -  +  -  :       19521 :     };
          +  -  +  -  +  
          -  +  -  +  +  
                   -  - ]
     108   [ +  -  +  - ]:        6507 : }
     109                 :             : 
     110                 :           1 : static UniValue RPCLockedMemoryInfo()
     111                 :             : {
     112                 :           1 :     LockedPool::Stats stats = LockedPoolManager::Instance().stats();
     113                 :           1 :     UniValue obj(UniValue::VOBJ);
     114   [ +  -  +  -  :           2 :     obj.pushKV("used", uint64_t(stats.used));
                   +  - ]
     115   [ +  -  +  -  :           2 :     obj.pushKV("free", uint64_t(stats.free));
                   +  - ]
     116   [ +  -  +  -  :           2 :     obj.pushKV("total", uint64_t(stats.total));
                   +  - ]
     117   [ +  -  +  -  :           2 :     obj.pushKV("locked", uint64_t(stats.locked));
                   +  - ]
     118   [ +  -  +  -  :           2 :     obj.pushKV("chunks_used", uint64_t(stats.chunks_used));
                   +  - ]
     119   [ +  -  +  -  :           2 :     obj.pushKV("chunks_free", uint64_t(stats.chunks_free));
                   +  - ]
     120                 :           1 :     return obj;
     121                 :           0 : }
     122                 :             : 
     123                 :             : #ifdef HAVE_MALLOC_INFO
     124                 :           1 : static std::string RPCMallocInfo()
     125                 :             : {
     126                 :           1 :     char *ptr = nullptr;
     127                 :           1 :     size_t size = 0;
     128                 :           1 :     FILE *f = open_memstream(&ptr, &size);
     129         [ +  - ]:           1 :     if (f) {
     130                 :           1 :         malloc_info(0, f);
     131                 :           1 :         fclose(f);
     132         [ +  - ]:           1 :         if (ptr) {
     133                 :           1 :             std::string rv(ptr, size);
     134                 :           1 :             free(ptr);
     135                 :           1 :             return rv;
     136                 :             :         }
     137                 :             :     }
     138                 :           0 :     return "";
     139                 :             : }
     140                 :             : #endif
     141                 :             : 
     142                 :        2171 : static RPCHelpMan getmemoryinfo()
     143                 :             : {
     144                 :             :     /* Please, avoid using the word "pool" here in the RPC interface or help,
     145                 :             :      * as users will undoubtedly confuse it with the other "memory pool"
     146                 :             :      */
     147                 :        2171 :     return RPCHelpMan{"getmemoryinfo",
     148                 :             :                 "Returns an object containing information about memory usage.\n",
     149                 :             :                 {
     150         [ +  - ]:        4342 :                     {"mode", RPCArg::Type::STR, RPCArg::Default{"stats"}, "determines what kind of information is returned.\n"
     151                 :             :             "  - \"stats\" returns general statistics about memory usage in the daemon.\n"
     152                 :             :             "  - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc)."},
     153                 :             :                 },
     154                 :             :                 {
     155                 :             :                     RPCResult{"mode \"stats\"",
     156                 :             :                         RPCResult::Type::OBJ, "", "",
     157                 :             :                         {
     158                 :             :                             {RPCResult::Type::OBJ, "locked", "Information about locked memory manager",
     159                 :             :                             {
     160                 :             :                                 {RPCResult::Type::NUM, "used", "Number of bytes used"},
     161                 :             :                                 {RPCResult::Type::NUM, "free", "Number of bytes available in current arenas"},
     162                 :             :                                 {RPCResult::Type::NUM, "total", "Total number of bytes managed"},
     163                 :             :                                 {RPCResult::Type::NUM, "locked", "Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk."},
     164                 :             :                                 {RPCResult::Type::NUM, "chunks_used", "Number allocated chunks"},
     165                 :             :                                 {RPCResult::Type::NUM, "chunks_free", "Number unused chunks"},
     166                 :             :                             }},
     167                 :             :                         }
     168   [ +  -  +  -  :       21710 :                     },
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  +  +  +  
             -  -  -  - ]
     169                 :             :                     RPCResult{"mode \"mallocinfo\"",
     170                 :             :                         RPCResult::Type::STR, "", "\"<malloc version=\"1\">...\""
     171   [ +  -  +  -  :        4342 :                     },
             +  -  +  - ]
     172                 :             :                 },
     173                 :        2171 :                 RPCExamples{
     174   [ +  -  +  -  :        4342 :                     HelpExampleCli("getmemoryinfo", "")
                   +  - ]
     175   [ +  -  +  -  :        8684 :             + HelpExampleRpc("getmemoryinfo", "")
             +  -  +  - ]
     176         [ +  - ]:        2171 :                 },
     177                 :           3 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     178                 :             : {
     179         [ +  + ]:           3 :     std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str();
     180         [ +  + ]:           3 :     if (mode == "stats") {
     181                 :           1 :         UniValue obj(UniValue::VOBJ);
     182   [ +  -  +  -  :           1 :         obj.pushKV("locked", RPCLockedMemoryInfo());
                   +  - ]
     183                 :           1 :         return obj;
     184         [ +  + ]:           2 :     } else if (mode == "mallocinfo") {
     185                 :             : #ifdef HAVE_MALLOC_INFO
     186   [ +  -  +  - ]:           1 :         return RPCMallocInfo();
     187                 :             : #else
     188                 :             :         throw JSONRPCError(RPC_INVALID_PARAMETER, "mallocinfo mode not available");
     189                 :             : #endif
     190                 :             :     } else {
     191   [ +  -  +  - ]:           2 :         throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + mode);
     192                 :             :     }
     193                 :           2 : },
     194   [ +  -  +  -  :       30394 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  +  +  +  -  
                -  -  - ]
     195   [ +  -  +  -  :       28223 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             -  -  -  - ]
     196                 :             : 
     197                 :           2 : static void EnableOrDisableLogCategories(UniValue cats, bool enable) {
     198                 :           2 :     cats = cats.get_array();
     199         [ +  + ]:           4 :     for (unsigned int i = 0; i < cats.size(); ++i) {
     200                 :           2 :         std::string cat = cats[i].get_str();
     201                 :             : 
     202                 :           2 :         bool success;
     203         [ +  + ]:           2 :         if (enable) {
     204   [ +  -  +  - ]:           1 :             success = LogInstance().EnableCategory(cat);
     205                 :             :         } else {
     206   [ +  -  +  - ]:           1 :             success = LogInstance().DisableCategory(cat);
     207                 :             :         }
     208                 :             : 
     209         [ -  + ]:           2 :         if (!success) {
     210   [ #  #  #  # ]:           0 :             throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown logging category " + cat);
     211                 :             :         }
     212                 :           2 :     }
     213                 :           2 : }
     214                 :             : 
     215                 :        2179 : static RPCHelpMan logging()
     216                 :             : {
     217                 :        2179 :     return RPCHelpMan{"logging",
     218                 :             :             "Gets and sets the logging configuration.\n"
     219                 :             :             "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
     220                 :             :             "When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
     221                 :             :             "The arguments are evaluated in order \"include\", \"exclude\".\n"
     222                 :             :             "If an item is both included and excluded, it will thus end up being excluded.\n"
     223   [ +  -  +  -  :        4358 :             "The valid logging categories are: " + LogInstance().LogCategoriesString() + "\n"
                   +  - ]
     224                 :             :             "In addition, the following are available as category names with special meanings:\n"
     225                 :        2179 :             "  - \"all\",  \"1\" : represent all logging categories.\n"
     226                 :             :             ,
     227                 :             :                 {
     228         [ +  - ]:        2179 :                     {"include", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "The categories to add to debug logging",
     229                 :             :                         {
     230         [ +  - ]:        2179 :                             {"include_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"},
     231                 :             :                         }},
     232         [ +  - ]:        2179 :                     {"exclude", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "The categories to remove from debug logging",
     233                 :             :                         {
     234         [ +  - ]:        2179 :                             {"exclude_category", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "the valid logging category"},
     235                 :             :                         }},
     236                 :             :                 },
     237                 :           0 :                 RPCResult{
     238                 :             :                     RPCResult::Type::OBJ_DYN, "", "keys are the logging categories, and values indicates its status",
     239                 :             :                     {
     240                 :             :                         {RPCResult::Type::BOOL, "category", "if being debug logged or not. false:inactive, true:active"},
     241                 :             :                     }
     242   [ +  -  +  -  :        6537 :                 },
          +  -  +  -  +  
          -  +  -  +  -  
             +  +  -  - ]
     243                 :        2179 :                 RPCExamples{
     244   [ +  -  +  -  :        4358 :                     HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"")
                   +  - ]
     245   [ +  -  +  -  :        8716 :             + HelpExampleRpc("logging", "[\"all\"], [\"libevent\"]")
             +  -  +  - ]
     246         [ +  - ]:        2179 :                 },
     247                 :          10 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     248                 :             : {
     249                 :          10 :     BCLog::CategoryMask original_log_categories = LogInstance().GetCategoryMask();
     250         [ +  + ]:          10 :     if (request.params[0].isArray()) {
     251         [ +  - ]:           1 :         EnableOrDisableLogCategories(request.params[0], true);
     252                 :             :     }
     253         [ +  + ]:          10 :     if (request.params[1].isArray()) {
     254         [ +  - ]:           1 :         EnableOrDisableLogCategories(request.params[1], false);
     255                 :             :     }
     256         [ -  + ]:          10 :     BCLog::CategoryMask updated_log_categories = LogInstance().GetCategoryMask();
     257                 :          10 :     BCLog::CategoryMask changed_log_categories = original_log_categories ^ updated_log_categories;
     258                 :             : 
     259                 :             :     // Update libevent logging if BCLog::LIBEVENT has changed.
     260         [ -  + ]:          10 :     if (changed_log_categories & BCLog::LIBEVENT) {
     261                 :           0 :         UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT));
     262                 :             :     }
     263                 :             : 
     264                 :          10 :     UniValue result(UniValue::VOBJ);
     265   [ +  -  +  -  :         290 :     for (const auto& logCatActive : LogInstance().LogCategoriesList()) {
                   +  + ]
     266   [ +  -  +  -  :         560 :         result.pushKV(logCatActive.category, logCatActive.active);
                   +  - ]
     267                 :          10 :     }
     268                 :             : 
     269                 :          10 :     return result;
     270                 :           0 : },
     271   [ +  -  +  -  :       43580 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  +  
          +  +  +  -  -  
             -  -  -  - ]
     272   [ +  -  +  -  :       23969 : }
          +  -  +  -  +  
          -  +  -  +  -  
                   -  - ]
     273                 :             : 
     274                 :        4328 : static RPCHelpMan echo(const std::string& name)
     275                 :             : {
     276                 :        4328 :     return RPCHelpMan{
     277                 :             :         name,
     278                 :             :         "Simply echo back the input arguments. This command is for testing.\n"
     279                 :             :                 "\nIt will return an internal bug report when arg9='trigger_internal_bug' is passed.\n"
     280                 :             :                 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
     281                 :             :                 "bitcoin-cli and the GUI. There is no server-side difference.",
     282                 :             :         {
     283   [ +  -  +  - ]:        8656 :             {"arg0", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     284   [ +  -  +  - ]:        8656 :             {"arg1", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     285   [ +  -  +  - ]:        8656 :             {"arg2", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     286   [ +  -  +  - ]:        8656 :             {"arg3", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     287   [ +  -  +  - ]:        8656 :             {"arg4", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     288   [ +  -  +  - ]:        8656 :             {"arg5", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     289   [ +  -  +  - ]:        8656 :             {"arg6", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     290   [ +  -  +  - ]:        8656 :             {"arg7", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     291   [ +  -  +  - ]:        8656 :             {"arg8", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     292   [ +  -  +  - ]:        8656 :             {"arg9", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "", RPCArgOptions{.skip_type_check = true}},
     293                 :             :         },
     294   [ +  -  +  -  :        8656 :                 RPCResult{RPCResult::Type::ANY, "", "Returns whatever was passed in"},
                   +  - ]
     295   [ +  -  +  - ]:       12984 :                 RPCExamples{""},
     296                 :          10 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     297                 :             : {
     298         [ +  + ]:          10 :     if (request.params[9].isStr()) {
     299                 :           1 :         CHECK_NONFATAL(request.params[9].get_str() != "trigger_internal_bug");
     300                 :             :     }
     301                 :             : 
     302                 :           9 :     return request.params;
     303                 :             : },
     304   [ +  -  +  -  :      155808 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                +  -  - ]
     305   [ +  -  +  -  :       47608 : }
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      - ]
     306                 :             : 
     307         [ +  - ]:        4338 : static RPCHelpMan echo() { return echo("echo"); }
     308         [ +  - ]:        4318 : static RPCHelpMan echojson() { return echo("echojson"); }
     309                 :             : 
     310                 :        2160 : static RPCHelpMan echoipc()
     311                 :             : {
     312                 :        2160 :     return RPCHelpMan{
     313                 :             :         "echoipc",
     314                 :             :         "Echo back the input argument, passing it through a spawned process in a multiprocess build.\n"
     315                 :             :         "This command is for testing.\n",
     316         [ +  - ]:        2160 :         {{"arg", RPCArg::Type::STR, RPCArg::Optional::NO, "The string to echo",}},
     317   [ +  -  +  -  :        4320 :         RPCResult{RPCResult::Type::STR, "echo", "The echoed string."},
                   +  - ]
     318   [ +  -  +  -  :        4320 :         RPCExamples{HelpExampleCli("echo", "\"Hello world\"") +
                   +  - ]
     319   [ +  -  +  -  :        8640 :                     HelpExampleRpc("echo", "\"Hello world\"")},
          +  -  +  -  +  
                      - ]
     320                 :           1 :         [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
     321                 :           1 :             interfaces::Init& local_init = *EnsureAnyNodeContext(request.context).init;
     322                 :           1 :             std::unique_ptr<interfaces::Echo> echo;
     323   [ +  -  -  + ]:           1 :             if (interfaces::Ipc* ipc = local_init.ipc()) {
     324                 :             :                 // Spawn a new bitcoin-node process and call makeEcho to get a
     325                 :             :                 // client pointer to a interfaces::Echo instance running in
     326                 :             :                 // that process. This is just for testing. A slightly more
     327                 :             :                 // realistic test spawning a different executable instead of
     328                 :             :                 // the same executable would add a new bitcoin-echo executable,
     329                 :             :                 // and spawn bitcoin-echo below instead of bitcoin-node. But
     330                 :             :                 // using bitcoin-node avoids the need to build and install a
     331                 :             :                 // new executable just for this one test.
     332         [ #  # ]:           0 :                 auto init = ipc->spawnProcess("bitcoin-node");
     333         [ #  # ]:           0 :                 echo = init->makeEcho();
     334   [ #  #  #  # ]:           0 :                 ipc->addCleanup(*echo, [init = init.release()] { delete init; });
     335                 :           0 :             } else {
     336                 :             :                 // IPC support is not available because this is a bitcoind
     337                 :             :                 // process not a bitcoind-node process, so just create a local
     338                 :             :                 // interfaces::Echo object and return it so the `echoipc` RPC
     339                 :             :                 // method will work, and the python test calling `echoipc`
     340                 :             :                 // can expect the same result.
     341         [ +  - ]:           2 :                 echo = local_init.makeEcho();
     342                 :             :             }
     343   [ +  -  +  -  :           2 :             return echo->echo(request.params[0].get_str());
             +  -  +  - ]
     344                 :           1 :         },
     345   [ +  -  +  -  :       19440 :     };
          +  -  +  -  +  
          -  +  -  +  +  
                   -  - ]
     346   [ +  -  +  - ]:        6480 : }
     347                 :             : 
     348                 :         219 : static UniValue SummaryToJSON(const IndexSummary&& summary, std::string index_name)
     349                 :             : {
     350                 :         219 :     UniValue ret_summary(UniValue::VOBJ);
     351   [ +  +  +  + ]:         219 :     if (!index_name.empty() && index_name != summary.name) return ret_summary;
     352                 :             : 
     353                 :         210 :     UniValue entry(UniValue::VOBJ);
     354   [ +  -  +  -  :         420 :     entry.pushKV("synced", summary.synced);
                   +  - ]
     355   [ +  -  +  -  :         420 :     entry.pushKV("best_block_height", summary.best_block_height);
                   +  - ]
     356   [ +  -  +  - ]:         420 :     ret_summary.pushKV(summary.name, std::move(entry));
     357                 :         210 :     return ret_summary;
     358                 :         210 : }
     359                 :             : 
     360                 :        2269 : static RPCHelpMan getindexinfo()
     361                 :             : {
     362                 :        2269 :     return RPCHelpMan{
     363                 :             :         "getindexinfo",
     364                 :             :         "Returns the status of one or all available indices currently running in the node.\n",
     365                 :             :                 {
     366         [ +  - ]:        2269 :                     {"index_name", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Filter results for an index with a specific name."},
     367                 :             :                 },
     368                 :           0 :                 RPCResult{
     369                 :             :                     RPCResult::Type::OBJ_DYN, "", "", {
     370                 :             :                         {
     371                 :             :                             RPCResult::Type::OBJ, "name", "The name of the index",
     372                 :             :                             {
     373                 :             :                                 {RPCResult::Type::BOOL, "synced", "Whether the index is synced or not"},
     374                 :             :                                 {RPCResult::Type::NUM, "best_block_height", "The block height to which the index is synced"},
     375                 :             :                             }
     376                 :             :                         },
     377                 :             :                     },
     378   [ +  -  +  -  :       13614 :                 },
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  +  
             +  -  -  -  
                      - ]
     379                 :        2269 :                 RPCExamples{
     380   [ +  -  +  -  :        4538 :                     HelpExampleCli("getindexinfo", "")
                   +  - ]
     381   [ +  -  +  -  :        9076 :                   + HelpExampleRpc("getindexinfo", "")
             +  -  +  - ]
     382   [ +  -  +  -  :        9076 :                   + HelpExampleCli("getindexinfo", "txindex")
             +  -  +  - ]
     383   [ +  -  +  -  :        9076 :                   + HelpExampleRpc("getindexinfo", "txindex")
             +  -  +  - ]
     384         [ +  - ]:        2269 :                 },
     385                 :         101 :                 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
     386                 :             : {
     387                 :         101 :     UniValue result(UniValue::VOBJ);
     388   [ +  -  +  +  :         101 :     const std::string index_name = request.params[0].isNull() ? "" : request.params[0].get_str();
          +  -  +  -  +  
                -  +  - ]
     389                 :             : 
     390         [ +  + ]:         101 :     if (g_txindex) {
     391   [ +  -  +  -  :          42 :         result.pushKVs(SummaryToJSON(g_txindex->GetSummary(), index_name));
             +  -  +  - ]
     392                 :             :     }
     393                 :             : 
     394         [ +  + ]:         101 :     if (g_coin_stats_index) {
     395   [ +  -  +  -  :          90 :         result.pushKVs(SummaryToJSON(g_coin_stats_index->GetSummary(), index_name));
             +  -  +  - ]
     396                 :             :     }
     397                 :             : 
     398         [ +  - ]:         101 :     ForEachBlockFilterIndex([&result, &index_name](const BlockFilterIndex& index) {
     399   [ +  -  +  -  :          87 :         result.pushKVs(SummaryToJSON(index.GetSummary(), index_name));
                   +  - ]
     400                 :          87 :     });
     401                 :             : 
     402                 :         101 :     return result;
     403                 :         101 : },
     404   [ +  -  +  -  :       22690 :     };
          +  -  +  -  +  
          -  +  -  +  +  
                   -  - ]
     405   [ +  -  +  -  :       15883 : }
          +  -  +  -  +  
             -  +  -  -  
                      - ]
     406                 :             : 
     407                 :        1209 : void RegisterNodeRPCCommands(CRPCTable& t)
     408                 :             : {
     409                 :        1209 :     static const CRPCCommand commands[]{
     410                 :             :         {"control", &getmemoryinfo},
     411                 :             :         {"control", &logging},
     412                 :             :         {"util", &getindexinfo},
     413                 :             :         {"hidden", &setmocktime},
     414                 :             :         {"hidden", &mockscheduler},
     415                 :             :         {"hidden", &echo},
     416                 :             :         {"hidden", &echojson},
     417                 :             :         {"hidden", &echoipc},
     418   [ +  +  +  -  :        1209 :     };
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  - ]
     419         [ +  + ]:       10881 :     for (const auto& c : commands) {
     420                 :        9672 :         t.appendCommand(c.name, &c);
     421                 :             :     }
     422                 :        1209 : }
        

Generated by: LCOV version 2.0-1