Inside Bitcoin
Opening the selected file…
Inside Bitcoin
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.
1001if (!CooldownIfHeadersAhead(chainman(), notifications(), *maybe_tip, m_interrupt_mining)) return {};1002}1003const BlockCreateOptions create_options{MergeMiningOptions(options, m_node.mining_args)};1004return std::make_unique<BlockTemplateImpl>(create_options,1005BlockAssembler{1006chainman().ActiveChainstate(),1007m_node.mempool.get(),1008create_options,1009}.CreateNewBlock(),1010m_node);1011}1013void interrupt() override1014{1015InterruptWait(notifications(), m_interrupt_mining);1016}1018bool checkBlock(const CBlock& block, const node::BlockCheckOptions& options, std::string& reason, std::string& debug) override1019{1020LOCK(chainman().GetMutex());1021BlockValidationState state{TestBlockValidity(chainman().ActiveChainstate(), block, /*check_pow=*/options.check_pow, /*check_merkle_root=*/options.check_merkle_root)};1022reason = state.GetRejectReason();1023debug = state.GetDebugMessage();1024return state.IsValid();1025}1027bool submitBlock(const CBlock& block_in, std::string& reason, std::string& debug) override1028{1029return SubmitBlock(chainman(), std::make_shared<const CBlock>(block_in), reason, debug);1030}1032std::vector<CTransactionRef> getTransactionsByTxID(const std::vector<Txid>& txids) override1033{1034if (!m_node.mempool) return {};1036std::vector<CTransactionRef> results;1037results.reserve(txids.size());1038LOCK(m_node.mempool->cs);1039for (const auto& txid : txids) {1040results.emplace_back(m_node.mempool->get(txid));1041}1042return results;1043}1045std::vector<CTransactionRef> getTransactionsByWitnessID(const std::vector<Wtxid>& wtxids) override1046{1047if (!m_node.mempool) return {};1049std::vector<CTransactionRef> results;1050results.reserve(wtxids.size());1051LOCK(m_node.mempool->cs);1052for (const auto& wtxid : wtxids) {1053results.emplace_back(m_node.mempool->get(wtxid));1054}1055return results;1056}1058const NodeContext* context() override { return &m_node; }1059ChainstateManager& chainman() { return *Assert(m_node.chainman); }1060KernelNotifications& notifications() { return *Assert(m_node.notifications); }1061// Treat as if guarded by notifications().m_tip_block_mutex1062bool m_interrupt_mining{false};1063const NodeContext& m_node;1064};1066class RpcImpl : public Rpc1067{1068public:1069explicit RpcImpl(NodeContext& node) : m_node(node) {}1071UniValue executeRpc(UniValue request, std::string uri, std::string user) override1072{1073JSONRPCRequest req;1074req.context = &m_node;1075req.URI = std::move(uri);1076req.authUser = std::move(user);1077HTTPStatusCode status;1078return ExecuteHTTPRPC(request, req, status);1079}1081NodeContext& m_node;1082};1083} // namespace1084} // namespace node1086namespace interfaces {1087std::unique_ptr<Node> MakeNode(node::NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }1088std::unique_ptr<Chain> MakeChain(node::NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }1089std::unique_ptr<Mining> MakeMining(const node::NodeContext& context, bool wait_loaded)1090{1091if (wait_loaded) {1092node::KernelNotifications& kernel_notifications(*Assert(context.notifications));1093util::SignalInterrupt& interrupt(*Assert(context.shutdown_signal));1094WAIT_LOCK(kernel_notifications.m_tip_block_mutex, lock);1095kernel_notifications.m_tip_block_cv.wait(lock, [&]() EXCLUSIVE_LOCKS_REQUIRED(kernel_notifications.m_tip_block_mutex) {1096return kernel_notifications.m_state.chainstate_loaded || interrupt;1097});1098if (interrupt) return nullptr;1099}1100return std::make_unique<node::MinerImpl>(context);1101}1102std::unique_ptr<Rpc> MakeRpc(node::NodeContext& context) { return std::make_unique<node::RpcImpl>(context); }1103} // namespace interfaces
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.