From bf546a200bba2879d0c65531e0f9b1dcef49a6ec Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Sun, 18 Oct 2026 01:10:41 -0500 Subject: [PATCH 01/10] Merge bitcoin/bitcoin#26140: refactor: Move CNodeState members guarded by g_msgproc_mutex to Peer 3a060ae7b67cc28fc60cf28cbc518fa1df24f545 scripted-diff: Rename nUnconnectingHeaders and fPreferHeaders (dergoegge) 279c53d7e4e920d3d09da74689761a2961b1a636 [net processing] Move m_recently_announced_invs from CNodeState to Peer (dergoegge) 938a8e2566bf2f819adeb75a08c0c8ba9a85fe1c [net processing] Annotate m_recently_announced_invs as guarded by g_msgproc_mutex (dergoegge) 8a2cb1f749ade31bb0655567cd0062db8a7164e5 [net processing] Move fPreferHeaders from CNodeState to Peer (dergoegge) 3605011e79d0d43ff532a2c3cc9cad4cc48eb06c [net processing] Annotate fPreferHeaders as guarded by g_msgproc_mutex (dergoegge) 4b84e502f5ba69d650191ce8f2e20b86c1d427ed [net processing] Move m_headers_sync_timeout from CNodeState to Peer (dergoegge) 689b747fc34a5670a24bb5c4b1986dd8670b55ef [net processing] Annotate m_headers_sync_timeout as guarded by g_msgproc_mutex (dergoegge) d8c0d1c345546c6066274edbf3bf4fb5d6f75419 [net processing] Move nUnconnectingHeaders from CNodeState to Peer (dergoegge) 5f80d8d1eec14253407ceed1a813619d3e5a0fe4 [net processing] Annotate nUnconnectingHeaders as guarded by g_msgproc_mutex (dergoegge) 1d87137227ee125018006935d55164a72265c935 [validation] Annotate ChainstateManager::m_best_header as guarded by cs_main (dergoegge) Pull request description: `nUnconnectingHeaders`, `m_headers_sync_timeout`, `fPreferHeaders` and `m_recently_announced_headers` are currently all `CNodeState` members even though they are only ever accessed from the message processing thread (therefore sufficiently guarded exclusively by `g_msgproc_mutex`). `CNodeState` exists purely to hold validation-specific state guarded by `cs_main` that is accessed by multiple threads. This PR adds thread-safety annotations for the above mentioned `CNodeState` members and moves them to `Peer`. ACKs for top commit: glozow: code review ACK 3a060ae7b67cc28fc60cf28cbc518fa1df24f545, as in I am convinced these members shouldn't be guarded by cs_main and belong in Peer/TxRelay. clang checked the annotations for me. hebasto: ACK 3a060ae7b67cc28fc60cf28cbc518fa1df24f545 Tree-SHA512: 2db27c03f2c6ed36ad7dfbb4f862eeed3c3e57f845cf8abb9e7cada36f976257311892020bbcff513fbe662a881c93270e3a126946ceb0c3f94213b546bcaa81 Dash adaptations: - src/net_processing.cpp: FindTxForGetData takes (const Peer&, const uint256& txid) not GenTxid; Dash has no wtxid relay and keeps its asset-unlock instance-hash lookup - src/net_processing.cpp: upstream's new `const TxRelay* GetTxRelay() const` is dropped; Dash already has one (respecting m_can_tx_relay) and m_tx_relay_mutex is already mutable - src/net_processing.cpp: HandleFewUnconnectingHeaders keeps Dash's GETHEADERS/GETHEADERS2 choice and the msg_type in its log line, now using the cs_main-snapshotted best_header - src/net_processing.cpp: UpdatePeerStateForReceivedHeaders call keeps Dash's GetHeadersLimit(pfrom, uses_compressed) in place of MAX_HEADERS_RESULTS - src/net_processing.cpp: Dash's DSTX-aware tx announcement loop inserts announce_hash into tx_relay->m_recently_announced_invs, not the CNodeState copy - src/net_processing.cpp: Dash-only fPreferHeadersCompressed (SENDHEADERS2) and m_recent_object_requests stay in CNodeState; upstream only moves fPreferHeaders - src/net_processing.cpp: the headers-sync timeout check keeps Dash's max_tip_age condition; only state.m_headers_sync_timeout becomes peer->m_headers_sync_timeout - test/functional/p2p_sendheaders_compressed.py: same MAX_UNCONNECTING_HEADERS -> MAX_NUM_UNCONNECTING_HEADERS_MSGS rename as in Dash's fork of p2p_sendheaders.py --- src/net_processing.cpp | 108 +++++++++--------- src/validation.h | 2 +- test/functional/p2p_sendheaders.py | 10 +- test/functional/p2p_sendheaders_compressed.py | 10 +- 4 files changed, 67 insertions(+), 63 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 9ca230901f5f..6bccb711b2ba 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -174,7 +174,7 @@ static constexpr double BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 0.5; /** Maximum number of headers to announce when relaying blocks with headers message.*/ static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8; /** Maximum number of unconnecting headers announcements before DoS score */ -static const int MAX_UNCONNECTING_HEADERS = 10; +static const int MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10; /** Minimum blocks required to signal NODE_NETWORK_LIMITED */ static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288; /** Average delay between local address broadcasts */ @@ -316,6 +316,9 @@ struct Peer { /** A bloom filter for which transactions to announce to the peer. See BIP37. */ std::unique_ptr m_bloom_filter PT_GUARDED_BY(m_bloom_filter_mutex) GUARDED_BY(m_bloom_filter_mutex){nullptr}; + /** A rolling bloom filter of all announced tx CInvs to this peer */ + CRollingBloomFilter m_recently_announced_invs GUARDED_BY(NetEventsInterface::g_msgproc_mutex){INVENTORY_MAX_RECENT_RELAY, 0.000001}; + mutable RecursiveMutex m_tx_inventory_mutex; /** A filter of all the txids that the peer has announced to * us or we have announced to the peer. We use this to avoid announcing @@ -445,6 +448,18 @@ struct Peer { /** Time of the last getheaders message to this peer */ NodeClock::time_point m_last_getheaders_timestamp GUARDED_BY(NetEventsInterface::g_msgproc_mutex){}; + /** Length of current-streak of unconnecting headers announcements */ + int m_num_unconnecting_headers_msgs GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0}; + + /** When to potentially disconnect peer for stalling headers download */ + std::chrono::microseconds m_headers_sync_timeout GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0us}; + + /** Whether this peer wants invs or headers (when possible) for block announcements */ + bool m_prefers_headers GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false}; + + /** Whether this peer wants invs or compressed headers (when possible) for block announcements */ + bool m_prefers_headers_compressed GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false}; + explicit Peer(NodeId id, ServiceFlags our_services) : m_id(id) , m_our_services{our_services} @@ -492,12 +507,8 @@ struct CNodeState { const CBlockIndex* pindexLastCommonBlock{nullptr}; //! The best header we have sent our peer. const CBlockIndex* pindexBestHeaderSent{nullptr}; - //! Length of current-streak of unconnecting headers announcements - int nUnconnectingHeaders{0}; //! Whether we've started headers synchronization with this peer. bool fSyncStarted{false}; - //! When to potentially disconnect peer for stalling headers download - std::chrono::microseconds m_headers_sync_timeout{0us}; //! Since when we're stalling block download progress (in microseconds), or 0. std::chrono::microseconds m_stalling_since{0us}; std::list vBlocksInFlight; @@ -505,10 +516,6 @@ struct CNodeState { std::chrono::microseconds m_downloading_since{0us}; //! Whether we consider this a preferred download peer. bool fPreferredDownload{false}; - //! Whether this peer wants invs or headers (when possible) for block announcements. - bool fPreferHeaders{false}; - //! Whether this peer wants invs or compressed headers (when possible) for block announcements. - bool fPreferHeadersCompressed{false}; /** Whether this peer wants invs or cmpctblocks (when possible) for block announcements. */ bool m_requested_hb_cmpctblocks{false}; /** Whether this peer will send us cmpctblocks if we request them. */ @@ -557,9 +564,6 @@ struct CNodeState { //! Whether this peer is an inbound connection const bool m_is_inbound; - //! A rolling bloom filter of all announced tx CInvs to this peer. - CRollingBloomFilter m_recently_announced_invs = CRollingBloomFilter{INVENTORY_MAX_RECENT_RELAY, 0.000001}; - //! The GETDATA-only objects (see IsGetDataOnlyObject) we have recently asked this peer for. The //! tracker cannot answer "did we ever ask?" on its own: an announcement is erased once it //! expires as the sole one for its hash, or once the object is accepted from anywhere. @@ -807,7 +811,8 @@ class PeerManagerImpl final : public PeerManager /** Potentially fetch blocks from this peer upon receipt of a new headers tip */ void HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, const CBlockIndex& last_header); /** Update peer state based on received headers message */ - void UpdatePeerStateForReceivedHeaders(CNode& pfrom, const CBlockIndex& last_header, bool received_new_header, bool may_have_more_headers); + void UpdatePeerStateForReceivedHeaders(CNode& pfrom, Peer& peer, const CBlockIndex& last_header, bool received_new_header, bool may_have_more_headers) + EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex); void SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlock& block, const BlockTransactionsRequest& req); @@ -1095,10 +1100,12 @@ class PeerManagerImpl final : public PeerManager std::atomic m_last_tip_update{0s}; /** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */ - CTransactionRef FindTxForGetData(const CNode* peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main); + CTransactionRef FindTxForGetData(const Peer& peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) + LOCKS_EXCLUDED(cs_main) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex); void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic& interruptMsgProc) - EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, peer.m_getdata_requests_mutex) LOCKS_EXCLUDED(::cs_main); + EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, peer.m_getdata_requests_mutex, NetEventsInterface::g_msgproc_mutex) + LOCKS_EXCLUDED(::cs_main); /** Process a new block. Perform any post-processing housekeeping */ void ProcessBlock(CNode& from, const std::shared_ptr& pblock, bool force_processing); @@ -2911,7 +2918,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& } //! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). -CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode* peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) +CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer& peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) { auto txinfo = m_mempool.info(txid); if (!txinfo.tx) { @@ -2933,7 +2940,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode* peer, const uint2 LOCK(cs_main); // Otherwise, the transaction must have been announced recently. - if (State(peer->GetId())->m_recently_announced_invs.contains(txid)) { + if (Assume(peer.GetTxRelay())->m_recently_announced_invs.contains(txid)) { // If it was, it can be relayed from either the mempool... if (txinfo.tx) return std::move(txinfo.tx); // ... or the relay pool. @@ -2987,7 +2994,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic bool push = false; if (inv.IsGenTxMsg()) { - CTransactionRef tx = FindTxForGetData(&pfrom, inv.hash, mempool_req, now); + CTransactionRef tx = FindTxForGetData(peer, inv.hash, mempool_req, now); if (tx) { CCoinJoinBroadcastTx dstx; if (inv.IsMsgDstx()) { @@ -3020,8 +3027,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic for (const uint256& parent_txid : parent_ids_to_add) { // Relaying a transaction with a recent but unconfirmed parent. if (WITH_LOCK(tx_relay->m_tx_inventory_mutex, return !tx_relay->m_tx_inventory_known_filter.contains(parent_txid))) { - LOCK(cs_main); - State(pfrom.GetId())->m_recently_announced_invs.insert(parent_txid); + tx_relay->m_recently_announced_invs.insert(parent_txid); } } } @@ -3142,38 +3148,37 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlo * * We'll send a getheaders message in response to try to connect the chain. * - * The peer can send up to MAX_UNCONNECTING_HEADERS in a row that + * The peer can send up to MAX_NUM_UNCONNECTING_HEADERS_MSGS in a row that * don't connect before given DoS points. * * Once a headers message is received that is valid and does connect, - * nUnconnectingHeaders gets reset back to 0. + * m_num_unconnecting_headers_msgs gets reset back to 0. */ void PeerManagerImpl::HandleFewUnconnectingHeaders(CNode& pfrom, Peer& peer, const std::vector& headers) { - LOCK(cs_main); - CNodeState *nodestate = State(pfrom.GetId()); - - nodestate->nUnconnectingHeaders++; + peer.m_num_unconnecting_headers_msgs++; // Try to fill in the missing headers. std::string msg_type = UsesCompressedHeaders(peer) ? NetMsgType::GETHEADERS2 : NetMsgType::GETHEADERS; - if (MaybeSendGetHeaders(pfrom, msg_type, GetLocator(m_chainman.m_best_header), peer)) { - LogPrint(BCLog::NET, "received header %s: missing prev block %s, sending %s (%d) to end (peer=%d, nUnconnectingHeaders=%d)\n", + const CBlockIndex* best_header{WITH_LOCK(cs_main, return m_chainman.m_best_header)}; + if (MaybeSendGetHeaders(pfrom, msg_type, GetLocator(best_header), peer)) { + LogPrint(BCLog::NET, "received header %s: missing prev block %s, sending %s (%d) to end (peer=%d, m_num_unconnecting_headers_msgs=%d)\n", headers[0].GetHash().ToString(), headers[0].hashPrevBlock.ToString(), msg_type, - m_chainman.m_best_header->nHeight, - pfrom.GetId(), nodestate->nUnconnectingHeaders); + best_header->nHeight, + pfrom.GetId(), peer.m_num_unconnecting_headers_msgs); } + // Set hashLastUnknownBlock for this peer, so that if we // eventually get the headers - even from a different peer - // we can use this peer to download. - UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash()); + WITH_LOCK(cs_main, UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash())); // The peer may just be broken, so periodically assign DoS points if this // condition persists. - if (nodestate->nUnconnectingHeaders % MAX_UNCONNECTING_HEADERS == 0) { - Misbehaving(peer, 20, strprintf("%d non-connecting headers", nodestate->nUnconnectingHeaders)); + if (peer.m_num_unconnecting_headers_msgs % MAX_NUM_UNCONNECTING_HEADERS_MSGS == 0) { + Misbehaving(peer, 20, strprintf("%d non-connecting headers", peer.m_num_unconnecting_headers_msgs)); } } @@ -3277,15 +3282,16 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c * whether that header was new and whether the headers message was full, * update the state we keep for the peer. */ -void PeerManagerImpl::UpdatePeerStateForReceivedHeaders(CNode& pfrom, +void PeerManagerImpl::UpdatePeerStateForReceivedHeaders(CNode& pfrom, Peer& peer, const CBlockIndex& last_header, bool received_new_header, bool may_have_more_headers) { + if (peer.m_num_unconnecting_headers_msgs > 0) { + LogPrint(BCLog::NET, "peer=%d: resetting m_num_unconnecting_headers_msgs (%d -> 0)\n", pfrom.GetId(), peer.m_num_unconnecting_headers_msgs); + } + peer.m_num_unconnecting_headers_msgs = 0; + LOCK(cs_main); CNodeState *nodestate = State(pfrom.GetId()); - if (nodestate->nUnconnectingHeaders > 0) { - LogPrint(BCLog::NET, "peer=%d: resetting nUnconnectingHeaders (%d -> 0)\n", pfrom.GetId(), nodestate->nUnconnectingHeaders); - } - nodestate->nUnconnectingHeaders = 0; UpdateBlockAvailability(pfrom.GetId(), last_header.GetBlockHash()); @@ -3390,7 +3396,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer, } } - UpdatePeerStateForReceivedHeaders(pfrom, *pindexLast, received_new_header, nCount == GetHeadersLimit(pfrom, uses_compressed)); + UpdatePeerStateForReceivedHeaders(pfrom, peer, *pindexLast, received_new_header, nCount == GetHeadersLimit(pfrom, uses_compressed)); // Consider immediately downloading blocks. HeadersDirectFetchBlocks(pfrom, peer, *pindexLast); @@ -4293,14 +4299,12 @@ void PeerManagerImpl::ProcessMessage( } if (msg_type == NetMsgType::SENDHEADERS) { - LOCK(cs_main); - State(pfrom.GetId())->fPreferHeaders = true; + peer->m_prefers_headers = true; return; } if (msg_type == NetMsgType::SENDHEADERS2) { - LOCK(cs_main); - State(pfrom.GetId())->fPreferHeadersCompressed = true; + peer->m_prefers_headers_compressed = true; return; } @@ -6457,7 +6461,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) LogPrint(BCLog::NET, "initial %s (%d) to peer=%d (startheight:%d)\n", msg_type, pindexStart->nHeight, pto->GetId(), peer->m_starting_height); state.fSyncStarted = true; - state.m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE + + peer->m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE + ( // Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling // to maintain precision @@ -6482,7 +6486,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) // add all to the inv queue. LOCK(peer->m_block_inv_mutex); std::vector vHeaders; - bool fRevertToInv = ((!state.fPreferHeaders && !state.fPreferHeadersCompressed && + bool fRevertToInv = ((!peer->m_prefers_headers && !peer->m_prefers_headers_compressed && (!state.m_requested_hb_cmpctblocks || peer->m_blocks_for_headers_relay.size() > 1)) || peer->m_blocks_for_headers_relay.size() > MAX_BLOCKS_TO_ANNOUNCE); const CBlockIndex *pBestIndex = nullptr; // last header queued for delivery @@ -6568,7 +6572,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock)); } state.pindexBestHeaderSent = pBestIndex; - } else if (state.fPreferHeadersCompressed) { + } else if (peer->m_prefers_headers_compressed) { std::vector vHeadersCompressed; std::list last_unique_versions; @@ -6582,7 +6586,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) // Push message to peer m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::HEADERS2, vHeadersCompressed)); state.pindexBestHeaderSent = pBestIndex; - } else if (state.fPreferHeaders) { + } else if (peer->m_prefers_headers) { if (vHeaders.size() > 1) { LogPrint(BCLog::NET, "%s: %u headers, range (%s, %s), to peer=%d\n", __func__, vHeaders.size(), @@ -6777,7 +6781,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) nInvType = MSG_DSTX; } // Send - State(pto->GetId())->m_recently_announced_invs.insert(announce_hash); + tx_relay->m_recently_announced_invs.insert(announce_hash); nRelayedTransactions++; { // Expire old relay messages @@ -6854,10 +6858,10 @@ bool PeerManagerImpl::SendMessages(CNode* pto) } } // Check for headers sync timeouts - if (state.fSyncStarted && state.m_headers_sync_timeout < std::chrono::microseconds::max()) { + if (state.fSyncStarted && peer->m_headers_sync_timeout < std::chrono::microseconds::max()) { // Detect whether this is a stalling initial-headers-sync peer if (m_chainman.m_best_header->Time() <= NodeClock::now() - m_chainman.m_options.max_tip_age) { - if (current_time > state.m_headers_sync_timeout && nSyncStarted == 1 && (m_num_preferred_download_peers - state.fPreferredDownload >= 1)) { + if (current_time > peer->m_headers_sync_timeout && nSyncStarted == 1 && (m_num_preferred_download_peers - state.fPreferredDownload >= 1)) { // Disconnect a peer (without NetPermissionFlags::NoBan permission) if it is our only sync peer, // and we have others we could be using instead. // Note: If all our peers are inbound, then we won't @@ -6876,13 +6880,13 @@ bool PeerManagerImpl::SendMessages(CNode* pto) // this peer (eventually). state.fSyncStarted = false; nSyncStarted--; - state.m_headers_sync_timeout = 0us; + peer->m_headers_sync_timeout = 0us; } } } else { // After we've caught up once, reset the timeout so we can't trigger // disconnect later. - state.m_headers_sync_timeout = std::chrono::microseconds::max(); + peer->m_headers_sync_timeout = std::chrono::microseconds::max(); } } diff --git a/src/validation.h b/src/validation.h index 566837c4b1fc..fb672d7621ac 100644 --- a/src/validation.h +++ b/src/validation.h @@ -1046,7 +1046,7 @@ class ChainstateManager std::set m_failed_blocks; /** Best header we've seen so far (used for getheaders queries' starting points). */ - CBlockIndex* m_best_header = nullptr; + CBlockIndex* m_best_header GUARDED_BY(::cs_main){nullptr}; //! The total number of bytes available for us to use across all in-memory //! coins caches. This will be split somehow across chainstates. diff --git a/test/functional/p2p_sendheaders.py b/test/functional/p2p_sendheaders.py index e853d20c5b3a..a8ae9685e534 100755 --- a/test/functional/p2p_sendheaders.py +++ b/test/functional/p2p_sendheaders.py @@ -545,15 +545,15 @@ def test_nonnull_locators(self, test_node, inv_node): blocks = [] # Now we test that if we repeatedly don't send connecting headers, we # don't go into an infinite loop trying to get them to connect. - MAX_UNCONNECTING_HEADERS = 10 - for _ in range(MAX_UNCONNECTING_HEADERS + 1): + MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10 + for _ in range(MAX_NUM_UNCONNECTING_HEADERS_MSGS + 1): blocks.append(create_block(tip, create_coinbase(height), block_time)) blocks[-1].solve() tip = blocks[-1].sha256 block_time += 1 height += 1 - for i in range(1, MAX_UNCONNECTING_HEADERS): + for i in range(1, MAX_NUM_UNCONNECTING_HEADERS_MSGS): # Send a header that doesn't connect, check that we get a getheaders. with p2p_lock: test_node.last_message.pop("getheaders2" if test_node.nServices & NODE_HEADERS_COMPRESSED else "getheaders", None) @@ -567,8 +567,8 @@ def test_nonnull_locators(self, test_node, inv_node): blocks = blocks[2:] # Now try to see how many unconnecting headers we can send - # before we get disconnected. Should be 5*MAX_UNCONNECTING_HEADERS - for i in range(5 * MAX_UNCONNECTING_HEADERS - 1): + # before we get disconnected. Should be 5*MAX_NUM_UNCONNECTING_HEADERS_MSGS + for i in range(5 * MAX_NUM_UNCONNECTING_HEADERS_MSGS - 1): # Send a header that doesn't connect, check that we get a getheaders. with p2p_lock: test_node.last_message.pop("getheaders2" if test_node.nServices & NODE_HEADERS_COMPRESSED else "getheaders", None) diff --git a/test/functional/p2p_sendheaders_compressed.py b/test/functional/p2p_sendheaders_compressed.py index 3a6d17d624df..4d0f005efdbb 100755 --- a/test/functional/p2p_sendheaders_compressed.py +++ b/test/functional/p2p_sendheaders_compressed.py @@ -554,15 +554,15 @@ def test_nonnull_locators(self, test_node, inv_node): blocks = [] # Now we test that if we repeatedly don't send connecting headers, we # don't go into an infinite loop trying to get them to connect. - MAX_UNCONNECTING_HEADERS = 10 - for _ in range(MAX_UNCONNECTING_HEADERS + 1): + MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10 + for _ in range(MAX_NUM_UNCONNECTING_HEADERS_MSGS + 1): blocks.append(create_block(tip, create_coinbase(height), block_time)) blocks[-1].solve() tip = blocks[-1].sha256 block_time += 1 height += 1 - for i in range(1, MAX_UNCONNECTING_HEADERS): + for i in range(1, MAX_NUM_UNCONNECTING_HEADERS_MSGS): # Send a header that doesn't connect, check that we get a getheaders. with p2p_lock: test_node.last_message.pop("getheaders2", None) @@ -576,8 +576,8 @@ def test_nonnull_locators(self, test_node, inv_node): blocks = blocks[2:] # Now try to see how many unconnecting headers we can send - # before we get disconnected. Should be 5*MAX_UNCONNECTING_HEADERS - for i in range(5 * MAX_UNCONNECTING_HEADERS - 1): + # before we get disconnected. Should be 5*MAX_NUM_UNCONNECTING_HEADERS_MSGS + for i in range(5 * MAX_NUM_UNCONNECTING_HEADERS_MSGS - 1): # Send a header that doesn't connect, check that we get a getheaders. with p2p_lock: test_node.last_message.pop("getheaders2", None) From 290ab768cbc0acc467bba38ff253c8ba1dbed1d2 Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Sun, 18 Oct 2026 01:10:41 -0500 Subject: [PATCH 02/10] Merge bitcoin/bitcoin#27482: kernel: chainparams updates for 25.x a2bef805c11a4ab391f4ea635bfde7dd2ec9ce81 kernel: update m_assumed_* chain params for 25.x (fanquake) 4128e01dbaa630396b0e7576ee8a1987267f77b9 kernel: update chainTxData for 25.x (fanquake) 00b2b114b442835c863e7772348cb1d1881ba0f2 kernel: update nMinimumChainWork & defaultAssumeValid for 25.x (fanquake) 07fcc0a82cfd08c991f61c2340630f0c4659a3a0 doc: update references to kernel/chainparams.cpp (fanquake) Pull request description: Update chainparams pre `25.x` branch off. Co-Author in the commits as a PR (#27223) had previously been opened too-early to do the same. Note: Remember that some variance is expected in the `m_assumed_*` sizes. ACKs for top commit: achow101: ACK a2bef805c11a4ab391f4ea635bfde7dd2ec9ce81 josibake: ACK https://github.com/bitcoin/bitcoin/pull/27482/commits/a2bef805c11a4ab391f4ea635bfde7dd2ec9ce81 gruve-p: ACK https://github.com/bitcoin/bitcoin/pull/27482/commits/a2bef805c11a4ab391f4ea635bfde7dd2ec9ce81 dergoegge: ACK a2bef805c11a4ab391f4ea635bfde7dd2ec9ce81 on the new mainnet params Tree-SHA512: 0b19c2ef15c6b15863d6a560a1053ee223057c7bfb617ffd3400b1734cee8f75bc6fd7f04d8f8e3f5af6220659a1987951a1b36945d6fe17d06972004fd62610 Dash adaptations: - doc/release-process.md: fixes the chainparams.cpp path in both of Dash's checklist items, since Dash splits upstream's single item into minor/major-release steps - src/kernel/chainparams.cpp: keeps Dash's own nMinimumChainWork, defaultAssumeValid, m_assumed_* and chainTxData values instead of upstream's Bitcoin 25.x values Not applicable to Dash (intentionally omitted): - src/kernel/chainparams.cpp: Bitcoin 25.x chain data (main/test/signet chainwork, assumevalid, sizes, txstats); Dash has its own chain, values and release-time updates, and no signet --- contrib/seeds/generate-seeds.py | 2 +- doc/release-process.md | 4 ++-- src/test/validation_tests.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/seeds/generate-seeds.py b/contrib/seeds/generate-seeds.py index 05ad6e6021c0..70d01bec71bb 100755 --- a/contrib/seeds/generate-seeds.py +++ b/contrib/seeds/generate-seeds.py @@ -3,7 +3,7 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. ''' -Script to generate list of seed nodes for chainparams.cpp. +Script to generate list of seed nodes for kernel/chainparams.cpp. This script expects two text files in the directory that is passed as an argument: diff --git a/doc/release-process.md b/doc/release-process.md index ae76bf26fa21..956b2754d406 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -12,7 +12,7 @@ Before every minor and major release: * [ ] Update version in `configure.ac` (don't forget to set `CLIENT_VERSION_IS_RELEASE` to `true`) * [ ] Write release notes (see below). To clear the release notes: `cp doc/release-notes-empty-template.md doc/release-notes.md` * [ ] Update flatpak [metainfo file](contrib/flatpak/org.dash.dash-core.metainfo.xml) with latest release tag and estimated release date -* [ ] Update the following variables in [`src/chainparams.cpp`](/src/chainparams.cpp) for mainnet and testnet: +* [ ] Update the following variables in [`src/kernel/chainparams.cpp`](/src/kernel/chainparams.cpp) for mainnet and testnet: - `nMinimumChainWork` with the "chainwork" value of RPC `getblockheader` using the same height as that selected for the previous step. - `defaultAssumeValid` with the output of RPC `getblockhash` using the `height` of `window_final_block_height` above (and update the block height comment with that height), taking into account the following: @@ -29,7 +29,7 @@ Before every minor and major release: Before every major release: * [ ] Update hardcoded [seeds](/contrib/seeds/README.md), see [this pull request](https://github.com/dashpay/dash/pull/5914) for an example. -* [ ] Update the following variables in [`src/chainparams.cpp`](/src/chainparams.cpp) for mainnet and testnet: +* [ ] Update the following variables in [`src/kernel/chainparams.cpp`](/src/kernel/chainparams.cpp) for mainnet and testnet: - `m_assumed_blockchain_size` and `m_assumed_chain_state_size` with the current size plus some overhead (see [this](#how-to-calculate-assumed-blockchain-and-chain-state-size) for information on how to calculate them). - `chainTxData` with statistics about the transaction count and rate. Use the output of the `getchaintxstats` RPC with an diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp index c2f4bb7472e1..f7a938196eec 100644 --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo) const auto params = CreateChainParams(*m_node.args, CBaseChainParams::REGTEST); // These heights don't have assumeutxo configurations associated, per the contents - // of chainparams.cpp. + // of kernel/chainparams.cpp. std::vector bad_heights{0, 100, 111, 115, 209, 211}; for (auto empty : bad_heights) { From 09767526b7941dc8f8ebe05c061cf7e5097ab3e2 Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Sun, 18 Oct 2026 02:03:45 -0500 Subject: [PATCH 03/10] Merge bitcoin/bitcoin#27884: test: Use TestNode datadir_path or chain_path where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aaaa3aefbdfca1c9243057eeefdc19940e60bf18 test: Use TestNode *_path properties where possible (MarcoFalke) dddd89962b26b5593860d016586ee8feb5aeea24 test: Allow pathlib.Path as RPC argument via authproxy (MarcoFalke) fa41614a0abc05cbfbf76d6af3a186ab8d79c3f2 scripted-diff: Use wallets_path and chain_path where possible (MarcoFalke) fa493fadfb0ac73b7c0ee308f6623213702ae6f4 test: Use wallet_dir lambda in wallet_multiwallet test where possible (MarcoFalke) Pull request description: It seems inconsistent, fragile and verbose to: * Call `get_datadir_path` to recreate the path that already exists as field in TestNode * Call `os.path.join` with the hardcoded chain name or `self.chain` to recreate the TestNode `chain_path` property * Sometimes even use the hardcoded node dir name (`"node0"`) Fix all issues by using the TestNode properties. ACKs for top commit: willcl-ark: re-ACK aaaa3aefbdfca1c9243057eeefdc19940e60bf18 theStack: Code-review ACK aaaa3aefbdfca1c9243057eeefdc19940e60bf18 🌊 Tree-SHA512: e4720278085beb8164e1fe6c1aa18f601558a9263494ce69a83764c1487007de63ebb51d1b1151862dc4d5b49ded6162a5c1553cd30ea1c28627d447db4d8e72 Dash adaptations: - test/functional/test_framework/test_node.py: chain_path keeps Dash's get_chain_folder() (devnet folder naming), now built on the new datadir_path; imports serialization_fallback, Dash's name for EncodeDecimal - test/functional/test_framework/util.py: no change, Dash already moved EncodeDecimal into authproxy as serialization_fallback; the authproxy pathlib.Path hunk applied to serialization_fallback - test/functional/wallet_backup.py: the Dash-only rmtree of evodb, llmq and indexes also uses chain_path, alongside upstream's blocks and chainstate - test/functional/wallet_hd.py: the Dash-only rmtree of evodb, llmq and indexes (both places) also uses chain_path, alongside upstream's blocks and chainstate - test/functional/wallet_backwards_compatibility.py: keeps Dash's version < 160000 cutoff and has no v16 wallets dir line, because Dash's set of old nodes is master/v19/v17 - test/functional/wallet_upgradewallet.py: converts Dash's v18_2 and v16_1 wallet paths to wallets_path in place of upstream's v16_3/v15_2/splithd lines, which Dash's test does not have - test/functional/wallet_descriptor.py: keeps Dash's explicit sqlite3 connect/close structure; only the wallet_db path moves to wallets_path - test/functional/rpc_whitelist.py: keeps Dash's extra 'quorum sign' in never_allowed while moving the conf write into run_test with restart_node - test/functional/rpc_blockchain.py: keeps Dash's log wording 'Test that getblock with invalid verbosity type...' while taking upstream's reordering and chain_path use - test/functional/wallet_migration.py: keeps 'import os', which upstream drops, because Dash's own test_wallet_name_with_slashes still uses os.path Not applicable to Dash (intentionally omitted): - test/functional/feature_txindex_compatibility.py: Dash already removed this test (merge of bitcoin#28753) along with the legacy -txindex check; none of the listed Dash-only tests has the same os.path.join(datadir, chain) pattern - test/functional/wallet_inactive_hdchains.py: test comes from bitcoin#23304 (inactive HD chains via sethdseed); Dash's HD wallet has no sethdseed or inactive-chain code - test/functional/feature_fee_estimation.py: edits the 'fresh estimation / RBF estimates' block from bitcoin#22539; Dash has no RBF and lacks that block; Dash already uses chain_path elsewhere --- test/functional/feature_abortnode.py | 6 +-- test/functional/feature_addrman.py | 2 +- test/functional/feature_anchors.py | 4 +- test/functional/feature_asmap.py | 2 +- test/functional/feature_blocksdir.py | 4 +- test/functional/feature_config_args.py | 4 +- test/functional/feature_filelock.py | 5 +-- test/functional/feature_includeconf.py | 24 +++++------ test/functional/feature_loadblock.py | 2 +- test/functional/feature_logging.py | 2 +- .../feature_posix_fs_permissions.py | 6 +-- test/functional/feature_pruning.py | 4 +- test/functional/feature_reindex.py | 3 +- .../feature_remove_pruned_files_on_startup.py | 8 ++-- test/functional/feature_settings.py | 2 +- test/functional/feature_startupnotify.py | 9 ++--- test/functional/interface_rpc.py | 2 +- test/functional/mempool_compatibility.py | 4 +- test/functional/mempool_persist.py | 4 +- test/functional/p2p_message_capture.py | 2 +- test/functional/rpc_blockchain.py | 12 +++--- test/functional/rpc_createmultisig.py | 2 +- test/functional/rpc_dumptxoutset.py | 2 +- test/functional/rpc_users.py | 15 ++++--- test/functional/rpc_whitelist.py | 12 ++---- test/functional/test_framework/authproxy.py | 3 ++ test/functional/test_framework/test_node.py | 10 ++++- test/functional/tool_wallet.py | 26 ++++++------ test/functional/wallet_backup.py | 40 +++++++++---------- .../wallet_backwards_compatibility.py | 10 ++--- test/functional/wallet_descriptor.py | 2 +- test/functional/wallet_hd.py | 24 +++++------ test/functional/wallet_keypool_topup.py | 2 +- test/functional/wallet_listtransactions.py | 4 +- test/functional/wallet_migration.py | 22 +++++----- test/functional/wallet_multiwallet.py | 10 ++--- test/functional/wallet_pruning.py | 2 +- test/functional/wallet_reorgsrestore.py | 2 +- test/functional/wallet_upgradetohd.py | 2 +- test/functional/wallet_upgradewallet.py | 8 ++-- 40 files changed, 150 insertions(+), 159 deletions(-) diff --git a/test/functional/feature_abortnode.py b/test/functional/feature_abortnode.py index 81467c8af034..91056c0d0e4f 100755 --- a/test/functional/feature_abortnode.py +++ b/test/functional/feature_abortnode.py @@ -9,10 +9,7 @@ - Mine a fork that requires disconnecting the tip. - Verify that dashd AbortNode's. """ - from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import get_datadir_path -import os class AbortNodeTest(BitcoinTestFramework): @@ -26,10 +23,9 @@ def setup_network(self): def run_test(self): self.generate(self.nodes[0], 3, sync_fun=self.no_op) - datadir = get_datadir_path(self.options.tmpdir, 0) # Deleting the undo file will result in reorg failure - os.unlink(os.path.join(datadir, self.chain, 'blocks', 'rev00000.dat')) + (self.nodes[0].chain_path / "blocks" / "rev00000.dat").unlink() # Connecting to a node with a more work chain will trigger a reorg # attempt. diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py index d8a8131367fa..a8d1b5c4eb52 100755 --- a/test/functional/feature_addrman.py +++ b/test/functional/feature_addrman.py @@ -52,7 +52,7 @@ def set_test_params(self): self.num_nodes = 1 def run_test(self): - peers_dat = os.path.join(self.nodes[0].datadir, self.chain, "peers.dat") + peers_dat = os.path.join(self.nodes[0].chain_path, "peers.dat") init_error = lambda reason: ( f"Error: Invalid or corrupt peers.dat \\({reason}\\). If you believe this " f"is a bug, please report it to {self.config['environment']['PACKAGE_BUGREPORT']}. " diff --git a/test/functional/feature_anchors.py b/test/functional/feature_anchors.py index ff4f86d341d7..cd1dd458cd47 100755 --- a/test/functional/feature_anchors.py +++ b/test/functional/feature_anchors.py @@ -23,9 +23,7 @@ def set_test_params(self): self.disable_autoconnect = False def run_test(self): - node_anchors_path = os.path.join( - self.nodes[0].datadir, "regtest", "anchors.dat" - ) + node_anchors_path = self.nodes[0].chain_path / "anchors.dat" self.log.info("When node starts, check if anchors.dat doesn't exist") assert not os.path.exists(node_anchors_path) diff --git a/test/functional/feature_asmap.py b/test/functional/feature_asmap.py index dfcc0e70b357..890b8afdae9e 100755 --- a/test/functional/feature_asmap.py +++ b/test/functional/feature_asmap.py @@ -121,7 +121,7 @@ def test_asmap_health_check(self): def run_test(self): self.node = self.nodes[0] - self.datadir = os.path.join(self.node.datadir, self.chain) + self.datadir = self.node.chain_path self.default_asmap = os.path.join(self.datadir, DEFAULT_ASMAP_FILENAME) self.asmap_raw = os.path.join(os.path.dirname(os.path.realpath(__file__)), ASMAP) diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py index 28e6d6cdf92a..ad066b566bcb 100755 --- a/test/functional/feature_blocksdir.py +++ b/test/functional/feature_blocksdir.py @@ -18,7 +18,7 @@ def set_test_params(self): def run_test(self): self.stop_node(0) - assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks")) + assert os.path.isdir(os.path.join(self.nodes[0].chain_path, "blocks")) assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "blocks")) shutil.rmtree(self.nodes[0].datadir) initialize_datadir(self.options.tmpdir, 0, self.chain) @@ -31,7 +31,7 @@ def run_test(self): self.log.info("mining blocks..") self.generatetoaddress(self.nodes[0], 10, self.nodes[0].get_deterministic_priv_key().address) assert os.path.isfile(os.path.join(blocksdir_path, self.chain, "blocks", "blk00000.dat")) - assert os.path.isdir(os.path.join(self.nodes[0].datadir, self.chain, "blocks", "index")) + assert os.path.isdir(os.path.join(self.nodes[0].chain_path, "blocks", "index")) if __name__ == '__main__': diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py index e67af8282d38..e45da3c5e2bd 100755 --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -32,7 +32,7 @@ def test_config_file_parser(self): self.stop_node(0) # Check that startup fails if conf= is set in bitcoin.conf or in an included conf file - bad_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_bad.conf') + bad_conf_file_path = self.nodes[0].datadir_path / "bitcoin_bad.conf" util.write_config(bad_conf_file_path, n=0, chain='', extra_config=f'conf=some.conf\n') conf_in_config_file_err = 'Error: Error reading configuration file: conf cannot be set in the configuration file; use includeconf= if you want to include additional config files' self.nodes[0].assert_start_raises_init_error( @@ -75,7 +75,7 @@ def test_config_file_parser(self): conf.write("wallet=foo\n") self.nodes[0].assert_start_raises_init_error(expected_msg=f'Error: Config setting for -wallet only applied on {self.chain} network when in [{self.chain}] section.') - main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'dash_main.conf') + main_conf_file_path = self.nodes[0].datadir_path / "dash_main.conf" util.write_config(main_conf_file_path, n=0, chain='', extra_config=f'includeconf={inc_conf_file_path}\n') with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: conf.write('acceptnonstdtxn=1\n') diff --git a/test/functional/feature_filelock.py b/test/functional/feature_filelock.py index 4d0b931fb90b..ac343315b589 100755 --- a/test/functional/feature_filelock.py +++ b/test/functional/feature_filelock.py @@ -3,7 +3,6 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Check that it's not possible to start a second bitcoind instance using the same datadir or wallet.""" -import os import random import string @@ -26,7 +25,7 @@ def setup_network(self): self.nodes[0].wait_for_rpc_connection() def run_test(self): - datadir = os.path.join(self.nodes[0].datadir, self.chain) + datadir = self.nodes[0].chain_path self.log.info(f"Using datadir {datadir}") self.log.info("Check that we can't start a second dashd instance using the same datadir") @@ -43,7 +42,7 @@ def run_test(self): def check_wallet_filelock(descriptors): wallet_name = ''.join([random.choice(string.ascii_lowercase) for _ in range(6)]) self.nodes[0].createwallet(wallet_name=wallet_name, descriptors=descriptors) - wallet_dir = os.path.join(datadir, 'wallets') + wallet_dir = self.nodes[0].wallets_path self.log.info("Check that we can't start a second dashd instance using the same wallet") if descriptors: expected_msg = f"Error: SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of {self.config['environment']['PACKAGE_NAME']}?" diff --git a/test/functional/feature_includeconf.py b/test/functional/feature_includeconf.py index 5d7bdb763457..5de4bb3e317f 100755 --- a/test/functional/feature_includeconf.py +++ b/test/functional/feature_includeconf.py @@ -14,27 +14,25 @@ 4. multiple includeconf arguments can be specified in the main config file. """ -import os - from test_framework.test_framework import BitcoinTestFramework + class IncludeConfTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 - def setup_chain(self): - super().setup_chain() + def run_test(self): # Create additional config files # - tmpdir/node0/relative.conf - with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f: f.write("uacomment=relative\n") # - tmpdir/node0/relative2.conf - with open(os.path.join(self.options.tmpdir, "node0", "relative2.conf"), "w", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative2.conf", "w", encoding="utf8") as f: f.write("uacomment=relative2\n") - with open(os.path.join(self.options.tmpdir, "node0", "dash.conf"), "a", encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "dash.conf", "a", encoding="utf8") as f: f.write("uacomment=main\nincludeconf=relative.conf\n") + self.restart_node(0) - def run_test(self): self.log.info("-includeconf works from config file. subversion should end with 'main; relative)/'") subversion = self.nodes[0].getnetworkinfo()["subversion"] @@ -52,7 +50,7 @@ def run_test(self): ) self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'") - with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative.conf", "a", encoding="utf8") as f: f.write("includeconf=relative2.conf\n") self.start_node(0) @@ -63,20 +61,20 @@ def run_test(self): self.log.info("-includeconf cannot contain invalid arg") # Commented out as long as we ignore invalid arguments in configuration files - #with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: + #with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f: # f.write("foo=bar\n") #self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Invalid configuration value foo") self.log.info("-includeconf cannot be invalid path") - os.remove(os.path.join(self.options.tmpdir, "node0", "relative.conf")) + (self.nodes[0].datadir_path / "relative.conf").unlink() self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Failed to include configuration file relative.conf") self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'") - with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: + with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f: # Restore initial file contents f.write("uacomment=relative\n") - with open(os.path.join(self.options.tmpdir, "node0", "dash.conf"), "a", encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "dash.conf", "a", encoding="utf8") as f: f.write("includeconf=relative2.conf\n") self.start_node(0) diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py index 562641fc44a5..23abb7d17e3d 100755 --- a/test/functional/feature_loadblock.py +++ b/test/functional/feature_loadblock.py @@ -37,7 +37,7 @@ def run_test(self): cfg_file = os.path.join(data_dir, "linearize.cfg") bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat") genesis_block = self.nodes[0].getblockhash(0) - blocks_dir = os.path.join(data_dir, self.chain, "blocks") + blocks_dir = self.nodes[0].chain_path / "blocks" hash_list = tempfile.NamedTemporaryFile(dir=data_dir, mode='w', delete=False, diff --git a/test/functional/feature_logging.py b/test/functional/feature_logging.py index e8529ea102fe..c703eb50a55b 100755 --- a/test/functional/feature_logging.py +++ b/test/functional/feature_logging.py @@ -16,7 +16,7 @@ def set_test_params(self): self.setup_clean_chain = True def relative_log_path(self, name): - return os.path.join(self.nodes[0].datadir, self.chain, name) + return os.path.join(self.nodes[0].chain_path, name) def run_test(self): # test default log file name diff --git a/test/functional/feature_posix_fs_permissions.py b/test/functional/feature_posix_fs_permissions.py index c5a543e97ae9..40528779e6e3 100755 --- a/test/functional/feature_posix_fs_permissions.py +++ b/test/functional/feature_posix_fs_permissions.py @@ -31,11 +31,11 @@ def check_file_permissions(self, file): def run_test(self): self.stop_node(0) - datadir = os.path.join(self.nodes[0].datadir, self.chain) + datadir = self.nodes[0].chain_path self.check_directory_permissions(datadir) - walletsdir = os.path.join(datadir, "wallets") + walletsdir = self.nodes[0].wallets_path self.check_directory_permissions(walletsdir) - debuglog = os.path.join(datadir, "debug.log") + debuglog = self.nodes[0].debug_log_path self.check_file_permissions(debuglog) diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index 0c0671b81ee0..c6ea4be253fd 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -102,7 +102,7 @@ def set_test_params(self): def setup_network(self): self.setup_nodes() - self.prunedir = os.path.join(self.nodes[2].datadir, self.chain, 'blocks', '') + self.prunedir = os.path.join(self.nodes[2].chain_path, 'blocks', '') self.connect_nodes(0, 1) self.connect_nodes(1, 2) @@ -307,7 +307,7 @@ def prune(index): assert_equal(ret + 1, node.getblockchaininfo()['pruneheight']) def has_block(index): - return os.path.isfile(os.path.join(self.nodes[node_number].datadir, self.chain, "blocks", f"blk{index:05}.dat")) + return os.path.isfile(os.path.join(self.nodes[node_number].chain_path, "blocks", f"blk{index:05}.dat")) # should not prune because chain tip of node 3 (995) < PruneAfterHeight (1000) assert_raises_rpc_error(-1, "Blockchain is too short for pruning", node.pruneblockchain, height(500)) diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py index c88b8429e852..54da05cfd4c8 100755 --- a/test/functional/feature_reindex.py +++ b/test/functional/feature_reindex.py @@ -10,7 +10,6 @@ - Verify that out-of-order blocks are correctly processed, see LoadExternalBlockFile() """ -import os from test_framework.test_framework import BitcoinTestFramework from test_framework.messages import MAGIC_BYTES from test_framework.util import assert_equal @@ -39,7 +38,7 @@ def out_of_order(self): # In this test environment, blocks will always be in order (since # we're generating them rather than getting them from peers), so to # test out-of-order handling, swap blocks 1 and 2 on disk. - blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat') + blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat" with open(blk0, 'r+b') as bf: # Read at least the first few blocks (including genesis) b = bf.read(2000) diff --git a/test/functional/feature_remove_pruned_files_on_startup.py b/test/functional/feature_remove_pruned_files_on_startup.py index 8ce4cd86c0e3..4dafce074fad 100755 --- a/test/functional/feature_remove_pruned_files_on_startup.py +++ b/test/functional/feature_remove_pruned_files_on_startup.py @@ -22,10 +22,10 @@ def mine_batches(self, blocks): self.sync_blocks() def run_test(self): - blk0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00000.dat') - rev0 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00000.dat') - blk1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'blk00001.dat') - rev1 = os.path.join(self.nodes[0].datadir, self.nodes[0].chain, 'blocks', 'rev00001.dat') + blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat" + rev0 = self.nodes[0].chain_path / "blocks" / "rev00000.dat" + blk1 = self.nodes[0].chain_path / "blocks" / "blk00001.dat" + rev1 = self.nodes[0].chain_path / "blocks" / "rev00001.dat" self.mine_batches(800) fo1 = os.open(blk0, os.O_RDONLY) fo2 = os.open(rev1, os.O_RDONLY) diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py index 835cb5df5f58..6ffa0fdc3906 100755 --- a/test/functional/feature_settings.py +++ b/test/functional/feature_settings.py @@ -21,7 +21,7 @@ def set_test_params(self): def run_test(self): node, = self.nodes - settings = Path(node.datadir, self.chain, "settings.json") + settings = Path(node.chain_path, "settings.json") conf = Path(node.datadir, "dash.conf") # Assert default settings file was created diff --git a/test/functional/feature_startupnotify.py b/test/functional/feature_startupnotify.py index ff5272b2817b..4eb679112393 100755 --- a/test/functional/feature_startupnotify.py +++ b/test/functional/feature_startupnotify.py @@ -3,9 +3,6 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test -startupnotify.""" - -import os - from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -21,12 +18,12 @@ def set_test_params(self): self.disable_syscall_sandbox = True def run_test(self): - tmpdir_file = os.path.join(self.options.tmpdir, NODE_DIR, FILE_NAME) - assert not os.path.exists(tmpdir_file) + tmpdir_file = self.nodes[0].datadir_path / FILE_NAME + assert not tmpdir_file.exists() self.log.info("Test -startupnotify command is run when node starts") self.restart_node(0, extra_args=[f"-startupnotify=echo '{FILE_NAME}' >> {NODE_DIR}/{FILE_NAME}"]) - self.wait_until(lambda: os.path.exists(tmpdir_file)) + self.wait_until(lambda: tmpdir_file.exists()) self.log.info("Test -startupnotify is executed once") diff --git a/test/functional/interface_rpc.py b/test/functional/interface_rpc.py index 3725c8971943..e873e2da0bff 100755 --- a/test/functional/interface_rpc.py +++ b/test/functional/interface_rpc.py @@ -46,7 +46,7 @@ def test_getrpcinfo(self): command = info['active_commands'][0] assert_equal(command['method'], 'getrpcinfo') assert_greater_than_or_equal(command['duration'], 0) - assert_equal(info['logpath'], os.path.join(self.nodes[0].datadir, self.chain, 'debug.log')) + assert_equal(info['logpath'], os.path.join(self.nodes[0].chain_path, 'debug.log')) def test_batch_request(self): self.log.info("Testing basic JSON-RPC batch request...") diff --git a/test/functional/mempool_compatibility.py b/test/functional/mempool_compatibility.py index 3cbdf5495c83..601bca73f2f5 100755 --- a/test/functional/mempool_compatibility.py +++ b/test/functional/mempool_compatibility.py @@ -62,8 +62,8 @@ def run_test(self): self.stop_node(1) self.log.info("Move mempool.dat from old to new node") - old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat') - new_node_mempool = os.path.join(new_node.datadir, self.chain, 'mempool.dat') + old_node_mempool = os.path.join(old_node.chain_path, 'mempool.dat') + new_node_mempool = os.path.join(new_node.chain_path, 'mempool.dat') os.rename(old_node_mempool, new_node_mempool) self.log.info("Start new node and verify mempool contains the tx") diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py index 5e4f9f36d7d6..dbb9c0258f4c 100755 --- a/test/functional/mempool_persist.py +++ b/test/functional/mempool_persist.py @@ -141,8 +141,8 @@ def run_test(self): self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet assert_equal(node2_balance, wallet_watch.getbalance()) - mempooldat0 = os.path.join(self.nodes[0].datadir, self.chain, 'mempool.dat') - mempooldat1 = os.path.join(self.nodes[1].datadir, self.chain, 'mempool.dat') + mempooldat0 = os.path.join(self.nodes[0].chain_path, 'mempool.dat') + mempooldat1 = os.path.join(self.nodes[1].chain_path, 'mempool.dat') self.log.debug("Force -persistmempool=0 node1 to savemempool to disk via RPC") assert not os.path.exists(mempooldat1) diff --git a/test/functional/p2p_message_capture.py b/test/functional/p2p_message_capture.py index 3ab0b79ba2b5..62ff4da8fd15 100755 --- a/test/functional/p2p_message_capture.py +++ b/test/functional/p2p_message_capture.py @@ -58,7 +58,7 @@ def set_test_params(self): self.setup_clean_chain = True def run_test(self): - capturedir = os.path.join(self.nodes[0].datadir, "regtest/message_capture") + capturedir = self.nodes[0].chain_path / "message_capture" # Connect a node so that the handshake occurs self.nodes[0].add_p2p_connection(P2PDataStore()) self.nodes[0].disconnect_p2ps() diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index bf8bfa0500d2..2f60919443f3 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -51,7 +51,6 @@ assert_raises_rpc_error, assert_is_hex_string, assert_is_hash_string, - get_datadir_path, ) from test_framework.wallet import MiniWallet @@ -646,16 +645,15 @@ def assert_vin_does_not_contain_prevout(verbosity): self.log.info("Test that getblock with verbosity 3 includes prevout") assert_vin_contains_prevout(3) - self.log.info("Test that getblock with verbosity 2 and 3 still works with pruned Undo data") - datadir = get_datadir_path(self.options.tmpdir, 0) - self.log.info("Test that getblock with invalid verbosity type returns proper error message") assert_raises_rpc_error(-3, "JSON value of type string is not of expected type number", node.getblock, blockhash, "2") + self.log.info("Test that getblock with verbosity 2 and 3 still works with pruned Undo data") + def move_block_file(old, new): - old_path = os.path.join(datadir, self.chain, 'blocks', old) - new_path = os.path.join(datadir, self.chain, 'blocks', new) - os.rename(old_path, new_path) + old_path = self.nodes[0].chain_path / "blocks" / old + new_path = self.nodes[0].chain_path / "blocks" / new + old_path.rename(new_path) # Move instead of deleting so we can restore chain state afterwards move_block_file('rev00000.dat', 'rev_wrong') diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index 13aa31e54f4b..0cfeaf1cf532 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -132,7 +132,7 @@ def do_multisig(self): try: node1.loadwallet('wmulti') except JSONRPCException as e: - path = os.path.join(self.options.tmpdir, "node1", "regtest", "wallets", "wmulti") + path = self.nodes[1].wallets_path / "wmulti" if e.error['code'] == -18 and "Wallet file verification failed. Failed to load database path '{}'. Path does not exist.".format(path) in e.error['message']: node1.createwallet(wallet_name='wmulti', disable_private_keys=True) else: diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py index 9c7da6d32c25..4839de64aaed 100755 --- a/test/functional/rpc_dumptxoutset.py +++ b/test/functional/rpc_dumptxoutset.py @@ -54,7 +54,7 @@ def run_test(self): # Specifying a path to an existing or invalid file will fail. assert_raises_rpc_error( -8, '{} already exists'.format(FILENAME), node.dumptxoutset, FILENAME) - invalid_path = str(Path(node.datadir) / "invalid" / "path") + invalid_path = node.datadir_path / "invalid" / "path" assert_raises_rpc_error( -8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path) diff --git a/test/functional/rpc_users.py b/test/functional/rpc_users.py index 4da1b63c2a3f..891a23c29fca 100755 --- a/test/functional/rpc_users.py +++ b/test/functional/rpc_users.py @@ -7,11 +7,9 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, - get_datadir_path, str_to_b64str, ) -import os import http.client import urllib.parse import subprocess @@ -37,8 +35,7 @@ def set_test_params(self): self.num_nodes = 2 self.supports_cli = False - def setup_chain(self): - super().setup_chain() + def conf_setup(self): #Append rpcauth to dash.conf before initialization self.rtpassword = "cA773lm788buwYe4g4WT+05pKyNruVKjQ25x3n0DQcM=" rpcauth = "rpcauth=rt:93648e835a54c573682c2eb19f882535$7681e9c5b74bdd85e78166031d2058e1069b3ed7ed967c93fc63abba06f31144" @@ -63,13 +60,15 @@ def setup_chain(self): rpcauth3 = lines[1] self.password = lines[3] - with open(os.path.join(get_datadir_path(self.options.tmpdir, 0), "dash.conf"), 'a', encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "dash.conf", "a", encoding="utf8") as f: f.write(rpcauth + "\n") f.write(rpcauth2 + "\n") f.write(rpcauth3 + "\n") - with open(os.path.join(get_datadir_path(self.options.tmpdir, 1), "dash.conf"), 'a', encoding='utf8') as f: + with open(self.nodes[1].datadir_path / "dash.conf", "a", encoding="utf8") as f: f.write("rpcuser={}\n".format(self.rpcuser)) f.write("rpcpassword={}\n".format(self.rpcpassword)) + self.restart_node(0) + self.restart_node(1) def test_auth(self, node, user, password): self.log.info('Correct...') @@ -85,6 +84,7 @@ def test_auth(self, node, user, password): assert_equal(401, call_with_auth(node, user+'wrong', password+'wrong').status) def run_test(self): + self.conf_setup() self.log.info('Check correctness of the rpcauth config option') url = urllib.parse.urlparse(self.nodes[0].url) @@ -111,8 +111,7 @@ def run_test(self): self.nodes[0].assert_start_raises_init_error(expected_msg=init_error, extra_args=['-rpcauth=foo$bar$baz']) self.log.info('Check that failure to write cookie file will abort the node gracefully') - cookie_file = os.path.join(get_datadir_path(self.options.tmpdir, 0), self.chain, '.cookie.tmp') - os.mkdir(cookie_file) + (self.nodes[0].chain_path / ".cookie.tmp").mkdir() self.nodes[0].assert_start_raises_init_error(expected_msg=init_error) diff --git a/test/functional/rpc_whitelist.py b/test/functional/rpc_whitelist.py index 6afe753b890f..61cdfd414610 100755 --- a/test/functional/rpc_whitelist.py +++ b/test/functional/rpc_whitelist.py @@ -6,11 +6,9 @@ A test for RPC users with restricted permissions """ from test_framework.test_framework import BitcoinTestFramework -import os from test_framework.util import ( - get_datadir_path, assert_equal, - str_to_b64str + str_to_b64str, ) import json import http.client @@ -49,8 +47,7 @@ def set_test_params(self): self.num_nodes = 1 self.supports_cli = False - def setup_chain(self): - super().setup_chain() + def run_test(self): # 0 => Username # 1 => Password (Hashed) # 2 => Permissions @@ -77,7 +74,7 @@ def setup_chain(self): ] # These commands shouldn't be allowed for any user to test failures self.never_allowed = ["getnetworkinfo", "quorum sign"] - with open(os.path.join(get_datadir_path(self.options.tmpdir, 0), "dash.conf"), 'a', encoding='utf8') as f: + with open(self.nodes[0].datadir_path / "dash.conf", "a", encoding="utf8") as f: f.write("\nrpcwhitelistdefault=0\n") for user in self.users: f.write("rpcauth=" + user[0] + ":" + user[1] + "\n") @@ -86,9 +83,8 @@ def setup_chain(self): for strangedude in self.strange_users: f.write("rpcauth=" + strangedude[0] + ":" + strangedude[1] + "\n") f.write("rpcwhitelist=" + strangedude[0] + strangedude[2] + "\n") + self.restart_node(0) - - def run_test(self): for user in self.users: permissions = user[2].replace(" ", "").split(",") # Pop all empty items diff --git a/test/functional/test_framework/authproxy.py b/test/functional/test_framework/authproxy.py index 94da59845efa..76960f5353c8 100644 --- a/test/functional/test_framework/authproxy.py +++ b/test/functional/test_framework/authproxy.py @@ -39,6 +39,7 @@ import http.client import json import logging +import pathlib import socket import time import urllib.parse @@ -62,6 +63,8 @@ def __init__(self, rpc_error, http_status=None): def serialization_fallback(o): if isinstance(o, decimal.Decimal): return str(o) + if isinstance(o, pathlib.Path): + return str(o) raise TypeError(repr(o) + " is not JSON serializable") class AuthServiceProxy(): diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 582570b0445b..ce4e047b1a8c 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -473,14 +473,22 @@ def replace_in_config(self, replacements): with open(self.bitcoinconf, 'w', encoding='utf8') as conf: conf.write(conf_data) + @property + def datadir_path(self) -> Path: + return Path(self.datadir) + @property def chain_path(self) -> Path: - return Path(self.datadir) / get_chain_folder(self.datadir, self.chain) + return self.datadir_path / get_chain_folder(self.datadir, self.chain) @property def debug_log_path(self) -> Path: return self.chain_path / 'debug.log' + @property + def wallets_path(self) -> Path: + return self.chain_path / "wallets" + def debug_log_size(self, **kwargs) -> int: with open(self.debug_log_path, **kwargs) as dl: dl.seek(0, 2) diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py index 9be4ed4c6d93..b4bb58a0ac77 100755 --- a/test/functional/tool_wallet.py +++ b/test/functional/tool_wallet.py @@ -166,12 +166,12 @@ def do_tool_createfromdump(self, wallet_name, dumpfile, file_format=None): if file_format is not None and file_format != dump_data["format"]: load_output += "Warning: Dumpfile wallet format \"{}\" does not match command line specified format \"{}\".\n".format(dump_data["format"], file_format) self.assert_tool_output(load_output, *args) - assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", wallet_name)) + assert (self.nodes[0].wallets_path / wallet_name).is_dir() self.assert_tool_output("The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n", '-wallet={}'.format(wallet_name), '-dumpfile={}'.format(rt_dumppath), 'dump') rt_dump_data = self.read_dump(rt_dumppath) - wallet_dat = os.path.join(self.nodes[0].datadir, "regtest/wallets/", wallet_name, "wallet.dat") + wallet_dat = self.nodes[0].wallets_path / wallet_name / "wallet.dat" if rt_dump_data["format"] == "bdb": self.assert_is_bdb(wallet_dat) else: @@ -186,7 +186,7 @@ def test_invalid_tool_commands_and_args(self): self.assert_raises_tool_error('Error parsing command line arguments: Invalid parameter -foo', '-foo') self.assert_raises_tool_error('No method provided. Run `dash-wallet -help` for valid methods.') self.assert_raises_tool_error('Wallet name must be provided when creating a new wallet.', 'create') - locked_dir = os.path.join(self.options.tmpdir, "node0", self.chain, "wallets") + locked_dir = self.nodes[0].wallets_path error = 'Error initializing wallet database environment "{}"!'.format(locked_dir) if self.options.descriptors: error = f"SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another instance of {self.config['environment']['PACKAGE_NAME']}?" @@ -195,7 +195,7 @@ def test_invalid_tool_commands_and_args(self): '-wallet=' + self.default_wallet_name, 'info', ) - path = os.path.join(self.options.tmpdir, "node0", self.chain, "wallets", "nonexistent.dat") + path = self.nodes[0].wallets_path / "nonexistent.dat" self.assert_raises_tool_error("Failed to load database path '{}'. Path does not exist.".format(path), '-wallet=nonexistent.dat', 'info') def test_tool_wallet_info(self): @@ -350,7 +350,7 @@ def test_dump_createfromdump(self): non_exist_dump = os.path.join(self.nodes[0].datadir, "wallet.nodump") self.assert_raises_tool_error('Unknown wallet file format "notaformat" provided. Please provide one of "bdb" or "sqlite".', '-wallet=todump', '-format=notaformat', '-dumpfile={}'.format(wallet_dump), 'createfromdump') self.assert_raises_tool_error('Dump file {} does not exist.'.format(non_exist_dump), '-wallet=todump', '-dumpfile={}'.format(non_exist_dump), 'createfromdump') - wallet_path = os.path.join(self.nodes[0].datadir, 'regtest', 'wallets', 'todump2') + wallet_path = self.nodes[0].wallets_path / "todump2" self.assert_raises_tool_error('Failed to create database path \'{}\'. Database already exists.'.format(wallet_path), '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump') self.assert_raises_tool_error("The -descriptors option can only be used with the 'create' command.", '-descriptors', '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump') @@ -366,18 +366,18 @@ def test_dump_createfromdump(self): dump_data["BITCOIN_CORE_WALLET_DUMP"] = "0" self.write_dump(dump_data, bad_ver_wallet_dump) self.assert_raises_tool_error('Error: Dumpfile version is not supported. This version of dash-wallet only supports version 1 dumpfiles. Got dumpfile with version 0', '-wallet=badload', '-dumpfile={}'.format(bad_ver_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() bad_ver_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_ver2.dump") dump_data["BITCOIN_CORE_WALLET_DUMP"] = "2" self.write_dump(dump_data, bad_ver_wallet_dump) self.assert_raises_tool_error('Error: Dumpfile version is not supported. This version of dash-wallet only supports version 1 dumpfiles. Got dumpfile with version 2', '-wallet=badload', '-dumpfile={}'.format(bad_ver_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() bad_magic_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_magic.dump") del dump_data["BITCOIN_CORE_WALLET_DUMP"] dump_data["not_the_right_magic"] = "1" self.write_dump(dump_data, bad_magic_wallet_dump, "not_the_right_magic") self.assert_raises_tool_error('Error: Dumpfile identifier record is incorrect. Got "not_the_right_magic", expected "BITCOIN_CORE_WALLET_DUMP".', '-wallet=badload', '-dumpfile={}'.format(bad_magic_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() self.log.info('Checking createfromdump handling of checksums') bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum1.dump") @@ -386,21 +386,21 @@ def test_dump_createfromdump(self): dump_data["checksum"] = "1" * 64 self.write_dump(dump_data, bad_sum_wallet_dump) self.assert_raises_tool_error('Error: Dumpfile checksum does not match. Computed {}, expected {}'.format(checksum, "1" * 64), '-wallet=bad', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum2.dump") del dump_data["checksum"] self.write_dump(dump_data, bad_sum_wallet_dump, skip_checksum=True) self.assert_raises_tool_error('Error: Missing checksum', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() bad_sum_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_sum3.dump") dump_data["checksum"] = "2" * 10 self.write_dump(dump_data, bad_sum_wallet_dump) self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() dump_data["checksum"] = "3" * 66 self.write_dump(dump_data, bad_sum_wallet_dump) self.assert_raises_tool_error('Error: Checksum is not the correct size', '-wallet=badload', '-dumpfile={}'.format(bad_sum_wallet_dump), 'createfromdump') - assert not os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest/wallets", "badload")) + assert not (self.nodes[0].wallets_path / "badload").is_dir() def test_chainless_conflicts(self): self.log.info("Test wallet tool when wallet contains conflicting transactions") @@ -473,7 +473,7 @@ def test_nonhd(self): self.stop_node(0) def run_test(self): - self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename) + self.wallet_path = os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename) self.test_invalid_tool_commands_and_args() # Warning: The following tests are order-dependent. self.test_tool_wallet_info() diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py index 7e105bf0651d..a29c10e1bf2b 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -105,16 +105,16 @@ def stop_three(self): self.stop_node(2) def erase_three(self): - os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)) - os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)) - os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)) + os.remove(os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename)) + os.remove(os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename)) + os.remove(os.path.join(self.nodes[2].wallets_path, self.default_wallet_name, self.wallet_data_filename)) def restore_invalid_wallet(self): node = self.nodes[3] invalid_wallet_file = os.path.join(self.nodes[0].datadir, 'invalid_wallet_file.bak') open(invalid_wallet_file, 'a', encoding="utf8").write('invald wallet') wallet_name = "res0" - not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name) + not_created_wallet_file = os.path.join(node.wallets_path, wallet_name) error_message = "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(not_created_wallet_file) assert_raises_rpc_error(-18, error_message, node.restorewallet, wallet_name, invalid_wallet_file) assert not os.path.exists(not_created_wallet_file) @@ -129,19 +129,19 @@ def restore_corrupt_bdb_wallet(self): dest.write(source.read(4096)) wallet_name = 'restore_corrupt_bdb' assert_raises_rpc_error(-4, 'corrupt', node.restorewallet, wallet_name, corrupt_file) - assert not os.path.exists(os.path.join(node.datadir, self.chain, 'wallets', wallet_name)) + assert not os.path.exists(os.path.join(node.wallets_path, wallet_name)) def restore_nonexistent_wallet(self): node = self.nodes[3] nonexistent_wallet_file = os.path.join(self.nodes[0].datadir, 'nonexistent_wallet.bak') wallet_name = "res0" assert_raises_rpc_error(-8, "Backup file does not exist", node.restorewallet, wallet_name, nonexistent_wallet_file) - not_created_wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name) + not_created_wallet_file = os.path.join(node.wallets_path, wallet_name) assert not os.path.exists(not_created_wallet_file) def restore_preserves_existing_directory(self): node = self.nodes[3] - wallet_dir = os.path.join(node.datadir, self.chain, 'wallets') + wallet_dir = node.wallets_path backup_file = os.path.join(self.nodes[0].datadir, 'wallet.bak') invalid_path = os.path.join(node.datadir, 'x' * 256) for wallet_name in ('restore_existing', os.path.join(node.datadir, 'restore_absolute')): @@ -161,7 +161,7 @@ def restore_wallet_existent_name(self): node = self.nodes[3] backup_file = os.path.join(self.nodes[0].datadir, 'wallet.bak') wallet_name = "res0" - wallet_file = os.path.join(node.datadir, self.chain, 'wallets', wallet_name) + wallet_file = os.path.join(node.wallets_path, wallet_name) error_message = "Failed to create database path '{}'. Database already exists.".format(wallet_file) assert_raises_rpc_error(-36, error_message, node.restorewallet, wallet_name, backup_file) assert os.path.exists(wallet_file) @@ -229,9 +229,9 @@ def run_test(self): self.nodes[3].restorewallet("res1", backup_file_1) self.nodes[3].restorewallet("res2", backup_file_2) - assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res0")) - assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res1")) - assert os.path.exists(os.path.join(self.nodes[3].datadir, self.chain, 'wallets', "res2")) + assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res0")) + assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res1")) + assert os.path.exists(os.path.join(self.nodes[3].wallets_path, "res2")) res0_rpc = self.nodes[3].get_wallet_rpc("res0") res1_rpc = self.nodes[3].get_wallet_rpc("res1") @@ -249,11 +249,11 @@ def run_test(self): self.erase_three() #start node2 with no chain - shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'blocks')) - shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate')) - shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'evodb')) - shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'llmq')) - shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'indexes')) + shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'blocks')) + shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'chainstate')) + shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'evodb')) + shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'llmq')) + shutil.rmtree(os.path.join(self.nodes[2].chain_path, 'indexes')) self.start_three(["-nowallet"]) # Create new wallets for the three nodes. @@ -277,10 +277,10 @@ def run_test(self): # Backup to source wallet file must fail sourcePaths = [ - os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename), - os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', self.default_wallet_name, self.wallet_data_filename), - os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name), - os.path.join(self.nodes[0].datadir, self.chain, 'wallets')] + os.path.join(self.nodes[0].wallets_path, self.default_wallet_name, self.wallet_data_filename), + os.path.join(self.nodes[0].wallets_path, '.', self.default_wallet_name, self.wallet_data_filename), + os.path.join(self.nodes[0].wallets_path, self.default_wallet_name), + os.path.join(self.nodes[0].wallets_path)] for sourcePath in sourcePaths: assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath) diff --git a/test/functional/wallet_backwards_compatibility.py b/test/functional/wallet_backwards_compatibility.py index 47d8d757254f..2826495de08d 100755 --- a/test/functional/wallet_backwards_compatibility.py +++ b/test/functional/wallet_backwards_compatibility.py @@ -68,8 +68,8 @@ def setup_nodes(self): def nodes_wallet_dir(self, node): if node.version < 160000: - return os.path.join(node.datadir, "regtest") - return os.path.join(node.datadir, "regtest/wallets") + return node.chain_path + return node.wallets_path def run_test(self): node_miner = self.nodes[0] @@ -161,9 +161,9 @@ def run_test(self): assert info['keypoolsize'] == 0 # Unload wallets and copy to older nodes: - node_master_wallets_dir = os.path.join(node_master.datadir, "regtest/wallets") - node_v19_wallets_dir = os.path.join(node_v19.datadir, "regtest/wallets") - node_v17_wallets_dir = os.path.join(node_v17.datadir, "regtest/wallets") + node_master_wallets_dir = node_master.wallets_path + node_v19_wallets_dir = node_v19.wallets_path + node_v17_wallets_dir = node_v17.wallets_path node_master.unloadwallet("w1") node_master.unloadwallet("w2") node_master.unloadwallet("w3") diff --git a/test/functional/wallet_descriptor.py b/test/functional/wallet_descriptor.py index 127e07948d97..1cde6e1c7cfa 100755 --- a/test/functional/wallet_descriptor.py +++ b/test/functional/wallet_descriptor.py @@ -198,7 +198,7 @@ def run_test(self): self.log.info("Test that loading descriptor wallet containing legacy key types throws error") self.nodes[0].createwallet(wallet_name="crashme", descriptors=True) self.nodes[0].unloadwallet("crashme") - wallet_db = os.path.join(self.nodes[0].datadir, self.chain, "wallets", "crashme", self.wallet_data_filename) + wallet_db = os.path.join(self.nodes[0].wallets_path, "crashme", self.wallet_data_filename) conn = sqlite3.connect(wallet_db) with conn: # add "cscript" entry: key type is uint160 (20 bytes), value type is CScript (zero-length here) diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py index 215aa0b1e935..14edc52d944b 100755 --- a/test/functional/wallet_hd.py +++ b/test/functional/wallet_hd.py @@ -87,14 +87,14 @@ def run_test(self): self.stop_node(1) # we need to delete the complete chain directory # otherwise node1 would auto-recover all funds in flag the keypool keys as used - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "evodb")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "llmq")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "indexes")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "blocks")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "evodb")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "llmq")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "indexes")) shutil.copyfile( os.path.join(self.nodes[1].datadir, "hd.bak"), - os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename), + os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename), ) self.start_node(1) @@ -115,14 +115,14 @@ def run_test(self): # Try a RPC based rescan self.stop_node(1) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "blocks")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "evodb")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "llmq")) - shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "indexes")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "blocks")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "chainstate")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "evodb")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "llmq")) + shutil.rmtree(os.path.join(self.nodes[1].chain_path, "indexes")) shutil.copyfile( os.path.join(self.nodes[1].datadir, "hd.bak"), - os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename), + os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename), ) self.start_node(1, extra_args=self.extra_args[1]) self.connect_nodes(0, 1) diff --git a/test/functional/wallet_keypool_topup.py b/test/functional/wallet_keypool_topup.py index 3fb868aba99e..8e5680fbd3db 100755 --- a/test/functional/wallet_keypool_topup.py +++ b/test/functional/wallet_keypool_topup.py @@ -33,7 +33,7 @@ def skip_test_if_missing_module(self): self.skip_if_no_wallet() def run_test(self): - wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename) + wallet_path = os.path.join(self.nodes[1].wallets_path, self.default_wallet_name, self.wallet_data_filename) wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak") self.generate(self.nodes[0], COINBASE_MATURITY + 1) diff --git a/test/functional/wallet_listtransactions.py b/test/functional/wallet_listtransactions.py index 4c6cc43f35b2..35e47231e91f 100755 --- a/test/functional/wallet_listtransactions.py +++ b/test/functional/wallet_listtransactions.py @@ -117,8 +117,8 @@ def run_externally_generated_address_test(self): # refill keypool otherwise the second node wouldn't recognize addresses generated on the first nodes self.nodes[0].keypoolrefill(1000) self.stop_nodes() - wallet0 = os.path.join(self.nodes[0].datadir, self.chain, self.default_wallet_name, "wallet.dat") - wallet2 = os.path.join(self.nodes[2].datadir, self.chain, self.default_wallet_name, "wallet.dat") + wallet0 = os.path.join(self.nodes[0].chain_path, self.default_wallet_name, "wallet.dat") + wallet2 = os.path.join(self.nodes[2].chain_path, self.default_wallet_name, "wallet.dat") shutil.copyfile(wallet0, wallet2) self.start_nodes() # reconnect nodes diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py index 33c8d27cf2e4..419772242846 100755 --- a/test/functional/wallet_migration.py +++ b/test/functional/wallet_migration.py @@ -36,7 +36,7 @@ def skip_test_if_missing_module(self): self.skip_if_no_bdb() def assert_is_sqlite(self, wallet_name): - wallet_file_path = os.path.join(self.nodes[0].datadir, "regtest/wallets", wallet_name, self.wallet_data_filename) + wallet_file_path = self.nodes[0].wallets_path / wallet_name / self.wallet_data_filename with open(wallet_file_path, 'rb') as f: file_magic = f.read(16) assert_equal(file_magic, b'SQLite format 3\x00') @@ -524,11 +524,11 @@ def test_unloaded_by_path(self): wallet.unloadwallet() - wallet_file_path = os.path.join(self.nodes[0].datadir, "regtest", "wallets", "notloaded2") + wallet_file_path = self.nodes[0].wallets_path / "notloaded2" self.nodes[0].migratewallet(wallet_file_path) # Because we gave the name by full path, the loaded wallet's name is that path too. - wallet = self.nodes[0].get_wallet_rpc(wallet_file_path) + wallet = self.nodes[0].get_wallet_rpc(str(wallet_file_path)) info = wallet.getwalletinfo() assert_equal(info["descriptors"], True) @@ -551,7 +551,7 @@ def test_wallet_name_with_slashes(self): backup_path = migrate_result["backup_path"] # Backup must live directly inside the wallet's own directory. - expected_wallet_dir = os.path.join(self.nodes[0].datadir, "regtest", "wallets", "nested", "subdir_wallet") + expected_wallet_dir = self.nodes[0].wallets_path / "nested" / "subdir_wallet" assert_equal(os.path.dirname(os.path.abspath(backup_path)), os.path.abspath(expected_wallet_dir)) # Basename must use the sanitized prefix derived from the wallet @@ -576,12 +576,12 @@ def test_direct_file(self): wallet = self.create_legacy_wallet("plainfile") wallet.unloadwallet() - wallets_dir = os.path.join(self.nodes[0].datadir, "regtest", "wallets") - wallet_path = os.path.join(wallets_dir, "plainfile") - wallet_dat_path = os.path.join(wallet_path, "wallet.dat") - shutil.copyfile(wallet_dat_path, os.path.join(wallets_dir, "plainfile.bak")) + wallets_dir = self.nodes[0].wallets_path + wallet_path = wallets_dir / "plainfile" + wallet_dat_path = wallet_path / "wallet.dat" + shutil.copyfile(wallet_dat_path, wallets_dir / "plainfile.bak") shutil.rmtree(wallet_path) - shutil.move(os.path.join(wallets_dir, "plainfile.bak"), wallet_path) + shutil.move(wallets_dir / "plainfile.bak", wallet_path) self.nodes[0].loadwallet("plainfile") info = wallet.getwalletinfo() @@ -593,8 +593,8 @@ def test_direct_file(self): assert_equal(info["descriptors"], True) assert_equal(info["format"], "sqlite") - assert os.path.isdir(wallet_path) - assert os.path.isfile(wallet_dat_path) + assert wallet_path.is_dir() + assert wallet_dat_path.is_file() def test_migrate_raw_p2sh(self): self.log.info("Test migration of watch-only raw p2sh script") diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index 2acdf4cfceaf..39a1088eed99 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -61,7 +61,7 @@ def add_options(self, parser): def run_test(self): node = self.nodes[0] - data_dir = lambda *p: os.path.join(node.datadir, self.chain, *p) + data_dir = lambda *p: os.path.join(node.chain_path, *p) wallet_dir = lambda *p: data_dir('wallets', *p) wallet = lambda name: node.get_wallet_rpc(name) @@ -296,7 +296,7 @@ def wallet_file(name): assert_equal(set(self.nodes[0].listwallets()), set(wallet_names)) # Fail to load if wallet doesn't exist - path = os.path.join(self.options.tmpdir, "node0", self.chain, "wallets", "wallets") + path = wallet_dir("wallets") assert_raises_rpc_error(-18, "Wallet file verification failed. Failed to load database path '{}'. Path does not exist.".format(path), self.nodes[0].loadwallet, 'wallets') # Fail to load duplicate wallets @@ -304,7 +304,7 @@ def wallet_file(name): if not self.options.descriptors: # This tests the default wallet that BDB makes, so SQLite wallet doesn't need to test this # Fail to load duplicate wallets by different ways (directory and filepath) - path = os.path.join(self.options.tmpdir, "node0", self.chain, "wallets", "wallet.dat") + path = wallet_dir("wallet.dat") assert_raises_rpc_error(-35, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, 'wallet.dat') # Only BDB doesn't open duplicate wallet files. SQLite does not have this limitation. While this may be desired in the future, it is not necessary @@ -319,13 +319,13 @@ def wallet_file(name): # Fail to load if a directory is specified that doesn't contain a wallet os.mkdir(wallet_dir('empty_wallet_dir')) - path = os.path.join(self.options.tmpdir, "node0", self.chain, "wallets", "empty_wallet_dir") + path = wallet_dir("empty_wallet_dir") assert_raises_rpc_error(-18, "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(path), self.nodes[0].loadwallet, 'empty_wallet_dir') self.log.info("Test dynamic wallet creation.") # Fail to create a wallet if it already exists. - path = os.path.join(self.options.tmpdir, "node0", self.chain, "wallets", "w2") + path = wallet_dir("w2") assert_raises_rpc_error(-4, "Failed to create database path '{}'. Database already exists.".format(path), self.nodes[0].createwallet, 'w2') # Successfully create a wallet with a new name diff --git a/test/functional/wallet_pruning.py b/test/functional/wallet_pruning.py index a3d21ccdfe71..0dcdfde8b7ba 100755 --- a/test/functional/wallet_pruning.py +++ b/test/functional/wallet_pruning.py @@ -115,7 +115,7 @@ def get_birthheight(self, wallet_file): def has_block(self, block_index): """Checks if the pruned node has the specific blk0000*.dat file""" - return os.path.isfile(os.path.join(self.nodes[1].datadir, self.chain, "blocks", f"blk{block_index:05}.dat")) + return os.path.isfile(os.path.join(self.nodes[1].chain_path, "blocks", f"blk{block_index:05}.dat")) def create_wallet(self, wallet_name, *, unload=False): """Creates and dumps a wallet on the non-pruned node0 to be later import by the pruned node""" diff --git a/test/functional/wallet_reorgsrestore.py b/test/functional/wallet_reorgsrestore.py index 1c79c6816ced..af01b9439ff9 100755 --- a/test/functional/wallet_reorgsrestore.py +++ b/test/functional/wallet_reorgsrestore.py @@ -89,7 +89,7 @@ def run_test(self): # Node0 wallet file is loaded on longest sync'ed node1 self.stop_node(1) self.nodes[0].backupwallet(os.path.join(self.nodes[0].datadir, 'wallet.bak')) - shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, self.default_wallet_name, self.wallet_data_filename)) + shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[1].chain_path, self.default_wallet_name, self.wallet_data_filename)) self.start_node(1) tx_after_reorg = self.nodes[1].gettransaction(txid) # Check that normal confirmed tx is confirmed again but with different blockhash diff --git a/test/functional/wallet_upgradetohd.py b/test/functional/wallet_upgradetohd.py index 219659f1e3cc..2f00de4fa35f 100755 --- a/test/functional/wallet_upgradetohd.py +++ b/test/functional/wallet_upgradetohd.py @@ -40,7 +40,7 @@ def recover_non_hd(self): self.log.info("Recover non-HD wallet to check different upgrade paths") node = self.nodes[0] self.stop_node(0) - shutil.copyfile(os.path.join(node.datadir, "non_hd.bak"), os.path.join(node.datadir, self.chain, self.default_wallet_name, self.wallet_data_filename)) + shutil.copyfile(os.path.join(node.datadir, "non_hd.bak"), os.path.join(node.chain_path, self.default_wallet_name, self.wallet_data_filename)) self.start_node(0) if not self.options.descriptors: assert 'hdchainid' not in node.getwalletinfo() diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py index 1ca6f37ee1ec..7c310b324b84 100755 --- a/test/functional/wallet_upgradewallet.py +++ b/test/functional/wallet_upgradewallet.py @@ -116,10 +116,10 @@ def run_test(self): self.log.info("Test upgradewallet RPC...") # Prepare for copying of the older wallet - node_master_wallet_dir = os.path.join(node_master.datadir, "regtest/wallets", self.default_wallet_name) - node_master_wallet = os.path.join(node_master_wallet_dir, self.default_wallet_name, self.wallet_data_filename) - v18_2_wallet = os.path.join(v18_2_node.datadir, "regtest/wallets/wallet.dat") - v16_1_wallet = os.path.join(v16_1_node.datadir, "regtest/wallets/wallet.dat") + node_master_wallet_dir = node_master.wallets_path / self.default_wallet_name + node_master_wallet = node_master_wallet_dir / self.default_wallet_name / self.wallet_data_filename + v18_2_wallet = v18_2_node.wallets_path / "wallet.dat" + v16_1_wallet = v16_1_node.wallets_path / "wallet.dat" self.stop_nodes() shutil.rmtree(node_master_wallet_dir) From 5bd92ee38d35edfd7f8a68813afff955b1dd915b Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Sun, 18 Oct 2026 02:03:45 -0500 Subject: [PATCH 04/10] Merge bitcoin/bitcoin#28070: test: Drop 22.x node from TxindexCompatibilityTest fafe43cb6c76a5f60194be128a40baf161d39920 scripted-diff: Use blocks_path where possible (MarcoFalke) fa060c15fb5081e66ed1ebe05dca6e8026f32c4f test: Add blocks_path property to TestNode (MarcoFalke) faba4fc3257c0e7d7bcb5146dab07ffe3193744b test: Drop 22.x node from TxindexCompatibilityTest (MarcoFalke) fa7f65b0f81f3a2899c8eb540182c7d9a90fff00 test: Use clean chain in MempoolCompatibilityTest (MarcoFalke) Pull request description: The node in this test was never really needed, because the compatibility tests shouldn't be used to test previous releases. (The test suite of the previous release itself should be used for that). So remove it. Also, other test changes. (See individual commits) ACKs for top commit: theStack: Code-review ACK fafe43cb6c76a5f60194be128a40baf161d39920 Tree-SHA512: 289f54695bf5310663ab38ebf1aa457f53d0aafae56e6657be0e75bf96b303165bad417dc7eaf4c40f0639aa92ce139e5bacb318a2eabab1f8e23a811cabe0cc Dash adaptations: - test/functional/mempool_compatibility.py: drops Dash's shutil.rmtree of node0's cached regtest dir (and the os/shutil imports); setup_clean_chain=True means no cached chain dir exists, so rmtree would raise - test/functional/mempool_compatibility.py: does not add upstream's COINBASE_MATURITY import context; Dash's version generates 100 blocks literally and never imported it - test/functional/feature_txindex_compatibility.py: upstream hunk not applied; Dash already deleted this test via bitcoin#28753, so the file stays deleted Not applicable to Dash (intentionally omitted): - test/functional/feature_txindex_compatibility.py: Dash already removed this test in merge bitcoin#28753 (upstream's later removal of it), so there is no file to edit --- test/functional/feature_abortnode.py | 2 +- test/functional/feature_dirsymlinks.py | 2 +- test/functional/feature_loadblock.py | 2 +- test/functional/feature_reindex.py | 2 +- .../feature_remove_pruned_files_on_startup.py | 8 ++++---- test/functional/feature_unsupported_utxo_db.py | 4 ++-- test/functional/mempool_compatibility.py | 15 +++++---------- test/functional/rpc_blockchain.py | 4 ++-- test/functional/test_framework/test_node.py | 4 ++++ 9 files changed, 21 insertions(+), 22 deletions(-) diff --git a/test/functional/feature_abortnode.py b/test/functional/feature_abortnode.py index 91056c0d0e4f..cd58414c661b 100755 --- a/test/functional/feature_abortnode.py +++ b/test/functional/feature_abortnode.py @@ -25,7 +25,7 @@ def run_test(self): self.generate(self.nodes[0], 3, sync_fun=self.no_op) # Deleting the undo file will result in reorg failure - (self.nodes[0].chain_path / "blocks" / "rev00000.dat").unlink() + (self.nodes[0].blocks_path / "rev00000.dat").unlink() # Connecting to a node with a more work chain will trigger a reorg # attempt. diff --git a/test/functional/feature_dirsymlinks.py b/test/functional/feature_dirsymlinks.py index 288754c04cdb..96f4aed08a06 100755 --- a/test/functional/feature_dirsymlinks.py +++ b/test/functional/feature_dirsymlinks.py @@ -26,7 +26,7 @@ def run_test(self): self.stop_node(0) rename_and_link( - from_name=self.nodes[0].chain_path / "blocks", + from_name=self.nodes[0].blocks_path, to_name=dir_new_blocks, ) rename_and_link( diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py index 23abb7d17e3d..666c289f216d 100755 --- a/test/functional/feature_loadblock.py +++ b/test/functional/feature_loadblock.py @@ -37,7 +37,7 @@ def run_test(self): cfg_file = os.path.join(data_dir, "linearize.cfg") bootstrap_file = os.path.join(self.options.tmpdir, "bootstrap.dat") genesis_block = self.nodes[0].getblockhash(0) - blocks_dir = self.nodes[0].chain_path / "blocks" + blocks_dir = self.nodes[0].blocks_path hash_list = tempfile.NamedTemporaryFile(dir=data_dir, mode='w', delete=False, diff --git a/test/functional/feature_reindex.py b/test/functional/feature_reindex.py index 54da05cfd4c8..2af46a3de7c7 100755 --- a/test/functional/feature_reindex.py +++ b/test/functional/feature_reindex.py @@ -38,7 +38,7 @@ def out_of_order(self): # In this test environment, blocks will always be in order (since # we're generating them rather than getting them from peers), so to # test out-of-order handling, swap blocks 1 and 2 on disk. - blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat" + blk0 = self.nodes[0].blocks_path / "blk00000.dat" with open(blk0, 'r+b') as bf: # Read at least the first few blocks (including genesis) b = bf.read(2000) diff --git a/test/functional/feature_remove_pruned_files_on_startup.py b/test/functional/feature_remove_pruned_files_on_startup.py index 4dafce074fad..49b6be7bda44 100755 --- a/test/functional/feature_remove_pruned_files_on_startup.py +++ b/test/functional/feature_remove_pruned_files_on_startup.py @@ -22,10 +22,10 @@ def mine_batches(self, blocks): self.sync_blocks() def run_test(self): - blk0 = self.nodes[0].chain_path / "blocks" / "blk00000.dat" - rev0 = self.nodes[0].chain_path / "blocks" / "rev00000.dat" - blk1 = self.nodes[0].chain_path / "blocks" / "blk00001.dat" - rev1 = self.nodes[0].chain_path / "blocks" / "rev00001.dat" + blk0 = self.nodes[0].blocks_path / "blk00000.dat" + rev0 = self.nodes[0].blocks_path / "rev00000.dat" + blk1 = self.nodes[0].blocks_path / "blk00001.dat" + rev1 = self.nodes[0].blocks_path / "rev00001.dat" self.mine_batches(800) fo1 = os.open(blk0, os.O_RDONLY) fo2 = os.open(rev1, os.O_RDONLY) diff --git a/test/functional/feature_unsupported_utxo_db.py b/test/functional/feature_unsupported_utxo_db.py index 36f970b36435..501848d8ced8 100755 --- a/test/functional/feature_unsupported_utxo_db.py +++ b/test/functional/feature_unsupported_utxo_db.py @@ -45,9 +45,9 @@ def run_test(self): self.log.info("Check init error") legacy_utxos_dir = self.nodes[0].chain_path / "chainstate" - legacy_blocks_dir = self.nodes[0].chain_path / "blocks" + legacy_blocks_dir = self.nodes[0].blocks_path recent_utxos_dir = self.nodes[1].chain_path / "chainstate" - recent_blocks_dir = self.nodes[1].chain_path / "blocks" + recent_blocks_dir = self.nodes[1].blocks_path shutil.copytree(legacy_utxos_dir, recent_utxos_dir) shutil.copytree(legacy_blocks_dir, recent_blocks_dir) self.nodes[1].assert_start_raises_init_error( diff --git a/test/functional/mempool_compatibility.py b/test/functional/mempool_compatibility.py index 601bca73f2f5..0624a58947be 100755 --- a/test/functional/mempool_compatibility.py +++ b/test/functional/mempool_compatibility.py @@ -10,9 +10,6 @@ Previous releases are required by this test, see test/README.md. """ -import os -import shutil - from test_framework.test_framework import BitcoinTestFramework from test_framework.wallet import MiniWallet @@ -23,6 +20,7 @@ def add_options(self, parser): def set_test_params(self): self.num_nodes = 2 + self.setup_clean_chain = True def skip_test_if_missing_module(self): self.skip_if_no_previous_releases() @@ -36,9 +34,6 @@ def setup_network(self): [], [], ] - # Delete v18.2.2 cached datadir to avoid making a legacy version try to - # make sense of our current database formats - shutil.rmtree(os.path.join(self.nodes[0].datadir, self.chain)) self.start_nodes() def run_test(self): @@ -62,9 +57,9 @@ def run_test(self): self.stop_node(1) self.log.info("Move mempool.dat from old to new node") - old_node_mempool = os.path.join(old_node.chain_path, 'mempool.dat') - new_node_mempool = os.path.join(new_node.chain_path, 'mempool.dat') - os.rename(old_node_mempool, new_node_mempool) + old_node_mempool = old_node.chain_path / "mempool.dat" + new_node_mempool = new_node.chain_path / "mempool.dat" + old_node_mempool.rename(new_node_mempool) self.log.info("Start new node and verify mempool contains the tx") self.start_node(1) @@ -77,7 +72,7 @@ def run_test(self): self.stop_node(1) self.log.info("Move mempool.dat from new to old node") - os.rename(new_node_mempool, old_node_mempool) + new_node_mempool.rename(old_node_mempool) self.log.info("Start old node again and verify mempool contains both txs") self.start_node(0, ['-nowallet']) diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 2f60919443f3..96026c96b7df 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -651,8 +651,8 @@ def assert_vin_does_not_contain_prevout(verbosity): self.log.info("Test that getblock with verbosity 2 and 3 still works with pruned Undo data") def move_block_file(old, new): - old_path = self.nodes[0].chain_path / "blocks" / old - new_path = self.nodes[0].chain_path / "blocks" / new + old_path = self.nodes[0].blocks_path / old + new_path = self.nodes[0].blocks_path / new old_path.rename(new_path) # Move instead of deleting so we can restore chain state afterwards diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index ce4e047b1a8c..7413569ed8cf 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -485,6 +485,10 @@ def chain_path(self) -> Path: def debug_log_path(self) -> Path: return self.chain_path / 'debug.log' + @property + def blocks_path(self) -> Path: + return self.chain_path / "blocks" + @property def wallets_path(self) -> Path: return self.chain_path / "wallets" From d2600bce065e89017c1285042588201f801b99d1 Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Sun, 18 Oct 2026 02:03:45 -0500 Subject: [PATCH 05/10] Merge bitcoin/bitcoin#28157: test doc: tests `acceptstalefeeestimates` option is only supported on regtest chain ee5a0369cc4305da7b3d26f37677de05ad797e51 test: ensure acceptstalefeeestimates is supported only on regtest chain (ismaelsadeeq) 22d5d4b2b2486feaef981e96f0321f020617f082 tx fees, policy: doc: update and delete unnecessary comment (ismaelsadeeq) Pull request description: This PR Follow up comments from [#27622](https://github.com/bitcoin/bitcoin/pull/27622) It test that the new `regtest-only` option `acceptstalefeeestimates` is not supported on [main, signet and test chains](https://github.com/bitcoin/bitcoin/pull/27622/files#r1235218268), removes an unnecessary [comment](https://github.com/bitcoin/bitcoin/pull/27622/files#r1235204323), and update fee estimator `MAXFILEAGE` [description comment](https://github.com/bitcoin/bitcoin/pull/27622/files#r1233887314). ACKs for top commit: jonatack: ACK ee5a0369cc4305da7b3d26f37677de05ad797e51 glozow: utACK ee5a0369cc4305da7b3d26f37677de05ad797e51 Tree-SHA512: 4755f25b08db62f37614ea768272b12580ee0d481fb7fa339379901a6132c66828777c6747d3fe67490ceace3a6ff248bf13bdf65720f6e5ba8642eb762acd3c --- src/policy/fees.cpp | 2 -- src/policy/fees.h | 5 +++-- test/functional/feature_config_args.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 4e69a18f25df..edc89c54e0c4 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -561,14 +561,12 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "rb")}; - // Whenever the fee estimation file is not present return early if (est_file.IsNull()) { LogPrintf("%s is not found. Continue anyway.\n", fs::PathToString(m_estimation_filepath)); return; } std::chrono::hours file_age = GetFeeEstimatorFileAge(); - // fee estimate file must not be too old to avoid wrong fee estimates. if (file_age > MAX_FILE_AGE && !read_stale_estimates) { LogPrintf("Fee estimation file %s too old (age=%lld > %lld hours) and will not be used to avoid serving stale estimates.\n", fs::PathToString(m_estimation_filepath), Ticks(file_age), Ticks(MAX_FILE_AGE)); return; diff --git a/src/policy/fees.h b/src/policy/fees.h index 3b6f6d9698f3..4694ef7b2997 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -25,8 +25,9 @@ // How often to flush fee estimates to fee_estimates.dat. static constexpr std::chrono::hours FEE_FLUSH_INTERVAL{1}; -/** fee_estimates.dat that are more than 60 hours (2.5 days) will not be read, - * as the estimates in the file are stale. +/** fee_estimates.dat that are more than 60 hours (2.5 days) old will not be read, + * as fee estimates are based on historical data and may be inaccurate if + * network activity has changed. */ static constexpr std::chrono::hours MAX_FILE_AGE{60}; diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py index e45da3c5e2bd..c172e737b127 100755 --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -7,6 +7,7 @@ import os import pathlib import re +import shutil import sys import tempfile import time @@ -367,6 +368,20 @@ def test_ignored_default_conf(self): f'is being used instead.') + r"[\s\S]*", env=env, match=ErrorMatch.FULL_REGEX) node.args = node_args + def test_acceptstalefeeestimates_arg_support(self): + self.log.info("Test -acceptstalefeeestimates option support") + conf_file = self.nodes[0].datadir_path / "dash.conf" + existing_paths = set(self.nodes[0].datadir_path.iterdir()) + for chain, chain_name in {("main", ""), ("test", "testnet3"), ("devnet", "devnet")}: + util.write_config(conf_file, n=0, chain=chain_name, extra_config='acceptstalefeeestimates=1\n') + self.nodes[0].assert_start_raises_init_error(expected_msg=f'Error: acceptstalefeeestimates is not supported on {chain} chain.') + util.write_config(conf_file, n=0, chain="regtest") # Reset to regtest + # Remove the chain dirs created by the failed starts above, so node0 keeps a single + # chain dir holding a debug.log, as combine_logs.py (run by Dash CI on every test) expects + for path in set(self.nodes[0].datadir_path.iterdir()) - existing_paths: + if path.is_dir(): + shutil.rmtree(path) + def run_test(self): self.test_log_buffer() self.test_args_log() @@ -380,6 +395,7 @@ def run_test(self): self.test_invalid_command_line_options() self.test_ignored_conf() self.test_ignored_default_conf() + self.test_acceptstalefeeestimates_arg_support() # Remove the -datadir argument so it doesn't override the config file self.nodes[0].args = [arg for arg in self.nodes[0].args if not arg.startswith("-datadir")] From bddd9bb8cc0bdd0653bb50bdc93565f00f15d73f Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Mon, 19 Oct 2026 13:01:12 -0500 Subject: [PATCH 06/10] Merge bitcoin/bitcoin#28858: doc: rewrite explanation for `-par=` d799ea26edfd63434b6d1cf55500de184dc67fac doc: rewrite explanation for -par= (fanquake) Pull request description: The negative bound for script threads comes from the machine which generates the man pages, so may only be correct for that machine. Any other placeholder value will also be wrong for some machines. Fix this be removing the value. This also fixes help2man incorrectly bolding the value, as if it were a paramater. Closes #28850. ACKs for top commit: maflcko: lgtm ACK d799ea26edfd63434b6d1cf55500de184dc67fac theStack: ACK d799ea26edfd63434b6d1cf55500de184dc67fac Tree-SHA512: 2eec0086faf4cc64bbf46b22949662f84d8546d2322c3d507fc44a4e1f64d228a2901af4fa4535c0771e3e14600be8308fc5dbd407b66ae6ae4f8878d8372c0a Dash adaptations: - src/init.cpp: -par help text was already changed by Dash (4e5cc4bb95, no -GetNumCores() bound, 'max: %d'); swapped in upstream's '0 = auto, up to %d, ...' wording on that line - src/init.cpp: applied the same wording to Dash-only -parbls, which shares -par's help-text format and was changed alongside it in 4e5cc4bb95 - src/init.cpp: kept Dash's -minimumchainwork line (devnet instead of signet) from the conflict hunk unchanged --- src/init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 224d3267b22e..79375e46740a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -623,9 +623,9 @@ void SetupServerArgs(ArgsManager& argsman) argsman.AddArg("-maxrecsigsage=", strprintf("Number of seconds to keep LLMQ recovery sigs (default: %u)", llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-mempoolexpiry=", strprintf("Do not keep transactions in the mempool longer than hours (default: %u)", DEFAULT_MEMPOOL_EXPIRY_HOURS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-minimumchainwork=", strprintf("Minimum work assumed to exist on a valid chain in hex (default: %s, testnet: %s, devnet: %s)", defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), testnetChainParams->GetConsensus().nMinimumChainWork.GetHex(), devnetChainParams->GetConsensus().nMinimumChainWork.GetHex()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS); - argsman.AddArg("-par=", strprintf("Set the number of script verification threads (0 = auto, <0 = leave that many cores free, max: %d, default: %d)", + argsman.AddArg("-par=", strprintf("Set the number of script verification threads (0 = auto, up to %d, <0 = leave that many cores free, default: %d)", MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - argsman.AddArg("-parbls=", strprintf("Set the number of BLS verification threads (0 = auto, <0 = leave that many cores free, max: %d, default: %d)", + argsman.AddArg("-parbls=", strprintf("Set the number of BLS verification threads (0 = auto, up to %d, <0 = leave that many cores free, default: %d)", llmq::MAX_BLSCHECK_THREADS, llmq::DEFAULT_BLSCHECK_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-persistmempool", strprintf("Whether to save the mempool on shutdown and load on restart (default: %u)", DEFAULT_PERSIST_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-pid=", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); From d6d11e7e11f9d428dca2f58d02a5dc2feb6a683c Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Mon, 19 Oct 2026 13:02:13 -0500 Subject: [PATCH 07/10] Merge bitcoin/bitcoin#28737: doc: Fix bugprone-lambda-function-name errors faa769db5a4c16fd171e9a39c33e245db4e7c134 Fix bugprone-lambda-function-name errors (MarcoFalke) Pull request description: Inside a lambda, `__func__` will evaluate to something like `"operator()"`. Fix this by either removing it, or by using the real name. https://clang.llvm.org/extra/clang-tidy/checks/bugprone/lambda-function-name.html ACKs for top commit: TheCharlatan: ACK faa769db5a4c16fd171e9a39c33e245db4e7c134 darosior: utACK faa769db5a4c16fd171e9a39c33e245db4e7c134 Tree-SHA512: 0b562bd4ebd7f46ca3ebabeee67851ad30bd522fa57e5010e833b163664e51f5df645ff9ca35d22c3479fb27d9267d4e5d0d417d42729bf3ccf80d7944970e4e Dash adaptations: - src/validation.cpp: takes upstream's new rename-error LogPrintf but keeps Dash's AbortNode(); Dash lacks the GetNotifications().fatalError() kernel-notifications refactor - src/rpc/masternode.cpp: masternode_payments RPC lambda logs self.m_name instead of __func__, same fix upstream applied to getmempoolancestors - src/evo/specialtxman.cpp: drops __func__ from the ForEachMN lambda log in FinishListForBlock and writes the function name as literal text - src/instantsend/signing.cpp: drops __func__ from the log_refusal lambda in CheckCanLockAssetUnlock and writes the function name as literal text - src/net_processing.cpp: drops __func__ from the ISDLOCK-skip log inside both RelayInvFiltered ForEachNode lambdas and writes the function name as literal text - src/qt/guiutil.cpp: drops __func__ from the loadStyleSheet loadFiles lambda's exception message and writes the function name as literal text - src/qt/guiutil_font.cpp: drops __func__ from the loadFonts importFont lambda's qDebug message and writes the function name as literal text --- src/.clang-tidy | 1 + src/evo/specialtxman.cpp | 2 +- src/instantsend/signing.cpp | 2 +- src/net_processing.cpp | 8 ++++---- src/qt/guiutil.cpp | 2 +- src/qt/guiutil_font.cpp | 2 +- src/rpc/masternode.cpp | 2 +- src/rpc/mempool.cpp | 2 +- src/util/check.h | 37 +++++++++++++++++++++---------------- src/validation.cpp | 4 ++-- 10 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/.clang-tidy b/src/.clang-tidy index e22cf9378e95..d127a4a60f52 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -2,6 +2,7 @@ Checks: ' -*, bugprone-argument-comment, bugprone-use-after-move, +bugprone-lambda-function-name, misc-unused-using-decls, modernize-use-default-member-init, modernize-use-emplace, diff --git a/src/evo/specialtxman.cpp b/src/evo/specialtxman.cpp index 5ff95df30da7..4085b40d454e 100644 --- a/src/evo/specialtxman.cpp +++ b/src/evo/specialtxman.cpp @@ -811,7 +811,7 @@ bool CSpecialTxProcessor::FinishListForBlock(const CBlock& block, gsl::not_null< if (payee != nullptr && dmn.proTxHash == payee->proTxHash && !isMNRewardReallocation) return; if (dmn.pdmnState->nConsecutivePayments == 0) return; if (debugLogs) { - LogPrint(BCLog::MNPAYMENTS, "%s -- MN %s, reset nConsecutivePayments %d->0\n", __func__, + LogPrint(BCLog::MNPAYMENTS, "FinishListForBlock -- MN %s, reset nConsecutivePayments %d->0\n", dmn.proTxHash.ToString(), dmn.pdmnState->nConsecutivePayments); } auto newState = std::make_shared(*dmn.pdmnState); diff --git a/src/instantsend/signing.cpp b/src/instantsend/signing.cpp index 39540d8625c2..802af1dc11c1 100644 --- a/src/instantsend/signing.cpp +++ b/src/instantsend/signing.cpp @@ -212,7 +212,7 @@ bool InstantSendSigner::CheckCanLockAssetUnlock(const CTransaction& tx, bool pri { const auto log_refusal = [&](std::string_view reason) { if (printDebug) { - LogPrint(BCLog::INSTANTSEND, "%s -- txid=%s: asset unlock not lockable: %s\n", __func__, + LogPrint(BCLog::INSTANTSEND, "CheckCanLockAssetUnlock -- txid=%s: asset unlock not lockable: %s\n", tx.GetHash().ToString(), reason); } return false; diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 6bccb711b2ba..2c66ed07a10f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2624,8 +2624,8 @@ void PeerManagerImpl::RelayInvFiltered(const CInv& inv, const CTransaction& rela } } // LOCK(tx_relay->m_bloom_filter_mutex) if (inv.type == MSG_ISDLOCK && PeerReconstructsISLockFromRecsig(*pnode, *peer)) { - LogPrint(BCLog::NET, "%s -- skipping ISDLOCK inv (peer wants recsigs): %s peer=%d\n", - __func__, inv.ToString(), peer->m_id); + LogPrint(BCLog::NET, "RelayInvFiltered -- skipping ISDLOCK inv (peer wants recsigs): %s peer=%d\n", + inv.ToString(), peer->m_id); return; } PushInv(*peer, inv); @@ -2654,8 +2654,8 @@ void PeerManagerImpl::RelayInvFiltered(const CInv& inv, const uint256& relatedTx } } // LOCK(tx_relay->m_bloom_filter_mutex) if (inv.type == MSG_ISDLOCK && PeerReconstructsISLockFromRecsig(*pnode, *peer)) { - LogPrint(BCLog::NET, "%s -- skipping ISDLOCK inv (peer wants recsigs): %s peer=%d\n", - __func__, inv.ToString(), peer->m_id); + LogPrint(BCLog::NET, "RelayInvFiltered -- skipping ISDLOCK inv (peer wants recsigs): %s peer=%d\n", + inv.ToString(), peer->m_id); return; } PushInv(*peer, inv); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 7639b2fab956..97d78a396ac6 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -898,7 +898,7 @@ void loadStyleSheet(bool fForceUpdate) for (const auto& file : vecFiles) { QFile qFile(file); if (!qFile.open(QFile::ReadOnly)) { - throw std::runtime_error(strprintf("%s: Failed to open file: %s", __func__, file.toStdString())); + throw std::runtime_error(strprintf("loadStyleSheet: Failed to open file: %s", file.toStdString())); } QString strStyle = QLatin1String(qFile.readAll()); diff --git a/src/qt/guiutil_font.cpp b/src/qt/guiutil_font.cpp index db86c3b28cc0..ea1e64ca748f 100644 --- a/src/qt/guiutil_font.cpp +++ b/src/qt/guiutil_font.cpp @@ -621,7 +621,7 @@ bool loadFonts() std::vector vecFontIds{}; auto importFont = [&vecFontIds](const QString& font_name) -> void { vecFontIds.push_back(QFontDatabase::addApplicationFont(font_name)); - qDebug() << qstrprintf("%s: %s loaded with id %d", __func__, font_name.toStdString(), vecFontIds.back()); + qDebug() << qstrprintf("loadFonts: %s loaded with id %d", font_name.toStdString(), vecFontIds.back()); }; // Import the embedded Roboto Mono used by fixedPitchFont(use_embedded_font=true) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index e5775c572ac3..a731165fd772 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -458,7 +458,7 @@ static RPCHelpMan masternode_payments() const MnRewardEra mn_reward_era{GetMnRewardEraAfter(pindex->pprev, chainman)}; if (!GetMasternodePayments(node.dmnman->GetListForBlock(pindex->pprev), pindex->pprev, blockSubsidy, nBlockFees, mn_reward_era, Params().GetConsensus(), voutMasternodePayments)) { - LogPrint(BCLog::MNPAYMENTS, "%s -- No masternode to pay (MN list probably empty)\n", __func__); + LogPrint(BCLog::MNPAYMENTS, "%s -- No masternode to pay (MN list probably empty)\n", self.m_name); } UniValue blockObj(UniValue::VOBJ); diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index 44336aef3dc2..536dde24d37b 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -462,7 +462,7 @@ static RPCHelpMan getmempoolancestors() throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool"); } - auto ancestors{mempool.AssumeCalculateMemPoolAncestors(__func__, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)}; + auto ancestors{mempool.AssumeCalculateMemPoolAncestors(self.m_name, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)}; if (!fVerbose) { UniValue o(UniValue::VARR); diff --git a/src/util/check.h b/src/util/check.h index 7ddcebf50674..00951dec8999 100644 --- a/src/util/check.h +++ b/src/util/check.h @@ -20,8 +20,6 @@ class NonFatalCheckError : public std::runtime_error NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func); }; -#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__) - /** Helper for CHECK_NONFATAL() */ template T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion) @@ -32,20 +30,6 @@ T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, co return std::forward(val); } -/** - * Identity function. Throw a NonFatalCheckError when the condition evaluates to false - * - * This should only be used - * - where the condition is assumed to be true, not for error handling or validating user input - * - where a failure to fulfill the condition is recoverable and does not abort the program - * - * For example in RPC code, where it is undesirable to crash the whole program, this can be generally used to replace - * asserts or recoverable logic errors. A NonFatalCheckError in RPC code is caught and passed as a string to the RPC - * caller, which can then report the issue to the developers. - */ -#define CHECK_NONFATAL(condition) \ - inline_check_non_fatal(condition, __FILE__, __LINE__, __func__, #condition) - #if defined(NDEBUG) #error "Cannot compile without assertions!" #endif @@ -69,6 +53,25 @@ T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* f return std::forward(val); } +// All macros may use __func__ inside a lambda, so put them under nolint. +// NOLINTBEGIN(bugprone-lambda-function-name) + +#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__) + +/** + * Identity function. Throw a NonFatalCheckError when the condition evaluates to false + * + * This should only be used + * - where the condition is assumed to be true, not for error handling or validating user input + * - where a failure to fulfill the condition is recoverable and does not abort the program + * + * For example in RPC code, where it is undesirable to crash the whole program, this can be generally used to replace + * asserts or recoverable logic errors. A NonFatalCheckError in RPC code is caught and passed as a string to the RPC + * caller, which can then report the issue to the developers. + */ +#define CHECK_NONFATAL(condition) \ + inline_check_non_fatal(condition, __FILE__, __LINE__, __func__, #condition) + /** Identity function. Abort if the value compares equal to zero */ #define Assert(val) inline_assertion_check(val, __FILE__, __LINE__, __func__, #val) @@ -91,4 +94,6 @@ T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] const char* f throw NonFatalCheckError( \ "Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__) +// NOLINTEND(bugprone-lambda-function-name) + #endif // BITCOIN_UTIL_CHECK_H diff --git a/src/validation.cpp b/src/validation.cpp index 03daf29ef5ce..045a9033e8f1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -7190,8 +7190,8 @@ bool ChainstateManager::ValidatedSnapshotCleanup() fs::path p_old, fs::path p_new, const fs::filesystem_error& err) { - LogPrintf("%s: error renaming file (%s): %s\n", - __func__, fs::PathToString(p_old), err.what()); + LogPrintf("Error renaming path (%s) -> (%s): %s\n", + fs::PathToString(p_old), fs::PathToString(p_new), err.what()); AbortNode(strprintf( "Rename of '%s' -> '%s' failed. " "Cannot clean up the background chainstate leveldb directory.", From 204d8a84a01a5d3d95d13809d5933b3c48b02643 Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Mon, 19 Oct 2026 13:03:30 -0500 Subject: [PATCH 08/10] Merge bitcoin/bitcoin#28530: tests, bug fix: DisconnectedBlockTransactions rewrite followups 9b3da70bd06b45482e7211aa95637a72bd115553 [test] DisconnectedBlockTransactions::DynamicMemoryUsage (glozow) b2d04479647af64ad7cf5ebfb6175251b2f6b72e bugfix: correct DisconnectedBlockTransactions memory usage (stickies-v) f4254e209801d6a790b5f0c251c0b32154a4e3cc assume duplicate transactions are not added to `iters_by_txid` (ismaelsadeeq) 29eb219c1247993378fce06c8f71aab20736c237 move only: move implementation code to disconnected_transactions.cpp (ismaelsadeeq) 81dfeddea70ae5feeaf79062585c2ff9f33c0ca3 refactor: update `MAX_DISCONNECTED_TX_POOL` from kb to bytes (ismaelsadeeq) Pull request description: This PR is a follow-up to fix review comments and a bugfix from #28385 The PR - Updated `DisconnectedBlockTransactions`'s `MAX_DISCONNECTED_TX_POOL` from kb to bytes. - Moved `DisconnectedBlockTransactions` implementation code to `kernel/disconnected_transactions.cpp`. - `AddTransactionsFromBlock` now assume duplicate transactions are not passed by asserting after inserting each transaction to `iters_by_txid`. - Included a Bug fix: In the current master we are underestimating the memory usage of `DisconnectedBlockTransactions`. * When adding and subtracting `cachedInnerUsage` we call `RecursiveDynamicUsage` with `CTransaction` which invokes this [`RecursiveDynamicUsage(const CTransaction& tx)`](https://github.com/bitcoin/bitcoin/blob/6e721c923c87abdb8d99674093d08d8c17bc52c2/src/core_memusage.h#L32) version of `RecursiveDynamicUsage`, the output of that call only account for the memory usage of the inputs and outputs of the `CTransaction`, this omits the memory usage of the `CTransaction` object and the control block. * This PR fixes this bug by calling `RecursiveDynamicUsage` with `CTransactionRef` when adding and subtracting `cachedInnerUsage` which invokes [`RecursiveDynamicUsage(const std::shared_ptr& p)`](https://github.com/bitcoin/bitcoin/blob/6e721c923c87abdb8d99674093d08d8c17bc52c2/src/core_memusage.h#L67) version of `RecursiveDynamicUsage` the output of the calculation accounts for the` CTransaction` object, the control blocks, inputs and outputs memory usage. * see [comment ](https://github.com/bitcoin/bitcoin/pull/28385#discussion_r1322948452) - Added test for DisconnectedBlockTransactions memory limit. ACKs for top commit: stickies-v: ACK 9b3da70bd06b45482e7211aa95637a72bd115553 - nice work! BrandonOdiwuor: re ACK 9b3da70bd06b45482e7211aa95637a72bd115553 glozow: ACK 9b3da70bd06b45482e7211aa95637a72bd115553 Tree-SHA512: 69b9595d09f4d0209038f97081d790cea92ccf63efb94e9e372749979fcbe527f7f17a8e454720cedd12021be0c8e11cf99874625d3dafd9ec602b12dbeb4098 Dash adaptations: - src/Makefile.test.include: test/disconnected_transactions.cpp added after descriptor_tests.cpp, keeping Dash's dynamic_activation_thresholds and evo_* test entries - src/validation.cpp: Dash-only Chainstate::MarkConflictingBlock now uses MAX_DISCONNECTED_TX_POOL_BYTES instead of MAX_DISCONNECTED_TX_POOL_SIZE * 1000 (constant renamed upstream) - src/test/validation_chainstatemanager_tests.cpp: Dash-only chainstatemanager_evodb_snapshot_only_flush_restart test now uses MAX_DISCONNECTED_TX_POOL_BYTES (constant renamed upstream) --- src/Makefile.am | 2 + src/Makefile.test.include | 1 + src/bench/disconnected_transactions.cpp | 2 +- src/kernel/disconnected_transactions.cpp | 90 ++++++++++++++++++ src/kernel/disconnected_transactions.h | 85 +++-------------- src/test/disconnected_transactions.cpp | 95 +++++++++++++++++++ .../validation_chainstatemanager_tests.cpp | 4 +- src/validation.cpp | 6 +- 8 files changed, 206 insertions(+), 79 deletions(-) create mode 100644 src/kernel/disconnected_transactions.cpp create mode 100644 src/test/disconnected_transactions.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 581d6a76d2bb..ad095c971a9f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -604,6 +604,7 @@ libbitcoin_node_a_SOURCES = \ kernel/coinstats.cpp \ kernel/context.cpp \ kernel/cs_main.cpp \ + kernel/disconnected_transactions.cpp \ kernel/mempool_persist.cpp \ llmq/blockprocessor.cpp \ llmq/commitment.cpp \ @@ -1317,6 +1318,7 @@ libdashkernel_la_SOURCES = \ kernel/coinstats.cpp \ kernel/context.cpp \ kernel/cs_main.cpp \ + kernel/disconnected_transactions.cpp \ kernel/mempool_persist.cpp \ key.cpp \ key_io.cpp \ diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 90a0ed75ed64..7fa85505e0b2 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -109,6 +109,7 @@ BITCOIN_TESTS =\ test/dip0020opcodes_tests.cpp \ test/dip14_tests.cpp \ test/descriptor_tests.cpp \ + test/disconnected_transactions.cpp \ test/dynamic_activation_thresholds_tests.cpp \ test/evo_assetlocks_tests.cpp \ test/evo_cbtx_tests.cpp \ diff --git a/src/bench/disconnected_transactions.cpp b/src/bench/disconnected_transactions.cpp index 264c0aa1e86f..91ce904dd941 100644 --- a/src/bench/disconnected_transactions.cpp +++ b/src/bench/disconnected_transactions.cpp @@ -73,7 +73,7 @@ static ReorgTxns CreateBlocks(size_t num_not_shared) static void Reorg(const ReorgTxns& reorg) { - DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_SIZE * 1000}; + DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_BYTES}; // Disconnect block const auto evicted = disconnectpool.AddTransactionsFromBlock(reorg.disconnected_txns); assert(evicted.empty()); diff --git a/src/kernel/disconnected_transactions.cpp b/src/kernel/disconnected_transactions.cpp new file mode 100644 index 000000000000..f865fed688cc --- /dev/null +++ b/src/kernel/disconnected_transactions.cpp @@ -0,0 +1,90 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include +#include +#include +#include + +#include +#include + +// It's almost certainly a logic bug if we don't clear out queuedTx before +// destruction, as we add to it while disconnecting blocks, and then we +// need to re-process remaining transactions to ensure mempool consistency. +// For now, assert() that we've emptied out this object on destruction. +// This assert() can always be removed if the reorg-processing code were +// to be refactored such that this assumption is no longer true (for +// instance if there was some other way we cleaned up the mempool after a +// reorg, besides draining this object). +DisconnectedBlockTransactions::~DisconnectedBlockTransactions() +{ + assert(queuedTx.empty()); + assert(iters_by_txid.empty()); + assert(cachedInnerUsage == 0); +} + +std::vector DisconnectedBlockTransactions::LimitMemoryUsage() +{ + std::vector evicted; + + while (!queuedTx.empty() && DynamicMemoryUsage() > m_max_mem_usage) { + evicted.emplace_back(queuedTx.front()); + cachedInnerUsage -= RecursiveDynamicUsage(queuedTx.front()); + iters_by_txid.erase(queuedTx.front()->GetHash()); + queuedTx.pop_front(); + } + return evicted; +} + +size_t DisconnectedBlockTransactions::DynamicMemoryUsage() const +{ + return cachedInnerUsage + memusage::DynamicUsage(iters_by_txid) + memusage::DynamicUsage(queuedTx); +} + +[[nodiscard]] std::vector DisconnectedBlockTransactions::AddTransactionsFromBlock(const std::vector& vtx) +{ + iters_by_txid.reserve(iters_by_txid.size() + vtx.size()); + for (auto block_it = vtx.rbegin(); block_it != vtx.rend(); ++block_it) { + auto it = queuedTx.insert(queuedTx.end(), *block_it); + auto [_, inserted] = iters_by_txid.emplace((*block_it)->GetHash(), it); + assert(inserted); // callers may never pass multiple transactions with the same txid + cachedInnerUsage += RecursiveDynamicUsage(*block_it); + } + return LimitMemoryUsage(); +} + +void DisconnectedBlockTransactions::removeForBlock(const std::vector& vtx) +{ + // Short-circuit in the common case of a block being added to the tip + if (queuedTx.empty()) { + return; + } + for (const auto& tx : vtx) { + auto iter = iters_by_txid.find(tx->GetHash()); + if (iter != iters_by_txid.end()) { + auto list_iter = iter->second; + iters_by_txid.erase(iter); + cachedInnerUsage -= RecursiveDynamicUsage(*list_iter); + queuedTx.erase(list_iter); + } + } +} + +void DisconnectedBlockTransactions::clear() +{ + cachedInnerUsage = 0; + iters_by_txid.clear(); + queuedTx.clear(); +} + +std::list DisconnectedBlockTransactions::take() +{ + std::list ret = std::move(queuedTx); + clear(); + return ret; +} diff --git a/src/kernel/disconnected_transactions.h b/src/kernel/disconnected_transactions.h index 7db39ba5cae3..401ec435e6bd 100644 --- a/src/kernel/disconnected_transactions.h +++ b/src/kernel/disconnected_transactions.h @@ -5,8 +5,6 @@ #ifndef BITCOIN_KERNEL_DISCONNECTED_TRANSACTIONS_H #define BITCOIN_KERNEL_DISCONNECTED_TRANSACTIONS_H -#include -#include #include #include @@ -14,8 +12,8 @@ #include #include -/** Maximum kilobytes for transactions to store for processing during reorg */ -static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20'000; +/** Maximum bytes for transactions to store for processing during reorg */ +static const unsigned int MAX_DISCONNECTED_TX_POOL_BYTES{20'000'000}; /** * DisconnectedBlockTransactions @@ -38,8 +36,7 @@ static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20'000; */ class DisconnectedBlockTransactions { private: - /** Cached dynamic memory usage for the CTransactions (memory for the shared pointers is - * included in the container calculations). */ + /** Cached dynamic memory usage for the `CTransactionRef`s */ uint64_t cachedInnerUsage = 0; const size_t m_max_mem_usage; std::list queuedTx; @@ -47,39 +44,15 @@ class DisconnectedBlockTransactions { std::unordered_map iters_by_txid; /** Trim the earliest-added entries until we are within memory bounds. */ - std::vector LimitMemoryUsage() - { - std::vector evicted; - - while (!queuedTx.empty() && DynamicMemoryUsage() > m_max_mem_usage) { - evicted.emplace_back(queuedTx.front()); - cachedInnerUsage -= RecursiveDynamicUsage(*queuedTx.front()); - iters_by_txid.erase(queuedTx.front()->GetHash()); - queuedTx.pop_front(); - } - return evicted; - } + std::vector LimitMemoryUsage(); public: - DisconnectedBlockTransactions(size_t max_mem_usage) : m_max_mem_usage{max_mem_usage} {} + DisconnectedBlockTransactions(size_t max_mem_usage) + : m_max_mem_usage{max_mem_usage} {} - // It's almost certainly a logic bug if we don't clear out queuedTx before - // destruction, as we add to it while disconnecting blocks, and then we - // need to re-process remaining transactions to ensure mempool consistency. - // For now, assert() that we've emptied out this object on destruction. - // This assert() can always be removed if the reorg-processing code were - // to be refactored such that this assumption is no longer true (for - // instance if there was some other way we cleaned up the mempool after a - // reorg, besides draining this object). - ~DisconnectedBlockTransactions() { - assert(queuedTx.empty()); - assert(iters_by_txid.empty()); - assert(cachedInnerUsage == 0); - } + ~DisconnectedBlockTransactions(); - size_t DynamicMemoryUsage() const { - return cachedInnerUsage + memusage::DynamicUsage(iters_by_txid) + memusage::DynamicUsage(queuedTx); - } + size_t DynamicMemoryUsage() const; /** Add transactions from the block, iterating through vtx in reverse order. Callers should call * this function for blocks in descending order by block height. @@ -88,50 +61,16 @@ class DisconnectedBlockTransactions { * corresponding entry in iters_by_txid. * @returns vector of transactions that were evicted for size-limiting. */ - [[nodiscard]] std::vector AddTransactionsFromBlock(const std::vector& vtx) - { - iters_by_txid.reserve(iters_by_txid.size() + vtx.size()); - for (auto block_it = vtx.rbegin(); block_it != vtx.rend(); ++block_it) { - auto it = queuedTx.insert(queuedTx.end(), *block_it); - iters_by_txid.emplace((*block_it)->GetHash(), it); - cachedInnerUsage += RecursiveDynamicUsage(**block_it); - } - return LimitMemoryUsage(); - } + [[nodiscard]] std::vector AddTransactionsFromBlock(const std::vector& vtx); /** Remove any entries that are in this block. */ - void removeForBlock(const std::vector& vtx) - { - // Short-circuit in the common case of a block being added to the tip - if (queuedTx.empty()) { - return; - } - for (const auto& tx : vtx) { - auto iter = iters_by_txid.find(tx->GetHash()); - if (iter != iters_by_txid.end()) { - auto list_iter = iter->second; - iters_by_txid.erase(iter); - cachedInnerUsage -= RecursiveDynamicUsage(**list_iter); - queuedTx.erase(list_iter); - } - } - } + void removeForBlock(const std::vector& vtx); size_t size() const { return queuedTx.size(); } - void clear() - { - cachedInnerUsage = 0; - iters_by_txid.clear(); - queuedTx.clear(); - } + void clear(); /** Clear all data structures and return the list of transactions. */ - std::list take() - { - std::list ret = std::move(queuedTx); - clear(); - return ret; - } + std::list take(); }; #endif // BITCOIN_KERNEL_DISCONNECTED_TRANSACTIONS_H diff --git a/src/test/disconnected_transactions.cpp b/src/test/disconnected_transactions.cpp new file mode 100644 index 000000000000..d4dc124b7b10 --- /dev/null +++ b/src/test/disconnected_transactions.cpp @@ -0,0 +1,95 @@ +// Copyright (c) 2023 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +// +#include +#include +#include +#include + +BOOST_FIXTURE_TEST_SUITE(disconnected_transactions, TestChain100Setup) + +//! Tests that DisconnectedBlockTransactions limits its own memory properly +BOOST_AUTO_TEST_CASE(disconnectpool_memory_limits) +{ + // Use the coinbase transactions from TestChain100Setup. It doesn't matter whether these + // transactions would realistically be in a block together, they just need distinct txids and + // uniform size for this test to work. + std::vector block_vtx(m_coinbase_txns); + BOOST_CHECK_EQUAL(block_vtx.size(), 100); + + // Roughly estimate sizes to sanity check that DisconnectedBlockTransactions::DynamicMemoryUsage + // is within an expected range. + + // Overhead for the hashmap depends on number of buckets + std::unordered_map temp_map; + temp_map.reserve(1); + const size_t MAP_1{memusage::DynamicUsage(temp_map)}; + temp_map.reserve(100); + const size_t MAP_100{memusage::DynamicUsage(temp_map)}; + + const size_t TX_USAGE{RecursiveDynamicUsage(block_vtx.front())}; + for (const auto& tx : block_vtx) + BOOST_CHECK_EQUAL(RecursiveDynamicUsage(tx), TX_USAGE); + + // Our overall formula is unordered map overhead + usage per entry. + // Implementations may vary, but we're trying to guess the usage of data structures. + const size_t ENTRY_USAGE_ESTIMATE{ + TX_USAGE + // list entry: 2 pointers (next pointer and prev pointer) + element itself + + memusage::MallocUsage((2 * sizeof(void*)) + sizeof(decltype(block_vtx)::value_type)) + // unordered map: 1 pointer for the hashtable + key and value + + memusage::MallocUsage(sizeof(void*) + sizeof(decltype(temp_map)::key_type) + + sizeof(decltype(temp_map)::value_type))}; + + // DisconnectedBlockTransactions that's just big enough for 1 transaction. + { + DisconnectedBlockTransactions disconnectpool{MAP_1 + ENTRY_USAGE_ESTIMATE}; + // Add just 2 (and not all 100) transactions to keep the unordered map's hashtable overhead + // to a minimum and avoid all (instead of all but 1) transactions getting evicted. + std::vector two_txns({block_vtx.at(0), block_vtx.at(1)}); + auto evicted_txns{disconnectpool.AddTransactionsFromBlock(two_txns)}; + BOOST_CHECK(disconnectpool.DynamicMemoryUsage() <= MAP_1 + ENTRY_USAGE_ESTIMATE); + + // Only 1 transaction can be kept + BOOST_CHECK_EQUAL(1, evicted_txns.size()); + // Transactions are added from back to front and eviction is FIFO. + BOOST_CHECK_EQUAL(block_vtx.at(1), evicted_txns.front()); + + disconnectpool.clear(); + } + + // DisconnectedBlockTransactions with a comfortable maximum memory usage so that nothing is evicted. + // Record usage so we can check size limiting in the next test. + size_t usage_full{0}; + { + const size_t USAGE_100_OVERESTIMATE{MAP_100 + ENTRY_USAGE_ESTIMATE * 100}; + DisconnectedBlockTransactions disconnectpool{USAGE_100_OVERESTIMATE}; + auto evicted_txns{disconnectpool.AddTransactionsFromBlock(block_vtx)}; + BOOST_CHECK_EQUAL(evicted_txns.size(), 0); + BOOST_CHECK(disconnectpool.DynamicMemoryUsage() <= USAGE_100_OVERESTIMATE); + + usage_full = disconnectpool.DynamicMemoryUsage(); + + disconnectpool.clear(); + } + + // DisconnectedBlockTransactions that's just a little too small for all of the transactions. + { + const size_t MAX_MEMUSAGE_99{usage_full - sizeof(void*)}; + DisconnectedBlockTransactions disconnectpool{MAX_MEMUSAGE_99}; + auto evicted_txns{disconnectpool.AddTransactionsFromBlock(block_vtx)}; + BOOST_CHECK(disconnectpool.DynamicMemoryUsage() <= MAX_MEMUSAGE_99); + + // Only 1 transaction needed to be evicted + BOOST_CHECK_EQUAL(1, evicted_txns.size()); + + // Transactions are added from back to front and eviction is FIFO. + // The last transaction of block_vtx should be the first to be evicted. + BOOST_CHECK_EQUAL(block_vtx.back(), evicted_txns.front()); + + disconnectpool.clear(); + } +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index ae988f0e7844..fd4faa38d45c 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -637,7 +637,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_snapshot_init, SnapshotTestSetup) // it will initialize instead of attempting to complete validation. // // Note that this is not a realistic use of DisconnectTip(). - DisconnectedBlockTransactions unused_pool{MAX_DISCONNECTED_TX_POOL_SIZE * 1000}; + DisconnectedBlockTransactions unused_pool{MAX_DISCONNECTED_TX_POOL_BYTES}; BlockValidationState unused_state; { LOCK2(::cs_main, bg_chainstate.MempoolMutex()); @@ -808,7 +808,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_evodb_snapshot_only_flush_restart, Sna // Keep this M2 marker-independence test below completion height; #25740 now // completes and cleans up immediately on restart when background is at base. - DisconnectedBlockTransactions unused_pool{MAX_DISCONNECTED_TX_POOL_SIZE * 1000}; + DisconnectedBlockTransactions unused_pool{MAX_DISCONNECTED_TX_POOL_BYTES}; BlockValidationState unused_state; { LOCK2(::cs_main, background_chainstate->MempoolMutex()); diff --git a/src/validation.cpp b/src/validation.cpp index 045a9033e8f1..470dc215b5dc 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3825,7 +3825,7 @@ bool Chainstate::ActivateBestChainStep(BlockValidationState& state, CBlockIndex* // Disconnect active blocks which are no longer in the best chain. bool fBlocksDisconnected = false; - DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_SIZE * 1000}; + DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_BYTES}; while (m_chain.Tip() && m_chain.Tip() != pindexFork) { if (!DisconnectTip(state, &disconnectpool)) { // This is likely a fatal error, but keep the mempool consistent, @@ -4172,7 +4172,7 @@ bool Chainstate::InvalidateBlock(BlockValidationState& state, CBlockIndex* pinde // ActivateBestChain considers blocks already in m_chain // unconditionally valid already, so force disconnect away from it. - DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_SIZE * 1000}; + DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_BYTES}; bool ret = DisconnectTip(state, &disconnectpool); // DisconnectTip will add transactions to disconnectpool. // Adjust the mempool to be consistent with the new tip, adding @@ -4309,7 +4309,7 @@ bool Chainstate::MarkConflictingBlock(BlockValidationState& state, CBlockIndex * { LOCK(MempoolMutex()); // Lock for as long as disconnectpool is in scope to make sure UpdateMempoolForReorg is called after DisconnectTip without unlocking in between - DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_SIZE * 1000}; + DisconnectedBlockTransactions disconnectpool{MAX_DISCONNECTED_TX_POOL_BYTES}; while (m_chain.Contains(pindex)) { const CBlockIndex* pindexOldTip = m_chain.Tip(); pindex_was_in_chain = true; From 2031251127c4fb064b767b4872aefbccb4f1d81d Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Mon, 19 Oct 2026 13:05:43 -0500 Subject: [PATCH 09/10] Merge bitcoin/bitcoin#28224: shutdown: Destroy kernel last, make test shutdown order consistent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit c1144f0076339c775f41d4b5fcfdc72191440d96 tests: Reset node context members on ~BasicTestingSetup (TheCharlatan) 9759af17ff7c28eb909cb73f62b78c90851ab74d shutdown: Destroy kernel last (TheCharlatan) Pull request description: The destruction/resetting of node context members in the tests should roughly follow the behavior of the `Shutdown` function in `init.cpp`. This was originally requested by MarcoFalke in this [comment](https://github.com/bitcoin/bitcoin/pull/25065#discussion_r890161249) in response to the [original pull request](https://github.com/bitcoin/bitcoin/pull/25065) introducing the `kernel::Context`. ACKs for top commit: maflcko: ACK c1144f0076339c775f41d4b5fcfdc72191440d96 🗣 achow101: ACK c1144f0076339c775f41d4b5fcfdc72191440d96 ryanofsky: Code review ACK c1144f0076339c775f41d4b5fcfdc72191440d96. No code changes since last review, just updated commits and descriptions Tree-SHA512: 819bb85ff82a5c6c60e429674d5684f3692fe9062500d00a87b361cc59e6bda145be21b5a4466dee6791faed910cbde4d26baab325bf6daa1813af13a63588ff Dash adaptations: - src/init.cpp: moved node.kernel.reset() after node.scheduler.reset() inside Dash's split Shutdown() (part 2), keeping PrepareShutdown/RestartRequested logic intact - src/test/util/setup_common.cpp: reordered ChainTestingSetup dtor to mempool, fee_estimator, chainman, scheduler after Dash's mn_sync reset; Dash already reset fee_estimator and scheduler last --- src/init.cpp | 2 +- src/test/util/setup_common.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 79375e46740a..7a4213320104 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -511,11 +511,11 @@ void Shutdown(NodeContext& node) PrepareShutdown(node); } // Shutdown part 2: delete wallet instance - node.kernel.reset(); node.mempool.reset(); node.fee_estimator.reset(); node.chainman.reset(); node.scheduler.reset(); + node.kernel.reset(); RemovePidFile(*node.args); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index a48562906521..eb28ea2f3344 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -233,6 +233,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve BasicTestingSetup::~BasicTestingSetup() { + m_node.kernel.reset(); SetMockTime(0s); // Reset mocktime for following tests LogInstance().DisconnectTestLogger(); // Close the disk-backed databases before deleting their data directory. @@ -295,9 +296,9 @@ ChainTestingSetup::~ChainTestingSetup() GetMainSignals().FlushBackgroundCallbacks(); GetMainSignals().UnregisterBackgroundSignalScheduler(); m_node.mn_sync.reset(); - m_node.chainman.reset(); m_node.mempool.reset(); m_node.fee_estimator.reset(); + m_node.chainman.reset(); m_node.scheduler.reset(); } From ed006411e390ff4ef3c625b191cc6e707dafdce4 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Sun, 18 Oct 2026 12:54:12 +0700 Subject: [PATCH 10/10] build: revert passing sanitizer flags to libsecp256k1 It is part of bitcoin#28875, backported in #7503. Since that merge every sanitizer job compiles libsecp256k1 with -fsanitize, so the TSan job instruments all of secp256k1's ECDSA code. It reverts _only_ libsecp256k1 sanitizer, other C code in the repo is still profiled. The UBSan suppression lines that came with the backport are kept: they are harmless without the instrumentation. --- configure.ac | 3 --- 1 file changed, 3 deletions(-) diff --git a/configure.ac b/configure.ac index d36c49ebfdf6..97cef0cc972a 100644 --- a/configure.ac +++ b/configure.ac @@ -2062,9 +2062,6 @@ CPPFLAGS_TEMP="$CPPFLAGS" unset CPPFLAGS CPPFLAGS="$CPPFLAGS_TEMP" -if test -n "$use_sanitizers"; then - export SECP_CFLAGS="$SECP_CFLAGS $SANITIZER_CFLAGS" -fi dnl The ECDH module is required by the wallet's Platform key provider dnl (DashPay contact request encryption, wallet/platformkeys.cpp). ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-ecdh --disable-openssl-tests"