Skip to content

Commit 16730b6

Browse files
committed
[net processing] Only advertise support for version 2 compact blocks
Subsequent commits will remove support.
1 parent cba909e commit 16730b6

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/net_processing.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ static constexpr double MAX_ADDR_RATE_PER_SECOND{0.1};
175175
* based increments won't go above this, but the MAX_ADDR_TO_SEND increment following GETADDR
176176
* is exempt from this limit). */
177177
static constexpr size_t MAX_ADDR_PROCESSING_TOKEN_BUCKET{MAX_ADDR_TO_SEND};
178+
/** The compactblocks version we support. See BIP 152. */
179+
static constexpr uint64_t CMPCTBLOCKS_VERSION{2};
178180

179181
// Internal stuff
180182
namespace {
@@ -1003,19 +1005,18 @@ void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid)
10031005
}
10041006
m_connman.ForNode(nodeid, [this](CNode* pfrom) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
10051007
AssertLockHeld(::cs_main);
1006-
uint64_t nCMPCTBLOCKVersion = 2;
10071008
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
10081009
// As per BIP152, we only get 3 of our peers to announce
10091010
// blocks using compact encodings.
1010-
m_connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [this, nCMPCTBLOCKVersion](CNode* pnodeStop){
1011-
m_connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion));
1011+
m_connman.ForNode(lNodesAnnouncingHeaderAndIDs.front(), [this](CNode* pnodeStop){
1012+
m_connman.PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*high_bandwidth=*/false, /*version=*/CMPCTBLOCKS_VERSION));
10121013
// save BIP152 bandwidth state: we select peer to be low-bandwidth
10131014
pnodeStop->m_bip152_highbandwidth_to = false;
10141015
return true;
10151016
});
10161017
lNodesAnnouncingHeaderAndIDs.pop_front();
10171018
}
1018-
m_connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/true, nCMPCTBLOCKVersion));
1019+
m_connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetCommonVersion()).Make(NetMsgType::SENDCMPCT, /*high_bandwidth=*/true, /*version=*/CMPCTBLOCKS_VERSION));
10191020
// save BIP152 bandwidth state: we select peer to be high-bandwidth
10201021
pfrom->m_bip152_highbandwidth_to = true;
10211022
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
@@ -2861,16 +2862,12 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
28612862
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDHEADERS));
28622863
}
28632864
if (pfrom.GetCommonVersion() >= SHORT_IDS_BLOCKS_VERSION) {
2864-
// Tell our peer we are willing to provide version 1 or 2 cmpctblocks
2865+
// Tell our peer we are willing to provide version 2 cmpctblocks.
28652866
// However, we do not request new block announcements using
28662867
// cmpctblock messages.
28672868
// We send this to non-NODE NETWORK peers as well, because
28682869
// they may wish to request compact blocks from us
2869-
bool fAnnounceUsingCMPCTBLOCK = false;
2870-
uint64_t nCMPCTBLOCKVersion = 2;
2871-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
2872-
nCMPCTBLOCKVersion = 1;
2873-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
2870+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, /*high_bandwidth=*/false, /*version=*/CMPCTBLOCKS_VERSION));
28742871
}
28752872
pfrom.fSuccessfullyConnected = true;
28762873
return;

test/functional/p2p_compactblocks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,8 @@ def received_sendcmpct():
192192
return (len(test_node.last_sendcmpct) > 0)
193193
test_node.wait_until(received_sendcmpct, timeout=30)
194194
with p2p_lock:
195-
# Check that the first version received is version 2
195+
# Check that version 2 is received.
196196
assert_equal(test_node.last_sendcmpct[0].version, 2)
197-
# And that we receive versions down to 1.
198-
assert_equal(test_node.last_sendcmpct[-1].version, 1)
199197
test_node.last_sendcmpct = []
200198

201199
tip = int(node.getbestblockhash(), 16)

test/functional/p2p_compactblocks_blocksonly.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def run_test(self):
4848
p2p_conn_high_bw = self.nodes[1].add_p2p_connection(P2PInterface())
4949
p2p_conn_low_bw = self.nodes[3].add_p2p_connection(P2PInterface())
5050
for conn in [p2p_conn_blocksonly, p2p_conn_high_bw, p2p_conn_low_bw]:
51-
assert_equal(conn.message_count['sendcmpct'], 2)
51+
assert_equal(conn.message_count['sendcmpct'], 1)
5252
conn.send_and_ping(msg_sendcmpct(announce=False, version=2))
5353

5454
# Nodes:
@@ -74,14 +74,14 @@ def run_test(self):
7474
# receiving a new valid block at the tip.
7575
p2p_conn_blocksonly.send_and_ping(msg_block(block0))
7676
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block0.sha256)
77-
assert_equal(p2p_conn_blocksonly.message_count['sendcmpct'], 2)
77+
assert_equal(p2p_conn_blocksonly.message_count['sendcmpct'], 1)
7878
assert_equal(p2p_conn_blocksonly.last_message['sendcmpct'].announce, False)
7979

8080
# A normal node participating in transaction relay should request BIP152
8181
# high bandwidth mode upon receiving a new valid block at the tip.
8282
p2p_conn_high_bw.send_and_ping(msg_block(block0))
8383
assert_equal(int(self.nodes[1].getbestblockhash(), 16), block0.sha256)
84-
p2p_conn_high_bw.wait_until(lambda: p2p_conn_high_bw.message_count['sendcmpct'] == 3)
84+
p2p_conn_high_bw.wait_until(lambda: p2p_conn_high_bw.message_count['sendcmpct'] == 2)
8585
assert_equal(p2p_conn_high_bw.last_message['sendcmpct'].announce, True)
8686

8787
# Don't send a block from the p2p_conn_low_bw so the low bandwidth node

0 commit comments

Comments
 (0)