Skip to content

Commit

Permalink
[net processing] Guard m_continuation_block with m_block_inv_mutex
Browse files Browse the repository at this point in the history
Summary:
Completes backport of [[bitcoin/bitcoin#19829 | core#19829]]:
bitcoin/bitcoin@3002b4a

Depends on D10871.

Ref T1696.

Test Plan:
With Clang and debug:
  ninja all check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Maniphest Tasks: T1696

Differential Revision: https://reviews.bitcoinabc.org/D10872
  • Loading branch information
jnewbery authored and Fabcien committed Jan 24, 2022
1 parent 3368e0a commit 9d5d1a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
30 changes: 18 additions & 12 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,17 +2055,21 @@ static void ProcessGetBlockData(const Config &config, CNode &pfrom, Peer &peer,
}
}

// Trigger the peer node to send a getblocks request for the next batch
// of inventory.
if (hash == peer.m_continuation_block) {
// Send immediately. This must send even if redundant, and
// we want it right after the last block so they don't wait for
// other stuff first.
std::vector<CInv> vInv;
vInv.push_back(
CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
peer.m_continuation_block = BlockHash();
{
LOCK(peer.m_block_inv_mutex);
// Trigger the peer node to send a getblocks request for the next
// batch of inventory.
if (hash == peer.m_continuation_block) {
// Send immediately. This must send even if redundant, and
// we want it right after the last block so they don't wait for
// other stuff first.
std::vector<CInv> vInv;
vInv.push_back(
CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
connman.PushMessage(&pfrom,
msgMaker.Make(NetMsgType::INV, vInv));
peer.m_continuation_block = BlockHash();
}
}
}
}
Expand Down Expand Up @@ -3532,7 +3536,9 @@ void PeerManager::ProcessMessage(const Config &config, CNode &pfrom,
// trigger the peer to getblocks the next batch of inventory.
LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n",
pindex->nHeight, pindex->GetBlockHash().ToString());
peer->m_continuation_block = pindex->GetBlockHash();
WITH_LOCK(peer->m_block_inv_mutex, {
peer->m_continuation_block = pindex->GetBlockHash();
});
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ struct Peer {
std::vector<BlockHash>
m_blocks_for_headers_relay GUARDED_BY(m_block_inv_mutex);

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

/** This peer's reported block height when we connected */
std::atomic<int> m_starting_height{-1};

/**
* Set of txids to reconsider once their parent transactions have been
Expand Down

0 comments on commit 9d5d1a6

Please sign in to comment.