Bitcoin Core  24.1.0
P2P Digital Currency
interfaces.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 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 <chain.h>
8 #include <chainparams.h>
9 #include <deploymentstatus.h>
10 #include <external_signer.h>
11 #include <init.h>
12 #include <interfaces/chain.h>
13 #include <interfaces/handler.h>
14 #include <interfaces/node.h>
15 #include <interfaces/wallet.h>
16 #include <mapport.h>
17 #include <net.h>
18 #include <net_processing.h>
19 #include <netaddress.h>
20 #include <netbase.h>
21 #include <node/blockstorage.h>
22 #include <kernel/chain.h>
23 #include <node/coin.h>
24 #include <node/context.h>
25 #include <node/transaction.h>
26 #include <node/interface_ui.h>
27 #include <policy/feerate.h>
28 #include <policy/fees.h>
29 #include <policy/policy.h>
30 #include <policy/rbf.h>
31 #include <policy/settings.h>
32 #include <primitives/block.h>
33 #include <primitives/transaction.h>
34 #include <rpc/protocol.h>
35 #include <rpc/server.h>
36 #include <shutdown.h>
38 #include <sync.h>
39 #include <txmempool.h>
40 #include <uint256.h>
41 #include <univalue.h>
42 #include <util/check.h>
43 #include <util/system.h>
44 #include <util/translation.h>
45 #include <validation.h>
46 #include <validationinterface.h>
47 #include <warnings.h>
48 
49 #if defined(HAVE_CONFIG_H)
50 #include <config/bitcoin-config.h>
51 #endif
52 
53 #include <any>
54 #include <memory>
55 #include <optional>
56 #include <utility>
57 
58 #include <boost/signals2/signal.hpp>
59 
61 using interfaces::Chain;
65 using interfaces::Node;
67 
68 namespace node {
69 // All members of the classes in this namespace are intentionally public, as the
70 // classes themselves are private.
71 namespace {
72 #ifdef ENABLE_EXTERNAL_SIGNER
73 class ExternalSignerImpl : public interfaces::ExternalSigner
74 {
75 public:
76  ExternalSignerImpl(::ExternalSigner signer) : m_signer(std::move(signer)) {}
77  std::string getName() override { return m_signer.m_name; }
79 };
80 #endif
81 
82 class NodeImpl : public Node
83 {
84 public:
85  explicit NodeImpl(NodeContext& context) { setContext(&context); }
86  void initLogging() override { InitLogging(*Assert(m_context->args)); }
87  void initParameterInteraction() override { InitParameterInteraction(*Assert(m_context->args)); }
88  bilingual_str getWarnings() override { return GetWarnings(true); }
89  uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
90  bool baseInitialize() override
91  {
92  if (!AppInitBasicSetup(gArgs)) return false;
93  if (!AppInitParameterInteraction(gArgs, /*use_syscall_sandbox=*/false)) return false;
94 
95  m_context->kernel = std::make_unique<kernel::Context>();
96  if (!AppInitSanityChecks(*m_context->kernel)) return false;
97 
98  if (!AppInitLockDataDirectory()) return false;
99  if (!AppInitInterfaces(*m_context)) return false;
100 
101  return true;
102  }
103  bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info) override
104  {
105  return AppInitMain(*m_context, tip_info);
106  }
107  void appShutdown() override
108  {
111  }
112  void startShutdown() override
113  {
114  StartShutdown();
115  // Stop RPC for clean shutdown if any of waitfor* commands is executed.
116  if (gArgs.GetBoolArg("-server", false)) {
117  InterruptRPC();
118  StopRPC();
119  }
120  }
121  bool shutdownRequested() override { return ShutdownRequested(); }
122  bool isSettingIgnored(const std::string& name) override
123  {
124  bool ignored = false;
125  gArgs.LockSettings([&](util::Settings& settings) {
126  if (auto* options = util::FindKey(settings.command_line_options, name)) {
127  ignored = !options->empty();
128  }
129  });
130  return ignored;
131  }
132  util::SettingsValue getPersistentSetting(const std::string& name) override { return gArgs.GetPersistentSetting(name); }
133  void updateRwSetting(const std::string& name, const util::SettingsValue& value) override
134  {
135  gArgs.LockSettings([&](util::Settings& settings) {
136  if (value.isNull()) {
137  settings.rw_settings.erase(name);
138  } else {
139  settings.rw_settings[name] = value;
140  }
141  });
143  }
144  void forceSetting(const std::string& name, const util::SettingsValue& value) override
145  {
146  gArgs.LockSettings([&](util::Settings& settings) {
147  if (value.isNull()) {
148  settings.forced_settings.erase(name);
149  } else {
150  settings.forced_settings[name] = value;
151  }
152  });
153  }
154  void resetSettings() override
155  {
156  gArgs.WriteSettingsFile(/*errors=*/nullptr, /*backup=*/true);
157  gArgs.LockSettings([&](util::Settings& settings) {
158  settings.rw_settings.clear();
159  });
161  }
162  void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
163  bool getProxy(Network net, Proxy& proxy_info) override { return GetProxy(net, proxy_info); }
164  size_t getNodeCount(ConnectionDirection flags) override
165  {
166  return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
167  }
168  bool getNodesStats(NodesStats& stats) override
169  {
170  stats.clear();
171 
172  if (m_context->connman) {
173  std::vector<CNodeStats> stats_temp;
174  m_context->connman->GetNodeStats(stats_temp);
175 
176  stats.reserve(stats_temp.size());
177  for (auto& node_stats_temp : stats_temp) {
178  stats.emplace_back(std::move(node_stats_temp), false, CNodeStateStats());
179  }
180 
181  // Try to retrieve the CNodeStateStats for each node.
182  if (m_context->peerman) {
183  TRY_LOCK(::cs_main, lockMain);
184  if (lockMain) {
185  for (auto& node_stats : stats) {
186  std::get<1>(node_stats) =
187  m_context->peerman->GetNodeStateStats(std::get<0>(node_stats).nodeid, std::get<2>(node_stats));
188  }
189  }
190  }
191  return true;
192  }
193  return false;
194  }
195  bool getBanned(banmap_t& banmap) override
196  {
197  if (m_context->banman) {
198  m_context->banman->GetBanned(banmap);
199  return true;
200  }
201  return false;
202  }
203  bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) override
204  {
205  if (m_context->banman) {
206  m_context->banman->Ban(net_addr, ban_time_offset);
207  return true;
208  }
209  return false;
210  }
211  bool unban(const CSubNet& ip) override
212  {
213  if (m_context->banman) {
214  m_context->banman->Unban(ip);
215  return true;
216  }
217  return false;
218  }
219  bool disconnectByAddress(const CNetAddr& net_addr) override
220  {
221  if (m_context->connman) {
222  return m_context->connman->DisconnectNode(net_addr);
223  }
224  return false;
225  }
226  bool disconnectById(NodeId id) override
227  {
228  if (m_context->connman) {
229  return m_context->connman->DisconnectNode(id);
230  }
231  return false;
232  }
233  std::vector<std::unique_ptr<interfaces::ExternalSigner>> listExternalSigners() override
234  {
235 #ifdef ENABLE_EXTERNAL_SIGNER
236  std::vector<ExternalSigner> signers = {};
237  const std::string command = gArgs.GetArg("-signer", "");
238  if (command == "") return {};
239  ExternalSigner::Enumerate(command, signers, Params().NetworkIDString());
240  std::vector<std::unique_ptr<interfaces::ExternalSigner>> result;
241  for (auto& signer : signers) {
242  result.emplace_back(std::make_unique<ExternalSignerImpl>(std::move(signer)));
243  }
244  return result;
245 #else
246  // This result is indistinguishable from a successful call that returns
247  // no signers. For the current GUI this doesn't matter, because the wallet
248  // creation dialog disables the external signer checkbox in both
249  // cases. The return type could be changed to std::optional<std::vector>
250  // (or something that also includes error messages) if this distinction
251  // becomes important.
252  return {};
253 #endif // ENABLE_EXTERNAL_SIGNER
254  }
255  int64_t getTotalBytesRecv() override { return m_context->connman ? m_context->connman->GetTotalBytesRecv() : 0; }
256  int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
257  size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }
258  size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }
259  bool getHeaderTip(int& height, int64_t& block_time) override
260  {
261  LOCK(::cs_main);
262  auto best_header = chainman().m_best_header;
263  if (best_header) {
264  height = best_header->nHeight;
265  block_time = best_header->GetBlockTime();
266  return true;
267  }
268  return false;
269  }
270  int getNumBlocks() override
271  {
272  LOCK(::cs_main);
273  return chainman().ActiveChain().Height();
274  }
275  uint256 getBestBlockHash() override
276  {
277  const CBlockIndex* tip = WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip());
278  return tip ? tip->GetBlockHash() : chainman().GetParams().GenesisBlock().GetHash();
279  }
280  int64_t getLastBlockTime() override
281  {
282  LOCK(::cs_main);
283  if (chainman().ActiveChain().Tip()) {
284  return chainman().ActiveChain().Tip()->GetBlockTime();
285  }
286  return chainman().GetParams().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
287  }
288  double getVerificationProgress() override
289  {
290  return GuessVerificationProgress(chainman().GetParams().TxData(), WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()));
291  }
292  bool isInitialBlockDownload() override {
293  return chainman().ActiveChainstate().IsInitialBlockDownload();
294  }
295  bool getReindex() override { return node::fReindex; }
296  bool getImporting() override { return node::fImporting; }
297  void setNetworkActive(bool active) override
298  {
299  if (m_context->connman) {
300  m_context->connman->SetNetworkActive(active);
301  }
302  }
303  bool getNetworkActive() override { return m_context->connman && m_context->connman->GetNetworkActive(); }
304  CFeeRate getDustRelayFee() override
305  {
306  if (!m_context->mempool) return CFeeRate{DUST_RELAY_TX_FEE};
307  return m_context->mempool->m_dust_relay_feerate;
308  }
309  UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override
310  {
311  JSONRPCRequest req;
312  req.context = m_context;
313  req.params = params;
314  req.strMethod = command;
315  req.URI = uri;
317  }
318  std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); }
319  void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); }
320  void rpcUnsetTimerInterface(RPCTimerInterface* iface) override { RPCUnsetTimerInterface(iface); }
321  bool getUnspentOutput(const COutPoint& output, Coin& coin) override
322  {
323  LOCK(::cs_main);
324  return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin);
325  }
326  TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) override
327  {
328  return BroadcastTransaction(*m_context, std::move(tx), err_string, max_tx_fee, /*relay=*/ true, /*wait_callback=*/ false);
329  }
330  WalletLoader& walletLoader() override
331  {
332  return *Assert(m_context->wallet_loader);
333  }
334  std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
335  {
336  return MakeHandler(::uiInterface.InitMessage_connect(fn));
337  }
338  std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
339  {
340  return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn));
341  }
342  std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
343  {
344  return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn));
345  }
346  std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
347  {
348  return MakeHandler(::uiInterface.ShowProgress_connect(fn));
349  }
350  std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override
351  {
352  return MakeHandler(::uiInterface.InitWallet_connect(fn));
353  }
354  std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
355  {
356  return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn));
357  }
358  std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override
359  {
360  return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn));
361  }
362  std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override
363  {
364  return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn));
365  }
366  std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override
367  {
368  return MakeHandler(::uiInterface.BannedListChanged_connect(fn));
369  }
370  std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
371  {
372  return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
373  fn(sync_state, BlockTip{block->nHeight, block->GetBlockTime(), block->GetBlockHash()},
374  GuessVerificationProgress(Params().TxData(), block));
375  }));
376  }
377  std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
378  {
379  return MakeHandler(
380  ::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, int64_t height, int64_t timestamp, bool presync) {
381  fn(sync_state, BlockTip{(int)height, timestamp, uint256{}}, presync);
382  }));
383  }
384  NodeContext* context() override { return m_context; }
385  void setContext(NodeContext* context) override
386  {
387  m_context = context;
388  }
389  ChainstateManager& chainman() { return *Assert(m_context->chainman); }
390  NodeContext* m_context{nullptr};
391 };
392 
393 bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active)
394 {
395  if (!index) return false;
396  if (block.m_hash) *block.m_hash = index->GetBlockHash();
397  if (block.m_height) *block.m_height = index->nHeight;
398  if (block.m_time) *block.m_time = index->GetBlockTime();
399  if (block.m_max_time) *block.m_max_time = index->GetBlockTimeMax();
400  if (block.m_mtp_time) *block.m_mtp_time = index->GetMedianTimePast();
401  if (block.m_in_active_chain) *block.m_in_active_chain = active[index->nHeight] == index;
402  if (block.m_locator) { *block.m_locator = GetLocator(index); }
403  if (block.m_next_block) FillBlock(active[index->nHeight] == index ? active[index->nHeight + 1] : nullptr, *block.m_next_block, lock, active);
404  if (block.m_data) {
405  REVERSE_LOCK(lock);
406  if (!ReadBlockFromDisk(*block.m_data, index, Params().GetConsensus())) block.m_data->SetNull();
407  }
408  block.found = true;
409  return true;
410 }
411 
412 class NotificationsProxy : public CValidationInterface
413 {
414 public:
415  explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)
416  : m_notifications(std::move(notifications)) {}
417  virtual ~NotificationsProxy() = default;
418  void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) override
419  {
420  m_notifications->transactionAddedToMempool(tx, mempool_sequence);
421  }
422  void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
423  {
424  m_notifications->transactionRemovedFromMempool(tx, reason, mempool_sequence);
425  }
426  void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override
427  {
428  m_notifications->blockConnected(kernel::MakeBlockInfo(index, block.get()));
429  }
430  void BlockDisconnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override
431  {
432  m_notifications->blockDisconnected(kernel::MakeBlockInfo(index, block.get()));
433  }
434  void UpdatedBlockTip(const CBlockIndex* index, const CBlockIndex* fork_index, bool is_ibd) override
435  {
436  m_notifications->updatedBlockTip();
437  }
438  void ChainStateFlushed(const CBlockLocator& locator) override { m_notifications->chainStateFlushed(locator); }
439  std::shared_ptr<Chain::Notifications> m_notifications;
440 };
441 
442 class NotificationsHandlerImpl : public Handler
443 {
444 public:
445  explicit NotificationsHandlerImpl(std::shared_ptr<Chain::Notifications> notifications)
446  : m_proxy(std::make_shared<NotificationsProxy>(std::move(notifications)))
447  {
449  }
450  ~NotificationsHandlerImpl() override { disconnect(); }
451  void disconnect() override
452  {
453  if (m_proxy) {
455  m_proxy.reset();
456  }
457  }
458  std::shared_ptr<NotificationsProxy> m_proxy;
459 };
460 
461 class RpcHandlerImpl : public Handler
462 {
463 public:
464  explicit RpcHandlerImpl(const CRPCCommand& command) : m_command(command), m_wrapped_command(&command)
465  {
466  m_command.actor = [this](const JSONRPCRequest& request, UniValue& result, bool last_handler) {
467  if (!m_wrapped_command) return false;
468  try {
469  return m_wrapped_command->actor(request, result, last_handler);
470  } catch (const UniValue& e) {
471  // If this is not the last handler and a wallet not found
472  // exception was thrown, return false so the next handler can
473  // try to handle the request. Otherwise, reraise the exception.
474  if (!last_handler) {
475  const UniValue& code = e["code"];
476  if (code.isNum() && code.getInt<int>() == RPC_WALLET_NOT_FOUND) {
477  return false;
478  }
479  }
480  throw;
481  }
482  };
484  }
485 
486  void disconnect() final
487  {
488  if (m_wrapped_command) {
489  m_wrapped_command = nullptr;
491  }
492  }
493 
494  ~RpcHandlerImpl() override { disconnect(); }
495 
498 };
499 
500 class ChainImpl : public Chain
501 {
502 public:
503  explicit ChainImpl(NodeContext& node) : m_node(node) {}
504  std::optional<int> getHeight() override
505  {
506  const int height{WITH_LOCK(::cs_main, return chainman().ActiveChain().Height())};
507  return height >= 0 ? std::optional{height} : std::nullopt;
508  }
509  uint256 getBlockHash(int height) override
510  {
511  LOCK(::cs_main);
512  return Assert(chainman().ActiveChain()[height])->GetBlockHash();
513  }
514  bool haveBlockOnDisk(int height) override
515  {
516  LOCK(::cs_main);
517  const CBlockIndex* block{chainman().ActiveChain()[height]};
518  return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
519  }
520  CBlockLocator getTipLocator() override
521  {
522  LOCK(::cs_main);
523  return chainman().ActiveChain().GetLocator();
524  }
525  CBlockLocator getActiveChainLocator(const uint256& block_hash) override
526  {
527  LOCK(::cs_main);
528  const CBlockIndex* index = chainman().m_blockman.LookupBlockIndex(block_hash);
529  return GetLocator(index);
530  }
531  std::optional<int> findLocatorFork(const CBlockLocator& locator) override
532  {
533  LOCK(::cs_main);
534  if (const CBlockIndex* fork = chainman().ActiveChainstate().FindForkInGlobalIndex(locator)) {
535  return fork->nHeight;
536  }
537  return std::nullopt;
538  }
539  bool findBlock(const uint256& hash, const FoundBlock& block) override
540  {
541  WAIT_LOCK(cs_main, lock);
542  return FillBlock(chainman().m_blockman.LookupBlockIndex(hash), block, lock, chainman().ActiveChain());
543  }
544  bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, const FoundBlock& block) override
545  {
546  WAIT_LOCK(cs_main, lock);
547  const CChain& active = chainman().ActiveChain();
548  return FillBlock(active.FindEarliestAtLeast(min_time, min_height), block, lock, active);
549  }
550  bool findAncestorByHeight(const uint256& block_hash, int ancestor_height, const FoundBlock& ancestor_out) override
551  {
552  WAIT_LOCK(cs_main, lock);
553  const CChain& active = chainman().ActiveChain();
554  if (const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
555  if (const CBlockIndex* ancestor = block->GetAncestor(ancestor_height)) {
556  return FillBlock(ancestor, ancestor_out, lock, active);
557  }
558  }
559  return FillBlock(nullptr, ancestor_out, lock, active);
560  }
561  bool findAncestorByHash(const uint256& block_hash, const uint256& ancestor_hash, const FoundBlock& ancestor_out) override
562  {
563  WAIT_LOCK(cs_main, lock);
564  const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash);
565  const CBlockIndex* ancestor = chainman().m_blockman.LookupBlockIndex(ancestor_hash);
566  if (block && ancestor && block->GetAncestor(ancestor->nHeight) != ancestor) ancestor = nullptr;
567  return FillBlock(ancestor, ancestor_out, lock, chainman().ActiveChain());
568  }
569  bool findCommonAncestor(const uint256& block_hash1, const uint256& block_hash2, const FoundBlock& ancestor_out, const FoundBlock& block1_out, const FoundBlock& block2_out) override
570  {
571  WAIT_LOCK(cs_main, lock);
572  const CChain& active = chainman().ActiveChain();
573  const CBlockIndex* block1 = chainman().m_blockman.LookupBlockIndex(block_hash1);
574  const CBlockIndex* block2 = chainman().m_blockman.LookupBlockIndex(block_hash2);
575  const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr;
576  // Using & instead of && below to avoid short circuiting and leaving
577  // output uninitialized. Cast bool to int to avoid -Wbitwise-instead-of-logical
578  // compiler warnings.
579  return int{FillBlock(ancestor, ancestor_out, lock, active)} &
580  int{FillBlock(block1, block1_out, lock, active)} &
581  int{FillBlock(block2, block2_out, lock, active)};
582  }
583  void findCoins(std::map<COutPoint, Coin>& coins) override { return FindCoins(m_node, coins); }
584  double guessVerificationProgress(const uint256& block_hash) override
585  {
586  LOCK(::cs_main);
587  return GuessVerificationProgress(chainman().GetParams().TxData(), chainman().m_blockman.LookupBlockIndex(block_hash));
588  }
589  bool hasBlocks(const uint256& block_hash, int min_height, std::optional<int> max_height) override
590  {
591  // hasBlocks returns true if all ancestors of block_hash in specified
592  // range have block data (are not pruned), false if any ancestors in
593  // specified range are missing data.
594  //
595  // For simplicity and robustness, min_height and max_height are only
596  // used to limit the range, and passing min_height that's too low or
597  // max_height that's too high will not crash or change the result.
598  LOCK(::cs_main);
599  if (const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
600  if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
601  for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
602  // Check pprev to not segfault if min_height is too low
603  if (block->nHeight <= min_height || !block->pprev) return true;
604  }
605  }
606  return false;
607  }
608  RBFTransactionState isRBFOptIn(const CTransaction& tx) override
609  {
610  if (!m_node.mempool) return IsRBFOptInEmptyMempool(tx);
611  LOCK(m_node.mempool->cs);
612  return IsRBFOptIn(tx, *m_node.mempool);
613  }
614  bool isInMempool(const uint256& txid) override
615  {
616  if (!m_node.mempool) return false;
617  LOCK(m_node.mempool->cs);
618  return m_node.mempool->exists(GenTxid::Txid(txid));
619  }
620  bool hasDescendantsInMempool(const uint256& txid) override
621  {
622  if (!m_node.mempool) return false;
623  LOCK(m_node.mempool->cs);
624  auto it = m_node.mempool->GetIter(txid);
625  return it && (*it)->GetCountWithDescendants() > 1;
626  }
627  bool broadcastTransaction(const CTransactionRef& tx,
628  const CAmount& max_tx_fee,
629  bool relay,
630  std::string& err_string) override
631  {
632  const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback=*/false);
633  // Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures.
634  // Note: this will need to be updated if BroadcastTransactions() is updated to return other non-mempool failures
635  // that Chain clients do not need to know about.
636  return TransactionError::OK == err;
637  }
638  void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize, CAmount* ancestorfees) override
639  {
640  ancestors = descendants = 0;
641  if (!m_node.mempool) return;
642  m_node.mempool->GetTransactionAncestry(txid, ancestors, descendants, ancestorsize, ancestorfees);
643  }
644  void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
645  {
646  const CTxMemPool::Limits default_limits{};
647 
648  const CTxMemPool::Limits& limits{m_node.mempool ? m_node.mempool->m_limits : default_limits};
649 
650  limit_ancestor_count = limits.ancestor_count;
651  limit_descendant_count = limits.descendant_count;
652  }
653  bool checkChainLimits(const CTransactionRef& tx) override
654  {
655  if (!m_node.mempool) return true;
656  LockPoints lp;
657  CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
658  CTxMemPool::setEntries ancestors;
659  const CTxMemPool::Limits& limits{m_node.mempool->m_limits};
660  std::string unused_error_string;
661  LOCK(m_node.mempool->cs);
662  return m_node.mempool->CalculateMemPoolAncestors(
663  entry, ancestors, limits.ancestor_count, limits.ancestor_size_vbytes,
664  limits.descendant_count, limits.descendant_size_vbytes, unused_error_string);
665  }
666  CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
667  {
668  if (!m_node.fee_estimator) return {};
669  return m_node.fee_estimator->estimateSmartFee(num_blocks, calc, conservative);
670  }
671  unsigned int estimateMaxBlocks() override
672  {
673  if (!m_node.fee_estimator) return 0;
674  return m_node.fee_estimator->HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
675  }
676  CFeeRate mempoolMinFee() override
677  {
678  if (!m_node.mempool) return {};
679  return m_node.mempool->GetMinFee();
680  }
681  CFeeRate relayMinFee() override
682  {
683  if (!m_node.mempool) return CFeeRate{DEFAULT_MIN_RELAY_TX_FEE};
684  return m_node.mempool->m_min_relay_feerate;
685  }
686  CFeeRate relayIncrementalFee() override
687  {
688  if (!m_node.mempool) return CFeeRate{DEFAULT_INCREMENTAL_RELAY_FEE};
689  return m_node.mempool->m_incremental_relay_feerate;
690  }
691  CFeeRate relayDustFee() override
692  {
693  if (!m_node.mempool) return CFeeRate{DUST_RELAY_TX_FEE};
694  return m_node.mempool->m_dust_relay_feerate;
695  }
696  bool havePruned() override
697  {
698  LOCK(::cs_main);
699  return chainman().m_blockman.m_have_pruned;
700  }
701  bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); }
702  bool isInitialBlockDownload() override {
703  return chainman().ActiveChainstate().IsInitialBlockDownload();
704  }
705  bool shutdownRequested() override { return ShutdownRequested(); }
706  void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
707  void initWarning(const bilingual_str& message) override { InitWarning(message); }
708  void initError(const bilingual_str& message) override { InitError(message); }
709  void showProgress(const std::string& title, int progress, bool resume_possible) override
710  {
711  ::uiInterface.ShowProgress(title, progress, resume_possible);
712  }
713  std::unique_ptr<Handler> handleNotifications(std::shared_ptr<Notifications> notifications) override
714  {
715  return std::make_unique<NotificationsHandlerImpl>(std::move(notifications));
716  }
717  void waitForNotificationsIfTipChanged(const uint256& old_tip) override
718  {
719  if (!old_tip.IsNull() && old_tip == WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()->GetBlockHash())) return;
721  }
722  std::unique_ptr<Handler> handleRpc(const CRPCCommand& command) override
723  {
724  return std::make_unique<RpcHandlerImpl>(command);
725  }
726  bool rpcEnableDeprecated(const std::string& method) override { return IsDeprecatedRPCEnabled(method); }
727  void rpcRunLater(const std::string& name, std::function<void()> fn, int64_t seconds) override
728  {
729  RPCRunLater(name, std::move(fn), seconds);
730  }
731  int rpcSerializationFlags() override { return RPCSerializationFlags(); }
732  util::SettingsValue getSetting(const std::string& name) override
733  {
734  return gArgs.GetSetting(name);
735  }
736  std::vector<util::SettingsValue> getSettingsList(const std::string& name) override
737  {
738  return gArgs.GetSettingsList(name);
739  }
740  util::SettingsValue getRwSetting(const std::string& name) override
741  {
742  util::SettingsValue result;
743  gArgs.LockSettings([&](const util::Settings& settings) {
744  if (const util::SettingsValue* value = util::FindKey(settings.rw_settings, name)) {
745  result = *value;
746  }
747  });
748  return result;
749  }
750  bool updateRwSetting(const std::string& name, const util::SettingsValue& value, bool write) override
751  {
752  gArgs.LockSettings([&](util::Settings& settings) {
753  if (value.isNull()) {
754  settings.rw_settings.erase(name);
755  } else {
756  settings.rw_settings[name] = value;
757  }
758  });
759  return !write || gArgs.WriteSettingsFile();
760  }
761  void requestMempoolTransactions(Notifications& notifications) override
762  {
763  if (!m_node.mempool) return;
764  LOCK2(::cs_main, m_node.mempool->cs);
765  for (const CTxMemPoolEntry& entry : m_node.mempool->mapTx) {
766  notifications.transactionAddedToMempool(entry.GetSharedTx(), 0 /* mempool_sequence */);
767  }
768  }
769  bool hasAssumedValidChain() override
770  {
771  return chainman().IsSnapshotActive();
772  }
773 
774  NodeContext* context() override { return &m_node; }
775  ChainstateManager& chainman() { return *Assert(m_node.chainman); }
776  NodeContext& m_node;
777 };
778 } // namespace
779 } // namespace node
780 
781 namespace interfaces {
782 std::unique_ptr<Node> MakeNode(node::NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
783 std::unique_ptr<Chain> MakeChain(node::NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }
784 } // namespace interfaces
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:414
virtual bool haveBlockOnDisk(int height)=0
Check that the block is available on disk (i.e.
std::map< std::string, SettingsValue > rw_settings
Map of setting name to read-write file setting value.
Definition: settings.h:37
Stored settings.
Definition: settings.h:31
Helper for findBlock to selectively return pieces of block data.
Definition: chain.h:50
virtual void ChainStateFlushed(const CBlockLocator &locator)
Notifies listeners of the new active block chain on-disk.
virtual bool findCommonAncestor(const uint256 &block_hash1, const uint256 &block_hash2, const FoundBlock &ancestor_out={}, const FoundBlock &block1_out={}, const FoundBlock &block2_out={})=0
Find most recent common ancestor between two blocks and optionally return block information.
virtual void findCoins(std::map< COutPoint, Coin > &coins)=0
Look up unspent output information.
bool ShutdownRequested()
Returns true if a shutdown is requested, false otherwise.
Definition: shutdown.cpp:89
virtual void getTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants, size_t *ancestorsize=nullptr, CAmount *ancestorfees=nullptr)=0
Calculate mempool ancestor and descendant counts for the given transaction.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
virtual void getPackageLimits(unsigned int &limit_ancestor_count, unsigned int &limit_descendant_count)=0
Get the node&#39;s package limits.
RPC timer "driver".
Definition: server.h:59
ArgsManager gArgs
Definition: system.cpp:86
Block tip (could be a header or not, depends on the subscribed signal).
Definition: node.h:276
virtual int rpcSerializationFlags()=0
Current RPC serialization flags.
std::any context
Definition: request.h:38
Enables interaction with an external signing device or service, such as a hardware wallet...
virtual void TransactionRemovedFromMempool(const CTransactionRef &tx, MemPoolRemovalReason reason, uint64_t mempool_sequence)
Notifies listeners of a transaction leaving mempool.
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or rep...
Definition: policy.h:35
void InitLogging(const ArgsManager &args)
Initialize global loggers.
Definition: init.cpp:745
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:88
BCLog::Logger & LogInstance()
Definition: logging.cpp:20
virtual std::optional< int > getHeight()=0
Get current chain height, not including genesis block (returns 0 if chain only contains genesis block...
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
virtual bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, const FoundBlock &block={})=0
Find first block in the chain with timestamp >= the given time and height >= than the given height...
CClientUIInterface uiInterface
int64_t GetBlockTime() const
Definition: chain.h:284
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:120
NodeContext & m_node
Definition: interfaces.cpp:776
virtual std::unique_ptr< Handler > handleNotifications(std::shared_ptr< Notifications > notifications)=0
Register handler for notifications.
virtual void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being disconnected.
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:158
#define TRY_LOCK(cs, name)
Definition: sync.h:265
RBFTransactionState IsRBFOptIn(const CTransaction &tx, const CTxMemPool &pool)
Determine whether an unconfirmed transaction is signaling opt-in to RBF according to BIP 125 This inv...
Definition: rbf.cpp:20
std::atomic_bool fReindex
void Shutdown(NodeContext &node)
Definition: init.cpp:211
A UTXO entry.
Definition: coins.h:30
Bilingual messages:
Definition: translation.h:18
Actor actor
Definition: server.h:117
virtual uint256 getBlockHash(int height)=0
Get block hash. Height must be valid or this function will abort.
virtual CFeeRate mempoolMinFee()=0
Mempool minimum fee.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:799
virtual std::vector< util::SettingsValue > getSettingsList(const std::string &arg)=0
Get list of settings values.
virtual CBlockLocator getActiveChainLocator(const uint256 &block_hash)=0
Return a locator that refers to a block in the active chain.
virtual void rpcRunLater(const std::string &name, std::function< void()> fn, int64_t seconds)=0
Run function after given number of seconds. Cancel any previous calls with same name.
Options struct containing limit options for a CTxMemPool.
int64_t * m_max_time
Definition: chain.h:71
An in-memory indexed chain of blocks.
Definition: chain.h:422
void appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:267
virtual CFeeRate relayDustFee()=0
Relay dust fee setting (-dustrelayfee), reflecting lowest rate it&#39;s economical to spend...
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the last common ancestor two blocks have.
Definition: chain.cpp:165
bool GetProxy(enum Network net, Proxy &proxyInfoOut)
Definition: netbase.cpp:623
virtual bool isInitialBlockDownload()=0
Check if in IBD.
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE
Default for -minrelaytxfee, minimum relay fee for transactions.
Definition: policy.h:57
bool removeCommand(const std::string &name, const CRPCCommand *pcmd)
Definition: server.cpp:274
::ExternalSigner m_signer
Definition: interfaces.cpp:78
void InterruptRPC()
Definition: server.cpp:294
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:527
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
Definition: system.cpp:1093
bool isNum() const
Definition: univalue.h:79
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Definition: txmempool.h:349
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
Definition: handler.cpp:35
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:654
void StartMapPort(bool use_upnp, bool use_natpmp)
Definition: mapport.cpp:327
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.
const CRPCCommand * m_wrapped_command
Definition: interfaces.cpp:497
std::unique_ptr< Node > MakeNode(node::NodeContext &context)
Return implementation of Node interface.
Definition: interfaces.cpp:782
Int getInt() const
Definition: univalue.h:137
void InitWarning(const bilingual_str &str)
Show warning message.
#define REVERSE_LOCK(g)
Definition: sync.h:242
void RPCRunLater(const std::string &name, std::function< void()> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:526
std::string m_name
Name of signer.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
Definition: settings.h:106
virtual double guessVerificationProgress(const uint256 &block_hash)=0
Estimate fraction of total transactions verified if blocks up to the specified block hash are verifie...
Implement this to subscribe to events generated in validation.
bool IsNull() const
Definition: uint256.h:34
int64_t * m_mtp_time
Definition: chain.h:72
CBlockLocator * m_locator
Definition: chain.h:74
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:520
bool AppInitBasicSetup(const ArgsManager &args)
Initialize bitcoin core: Basic context setup.
Definition: init.cpp:775
RBFTransactionState
The rbf state of unconfirmed transactions.
Definition: rbf.h:27
uint256 * m_hash
Definition: chain.h:68
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:88
virtual void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being connected.
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:447
virtual std::optional< int > findLocatorFork(const CBlockLocator &locator)=0
Return height of the highest block on chain in common with the locator, which will either be the orig...
CRPCCommand m_command
Definition: interfaces.cpp:496
std::string strMethod
Definition: request.h:32
uint256 GetBlockHash() const
Definition: chain.h:264
virtual bool hasDescendantsInMempool(const uint256 &txid)=0
Check if transaction has descendants in mempool.
CBlockIndex * FindEarliestAtLeast(int64_t nTime, int height) const
Find the earliest block with timestamp equal or greater than the given time and height equal or great...
Definition: chain.cpp:71
NodeContext struct containing references to chain state and connection state.
Definition: context.h:43
#define LOCK2(cs1, cs2)
Definition: sync.h:262
std::string name
Definition: server.h:116
CRPCTable tableRPC
Definition: server.cpp:544
virtual bool hasAssumedValidChain()=0
Return true if an assumed-valid chain is in use.
RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction &tx)
Definition: rbf.cpp:52
virtual bool isInMempool(const uint256 &txid)=0
Check if transaction is in mempool.
virtual bool findAncestorByHeight(const uint256 &block_hash, int ancestor_height, const FoundBlock &ancestor_out={})=0
Find ancestor of block at specified height and optionally return ancestor information.
void Interrupt(NodeContext &node)
Interrupt threads.
Definition: init.cpp:192
UniValue params
Definition: request.h:33
virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation *calc=nullptr)=0
Estimate smart fee.
CBlock * m_data
Definition: chain.h:76
#define LOCK(cs)
Definition: sync.h:261
const char * name
Definition: rest.cpp:46
bool InitError(const bilingual_str &str)
Show error message.
CTransactionRef GetSharedTx() const
Definition: txmempool.h:130
const FoundBlock * m_next_block
Definition: chain.h:75
virtual std::unique_ptr< Handler > handleRpc(const CRPCCommand &command)=0
Register handler for RPC.
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
Notifies listeners when the block chain tip advances.
std::map< std::string, std::vector< SettingsValue > > command_line_options
Map of setting name to list of command line values.
Definition: settings.h:35
bool AppInitMain(NodeContext &node, interfaces::BlockAndHeaderTipInfo *tip_info)
Bitcoin core main initialization.
Definition: init.cpp:1093
int64_t GetBlockTimeMax() const
Definition: chain.h:289
virtual bool findBlock(const uint256 &hash, const FoundBlock &block={})=0
Return whether node has the block and optionally return block metadata or contents.
uint32_t GetCategoryMask() const
Definition: logging.h:172
WalletContext context
virtual void waitForNotificationsIfTipChanged(const uint256 &old_tip)=0
Wait for pending notifications to be processed unless block hash points to the current chain tip...
TransactionError BroadcastTransaction(NodeContext &node, const CTransactionRef tx, std::string &err_string, const CAmount &max_tx_fee, bool relay, bool wait_callback)
Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
Definition: transaction.cpp:33
NodeContext * m_context
Definition: interfaces.cpp:390
virtual void requestMempoolTransactions(Notifications &notifications)=0
Synchronously send transactionAddedToMempool notifications about all current mempool transactions to ...
Network
A network type.
Definition: netaddress.h:44
static CService ip(uint32_t i)
Block and header tip information.
Definition: node.h:49
int64_t NodeId
Definition: net.h:93
#define WAIT_LOCK(cs, name)
Definition: sync.h:266
static bool Enumerate(const std::string &command, std::vector< ExternalSigner > &signers, const std::string chain)
Obtain a list of signers.
std::shared_ptr< NotificationsProxy > m_proxy
Definition: interfaces.cpp:458
Invalid wallet specified.
Definition: protocol.h:80
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:34
Wallet chain client that in addition to having chain client methods for starting up, shutting down, and registering RPCs, also has additional methods (called by the GUI) to load and create wallets.
Definition: wallet.h:319
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:349
bool isNull() const
Definition: univalue.h:74
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:305
int64_t GetMedianTimePast() const
Definition: chain.h:296
void FindCoins(const NodeContext &node, std::map< COutPoint, Coin > &coins)
Look up unspent output information.
Definition: coin.cpp:12
External signer interface used by the GUI.
Definition: node.h:59
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:509
virtual void initWarning(const bilingual_str &message)=0
Send init warning.
Definition: init.h:25
Definition: netbase.h:48
Generic interface for managing an event handler or callback function registered with another interfac...
Definition: handler.h:22
int flags
Definition: bitcoin-tx.cpp:525
virtual node::NodeContext * context()
Get internal node context.
Definition: chain.h:319
static constexpr unsigned int DUST_RELAY_TX_FEE
Min feerate for defining dust.
Definition: policy.h:55
Network address.
Definition: netaddress.h:117
256-bit opaque blob.
Definition: uint256.h:119
virtual bool isReadyToBroadcast()=0
Check if the node is ready to broadcast transactions.
virtual bool checkChainLimits(const CTransactionRef &tx)=0
Check if transaction will pass the mempool&#39;s chain limits.
std::unique_ptr< Chain > MakeChain(node::NodeContext &node)
Return implementation of Chain interface.
Definition: interfaces.cpp:783
bilingual_str GetWarnings(bool verbose)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:31
void StopRPC()
Definition: server.cpp:305
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
Definition: system.cpp:572
const auto command
virtual util::SettingsValue getRwSetting(const std::string &name)=0
Return <datadir>/settings.json setting value.
virtual bool findAncestorByHash(const uint256 &block_hash, const uint256 &ancestor_hash, const FoundBlock &ancestor_out={})=0
Return whether block descends from a specified ancestor, and optionally return ancestor information...
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Definition: chain.h:117
void SetNull()
Definition: block.h:94
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:151
const CChainParams & Params()
Return the currently selected parameters.
int RPCSerializationFlags()
Definition: server.cpp:536
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess how far we are in the verification process at the given block index require cs_main if pindex h...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:604
std::string URI
Definition: request.h:35
int64_t * m_time
Definition: chain.h:70
virtual bool updateRwSetting(const std::string &name, const util::SettingsValue &value, bool write=true)=0
Write a setting to <datadir>/settings.json.
virtual void initMessage(const std::string &message)=0
Send init message.
virtual util::SettingsValue getSetting(const std::string &arg)=0
Get settings value.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: validation.cpp:121
bool AppInitParameterInteraction(const ArgsManager &args, bool use_syscall_sandbox)
Initialization: parameter interaction.
Definition: init.cpp:820
bool AppInitSanityChecks(const kernel::Context &kernel)
Initialization sanity checks.
Definition: init.cpp:1061
TransactionError
Definition: error.h:22
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:32
virtual RBFTransactionState isRBFOptIn(const CTransaction &tx)=0
Check if transaction is RBF opt in.
bool * m_in_active_chain
Definition: chain.h:73
virtual bool hasBlocks(const uint256 &block_hash, int min_height=0, std::optional< int > max_height={})=0
Return true if data is available for all blocks in the specified range of blocks. ...
virtual void TransactionAddedToMempool(const CTransactionRef &tx, uint64_t mempool_sequence)
Notifies listeners of a transaction having been added to mempool.
void StartShutdown()
Request shutdown of the application.
Definition: shutdown.cpp:58
virtual void showProgress(const std::string &title, int progress, bool resume_possible)=0
Send progress indicator.
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:41
Wrapper around std::unique_lock style lock for Mutex.
Definition: sync.h:152
virtual unsigned int estimateMaxBlocks()=0
Fee estimator max target.
CBlockLocator GetLocator(const CBlockIndex *index)
Get a locator for a block index entry.
Definition: chain.cpp:50
virtual bool shutdownRequested()=0
Check if shutdown requested.
bool AppInitInterfaces(NodeContext &node)
Initialize node and wallet interface pointers.
Definition: init.cpp:1087
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex *index, const CBlock *data)
Return data from block index.
Definition: chain.cpp:13
virtual void disconnect()=0
Disconnect the handler.
bool AppInitLockDataDirectory()
Lock bitcoin core data directory.
Definition: init.cpp:1075
virtual bool broadcastTransaction(const CTransactionRef &tx, const CAmount &max_tx_fee, bool relay, std::string &err_string)=0
Transaction is added to memory pool, if the transaction fee is below the amount specified by max_tx_f...
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:287
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:164
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: chain.cpp:120
std::map< std::string, SettingsValue > forced_settings
Map of setting name to forced setting value.
Definition: settings.h:33
virtual CBlockLocator getTipLocator()=0
Get locator for the current chain tip.
void LockSettings(Fn &&fn)
Access settings with lock held.
Definition: system.h:474
full block available in blk*.dat
Definition: chain.h:127
std::atomic_bool fImporting
util::SettingsValue GetPersistentSetting(const std::string &name) const
Get current setting from config file or read/write settings file, ignoring nonpersistent command line...
Definition: system.cpp:592
virtual bool rpcEnableDeprecated(const std::string &method)=0
Check if deprecated RPC is enabled.
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:485
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
Definition: system.cpp:1101
ConnectionDirection
Definition: netbase.h:32
virtual void initError(const bilingual_str &message)=0
Send init error.
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:69
virtual CFeeRate relayIncrementalFee()=0
Relay incremental fee setting (-incrementalrelayfee), reflecting cost of relay.
virtual CFeeRate relayMinFee()=0
Relay current minimum fee (from -minrelaytxfee and -incrementalrelayfee settings).
unsigned int nTx
Number of transactions in this block.
Definition: chain.h:183
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:54
static GenTxid Txid(const uint256 &hash)
Definition: transaction.h:425
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
Definition: init.cpp:656
virtual bool havePruned()=0
Check if any block has been pruned.
#define Assert(val)
Identity function.
Definition: check.h:74
std::shared_ptr< Chain::Notifications > m_notifications
Definition: interfaces.cpp:439
LockPoints lp