Skip to content

Commit 3368e0a

Browse files
jnewberyFabcien
authored andcommitted
[net processing] Move hashContinue to net processing
Summary: ``` Also rename to m_continuation_block to better communicate meaning. ``` Partial backport of [[bitcoin/bitcoin#19829 | core#19829]]: bitcoin/bitcoin@184557e Depends on D10870. Ref T1696. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Maniphest Tasks: T1696 Differential Revision: https://reviews.bitcoinabc.org/D10871
1 parent 81ea1b1 commit 3368e0a

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/net.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -3335,7 +3335,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn,
33353335
m_inbound_onion(inbound_onion) {
33363336
hSocket = hSocketIn;
33373337
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
3338-
hashContinue = BlockHash();
33393338
if (conn_type_in != ConnectionType::BLOCK_RELAY) {
33403339
m_tx_relay = std::make_unique<TxRelay>();
33413340
}

src/net.h

-2
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,6 @@ class CNode {
10961096
mapMsgCmdSize mapRecvBytesPerMsgCmd GUARDED_BY(cs_vRecv);
10971097

10981098
public:
1099-
BlockHash hashContinue;
1100-
11011099
// flood relay
11021100
std::vector<CAddress> vAddrToSend;
11031101
std::unique_ptr<CRollingBloomFilter> m_addr_known = nullptr;

src/net_processing.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ static void RelayAddress(const CNode &originator, const CAddress &addr,
18941894
connman.ForEachNodeThen(std::move(sortfunc), std::move(pushfunc));
18951895
}
18961896

1897-
static void ProcessGetBlockData(const Config &config, CNode &pfrom,
1897+
static void ProcessGetBlockData(const Config &config, CNode &pfrom, Peer &peer,
18981898
const CInv &inv, CConnman &connman,
18991899
const std::atomic<bool> &interruptMsgProc) {
19001900
const Consensus::Params &consensusParams =
@@ -2057,15 +2057,15 @@ static void ProcessGetBlockData(const Config &config, CNode &pfrom,
20572057

20582058
// Trigger the peer node to send a getblocks request for the next batch
20592059
// of inventory.
2060-
if (hash == pfrom.hashContinue) {
2060+
if (hash == peer.m_continuation_block) {
20612061
// Send immediately. This must send even if redundant, and
20622062
// we want it right after the last block so they don't wait for
20632063
// other stuff first.
20642064
std::vector<CInv> vInv;
20652065
vInv.push_back(
20662066
CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
20672067
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
2068-
pfrom.hashContinue = BlockHash();
2068+
peer.m_continuation_block = BlockHash();
20692069
}
20702070
}
20712071
}
@@ -2257,7 +2257,8 @@ static void ProcessGetData(const Config &config, CNode &pfrom, Peer &peer,
22572257
if (it != peer.m_getdata_requests.end() && !pfrom.fPauseSend) {
22582258
const CInv &inv = *it++;
22592259
if (inv.IsGenBlkMsg()) {
2260-
ProcessGetBlockData(config, pfrom, inv, connman, interruptMsgProc);
2260+
ProcessGetBlockData(config, pfrom, peer, inv, connman,
2261+
interruptMsgProc);
22612262
}
22622263
// else: If the first item on the queue is an unknown type, we erase it
22632264
// and continue processing the queue on the next call.
@@ -3531,7 +3532,7 @@ void PeerManager::ProcessMessage(const Config &config, CNode &pfrom,
35313532
// trigger the peer to getblocks the next batch of inventory.
35323533
LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n",
35333534
pindex->nHeight, pindex->GetBlockHash().ToString());
3534-
pfrom.hashContinue = pindex->GetBlockHash();
3535+
peer->m_continuation_block = pindex->GetBlockHash();
35353536
break;
35363537
}
35373538
}

src/net_processing.h

+7
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ struct Peer {
9393

9494
/** This peer's reported block height when we connected */
9595
std::atomic<int> m_starting_height{-1};
96+
/**
97+
* The final block hash that we sent in an `inv` message to this peer.
98+
* When the peer requests this block, we send an `inv` message to trigger
99+
* the peer to request the next sequence of block hashes.
100+
* Most peers use headers-first syncing, which doesn't use this mechanism
101+
*/
102+
BlockHash m_continuation_block{};
96103

97104
/**
98105
* Set of txids to reconsider once their parent transactions have been

0 commit comments

Comments
 (0)