LCOV - code coverage report
Current view: top level - src/node - interfaces.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 39.8 % 528 210
Test Date: 2024-08-28 04:44:32 Functions: 37.0 % 162 60
Branches: 27.4 % 672 184

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2018-2022 The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <addrdb.h>
       6                 :             : #include <banman.h>
       7                 :             : #include <blockfilter.h>
       8                 :             : #include <chain.h>
       9                 :             : #include <chainparams.h>
      10                 :             : #include <common/args.h>
      11                 :             : #include <consensus/validation.h>
      12                 :             : #include <deploymentstatus.h>
      13                 :             : #include <external_signer.h>
      14                 :             : #include <index/blockfilterindex.h>
      15                 :             : #include <init.h>
      16                 :             : #include <interfaces/chain.h>
      17                 :             : #include <interfaces/handler.h>
      18                 :             : #include <interfaces/mining.h>
      19                 :             : #include <interfaces/node.h>
      20                 :             : #include <interfaces/wallet.h>
      21                 :             : #include <kernel/chain.h>
      22                 :             : #include <kernel/context.h>
      23                 :             : #include <kernel/mempool_entry.h>
      24                 :             : #include <logging.h>
      25                 :             : #include <mapport.h>
      26                 :             : #include <net.h>
      27                 :             : #include <net_processing.h>
      28                 :             : #include <netaddress.h>
      29                 :             : #include <netbase.h>
      30                 :             : #include <node/blockstorage.h>
      31                 :             : #include <node/coin.h>
      32                 :             : #include <node/context.h>
      33                 :             : #include <node/interface_ui.h>
      34                 :             : #include <node/mini_miner.h>
      35                 :             : #include <node/miner.h>
      36                 :             : #include <node/transaction.h>
      37                 :             : #include <node/types.h>
      38                 :             : #include <node/warnings.h>
      39                 :             : #include <policy/feerate.h>
      40                 :             : #include <policy/fees.h>
      41                 :             : #include <policy/policy.h>
      42                 :             : #include <policy/rbf.h>
      43                 :             : #include <policy/settings.h>
      44                 :             : #include <primitives/block.h>
      45                 :             : #include <primitives/transaction.h>
      46                 :             : #include <rpc/protocol.h>
      47                 :             : #include <rpc/server.h>
      48                 :             : #include <support/allocators/secure.h>
      49                 :             : #include <sync.h>
      50                 :             : #include <txmempool.h>
      51                 :             : #include <uint256.h>
      52                 :             : #include <univalue.h>
      53                 :             : #include <util/check.h>
      54                 :             : #include <util/result.h>
      55                 :             : #include <util/signalinterrupt.h>
      56                 :             : #include <util/string.h>
      57                 :             : #include <util/translation.h>
      58                 :             : #include <validation.h>
      59                 :             : #include <validationinterface.h>
      60                 :             : 
      61                 :             : #include <config/bitcoin-config.h> // IWYU pragma: keep
      62                 :             : 
      63                 :             : #include <any>
      64                 :             : #include <memory>
      65                 :             : #include <optional>
      66                 :             : #include <utility>
      67                 :             : 
      68                 :             : #include <boost/signals2/signal.hpp>
      69                 :             : 
      70                 :             : using interfaces::BlockTip;
      71                 :             : using interfaces::Chain;
      72                 :             : using interfaces::FoundBlock;
      73                 :             : using interfaces::Handler;
      74                 :             : using interfaces::MakeSignalHandler;
      75                 :             : using interfaces::Mining;
      76                 :             : using interfaces::Node;
      77                 :             : using interfaces::WalletLoader;
      78                 :             : using node::BlockAssembler;
      79                 :             : using util::Join;
      80                 :             : 
      81                 :             : namespace node {
      82                 :             : // All members of the classes in this namespace are intentionally public, as the
      83                 :             : // classes themselves are private.
      84                 :             : namespace {
      85                 :             : #ifdef ENABLE_EXTERNAL_SIGNER
      86                 :             : class ExternalSignerImpl : public interfaces::ExternalSigner
      87                 :             : {
      88                 :             : public:
      89                 :           0 :     ExternalSignerImpl(::ExternalSigner signer) : m_signer(std::move(signer)) {}
      90                 :           0 :     std::string getName() override { return m_signer.m_name; }
      91                 :             :     ::ExternalSigner m_signer;
      92                 :             : };
      93                 :             : #endif
      94                 :             : 
      95                 :             : class NodeImpl : public Node
      96                 :             : {
      97                 :             : public:
      98                 :           0 :     explicit NodeImpl(NodeContext& context) { setContext(&context); }
      99                 :           0 :     void initLogging() override { InitLogging(args()); }
     100                 :           0 :     void initParameterInteraction() override { InitParameterInteraction(args()); }
     101   [ #  #  #  #  :           0 :     bilingual_str getWarnings() override { return Join(Assert(m_context->warnings)->GetMessages(), Untranslated("<hr />")); }
             #  #  #  # ]
     102                 :           0 :     int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
     103                 :           0 :     uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
     104                 :           0 :     bool baseInitialize() override
     105                 :             :     {
     106         [ #  # ]:           0 :         if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false;
     107         [ #  # ]:           0 :         if (!AppInitParameterInteraction(args())) return false;
     108                 :             : 
     109                 :           0 :         m_context->warnings = std::make_unique<node::Warnings>();
     110                 :           0 :         m_context->kernel = std::make_unique<kernel::Context>();
     111                 :           0 :         m_context->ecc_context = std::make_unique<ECC_Context>();
     112         [ #  # ]:           0 :         if (!AppInitSanityChecks(*m_context->kernel)) return false;
     113                 :             : 
     114         [ #  # ]:           0 :         if (!AppInitLockDataDirectory()) return false;
     115         [ #  # ]:           0 :         if (!AppInitInterfaces(*m_context)) return false;
     116                 :             : 
     117                 :             :         return true;
     118                 :             :     }
     119                 :           0 :     bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
     120                 :             :     {
     121         [ #  # ]:           0 :         if (AppInitMain(*m_context, tip_info)) return true;
     122                 :             :         // Error during initialization, set exit status before continue
     123                 :           0 :         m_context->exit_status.store(EXIT_FAILURE);
     124                 :           0 :         return false;
     125                 :             :     }
     126                 :           0 :     void appShutdown() override
     127                 :             :     {
     128                 :           0 :         Interrupt(*m_context);
     129                 :           0 :         Shutdown(*m_context);
     130                 :           0 :     }
     131                 :           0 :     void startShutdown() override
     132                 :             :     {
     133         [ #  # ]:           0 :         if (!(*Assert(Assert(m_context)->shutdown))()) {
     134                 :           0 :             LogError("Failed to send shutdown signal\n");
     135                 :             :         }
     136                 :             :         // Stop RPC for clean shutdown if any of waitfor* commands is executed.
     137   [ #  #  #  # ]:           0 :         if (args().GetBoolArg("-server", false)) {
     138                 :           0 :             InterruptRPC();
     139                 :           0 :             StopRPC();
     140                 :             :         }
     141                 :           0 :     }
     142                 :           0 :     bool shutdownRequested() override { return ShutdownRequested(*Assert(m_context)); };
     143                 :           0 :     bool isSettingIgnored(const std::string& name) override
     144                 :             :     {
     145                 :           0 :         bool ignored = false;
     146                 :           0 :         args().LockSettings([&](common::Settings& settings) {
     147         [ #  # ]:           0 :             if (auto* options = common::FindKey(settings.command_line_options, name)) {
     148                 :           0 :                 ignored = !options->empty();
     149                 :             :             }
     150                 :           0 :         });
     151                 :           0 :         return ignored;
     152                 :             :     }
     153                 :           0 :     common::SettingsValue getPersistentSetting(const std::string& name) override { return args().GetPersistentSetting(name); }
     154                 :           0 :     void updateRwSetting(const std::string& name, const common::SettingsValue& value) override
     155                 :             :     {
     156                 :           0 :         args().LockSettings([&](common::Settings& settings) {
     157         [ #  # ]:           0 :             if (value.isNull()) {
     158                 :           0 :                 settings.rw_settings.erase(name);
     159                 :             :             } else {
     160                 :           0 :                 settings.rw_settings[name] = value;
     161                 :             :             }
     162                 :           0 :         });
     163                 :           0 :         args().WriteSettingsFile();
     164                 :           0 :     }
     165                 :           0 :     void forceSetting(const std::string& name, const common::SettingsValue& value) override
     166                 :             :     {
     167                 :           0 :         args().LockSettings([&](common::Settings& settings) {
     168         [ #  # ]:           0 :             if (value.isNull()) {
     169                 :           0 :                 settings.forced_settings.erase(name);
     170                 :             :             } else {
     171                 :           0 :                 settings.forced_settings[name] = value;
     172                 :             :             }
     173                 :           0 :         });
     174                 :           0 :     }
     175                 :           0 :     void resetSettings() override
     176                 :             :     {
     177                 :           0 :         args().WriteSettingsFile(/*errors=*/nullptr, /*backup=*/true);
     178                 :           0 :         args().LockSettings([&](common::Settings& settings) {
     179         [ #  # ]:           0 :             settings.rw_settings.clear();
     180                 :             :         });
     181                 :           0 :         args().WriteSettingsFile();
     182                 :           0 :     }
     183                 :           0 :     void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
     184                 :           0 :     bool getProxy(Network net, Proxy& proxy_info) override { return GetProxy(net, proxy_info); }
     185                 :           0 :     size_t getNodeCount(ConnectionDirection flags) override
     186                 :             :     {
     187         [ #  # ]:           0 :         return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
     188                 :             :     }
     189                 :           0 :     bool getNodesStats(NodesStats& stats) override
     190                 :             :     {
     191                 :           0 :         stats.clear();
     192                 :             : 
     193         [ #  # ]:           0 :         if (m_context->connman) {
     194                 :           0 :             std::vector<CNodeStats> stats_temp;
     195         [ #  # ]:           0 :             m_context->connman->GetNodeStats(stats_temp);
     196                 :             : 
     197         [ #  # ]:           0 :             stats.reserve(stats_temp.size());
     198         [ #  # ]:           0 :             for (auto& node_stats_temp : stats_temp) {
     199         [ #  # ]:           0 :                 stats.emplace_back(std::move(node_stats_temp), false, CNodeStateStats());
     200                 :             :             }
     201                 :             : 
     202                 :             :             // Try to retrieve the CNodeStateStats for each node.
     203         [ #  # ]:           0 :             if (m_context->peerman) {
     204         [ #  # ]:           0 :                 TRY_LOCK(::cs_main, lockMain);
     205         [ #  # ]:           0 :                 if (lockMain) {
     206         [ #  # ]:           0 :                     for (auto& node_stats : stats) {
     207                 :           0 :                         std::get<1>(node_stats) =
     208         [ #  # ]:           0 :                             m_context->peerman->GetNodeStateStats(std::get<0>(node_stats).nodeid, std::get<2>(node_stats));
     209                 :             :                     }
     210                 :             :                 }
     211                 :           0 :             }
     212                 :           0 :             return true;
     213                 :           0 :         }
     214                 :             :         return false;
     215                 :             :     }
     216                 :           0 :     bool getBanned(banmap_t& banmap) override
     217                 :             :     {
     218         [ #  # ]:           0 :         if (m_context->banman) {
     219                 :           0 :             m_context->banman->GetBanned(banmap);
     220                 :           0 :             return true;
     221                 :             :         }
     222                 :             :         return false;
     223                 :             :     }
     224                 :           0 :     bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) override
     225                 :             :     {
     226         [ #  # ]:           0 :         if (m_context->banman) {
     227                 :           0 :             m_context->banman->Ban(net_addr, ban_time_offset);
     228                 :           0 :             return true;
     229                 :             :         }
     230                 :             :         return false;
     231                 :             :     }
     232                 :           0 :     bool unban(const CSubNet& ip) override
     233                 :             :     {
     234         [ #  # ]:           0 :         if (m_context->banman) {
     235                 :           0 :             m_context->banman->Unban(ip);
     236                 :           0 :             return true;
     237                 :             :         }
     238                 :             :         return false;
     239                 :             :     }
     240                 :           0 :     bool disconnectByAddress(const CNetAddr& net_addr) override
     241                 :             :     {
     242         [ #  # ]:           0 :         if (m_context->connman) {
     243                 :           0 :             return m_context->connman->DisconnectNode(net_addr);
     244                 :             :         }
     245                 :             :         return false;
     246                 :             :     }
     247                 :           0 :     bool disconnectById(NodeId id) override
     248                 :             :     {
     249         [ #  # ]:           0 :         if (m_context->connman) {
     250                 :           0 :             return m_context->connman->DisconnectNode(id);
     251                 :             :         }
     252                 :             :         return false;
     253                 :             :     }
     254                 :           0 :     std::vector<std::unique_ptr<interfaces::ExternalSigner>> listExternalSigners() override
     255                 :             :     {
     256                 :             : #ifdef ENABLE_EXTERNAL_SIGNER
     257                 :           0 :         std::vector<ExternalSigner> signers = {};
     258   [ #  #  #  #  :           0 :         const std::string command = args().GetArg("-signer", "");
             #  #  #  # ]
     259         [ #  # ]:           0 :         if (command == "") return {};
     260   [ #  #  #  #  :           0 :         ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());
                   #  # ]
     261                 :           0 :         std::vector<std::unique_ptr<interfaces::ExternalSigner>> result;
     262         [ #  # ]:           0 :         result.reserve(signers.size());
     263         [ #  # ]:           0 :         for (auto& signer : signers) {
     264   [ #  #  #  # ]:           0 :             result.emplace_back(std::make_unique<ExternalSignerImpl>(std::move(signer)));
     265                 :             :         }
     266                 :           0 :         return result;
     267                 :             : #else
     268                 :             :         // This result is indistinguishable from a successful call that returns
     269                 :             :         // no signers. For the current GUI this doesn't matter, because the wallet
     270                 :             :         // creation dialog disables the external signer checkbox in both
     271                 :             :         // cases. The return type could be changed to std::optional<std::vector>
     272                 :             :         // (or something that also includes error messages) if this distinction
     273                 :             :         // becomes important.
     274                 :             :         return {};
     275                 :             : #endif // ENABLE_EXTERNAL_SIGNER
     276                 :           0 :     }
     277         [ #  # ]:           0 :     int64_t getTotalBytesRecv() override { return m_context->connman ? m_context->connman->GetTotalBytesRecv() : 0; }
     278         [ #  # ]:           0 :     int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
     279         [ #  # ]:           0 :     size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }
     280         [ #  # ]:           0 :     size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }
     281         [ #  # ]:           0 :     size_t getMempoolMaxUsage() override { return m_context->mempool ? m_context->mempool->m_opts.max_size_bytes : 0; }
     282                 :           0 :     bool getHeaderTip(int& height, int64_t& block_time) override
     283                 :             :     {
     284                 :           0 :         LOCK(::cs_main);
     285         [ #  # ]:           0 :         auto best_header = chainman().m_best_header;
     286         [ #  # ]:           0 :         if (best_header) {
     287                 :           0 :             height = best_header->nHeight;
     288                 :           0 :             block_time = best_header->GetBlockTime();
     289                 :           0 :             return true;
     290                 :             :         }
     291                 :             :         return false;
     292                 :           0 :     }
     293                 :           0 :     std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
     294                 :             :     {
     295         [ #  # ]:           0 :         if (m_context->connman)
     296                 :           0 :             return m_context->connman->getNetLocalAddresses();
     297                 :             :         else
     298                 :           0 :             return {};
     299                 :             :     }
     300                 :           0 :     int getNumBlocks() override
     301                 :             :     {
     302                 :           0 :         LOCK(::cs_main);
     303   [ #  #  #  #  :           0 :         return chainman().ActiveChain().Height();
                   #  # ]
     304                 :           0 :     }
     305                 :           0 :     uint256 getBestBlockHash() override
     306                 :             :     {
     307   [ #  #  #  #  :           0 :         const CBlockIndex* tip = WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip());
             #  #  #  # ]
     308         [ #  # ]:           0 :         return tip ? tip->GetBlockHash() : chainman().GetParams().GenesisBlock().GetHash();
     309                 :             :     }
     310                 :           0 :     int64_t getLastBlockTime() override
     311                 :             :     {
     312                 :           0 :         LOCK(::cs_main);
     313   [ #  #  #  #  :           0 :         if (chainman().ActiveChain().Tip()) {
             #  #  #  # ]
     314   [ #  #  #  #  :           0 :             return chainman().ActiveChain().Tip()->GetBlockTime();
                   #  # ]
     315                 :             :         }
     316         [ #  # ]:           0 :         return chainman().GetParams().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
     317                 :           0 :     }
     318                 :           0 :     double getVerificationProgress() override
     319                 :             :     {
     320   [ #  #  #  #  :           0 :         return GuessVerificationProgress(chainman().GetParams().TxData(), WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()));
             #  #  #  # ]
     321                 :             :     }
     322                 :           0 :     bool isInitialBlockDownload() override
     323                 :             :     {
     324                 :           0 :         return chainman().IsInitialBlockDownload();
     325                 :             :     }
     326                 :           0 :     bool isLoadingBlocks() override { return chainman().m_blockman.LoadingBlocks(); }
     327                 :           0 :     void setNetworkActive(bool active) override
     328                 :             :     {
     329         [ #  # ]:           0 :         if (m_context->connman) {
     330                 :           0 :             m_context->connman->SetNetworkActive(active);
     331                 :             :         }
     332                 :           0 :     }
     333   [ #  #  #  # ]:           0 :     bool getNetworkActive() override { return m_context->connman && m_context->connman->GetNetworkActive(); }
     334                 :           0 :     CFeeRate getDustRelayFee() override
     335                 :             :     {
     336         [ #  # ]:           0 :         if (!m_context->mempool) return CFeeRate{DUST_RELAY_TX_FEE};
     337                 :           0 :         return m_context->mempool->m_opts.dust_relay_feerate;
     338                 :             :     }
     339                 :           0 :     UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override
     340                 :             :     {
     341                 :           0 :         JSONRPCRequest req;
     342                 :           0 :         req.context = m_context;
     343         [ #  # ]:           0 :         req.params = params;
     344         [ #  # ]:           0 :         req.strMethod = command;
     345         [ #  # ]:           0 :         req.URI = uri;
     346         [ #  # ]:           0 :         return ::tableRPC.execute(req);
     347                 :           0 :     }
     348                 :           0 :     std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); }
     349                 :           0 :     void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); }
     350                 :           0 :     void rpcUnsetTimerInterface(RPCTimerInterface* iface) override { RPCUnsetTimerInterface(iface); }
     351                 :           0 :     std::optional<Coin> getUnspentOutput(const COutPoint& output) override
     352                 :             :     {
     353                 :           0 :         LOCK(::cs_main);
     354                 :           0 :         Coin coin;
     355   [ #  #  #  #  :           0 :         if (chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin)) return coin;
          #  #  #  #  #  
                      # ]
     356                 :           0 :         return {};
     357         [ #  # ]:           0 :     }
     358                 :           0 :     TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) override
     359                 :             :     {
     360   [ #  #  #  # ]:           0 :         return BroadcastTransaction(*m_context, std::move(tx), err_string, max_tx_fee, /*relay=*/ true, /*wait_callback=*/ false);
     361                 :             :     }
     362                 :           0 :     WalletLoader& walletLoader() override
     363                 :             :     {
     364                 :           0 :         return *Assert(m_context->wallet_loader);
     365                 :             :     }
     366                 :           0 :     std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
     367                 :             :     {
     368   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.InitMessage_connect(fn));
     369                 :             :     }
     370                 :           0 :     std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
     371                 :             :     {
     372   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.ThreadSafeMessageBox_connect(fn));
     373                 :             :     }
     374                 :           0 :     std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
     375                 :             :     {
     376   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.ThreadSafeQuestion_connect(fn));
     377                 :             :     }
     378                 :           0 :     std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
     379                 :             :     {
     380   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.ShowProgress_connect(fn));
     381                 :             :     }
     382                 :           0 :     std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override
     383                 :             :     {
     384   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.InitWallet_connect(fn));
     385                 :             :     }
     386                 :           0 :     std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
     387                 :             :     {
     388   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn));
     389                 :             :     }
     390                 :           0 :     std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override
     391                 :             :     {
     392   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn));
     393                 :             :     }
     394                 :           0 :     std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override
     395                 :             :     {
     396   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.NotifyAlertChanged_connect(fn));
     397                 :             :     }
     398                 :           0 :     std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override
     399                 :             :     {
     400   [ #  #  #  # ]:           0 :         return MakeSignalHandler(::uiInterface.BannedListChanged_connect(fn));
     401                 :             :     }
     402                 :           0 :     std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
     403                 :             :     {
     404   [ #  #  #  #  :           0 :         return MakeSignalHandler(::uiInterface.NotifyBlockTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
                   #  # ]
     405                 :           0 :             fn(sync_state, BlockTip{block->nHeight, block->GetBlockTime(), block->GetBlockHash()},
     406                 :           0 :                 GuessVerificationProgress(Params().TxData(), block));
     407         [ #  # ]:           0 :         }));
     408                 :             :     }
     409                 :           0 :     std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
     410                 :             :     {
     411                 :           0 :         return MakeSignalHandler(
     412   [ #  #  #  #  :           0 :             ::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, int64_t height, int64_t timestamp, bool presync) {
                   #  # ]
     413                 :           0 :                 fn(sync_state, BlockTip{(int)height, timestamp, uint256{}}, presync);
     414         [ #  # ]:           0 :             }));
     415                 :             :     }
     416                 :           0 :     NodeContext* context() override { return m_context; }
     417                 :           0 :     void setContext(NodeContext* context) override
     418                 :             :     {
     419                 :           0 :         m_context = context;
     420                 :           0 :     }
     421                 :           0 :     ArgsManager& args() { return *Assert(Assert(m_context)->args); }
     422                 :           0 :     ChainstateManager& chainman() { return *Assert(m_context->chainman); }
     423                 :             :     NodeContext* m_context{nullptr};
     424                 :             : };
     425                 :             : 
     426                 :             : // NOLINTNEXTLINE(misc-no-recursion)
     427                 :        2056 : bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active, const BlockManager& blockman)
     428                 :             : {
     429         [ +  + ]:        2056 :     if (!index) return false;
     430         [ +  + ]:        2035 :     if (block.m_hash) *block.m_hash = index->GetBlockHash();
     431         [ +  + ]:        2035 :     if (block.m_height) *block.m_height = index->nHeight;
     432         [ +  + ]:        2035 :     if (block.m_time) *block.m_time = index->GetBlockTime();
     433         [ +  + ]:        2035 :     if (block.m_max_time) *block.m_max_time = index->GetBlockTimeMax();
     434         [ +  + ]:        2035 :     if (block.m_mtp_time) *block.m_mtp_time = index->GetMedianTimePast();
     435   [ +  +  +  - ]:        3079 :     if (block.m_in_active_chain) *block.m_in_active_chain = active[index->nHeight] == index;
     436         [ +  + ]:        2035 :     if (block.m_locator) { *block.m_locator = GetLocator(index); }
     437   [ +  +  +  -  :        3089 :     if (block.m_next_block) FillBlock(active[index->nHeight] == index ? active[index->nHeight + 1] : nullptr, *block.m_next_block, lock, active, blockman);
             +  -  +  - ]
     438         [ +  + ]:        2035 :     if (block.m_data) {
     439                 :         526 :         REVERSE_LOCK(lock);
     440   [ +  -  +  + ]:         526 :         if (!blockman.ReadBlockFromDisk(*block.m_data, *index)) block.m_data->SetNull();
     441                 :         526 :     }
     442                 :        2035 :     block.found = true;
     443                 :        2035 :     return true;
     444                 :             : }
     445                 :             : 
     446                 :             : class NotificationsProxy : public CValidationInterface
     447                 :             : {
     448                 :             : public:
     449                 :          22 :     explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)
     450                 :          22 :         : m_notifications(std::move(notifications)) {}
     451         [ +  - ]:          22 :     virtual ~NotificationsProxy() = default;
     452                 :           2 :     void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override
     453                 :             :     {
     454                 :           2 :         m_notifications->transactionAddedToMempool(tx.info.m_tx);
     455                 :           2 :     }
     456                 :           0 :     void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
     457                 :             :     {
     458                 :           0 :         m_notifications->transactionRemovedFromMempool(tx, reason);
     459                 :           0 :     }
     460                 :           6 :     void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override
     461                 :             :     {
     462                 :           6 :         m_notifications->blockConnected(role, kernel::MakeBlockInfo(index, block.get()));
     463                 :           6 :     }
     464                 :           0 :     void BlockDisconnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override
     465                 :             :     {
     466                 :           0 :         m_notifications->blockDisconnected(kernel::MakeBlockInfo(index, block.get()));
     467                 :           0 :     }
     468                 :           6 :     void UpdatedBlockTip(const CBlockIndex* index, const CBlockIndex* fork_index, bool is_ibd) override
     469                 :             :     {
     470                 :           6 :         m_notifications->updatedBlockTip();
     471                 :           6 :     }
     472                 :           0 :     void ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator) override {
     473                 :           0 :         m_notifications->chainStateFlushed(role, locator);
     474                 :           0 :     }
     475                 :             :     std::shared_ptr<Chain::Notifications> m_notifications;
     476                 :             : };
     477                 :             : 
     478                 :             : class NotificationsHandlerImpl : public Handler
     479                 :             : {
     480                 :             : public:
     481                 :          22 :     explicit NotificationsHandlerImpl(ValidationSignals& signals, std::shared_ptr<Chain::Notifications> notifications)
     482         [ +  - ]:          22 :         : m_signals{signals}, m_proxy{std::make_shared<NotificationsProxy>(std::move(notifications))}
     483                 :             :     {
     484   [ +  -  +  - ]:          44 :         m_signals.RegisterSharedValidationInterface(m_proxy);
     485         [ -  - ]:          22 :     }
     486         [ -  + ]:          44 :     ~NotificationsHandlerImpl() override { disconnect(); }
     487                 :          22 :     void disconnect() override
     488                 :             :     {
     489         [ +  - ]:          22 :         if (m_proxy) {
     490   [ +  -  +  - ]:          44 :             m_signals.UnregisterSharedValidationInterface(m_proxy);
     491                 :          22 :             m_proxy.reset();
     492                 :             :         }
     493                 :          22 :     }
     494                 :             :     ValidationSignals& m_signals;
     495                 :             :     std::shared_ptr<NotificationsProxy> m_proxy;
     496                 :             : };
     497                 :             : 
     498                 :             : class RpcHandlerImpl : public Handler
     499                 :             : {
     500                 :             : public:
     501         [ +  - ]:        1242 :     explicit RpcHandlerImpl(const CRPCCommand& command) : m_command(command), m_wrapped_command(&command)
     502                 :             :     {
     503                 :        1242 :         m_command.actor = [this](const JSONRPCRequest& request, UniValue& result, bool last_handler) {
     504         [ #  # ]:           0 :             if (!m_wrapped_command) return false;
     505                 :           0 :             try {
     506         [ #  # ]:           0 :                 return m_wrapped_command->actor(request, result, last_handler);
     507         [ -  - ]:           0 :             } catch (const UniValue& e) {
     508                 :             :                 // If this is not the last handler and a wallet not found
     509                 :             :                 // exception was thrown, return false so the next handler can
     510                 :             :                 // try to handle the request. Otherwise, reraise the exception.
     511         [ -  - ]:           0 :                 if (!last_handler) {
     512   [ -  -  -  - ]:           0 :                     const UniValue& code = e["code"];
     513   [ -  -  -  -  :           0 :                     if (code.isNum() && code.getInt<int>() == RPC_WALLET_NOT_FOUND) {
                   -  - ]
     514                 :           0 :                         return false;
     515                 :             :                     }
     516                 :             :                 }
     517                 :           0 :                 throw;
     518                 :           0 :             }
     519                 :        1242 :         };
     520         [ +  - ]:        1242 :         ::tableRPC.appendCommand(m_command.name, &m_command);
     521                 :        1242 :     }
     522                 :             : 
     523                 :        1242 :     void disconnect() final
     524                 :             :     {
     525         [ +  - ]:        1242 :         if (m_wrapped_command) {
     526                 :        1242 :             m_wrapped_command = nullptr;
     527                 :        1242 :             ::tableRPC.removeCommand(m_command.name, &m_command);
     528                 :             :         }
     529                 :        1242 :     }
     530                 :             : 
     531                 :        2484 :     ~RpcHandlerImpl() override { disconnect(); }
     532                 :             : 
     533                 :             :     CRPCCommand m_command;
     534                 :             :     const CRPCCommand* m_wrapped_command;
     535                 :             : };
     536                 :             : 
     537                 :             : class ChainImpl : public Chain
     538                 :             : {
     539                 :             : public:
     540                 :         597 :     explicit ChainImpl(NodeContext& node) : m_node(node) {}
     541                 :           8 :     std::optional<int> getHeight() override
     542                 :             :     {
     543   [ +  -  +  -  :          24 :         const int height{WITH_LOCK(::cs_main, return chainman().ActiveChain().Height())};
                   +  - ]
     544         [ +  - ]:           8 :         return height >= 0 ? std::optional{height} : std::nullopt;
     545                 :             :     }
     546                 :           9 :     uint256 getBlockHash(int height) override
     547                 :             :     {
     548                 :           9 :         LOCK(::cs_main);
     549   [ +  -  +  -  :          18 :         return Assert(chainman().ActiveChain()[height])->GetBlockHash();
          +  -  +  -  +  
                      - ]
     550                 :           9 :     }
     551                 :           0 :     bool haveBlockOnDisk(int height) override
     552                 :             :     {
     553                 :           0 :         LOCK(::cs_main);
     554   [ #  #  #  #  :           0 :         const CBlockIndex* block{chainman().ActiveChain()[height]};
                   #  # ]
     555   [ #  #  #  #  :           0 :         return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
             #  #  #  # ]
     556                 :           0 :     }
     557                 :           3 :     CBlockLocator getTipLocator() override
     558                 :             :     {
     559                 :           3 :         LOCK(::cs_main);
     560   [ +  -  +  -  :           3 :         return chainman().ActiveChain().GetLocator();
                   +  - ]
     561                 :           3 :     }
     562                 :           2 :     CBlockLocator getActiveChainLocator(const uint256& block_hash) override
     563                 :             :     {
     564                 :           2 :         LOCK(::cs_main);
     565   [ +  -  +  - ]:           2 :         const CBlockIndex* index = chainman().m_blockman.LookupBlockIndex(block_hash);
     566         [ +  - ]:           2 :         return GetLocator(index);
     567                 :           2 :     }
     568                 :           4 :     std::optional<int> findLocatorFork(const CBlockLocator& locator) override
     569                 :             :     {
     570                 :           4 :         LOCK(::cs_main);
     571   [ +  -  +  -  :           4 :         if (const CBlockIndex* fork = chainman().ActiveChainstate().FindForkInGlobalIndex(locator)) {
             +  -  +  - ]
     572                 :           4 :             return fork->nHeight;
     573                 :             :         }
     574                 :           0 :         return std::nullopt;
     575                 :           4 :     }
     576                 :           9 :     bool hasBlockFilterIndex(BlockFilterType filter_type) override
     577                 :             :     {
     578                 :           9 :         return GetBlockFilterIndex(filter_type) != nullptr;
     579                 :             :     }
     580                 :           0 :     std::optional<bool> blockFilterMatchesAny(BlockFilterType filter_type, const uint256& block_hash, const GCSFilter::ElementSet& filter_set) override
     581                 :             :     {
     582                 :           0 :         const BlockFilterIndex* block_filter_index{GetBlockFilterIndex(filter_type)};
     583         [ #  # ]:           0 :         if (!block_filter_index) return std::nullopt;
     584                 :             : 
     585                 :           0 :         BlockFilter filter;
     586   [ #  #  #  #  :           0 :         const CBlockIndex* index{WITH_LOCK(::cs_main, return chainman().m_blockman.LookupBlockIndex(block_hash))};
             #  #  #  # ]
     587   [ #  #  #  #  :           0 :         if (index == nullptr || !block_filter_index->LookupFilter(index, filter)) return std::nullopt;
                   #  # ]
     588         [ #  # ]:           0 :         return filter.GetFilter().MatchAny(filter_set);
     589                 :           0 :     }
     590                 :        1510 :     bool findBlock(const uint256& hash, const FoundBlock& block) override
     591                 :             :     {
     592                 :        1510 :         WAIT_LOCK(cs_main, lock);
     593   [ +  -  +  -  :        1510 :         return FillBlock(chainman().m_blockman.LookupBlockIndex(hash), block, lock, chainman().ActiveChain(), chainman().m_blockman);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     594                 :        1510 :     }
     595                 :           5 :     bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, const FoundBlock& block) override
     596                 :             :     {
     597                 :           5 :         WAIT_LOCK(cs_main, lock);
     598   [ +  -  +  - ]:           5 :         const CChain& active = chainman().ActiveChain();
     599   [ +  -  +  -  :           5 :         return FillBlock(active.FindEarliestAtLeast(min_time, min_height), block, lock, active, chainman().m_blockman);
             +  -  +  - ]
     600                 :           5 :     }
     601                 :           3 :     bool findAncestorByHeight(const uint256& block_hash, int ancestor_height, const FoundBlock& ancestor_out) override
     602                 :             :     {
     603                 :           3 :         WAIT_LOCK(cs_main, lock);
     604   [ +  -  +  - ]:           3 :         const CChain& active = chainman().ActiveChain();
     605   [ +  -  +  -  :           3 :         if (const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
                   +  - ]
     606   [ +  -  +  + ]:           3 :             if (const CBlockIndex* ancestor = block->GetAncestor(ancestor_height)) {
     607   [ +  -  +  - ]:           2 :                 return FillBlock(ancestor, ancestor_out, lock, active, chainman().m_blockman);
     608                 :             :             }
     609                 :             :         }
     610   [ +  -  +  - ]:           1 :         return FillBlock(nullptr, ancestor_out, lock, active, chainman().m_blockman);
     611                 :           3 :     }
     612                 :           2 :     bool findAncestorByHash(const uint256& block_hash, const uint256& ancestor_hash, const FoundBlock& ancestor_out) override
     613                 :             :     {
     614                 :           2 :         WAIT_LOCK(cs_main, lock);
     615   [ +  -  +  - ]:           2 :         const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash);
     616   [ +  -  +  - ]:           2 :         const CBlockIndex* ancestor = chainman().m_blockman.LookupBlockIndex(ancestor_hash);
     617   [ +  -  +  -  :           2 :         if (block && ancestor && block->GetAncestor(ancestor->nHeight) != ancestor) ancestor = nullptr;
                   +  + ]
     618   [ +  -  +  -  :           2 :         return FillBlock(ancestor, ancestor_out, lock, chainman().ActiveChain(), chainman().m_blockman);
          +  -  +  -  +  
                      - ]
     619                 :           2 :     }
     620                 :           3 :     bool findCommonAncestor(const uint256& block_hash1, const uint256& block_hash2, const FoundBlock& ancestor_out, const FoundBlock& block1_out, const FoundBlock& block2_out) override
     621                 :             :     {
     622                 :           3 :         WAIT_LOCK(cs_main, lock);
     623   [ +  -  +  - ]:           3 :         const CChain& active = chainman().ActiveChain();
     624   [ +  -  +  - ]:           3 :         const CBlockIndex* block1 = chainman().m_blockman.LookupBlockIndex(block_hash1);
     625   [ +  -  +  - ]:           3 :         const CBlockIndex* block2 = chainman().m_blockman.LookupBlockIndex(block_hash2);
     626   [ +  +  +  - ]:           3 :         const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr;
     627                 :             :         // Using & instead of && below to avoid short circuiting and leaving
     628                 :             :         // output uninitialized. Cast bool to int to avoid -Wbitwise-instead-of-logical
     629                 :             :         // compiler warnings.
     630   [ +  -  +  - ]:           3 :         return int{FillBlock(ancestor, ancestor_out, lock, active, chainman().m_blockman)} &
     631   [ +  -  +  - ]:           3 :                int{FillBlock(block1, block1_out, lock, active, chainman().m_blockman)} &
     632   [ +  -  +  -  :           3 :                int{FillBlock(block2, block2_out, lock, active, chainman().m_blockman)};
                   +  - ]
     633                 :           3 :     }
     634                 :           0 :     void findCoins(std::map<COutPoint, Coin>& coins) override { return FindCoins(m_node, coins); }
     635                 :         537 :     double guessVerificationProgress(const uint256& block_hash) override
     636                 :             :     {
     637                 :         537 :         LOCK(::cs_main);
     638   [ +  -  +  -  :         537 :         return GuessVerificationProgress(chainman().GetParams().TxData(), chainman().m_blockman.LookupBlockIndex(block_hash));
          +  -  +  -  +  
                      - ]
     639                 :         537 :     }
     640                 :          23 :     bool hasBlocks(const uint256& block_hash, int min_height, std::optional<int> max_height) override
     641                 :             :     {
     642                 :             :         // hasBlocks returns true if all ancestors of block_hash in specified
     643                 :             :         // range have block data (are not pruned), false if any ancestors in
     644                 :             :         // specified range are missing data.
     645                 :             :         //
     646                 :             :         // For simplicity and robustness, min_height and max_height are only
     647                 :             :         // used to limit the range, and passing min_height that's too low or
     648                 :             :         // max_height that's too high will not crash or change the result.
     649                 :          23 :         LOCK(::cs_main);
     650   [ +  -  +  -  :          23 :         if (const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
                   +  - ]
     651   [ +  +  +  +  :          23 :             if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
                   +  - ]
     652         [ +  + ]:        1290 :             for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
     653                 :             :                 // Check pprev to not segfault if min_height is too low
     654   [ +  +  +  + ]:        1276 :                 if (block->nHeight <= min_height || !block->pprev) return true;
     655                 :             :             }
     656                 :             :         }
     657                 :             :         return false;
     658                 :          23 :     }
     659                 :           0 :     RBFTransactionState isRBFOptIn(const CTransaction& tx) override
     660                 :             :     {
     661         [ #  # ]:           0 :         if (!m_node.mempool) return IsRBFOptInEmptyMempool(tx);
     662                 :           0 :         LOCK(m_node.mempool->cs);
     663   [ #  #  #  # ]:           0 :         return IsRBFOptIn(tx, *m_node.mempool);
     664                 :           0 :     }
     665                 :          10 :     bool isInMempool(const uint256& txid) override
     666                 :             :     {
     667         [ +  - ]:          10 :         if (!m_node.mempool) return false;
     668                 :          10 :         LOCK(m_node.mempool->cs);
     669   [ +  -  +  - ]:          10 :         return m_node.mempool->exists(GenTxid::Txid(txid));
     670                 :          10 :     }
     671                 :           0 :     bool hasDescendantsInMempool(const uint256& txid) override
     672                 :             :     {
     673         [ #  # ]:           0 :         if (!m_node.mempool) return false;
     674                 :           0 :         LOCK(m_node.mempool->cs);
     675         [ #  # ]:           0 :         const auto entry{m_node.mempool->GetEntry(Txid::FromUint256(txid))};
     676         [ #  # ]:           0 :         if (entry == nullptr) return false;
     677                 :           0 :         return entry->GetCountWithDescendants() > 1;
     678                 :           0 :     }
     679                 :           5 :     bool broadcastTransaction(const CTransactionRef& tx,
     680                 :             :         const CAmount& max_tx_fee,
     681                 :             :         bool relay,
     682                 :             :         std::string& err_string) override
     683                 :             :     {
     684   [ +  -  +  -  :          10 :         const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback=*/false);
                   +  - ]
     685                 :             :         // Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures.
     686                 :             :         // Note: this will need to be updated if BroadcastTransactions() is updated to return other non-mempool failures
     687                 :             :         // that Chain clients do not need to know about.
     688                 :           5 :         return TransactionError::OK == err;
     689                 :             :     }
     690                 :      461533 :     void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize, CAmount* ancestorfees) override
     691                 :             :     {
     692                 :      461533 :         ancestors = descendants = 0;
     693         [ +  - ]:      461533 :         if (!m_node.mempool) return;
     694                 :      461533 :         m_node.mempool->GetTransactionAncestry(txid, ancestors, descendants, ancestorsize, ancestorfees);
     695                 :             :     }
     696                 :             : 
     697                 :          18 :     std::map<COutPoint, CAmount> calculateIndividualBumpFees(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
     698                 :             :     {
     699         [ -  + ]:          18 :         if (!m_node.mempool) {
     700                 :           0 :             std::map<COutPoint, CAmount> bump_fees;
     701         [ #  # ]:           0 :             for (const auto& outpoint : outpoints) {
     702         [ #  # ]:           0 :                 bump_fees.emplace(outpoint, 0);
     703                 :             :             }
     704                 :             :             return bump_fees;
     705                 :           0 :         }
     706         [ +  - ]:          18 :         return MiniMiner(*m_node.mempool, outpoints).CalculateBumpFees(target_feerate);
     707                 :             :     }
     708                 :             : 
     709                 :         336 :     std::optional<CAmount> calculateCombinedBumpFee(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
     710                 :             :     {
     711         [ -  + ]:         336 :         if (!m_node.mempool) {
     712                 :           0 :             return 0;
     713                 :             :         }
     714         [ +  - ]:         336 :         return MiniMiner(*m_node.mempool, outpoints).CalculateTotalBumpFees(target_feerate);
     715                 :             :     }
     716                 :         121 :     void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
     717                 :             :     {
     718                 :         121 :         const CTxMemPool::Limits default_limits{};
     719                 :             : 
     720         [ +  - ]:         121 :         const CTxMemPool::Limits& limits{m_node.mempool ? m_node.mempool->m_opts.limits : default_limits};
     721                 :             : 
     722                 :         121 :         limit_ancestor_count = limits.ancestor_count;
     723                 :         121 :         limit_descendant_count = limits.descendant_count;
     724                 :         121 :     }
     725                 :          13 :     util::Result<void> checkChainLimits(const CTransactionRef& tx) override
     726                 :             :     {
     727         [ -  + ]:          13 :         if (!m_node.mempool) return {};
     728                 :          13 :         LockPoints lp;
     729                 :          13 :         CTxMemPoolEntry entry(tx, 0, 0, 0, 0, false, 0, lp);
     730         [ +  - ]:          13 :         LOCK(m_node.mempool->cs);
     731   [ +  -  +  -  :          39 :         return m_node.mempool->CheckPackageLimits({tx}, entry.GetTxSize());
          +  +  +  -  -  
                -  -  - ]
     732   [ +  -  +  - ]:          39 :     }
     733                 :          22 :     CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
     734                 :             :     {
     735         [ +  - ]:          22 :         if (!m_node.fee_estimator) return {};
     736                 :           0 :         return m_node.fee_estimator->estimateSmartFee(num_blocks, calc, conservative);
     737                 :             :     }
     738                 :          15 :     unsigned int estimateMaxBlocks() override
     739                 :             :     {
     740         [ -  + ]:          15 :         if (!m_node.fee_estimator) return 0;
     741                 :           0 :         return m_node.fee_estimator->HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
     742                 :             :     }
     743                 :           0 :     CFeeRate mempoolMinFee() override
     744                 :             :     {
     745         [ #  # ]:           0 :         if (!m_node.mempool) return {};
     746                 :           0 :         return m_node.mempool->GetMinFee();
     747                 :             :     }
     748                 :           4 :     CFeeRate relayMinFee() override
     749                 :             :     {
     750         [ -  + ]:           4 :         if (!m_node.mempool) return CFeeRate{DEFAULT_MIN_RELAY_TX_FEE};
     751                 :           4 :         return m_node.mempool->m_opts.min_relay_feerate;
     752                 :             :     }
     753                 :           0 :     CFeeRate relayIncrementalFee() override
     754                 :             :     {
     755         [ #  # ]:           0 :         if (!m_node.mempool) return CFeeRate{DEFAULT_INCREMENTAL_RELAY_FEE};
     756                 :           0 :         return m_node.mempool->m_opts.incremental_relay_feerate;
     757                 :             :     }
     758                 :          42 :     CFeeRate relayDustFee() override
     759                 :             :     {
     760         [ -  + ]:          42 :         if (!m_node.mempool) return CFeeRate{DUST_RELAY_TX_FEE};
     761                 :          42 :         return m_node.mempool->m_opts.dust_relay_feerate;
     762                 :             :     }
     763                 :           2 :     bool havePruned() override
     764                 :             :     {
     765                 :           2 :         LOCK(::cs_main);
     766   [ +  -  +  - ]:           2 :         return chainman().m_blockman.m_have_pruned;
     767                 :           2 :     }
     768   [ #  #  #  # ]:           0 :     bool isReadyToBroadcast() override { return !chainman().m_blockman.LoadingBlocks() && !isInitialBlockDownload(); }
     769                 :          13 :     bool isInitialBlockDownload() override
     770                 :             :     {
     771                 :          13 :         return chainman().IsInitialBlockDownload();
     772                 :             :     }
     773                 :         536 :     bool shutdownRequested() override { return ShutdownRequested(m_node); }
     774                 :           5 :     void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
     775                 :           0 :     void initWarning(const bilingual_str& message) override { InitWarning(message); }
     776                 :           3 :     void initError(const bilingual_str& message) override { InitError(message); }
     777                 :          16 :     void showProgress(const std::string& title, int progress, bool resume_possible) override
     778                 :             :     {
     779                 :          16 :         ::uiInterface.ShowProgress(title, progress, resume_possible);
     780                 :          16 :     }
     781                 :          22 :     std::unique_ptr<Handler> handleNotifications(std::shared_ptr<Notifications> notifications) override
     782                 :             :     {
     783                 :          22 :         return std::make_unique<NotificationsHandlerImpl>(validation_signals(), std::move(notifications));
     784                 :             :     }
     785                 :           6 :     void waitForNotificationsIfTipChanged(const uint256& old_tip) override
     786                 :             :     {
     787   [ +  +  -  +  :          12 :         if (!old_tip.IsNull() && old_tip == WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()->GetBlockHash())) return;
          +  -  +  -  +  
                -  +  - ]
     788                 :           4 :         validation_signals().SyncWithValidationInterfaceQueue();
     789                 :             :     }
     790                 :        1242 :     std::unique_ptr<Handler> handleRpc(const CRPCCommand& command) override
     791                 :             :     {
     792                 :        1242 :         return std::make_unique<RpcHandlerImpl>(command);
     793                 :             :     }
     794                 :           0 :     bool rpcEnableDeprecated(const std::string& method) override { return IsDeprecatedRPCEnabled(method); }
     795                 :           0 :     void rpcRunLater(const std::string& name, std::function<void()> fn, int64_t seconds) override
     796                 :             :     {
     797         [ #  # ]:           0 :         RPCRunLater(name, std::move(fn), seconds);
     798                 :           0 :     }
     799                 :           0 :     common::SettingsValue getSetting(const std::string& name) override
     800                 :             :     {
     801                 :           0 :         return args().GetSetting(name);
     802                 :             :     }
     803                 :           4 :     std::vector<common::SettingsValue> getSettingsList(const std::string& name) override
     804                 :             :     {
     805                 :           4 :         return args().GetSettingsList(name);
     806                 :             :     }
     807                 :           3 :     common::SettingsValue getRwSetting(const std::string& name) override
     808                 :             :     {
     809         [ +  - ]:           3 :         common::SettingsValue result;
     810   [ +  -  +  - ]:           3 :         args().LockSettings([&](const common::Settings& settings) {
     811         [ +  + ]:           3 :             if (const common::SettingsValue* value = common::FindKey(settings.rw_settings, name)) {
     812                 :           2 :                 result = *value;
     813                 :             :             }
     814                 :           3 :         });
     815                 :           3 :         return result;
     816                 :           0 :     }
     817                 :          10 :     bool updateRwSetting(const std::string& name,
     818                 :             :                          const interfaces::SettingsUpdate& update_settings_func) override
     819                 :             :     {
     820                 :          10 :         std::optional<interfaces::SettingsAction> action;
     821                 :          10 :         args().LockSettings([&](common::Settings& settings) {
     822                 :          10 :             auto* ptr_value = common::FindKey(settings.rw_settings, name);
     823                 :             :             // Create value if it doesn't exist
     824         [ +  + ]:          10 :             auto& value = ptr_value ? *ptr_value : settings.rw_settings[name];
     825                 :          10 :             action = update_settings_func(value);
     826                 :          10 :         });
     827         [ +  - ]:          10 :         if (!action) return false;
     828                 :             :         // Now dump value to disk if requested
     829   [ +  -  +  - ]:          10 :         return *action == interfaces::SettingsAction::SKIP_WRITE || args().WriteSettingsFile();
     830                 :             :     }
     831                 :           0 :     bool overwriteRwSetting(const std::string& name, common::SettingsValue& value, bool write) override
     832                 :             :     {
     833         [ #  # ]:           0 :         if (value.isNull()) return deleteRwSettings(name, write);
     834         [ #  # ]:           0 :         return updateRwSetting(name, [&](common::SettingsValue& settings) {
     835                 :           0 :             settings = std::move(value);
     836         [ #  # ]:           0 :             return write ? interfaces::SettingsAction::WRITE : interfaces::SettingsAction::SKIP_WRITE;
     837                 :             :         });
     838                 :             :     }
     839                 :           0 :     bool deleteRwSettings(const std::string& name, bool write) override
     840                 :             :     {
     841                 :           0 :         args().LockSettings([&](common::Settings& settings) {
     842         [ #  # ]:           0 :             settings.rw_settings.erase(name);
     843                 :             :         });
     844   [ #  #  #  # ]:           0 :         return !write || args().WriteSettingsFile();
     845                 :             :     }
     846                 :          15 :     void requestMempoolTransactions(Notifications& notifications) override
     847                 :             :     {
     848         [ +  - ]:          15 :         if (!m_node.mempool) return;
     849         [ +  - ]:          15 :         LOCK2(::cs_main, m_node.mempool->cs);
     850   [ +  -  +  -  :          19 :         for (const CTxMemPoolEntry& entry : m_node.mempool->entryAll()) {
                   +  + ]
     851   [ +  -  +  - ]:          12 :             notifications.transactionAddedToMempool(entry.GetSharedTx());
     852         [ +  - ]:          15 :         }
     853         [ +  - ]:          30 :     }
     854                 :           1 :     bool hasAssumedValidChain() override
     855                 :             :     {
     856                 :           1 :         return chainman().IsSnapshotActive();
     857                 :             :     }
     858                 :             : 
     859                 :          47 :     NodeContext* context() override { return &m_node; }
     860                 :          27 :     ArgsManager& args() { return *Assert(m_node.args); }
     861                 :        5716 :     ChainstateManager& chainman() { return *Assert(m_node.chainman); }
     862                 :          26 :     ValidationSignals& validation_signals() { return *Assert(m_node.validation_signals); }
     863                 :             :     NodeContext& m_node;
     864                 :             : };
     865                 :             : 
     866                 :             : class MinerImpl : public Mining
     867                 :             : {
     868                 :             : public:
     869                 :           0 :     explicit MinerImpl(NodeContext& node) : m_node(node) {}
     870                 :             : 
     871                 :           0 :     bool isTestChain() override
     872                 :             :     {
     873                 :           0 :         return chainman().GetParams().IsTestChain();
     874                 :             :     }
     875                 :             : 
     876                 :           0 :     bool isInitialBlockDownload() override
     877                 :             :     {
     878                 :           0 :         return chainman().IsInitialBlockDownload();
     879                 :             :     }
     880                 :             : 
     881                 :           0 :     std::optional<uint256> getTipHash() override
     882                 :             :     {
     883                 :           0 :         LOCK(::cs_main);
     884   [ #  #  #  #  :           0 :         CBlockIndex* tip{chainman().ActiveChain().Tip()};
                   #  # ]
     885         [ #  # ]:           0 :         if (!tip) return {};
     886                 :           0 :         return tip->GetBlockHash();
     887                 :           0 :     }
     888                 :             : 
     889                 :           0 :     bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) override
     890                 :             :     {
     891                 :           0 :         return chainman().ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/new_block);
     892                 :             :     }
     893                 :             : 
     894                 :           0 :     unsigned int getTransactionsUpdated() override
     895                 :             :     {
     896                 :           0 :         return context()->mempool->GetTransactionsUpdated();
     897                 :             :     }
     898                 :             : 
     899                 :           0 :     bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) override
     900                 :             :     {
     901                 :           0 :         LOCK(cs_main);
     902   [ #  #  #  #  :           0 :         CBlockIndex* tip{chainman().ActiveChain().Tip()};
                   #  # ]
     903                 :             :         // Fail if the tip updated before the lock was taken
     904         [ #  # ]:           0 :         if (block.hashPrevBlock != tip->GetBlockHash()) {
     905         [ #  # ]:           0 :             state.Error("Block does not connect to current chain tip.");
     906                 :           0 :             return false;
     907                 :             :         }
     908                 :             : 
     909   [ #  #  #  #  :           0 :         return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root);
             #  #  #  # ]
     910                 :           0 :     }
     911                 :             : 
     912                 :           0 :     std::unique_ptr<CBlockTemplate> createNewBlock(const CScript& script_pub_key, const BlockCreateOptions& options) override
     913                 :             :     {
     914                 :           0 :         BlockAssembler::Options assemble_options{options};
     915                 :           0 :         ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
     916         [ #  # ]:           0 :         return BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key);
     917                 :             :     }
     918                 :             : 
     919                 :           0 :     NodeContext* context() override { return &m_node; }
     920                 :           0 :     ChainstateManager& chainman() { return *Assert(m_node.chainman); }
     921                 :             :     NodeContext& m_node;
     922                 :             : };
     923                 :             : } // namespace
     924                 :             : } // namespace node
     925                 :             : 
     926                 :             : namespace interfaces {
     927                 :           0 : std::unique_ptr<Node> MakeNode(node::NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
     928                 :         597 : std::unique_ptr<Chain> MakeChain(node::NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }
     929                 :           0 : std::unique_ptr<Mining> MakeMining(node::NodeContext& context) { return std::make_unique<node::MinerImpl>(context); }
     930                 :             : } // namespace interfaces
        

Generated by: LCOV version 2.0-1