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.
1001}1002}1004bool CTxMemPool::GetLoadTried() const1005{1006LOCK(cs);1007return m_load_tried;1008}1010void CTxMemPool::SetLoadTried(bool load_tried)1011{1012LOCK(cs);1013m_load_tried = load_tried;1014}1016std::vector<CTxMemPool::txiter> CTxMemPool::GatherClusters(const std::vector<Txid>& txids) const1017{1018AssertLockHeld(cs);1020std::vector<CTxMemPool::txiter> ret;1021std::set<const CTxMemPoolEntry*> unique_cluster_representatives;1022for (auto txid : txids) {1023auto it = mapTx.find(txid);1024if (it != mapTx.end()) {1025// Note that TxGraph::GetCluster will return results in graph1026// order, which is deterministic (as long as we are not modifying1027// the graph).1028auto cluster = m_txgraph->GetCluster(*it, TxGraph::Level::MAIN);1029if (unique_cluster_representatives.insert(static_cast<const CTxMemPoolEntry*>(&(**cluster.begin()))).second) {1030for (auto tx : cluster) {1031ret.emplace_back(mapTx.iterator_to(static_cast<const CTxMemPoolEntry&>(*tx)));1032}1033}1034}1035}1036if (ret.size() > 500) {1037return {};1038}1039return ret;1040}1042util::Result<std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>>> CTxMemPool::ChangeSet::CalculateChunksForRBF()1043{1044LOCK(m_pool->cs);1046if (!CheckMemPoolPolicyLimits()) {1047return util::Error{Untranslated("cluster size limit exceeded")};1048}1050return m_pool->m_txgraph->GetMainStagingDiagrams();1051}1053CTxMemPool::ChangeSet::TxHandle CTxMemPool::ChangeSet::StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)1054{1055LOCK(m_pool->cs);1056Assume(m_to_add.find(tx->GetHash()) == m_to_add.end());1057Assume(!m_dependencies_processed);1059// We need to process dependencies after adding a new transaction.1060m_dependencies_processed = false;1062CAmount delta{0};1063m_pool->ApplyDelta(tx->GetHash(), delta);1065FeePerWeight feerate(fee, GetSigOpsAdjustedWeight(GetTransactionWeight(*tx), sigops_cost, ::nBytesPerSigOp));1066auto newit = m_to_add.emplace(tx, fee, time, entry_height, entry_sequence, spends_coinbase, sigops_cost, lp).first;1067m_pool->m_txgraph->AddTransaction(const_cast<CTxMemPoolEntry&>(*newit), feerate);1068if (delta) {1069newit->UpdateModifiedFee(delta);1070m_pool->m_txgraph->SetTransactionFee(*newit, newit->GetModifiedFee());1071}1073m_entry_vec.push_back(newit);1075return newit;1076}1078void CTxMemPool::ChangeSet::StageRemoval(CTxMemPool::txiter it)1079{1080LOCK(m_pool->cs);1081m_pool->m_txgraph->RemoveTransaction(*it);1082m_to_remove.insert(it);1083}1085void CTxMemPool::ChangeSet::Apply()1086{1087LOCK(m_pool->cs);1088if (!m_dependencies_processed) {1089ProcessDependencies();1090}1091m_pool->Apply(this);1092m_to_add.clear();1093m_to_remove.clear();1094m_entry_vec.clear();1095m_ancestors.clear();1096}1098void CTxMemPool::ChangeSet::ProcessDependencies()1099{1100LOCK(m_pool->cs);1101Assume(!m_dependencies_processed); // should only call this once.1102for (const auto& entryptr : m_entry_vec) {1103for (const auto &txin : entryptr->GetSharedTx()->vin) {1104std::optional<txiter> piter = m_pool->GetIter(txin.prevout.hash);1105if (!piter) {1106auto it = m_to_add.find(txin.prevout.hash);1107if (it != m_to_add.end()) {1108piter = std::make_optional(it);1109}1110}1111if (piter) {1112m_pool->m_txgraph->AddDependency(/*parent=*/**piter, /*child=*/*entryptr);1113}1114}1115}1116m_dependencies_processed = true;1117return;1118}1120bool CTxMemPool::ChangeSet::CheckMemPoolPolicyLimits()1121{1122LOCK(m_pool->cs);1123if (!m_dependencies_processed) {1124ProcessDependencies();1125}1127return !m_pool->m_txgraph->IsOversized(TxGraph::Level::TOP);1128}1130std::vector<FeePerWeight> CTxMemPool::GetFeerateDiagram() const1131{1132FeePerWeight zero{};1133std::vector<FeePerWeight> ret;1135ret.emplace_back(zero);1137StartBlockBuilding();1139std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef> dummy;1141FeePerWeight last_selection = GetBlockBuilderChunk(dummy);1142while (last_selection != FeePerWeight{}) {1143last_selection += ret.back();1144ret.emplace_back(last_selection);1145IncludeBuilderChunk();1146last_selection = GetBlockBuilderChunk(dummy);1147}1148StopBlockBuilding();1149return ret;1150}