From 9a23079df33d9d728bf7435fc1d07d0f414f7429 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Tue, 9 May 2023 11:58:07 -0400 Subject: [PATCH 1/5] p2p: Avoid prematurely clearing download state for other peers Github-Pull: #27608 Rebased-From: 52e52071e01f4e98d87a47e1d5f3c5c3cc6dbaf4 --- src/net_processing.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 68bd91297c1..8a2ae2c18ec 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -882,8 +882,11 @@ private: /** Remove this block from our tracked requested blocks. Called if: * - the block has been received from a peer * - the request for the block has timed out + * If "from_peer" is specified, then only remove the block if it is in + * flight from that peer (to avoid one peer's network traffic from + * affecting another's state). */ - void RemoveBlockRequest(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + void RemoveBlockRequest(const uint256& hash, std::optional from_peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /* Mark a block as in flight * Returns false, still setting pit, if the block was already in flight from the same peer @@ -1119,7 +1122,7 @@ bool PeerManagerImpl::IsBlockRequested(const uint256& hash) return mapBlocksInFlight.find(hash) != mapBlocksInFlight.end(); } -void PeerManagerImpl::RemoveBlockRequest(const uint256& hash) +void PeerManagerImpl::RemoveBlockRequest(const uint256& hash, std::optional from_peer) { auto it = mapBlocksInFlight.find(hash); if (it == mapBlocksInFlight.end()) { @@ -1128,6 +1131,12 @@ void PeerManagerImpl::RemoveBlockRequest(const uint256& hash) } auto [node_id, list_it] = it->second; + + if (from_peer && node_id != *from_peer) { + // Block was requested by another peer + return; + } + CNodeState *state = State(node_id); assert(state != nullptr); @@ -1163,7 +1172,7 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, st } // Make sure it's not listed somewhere already. - RemoveBlockRequest(hash); + RemoveBlockRequest(hash, std::nullopt); std::list::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(), {&block, std::unique_ptr(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)}); @@ -3154,6 +3163,11 @@ void PeerManagerImpl::ProcessBlock(CNode& node, const std::shared_ptr(); + // In case this block came from a different peer than we requested + // from, we can erase the block request now anyway (as we just stored + // this block to disk). + LOCK(cs_main); + RemoveBlockRequest(block->GetHash(), std::nullopt); } else { LOCK(cs_main); mapBlockSource.erase(block->GetHash()); @@ -4301,7 +4315,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, PartiallyDownloadedBlock& partialBlock = *(*queuedBlockIt)->partialBlock; ReadStatus status = partialBlock.InitData(cmpctblock, vExtraTxnForCompact); if (status == READ_STATUS_INVALID) { - RemoveBlockRequest(pindex->GetBlockHash()); // Reset in-flight state in case Misbehaving does not result in a disconnect + RemoveBlockRequest(pindex->GetBlockHash(), pfrom.GetId()); // Reset in-flight state in case Misbehaving does not result in a disconnect Misbehaving(*peer, 100, "invalid compact block"); return; } else if (status == READ_STATUS_FAILED) { @@ -4396,7 +4410,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, // process from some other peer. We do this after calling // ProcessNewBlock so that a malleated cmpctblock announcement // can't be used to interfere with block relay. - RemoveBlockRequest(pblock->GetHash()); + RemoveBlockRequest(pblock->GetHash(), std::nullopt); } } return; @@ -4428,7 +4442,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, PartiallyDownloadedBlock& partialBlock = *it->second.second->partialBlock; ReadStatus status = partialBlock.FillBlock(*pblock, resp.txn); if (status == READ_STATUS_INVALID) { - RemoveBlockRequest(resp.blockhash); // Reset in-flight state in case Misbehaving does not result in a disconnect + RemoveBlockRequest(resp.blockhash, pfrom.GetId()); // Reset in-flight state in case Misbehaving does not result in a disconnect Misbehaving(*peer, 100, "invalid compact block/non-matching block transactions"); return; } else if (status == READ_STATUS_FAILED) { @@ -4454,7 +4468,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, // though the block was successfully read, and rely on the // handling in ProcessNewBlock to ensure the block index is // updated, etc. - RemoveBlockRequest(resp.blockhash); // it is now an empty pointer + RemoveBlockRequest(resp.blockhash, pfrom.GetId()); // it is now an empty pointer fBlockRead = true; // mapBlockSource is used for potentially punishing peers and // updating which peers send us compact blocks, so the race @@ -4543,7 +4557,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, // Always process the block if we requested it, since we may // need it even when it's not a candidate for a new best tip. forceProcessing = IsBlockRequested(hash); - RemoveBlockRequest(hash); + RemoveBlockRequest(hash, pfrom.GetId()); // mapBlockSource is only used for punishing peers and setting // which peers send us compact blocks, so the race between here and // cs_main in ProcessNewBlock is fine. From 1adbcd302fe3b937e9078fa0e21b3252a0e642de Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Mon, 8 May 2023 15:37:11 +1000 Subject: [PATCH 2/5] txmempool: have CompareDepthAndScore sort missing txs first We use CompareDepthAndScore to choose an order of txs to inv. Rather than sorting txs that have been evicted from the mempool at the end of the list, sort them at the beginning so they are removed from the queue immediately. Github-Pull: #27610 Rebased-From: 228e9201efb5574b1b96bb924de1d2e8dd1317f3 --- src/txmempool.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 032dfee3ea6..2111367f759 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -754,11 +754,16 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid) { + /* Return `true` if hasha should be considered sooner than hashb. Namely when: + * a is not in the mempool, but b is + * both are in the mempool and a has fewer ancestors than b + * both are in the mempool and a has a higher score than b + */ LOCK(cs); - indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha); - if (i == mapTx.end()) return false; indexed_transaction_set::const_iterator j = wtxid ? get_iter_from_wtxid(hashb) : mapTx.find(hashb); - if (j == mapTx.end()) return true; + if (j == mapTx.end()) return false; + indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha); + if (i == mapTx.end()) return true; uint64_t counta = i->GetCountWithAncestors(); uint64_t countb = j->GetCountWithAncestors(); if (counta == countb) { From 7ef71e30c9bc108e29dec008490db5a0fa051629 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Mon, 8 May 2023 17:14:53 +1000 Subject: [PATCH 3/5] net_processing: Boost inv trickle rate If transactions are being added to the mempool at a rate faster than 7tx/s (INVENTORY_BROADCAST_PER_SECOND) then peers' inventory_to_send queue can become relatively large. If this happens, increase the number of txids we include in an INV message (normally capped at 35) by 5 for each 1000 txids in the queue. This will tend to clear a temporary excess out reasonably quickly; an excess of 4000 invs to send will be cleared down to 1000 in about 30 minutes, while an excess of 20000 invs would be cleared down to 1000 in about 60 minutes. Github-Pull: #27610 Rebased-From: 5b3406094f2679dfb3763de4414257268565b943 --- src/net_processing.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 8a2ae2c18ec..b55c593934a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -5674,7 +5674,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto) // especially since we have many peers and some will draw much shorter delays. unsigned int nRelayedTransactions = 0; LOCK(tx_relay->m_bloom_filter_mutex); - while (!vInvTx.empty() && nRelayedTransactions < INVENTORY_BROADCAST_MAX) { + size_t broadcast_max{INVENTORY_BROADCAST_MAX + (tx_relay->m_tx_inventory_to_send.size()/1000)*5}; + broadcast_max = std::min(1000, broadcast_max); + while (!vInvTx.empty() && nRelayedTransactions < broadcast_max) { // Fetch the top element from the heap std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder); std::set::iterator it = vInvTx.back(); From 3ea4a115c213fd67c80a0ad2301b170b805303c9 Mon Sep 17 00:00:00 2001 From: fanquake Date: Thu, 11 May 2023 18:22:01 +0100 Subject: [PATCH 4/5] build: bump version to v25.0rc2 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 102cf00e563..e60ddbea7d0 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ([2.69]) define(_CLIENT_VERSION_MAJOR, 25) define(_CLIENT_VERSION_MINOR, 0) define(_CLIENT_VERSION_BUILD, 0) -define(_CLIENT_VERSION_RC, 1) +define(_CLIENT_VERSION_RC, 2) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2023) define(_COPYRIGHT_HOLDERS,[The %s developers]) From 49a2d66f4e3a01aa697c1b9e5994fd8300953951 Mon Sep 17 00:00:00 2001 From: fanquake Date: Thu, 11 May 2023 18:26:09 +0100 Subject: [PATCH 5/5] doc: update manual pages for v25.0rc2 --- doc/man/bitcoin-cli.1 | 6 +++--- doc/man/bitcoin-qt.1 | 6 +++--- doc/man/bitcoin-tx.1 | 6 +++--- doc/man/bitcoin-util.1 | 6 +++--- doc/man/bitcoin-wallet.1 | 6 +++--- doc/man/bitcoind.1 | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/doc/man/bitcoin-cli.1 b/doc/man/bitcoin-cli.1 index 70c9fb039a4..b6a14006e5a 100644 --- a/doc/man/bitcoin-cli.1 +++ b/doc/man/bitcoin-cli.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-CLI "1" "April 2023" "bitcoin-cli v25.0.0rc1" "User Commands" +.TH BITCOIN-CLI "1" "May 2023" "bitcoin-cli v25.0.0rc2" "User Commands" .SH NAME -bitcoin-cli \- manual page for bitcoin-cli v25.0.0rc1 +bitcoin-cli \- manual page for bitcoin-cli v25.0.0rc2 .SH SYNOPSIS .B bitcoin-cli [\fI\,options\/\fR] \fI\, \/\fR[\fI\,params\/\fR] \fI\,Send command to Bitcoin Core\/\fR @@ -15,7 +15,7 @@ bitcoin-cli \- manual page for bitcoin-cli v25.0.0rc1 .B bitcoin-cli [\fI\,options\/\fR] \fI\,help Get help for a command\/\fR .SH DESCRIPTION -Bitcoin Core RPC client version v25.0.0rc1 +Bitcoin Core RPC client version v25.0.0rc2 .SH OPTIONS .HP \-? diff --git a/doc/man/bitcoin-qt.1 b/doc/man/bitcoin-qt.1 index bac94df373e..96a552ebc4a 100644 --- a/doc/man/bitcoin-qt.1 +++ b/doc/man/bitcoin-qt.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-QT "1" "April 2023" "bitcoin-qt v25.0.0rc1" "User Commands" +.TH BITCOIN-QT "1" "May 2023" "bitcoin-qt v25.0.0rc2" "User Commands" .SH NAME -bitcoin-qt \- manual page for bitcoin-qt v25.0.0rc1 +bitcoin-qt \- manual page for bitcoin-qt v25.0.0rc2 .SH SYNOPSIS .B bitcoin-qt [\fI\,command-line options\/\fR] .SH DESCRIPTION -Bitcoin Core version v25.0.0rc1 +Bitcoin Core version v25.0.0rc2 .SH OPTIONS .HP \-? diff --git a/doc/man/bitcoin-tx.1 b/doc/man/bitcoin-tx.1 index 97458c8efdb..a9c70c93344 100644 --- a/doc/man/bitcoin-tx.1 +++ b/doc/man/bitcoin-tx.1 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-TX "1" "April 2023" "bitcoin-tx v25.0.0rc1" "User Commands" +.TH BITCOIN-TX "1" "May 2023" "bitcoin-tx v25.0.0rc2" "User Commands" .SH NAME -bitcoin-tx \- manual page for bitcoin-tx v25.0.0rc1 +bitcoin-tx \- manual page for bitcoin-tx v25.0.0rc2 .SH SYNOPSIS .B bitcoin-tx [\fI\,options\/\fR] \fI\, \/\fR[\fI\,commands\/\fR] \fI\,Update hex-encoded bitcoin transaction\/\fR @@ -9,7 +9,7 @@ bitcoin-tx \- manual page for bitcoin-tx v25.0.0rc1 .B bitcoin-tx [\fI\,options\/\fR] \fI\,-create \/\fR[\fI\,commands\/\fR] \fI\,Create hex-encoded bitcoin transaction\/\fR .SH DESCRIPTION -Bitcoin Core bitcoin\-tx utility version v25.0.0rc1 +Bitcoin Core bitcoin\-tx utility version v25.0.0rc2 .SH OPTIONS .HP \-? diff --git a/doc/man/bitcoin-util.1 b/doc/man/bitcoin-util.1 index 2627571fc9a..0d997e24830 100644 --- a/doc/man/bitcoin-util.1 +++ b/doc/man/bitcoin-util.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-UTIL "1" "April 2023" "bitcoin-util v25.0.0rc1" "User Commands" +.TH BITCOIN-UTIL "1" "May 2023" "bitcoin-util v25.0.0rc2" "User Commands" .SH NAME -bitcoin-util \- manual page for bitcoin-util v25.0.0rc1 +bitcoin-util \- manual page for bitcoin-util v25.0.0rc2 .SH SYNOPSIS .B bitcoin-util [\fI\,options\/\fR] [\fI\,commands\/\fR] \fI\,Do stuff\/\fR .SH DESCRIPTION -Bitcoin Core bitcoin\-util utility version v25.0.0rc1 +Bitcoin Core bitcoin\-util utility version v25.0.0rc2 .SH OPTIONS .HP \-? diff --git a/doc/man/bitcoin-wallet.1 b/doc/man/bitcoin-wallet.1 index d26e5fa1bf6..0919f84ecf4 100644 --- a/doc/man/bitcoin-wallet.1 +++ b/doc/man/bitcoin-wallet.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIN-WALLET "1" "April 2023" "bitcoin-wallet v25.0.0rc1" "User Commands" +.TH BITCOIN-WALLET "1" "May 2023" "bitcoin-wallet v25.0.0rc2" "User Commands" .SH NAME -bitcoin-wallet \- manual page for bitcoin-wallet v25.0.0rc1 +bitcoin-wallet \- manual page for bitcoin-wallet v25.0.0rc2 .SH DESCRIPTION -Bitcoin Core bitcoin\-wallet version v25.0.0rc1 +Bitcoin Core bitcoin\-wallet version v25.0.0rc2 .PP bitcoin\-wallet is an offline tool for creating and interacting with Bitcoin Core wallet files. By default bitcoin\-wallet will act on wallets in the default mainnet wallet directory in the datadir. diff --git a/doc/man/bitcoind.1 b/doc/man/bitcoind.1 index 6aea1a1fe13..e2193b5e529 100644 --- a/doc/man/bitcoind.1 +++ b/doc/man/bitcoind.1 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH BITCOIND "1" "April 2023" "bitcoind v25.0.0rc1" "User Commands" +.TH BITCOIND "1" "May 2023" "bitcoind v25.0.0rc2" "User Commands" .SH NAME -bitcoind \- manual page for bitcoind v25.0.0rc1 +bitcoind \- manual page for bitcoind v25.0.0rc2 .SH SYNOPSIS .B bitcoind [\fI\,options\/\fR] \fI\,Start Bitcoin Core\/\fR .SH DESCRIPTION -Bitcoin Core version v25.0.0rc1 +Bitcoin Core version v25.0.0rc2 .SH OPTIONS .HP \-?