Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251return false;252}253bool unban(const CSubNet& ip) override254{255if (m_context->banman) {256m_context->banman->Unban(ip);257return true;258}259return false;260}261bool disconnectByAddress(const CNetAddr& net_addr) override262{263if (m_context->connman) {264return m_context->connman->DisconnectNode(net_addr);265}266return false;267}268bool disconnectById(NodeId id) override269{270if (m_context->connman) {271return m_context->connman->DisconnectNode(id);272}273return false;274}275std::vector<std::unique_ptr<interfaces::ExternalSigner>> listExternalSigners() override276{277#ifdef ENABLE_EXTERNAL_SIGNER278std::vector<ExternalSigner> signers = {};279const std::string command = args().GetArg("-signer", "");280if (command == "") return {};281ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());282std::vector<std::unique_ptr<interfaces::ExternalSigner>> result;283result.reserve(signers.size());284for (auto& signer : signers) {285result.emplace_back(std::make_unique<ExternalSignerImpl>(std::move(signer)));286}287return result;288#else289// This result is indistinguishable from a successful call that returns290// no signers. For the current GUI this doesn't matter, because the wallet291// creation dialog disables the external signer checkbox in both292// cases. The return type could be changed to std::optional<std::vector>293// (or something that also includes error messages) if this distinction294// becomes important.295return {};296#endif // ENABLE_EXTERNAL_SIGNER297}298int64_t getTotalBytesRecv() override { return m_context->connman ? m_context->connman->GetTotalBytesRecv() : 0; }299int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }300size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }301size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }302size_t getMempoolMaxUsage() override { return m_context->mempool ? m_context->mempool->m_opts.max_size_bytes : 0; }303bool getHeaderTip(int& height, int64_t& block_time) override304{305LOCK(::cs_main);306auto best_header = chainman().m_best_header;307if (best_header) {308height = best_header->nHeight;309block_time = best_header->GetBlockTime();310return true;311}312return false;313}314std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override315{316if (m_context->connman)317return m_context->connman->getNetLocalAddresses();318else319return {};320}321int getNumBlocks() override322{323LOCK(::cs_main);324return chainman().ActiveChain().Height();325}326uint256 getBestBlockHash() override327{328const CBlockIndex* tip = WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip());329return tip ? tip->GetBlockHash() : chainman().GetParams().GenesisBlock().GetHash();330}331int64_t getLastBlockTime() override332{333LOCK(::cs_main);334if (chainman().ActiveChain().Tip()) {335return chainman().ActiveChain().Tip()->GetBlockTime();336}337return chainman().GetParams().GenesisBlock().GetBlockTime(); // Genesis block's time of current network338}339double getVerificationProgress() override340{341LOCK(chainman().GetMutex());342return chainman().GuessVerificationProgress(chainman().ActiveTip());343}344bool isInitialBlockDownload() override345{346return chainman().IsInitialBlockDownload();347}348bool isLoadingBlocks() override { return chainman().m_blockman.LoadingBlocks(); }349void setNetworkActive(bool active) override350{351if (m_context->connman) {352m_context->connman->SetNetworkActive(active);353}354}355bool getNetworkActive() override { return m_context->connman && m_context->connman->GetNetworkActive(); }356CFeeRate getDustRelayFee() override357{358if (!m_context->mempool) return CFeeRate{DUST_RELAY_TX_FEE};359return m_context->mempool->m_opts.dust_relay_feerate;360}361UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override362{363JSONRPCRequest req;364req.context = m_context;365req.params = params;366req.strMethod = command;367req.URI = uri;368return ::tableRPC.execute(req);369}370std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); }371std::optional<Coin> getUnspentOutput(const COutPoint& output) override372{373LOCK(::cs_main);374return chainman().ActiveChainstate().CoinsTip().GetCoin(output);375}376TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) override377{378return BroadcastTransaction(*m_context,379std::move(tx),380err_string,381max_tx_fee,382TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL,383/*wait_callback=*/false);384}385WalletLoader& walletLoader() override386{387return *Assert(m_context->wallet_loader);388}389std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override390{391return MakeSignalHandler(::uiInterface.InitMessage.connect(fn));392}393std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override394{395return MakeSignalHandler(::uiInterface.ThreadSafeMessageBox.connect(fn));396}397std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override398{399return MakeSignalHandler(::uiInterface.ThreadSafeQuestion.connect(fn));400}401std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override402{403return MakeSignalHandler(::uiInterface.ShowProgress.connect(fn));404}405std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) override406{407return MakeSignalHandler(::uiInterface.InitWallet.connect(fn));408}409std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override410{411return MakeSignalHandler(::uiInterface.NotifyNumConnectionsChanged.connect(fn));412}413std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override414{415return MakeSignalHandler(::uiInterface.NotifyNetworkActiveChanged.connect(fn));416}417std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override418{419return MakeSignalHandler(::uiInterface.NotifyAlertChanged.connect(fn));420}421std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override422{423return MakeSignalHandler(::uiInterface.BannedListChanged.connect(fn));424}425std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override426{427return MakeSignalHandler(::uiInterface.NotifyBlockTip.connect([fn](SynchronizationState sync_state, const CBlockIndex& block, double verification_progress) {428fn(sync_state, BlockTip{block.nHeight, block.GetBlockTime(), block.GetBlockHash()}, verification_progress);429}));430}431std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override432{433return MakeSignalHandler(434::uiInterface.NotifyHeaderTip.connect([fn](SynchronizationState sync_state, int64_t height, int64_t timestamp, bool presync) {435fn(sync_state, BlockTip{(int)height, timestamp, uint256{}}, presync);436}));437}438NodeContext* context() override { return m_context; }439void setContext(NodeContext* context) override440{441m_context = context;442}443ArgsManager& args() { return *Assert(Assert(m_context)->args); }444ChainstateManager& chainman() { return *Assert(m_context->chainman); }445NodeContext* m_context{nullptr};446};448// NOLINTNEXTLINE(misc-no-recursion)449bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<RecursiveMutex>& lock, const CChain& active, const BlockManager& blockman) EXCLUSIVE_LOCKS_REQUIRED(cs_main)450{451if (!index) return false;452if (block.m_hash) *block.m_hash = index->GetBlockHash();453if (block.m_height) *block.m_height = index->nHeight;454if (block.m_time) *block.m_time = index->GetBlockTime();455if (block.m_max_time) *block.m_max_time = index->GetBlockTimeMax();456if (block.m_mtp_time) *block.m_mtp_time = index->GetMedianTimePast();457if (block.m_in_active_chain) *block.m_in_active_chain = active[index->nHeight] == index;458if (block.m_locator) { *block.m_locator = GetLocator(index); }459if (block.m_next_block) FillBlock(active[index->nHeight] == index ? active[index->nHeight + 1] : nullptr, *block.m_next_block, lock, active, blockman);460if (block.m_data) {461REVERSE_LOCK(lock, cs_main);462if (!blockman.ReadBlock(*block.m_data, *index)) block.m_data->SetNull();463}464block.found = true;465return true;466}468class NotificationsProxy : public CValidationInterface469{470public:471explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)472: m_notifications(std::move(notifications)) {}473virtual ~NotificationsProxy() = default;474void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override475{476m_notifications->transactionAddedToMempool(tx.info.m_tx);477}478void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override479{480m_notifications->transactionRemovedFromMempool(tx, reason);481}482void BlockConnected(const ChainstateRole& role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override483{484m_notifications->blockConnected(role, kernel::MakeBlockInfo(index, block.get()));485}486void BlockDisconnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* index) override487{488m_notifications->blockDisconnected(kernel::MakeBlockInfo(index, block.get()));489}490void UpdatedBlockTip(const CBlockIndex* index, const CBlockIndex* fork_index, bool is_ibd) override491{492m_notifications->updatedBlockTip();493}494void ChainStateFlushed(const ChainstateRole& role, const CBlockLocator& locator) override495{496m_notifications->chainStateFlushed(role, locator);497}498std::shared_ptr<Chain::Notifications> m_notifications;499};
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.