LCOV - code coverage report
Current view: top level - src/rpc - node.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 54.9 % 235 129
Test Date: 2026-12-01 06:04:45 Functions: 77.3 % 22 17
Branches: 36.1 % 732 264

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

Generated by: LCOV version 2.0-1